Jeff Verkoeyen 5b3a6cf2ee Add temporary_clone_at_ref script and use it in api_diff.
Summary: This script is a general-purpose tool for creating a clone of the repo at a specific ref. It will be helpful for use in other API diffing tools.

Reviewers: ajsecord, #mdc_ios_owners

Reviewed By: ajsecord, #mdc_ios_owners

Subscribers: ajsecord

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D784
2016-04-27 15:43:13 -04:00

127 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2016-present Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
old_commit=""
new_commit=""
VERBOSE=0
usage() {
echo "Usage: $0 -o [old commit] -n [new commit]]"
echo
echo "Example usage: $0 -o v2.0.0 -n develop"
}
while getopts "h?vo:n:" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
v) VERBOSE=1
;;
o) old_commit=$(git rev-parse $OPTARG)
;;
n) new_commit=$(git rev-parse $OPTARG)
;;
esac
done
log() {
if [ "$VERBOSE" -eq "1" ]; then
echo "$@"
fi
}
if [[ -z "$old_commit" || -z "$new_commit" ]]; then
usage
exit 0
fi
logger() {
while read data; do
log "$data"
done
}
validate_commit() {
git cat-file -t $1 >> /dev/null 2> /dev/null || { echo "$1 is not a valid commit."; exit 1; }
}
validate_commit $old_commit
validate_commit $new_commit
# Compute directories relative to the script's known location in scripts/
SCRIPTS_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
log "Installing objc-diff..."
"$SCRIPTS_PATH/install_objc_diff" \
2>&1 | logger || { echo "Failed to install objc-diff."; exit 1; }
objc_diff() {
$($SCRIPTS_PATH/install_objc_diff -p) "$@"
}
TMP_PATH=$(mktemp -d)
OLD_ROOT_PATH="$TMP_PATH/old"
NEW_ROOT_PATH="$TMP_PATH/new"
"$SCRIPTS_PATH/temporary_clone_at_ref" "$OLD_ROOT_PATH" $old_commit
"$SCRIPTS_PATH/temporary_clone_at_ref" "$NEW_ROOT_PATH" $new_commit
old_header_search_paths=""
new_header_search_paths=""
for d in $NEW_ROOT_PATH/components/*/src; do
folder=$(dirname $d)
component=$(basename $folder)
old_header_search_paths="$old_header_search_paths --oldargs -I$OLD_ROOT_PATH/components/$component/src/ "
new_header_search_paths="$new_header_search_paths --newargs -I$NEW_ROOT_PATH/components/$component/src/ "
done
echo "## API diffs"
echo
echo "Auto-generated by running:"
echo
echo " scripts/api_diff -o $old_commit -n $new_commit"
for d in $NEW_ROOT_PATH/components/*/src; do
folder=$(dirname $d)
component=$(basename $folder)
echo
echo "### $component"
echo
if [ ! -d "$OLD_ROOT_PATH/components/$component/src" ]; then
echo "**New component.**"
continue
fi
objc_diff \
--xml \
--sdk iphonesimulator \
--old "$OLD_ROOT_PATH/components/$component/src" \
--new "$NEW_ROOT_PATH/components/$component/src" \
$old_header_search_paths \
$new_header_search_paths | $SCRIPTS_PATH/objc_diff_xml_to_md $old_commit $new_commit components/$component/src
done
if [ ! -z "$TMP_PATH" ]; then
log "Cleaning up..."
rm -rf $TMP_PATH
fi