Jeff Verkoeyen 2b0359e1c5 Use rev-list to retrieve a ref's sha in scripts/api_diff.
Summary:
`git rev-list -n 1 <ref>` returns the nearest commit's sha for a given ref.
`git rev-parse <ref>` returns the sha for the ref itself. E.g. tags have their own sha distinct from the commit to which they're associated.

GitHub doesn't reconcile shas for tags, so `git rev-list` ensures that our api_diff output will always be linkable on GitHub.

Reviewers: #mdc_ios_owners, iangordon

Reviewed By: #mdc_ios_owners, iangordon

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D787
2016-04-27 16:08:27 -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-list -n 1 $OPTARG)
;;
n) new_commit=$(git rev-list -n 1 $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