blob: 700b4db0b065473feafb28a2b028c2a54eb8084e [file] [log] [blame]
#!/bin/bash
#
# Copyright 2016-present the Material Components for iOS authors. 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.
# Writes a CHANGELOG.md-ready API diff for the latest release to stdout.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; pushd $DIR >> /dev/null
MDC_ROOT="$(git rev-parse --show-toplevel | tail -n1)"; popd >> /dev/null
cd $MDC_ROOT
if [ ! $(git rev-parse --verify release-candidate 2> /dev/null) ]; then
echo "Please cut a release first by running scripts/release/cut."
exit 1
fi
validate_commit() {
git cat-file -t $1 >> /dev/null 2> /dev/null || { echo "$1 is not a valid commit."; exit 1; }
}
# Verify commits
old_commit=$(git rev-list -n 1 origin/stable)
new_commit=$(git rev-list -n 1 release-candidate)
if [[ -z "$old_commit" || -z "$new_commit" ]]; then
# Change message to say commits are not present
exit 0
fi
validate_commit $old_commit
validate_commit $new_commit
# Create temp directories for old commit and new commit
# Compute directories relative to the script's known location in scripts/
SCRIPTS_PATH="$MDC_ROOT/scripts"
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
# Find command in all component src directories and grab search path for "Material$component.h"
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"
path_api_diff() {
$SCRIPTS_PATH/external/material-motion-apidiff/src/pathapidiff "$@"
}
# Run new pathdiff script on each umbrella header in array
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
if [ $component == "Ink" ] || [ $component == "Snackbar" ]; then
echo "**THIS COMPONENT DIFF MUST BE DONE MANUALLY**"
else
path_api_diff \
$OLD_ROOT_PATH \
$NEW_ROOT_PATH \
objc \
"/components/$component/src/Material$component.h"
fi
done
if [ ! -z "$TMP_PATH" ]; then
echo "Cleaning up..."
rm -rf $TMP_PATH
fi