blob: c139c73fa4437065b74160e0d5242ff22589d716 [file] [log] [blame]
Jeff Gaston043d21f2019-03-20 14:53:42 -04001#!/bin/bash
2#
3# Copyright (C) 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17set -e
18
19supportRoot="$(cd $(dirname $0)/.. && pwd)"
20checkoutRoot="$(cd ${supportRoot}/../.. && pwd)"
21
22function usage() {
23 echo "usage: $0 <git treeish>"
24 echo
25 echo "For example, $0 HEAD^"
26 echo
27 echo "Validates that libraries built from <git treeish>* are the same as the build outputs at HEAD."
28 echo "This can be used to validate that a refactor did not change the outputs."
29 echo
30 echo "* A git treeish is what you type when you run 'git checkout <git treeish>'"
31 echo " See also https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftree-ishatree-ishalsotreeish ."
32 return 1
33}
34
35oldCommit="$1"
36if [ "$oldCommit" == "" ]; then
37 usage
38fi
39newCommit="$(git log -1 --format=%H)"
40
41oldOutPath="${checkoutRoot}/out-old"
42newOutPath="${checkoutRoot}/out-new"
43tempOutPath="${checkoutRoot}/out"
44
45function echoAndDo() {
46 echo "$*"
47 eval "$*"
48}
49
50function doBuild() {
51 ./gradlew createArchive
52 unzip "${tempOutPath}/dist/top-of-tree-m2repository-all-0.zip" -d "${tempOutPath}/dist/top-of-tree-m2repository-all-0.unzipped"
53}
54
55rm -rf "$oldOutPath" "$newOutPath" "$tempOutPath"
56
57echo building new commit
58echoAndDo git checkout "$newCommit"
59doBuild
60mv "$tempOutPath" "$newOutPath"
61
62
63echo building previous commit
64echoAndDo git checkout "$oldCommit"
65if doBuild; then
66 echo previous build succeeded
67else
68 echo previous build failed
69 git checkout "$newCommit"
70 exit 1
71fi
72git checkout "$newCommit"
73mv "$tempOutPath" "$oldOutPath"
74
75echo
76echo diffing results
77# Don't care about maven-metadata files because they have timestamps in them
78# We might care to know whether .sha1 or .md5 files have changed, but changes in those files will always be accompanied by more meaningful changes in other files, so we don't need to show changes in .sha1 or .md5 files
79echoAndDo diff -r -x "maven-metadata*" -x "*.sha1" -x "*.md5" "$oldOutPath/dist/top-of-tree-m2repository-all-0.unzipped" "$newOutPath/dist/top-of-tree-m2repository-all-0.unzipped"
80echo end of difference