blob: a4724e9ea337c71ecfce195632505bbb7b78c788 [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
Jeff Gaston043d21f2019-03-20 14:53:42 -040058doBuild
59mv "$tempOutPath" "$newOutPath"
60
61
62echo building previous commit
63echoAndDo git checkout "$oldCommit"
64if doBuild; then
65 echo previous build succeeded
66else
67 echo previous build failed
Sam Gilbert879722d2019-06-07 14:04:19 -040068 git checkout -
Jeff Gaston043d21f2019-03-20 14:53:42 -040069 exit 1
70fi
Sam Gilbert879722d2019-06-07 14:04:19 -040071git checkout -
Jeff Gaston043d21f2019-03-20 14:53:42 -040072mv "$tempOutPath" "$oldOutPath"
73
74echo
75echo diffing results
76# Don't care about maven-metadata files because they have timestamps in them
77# 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
78echoAndDo 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"
79echo end of difference