Jeff Verkoeyen 0454b94f51 Pull objc-diff installation out to its own script.
Summary:
This will allow us to more easily use objc-diff in other tools.

New script has two "modes":

- No arguments: clones and builds objc-diff
- -p: Echos path to the objc-diff binary and exits (produces no other output)

Reviewers: ajsecord, #mdc_ios_owners

Reviewed By: ajsecord, #mdc_ios_owners

Subscribers: ajsecord

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D783
2016-04-27 15:40:15 -04:00

145 lines
3.5 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 )"
REPO_ROOT_PATH="$( cd "$( dirname $SCRIPTS_PATH )" && pwd )"
SYSROOT="$(xcode-select --print-path)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
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"
# prep_repo <path> <commit>
prep_repo() {
if [ ! -d "$1" ]; then
git clone "$REPO_ROOT_PATH" "$1" \
2>&1 | logger || { echo "Failed to clone."; exit 1; }
fi
pushd $1 >> /dev/null
git remote add github git@github.com:google/material-components-ios.git 2>&1 | logger
git fetch \
2>&1 | logger || { echo "Failed to update repo."; exit 1; }
git checkout "$2" 2>&1 | logger
popd >> /dev/null
}
prep_repo $OLD_ROOT_PATH $old_commit
prep_repo $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