[go: nahoru, domu]

blob: 45c29c89d61a5492836ab392f9f35048334c192d [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
Jeff Gastonfd450352020-01-31 16:39:32 -050022function die() {
23 echo "$@" >&2
24 exit 1
25}
26
Jeff Gaston043d21f2019-03-20 14:53:42 -040027function usage() {
Jeff Gastonfd450352020-01-31 16:39:32 -050028 violation="$1"
29 die "
30 Usage: $0 <git treeish>
31 $0 <path>:<git treeish> <path>:<git treeish>
32
33 Validates that libraries built from the given versions are the same as
34 the build outputs built at HEAD. This can be used to validate that a refactor
35 did not change the outputs. If a git treeish is given with no path, the path is considered to be frameworks/support
36
37 Example: $0 HEAD^
38 Example: $0 prebuilts/androidx/external:HEAD^ frameworks/support:work^
39
40 * A git treeish is what you type when you run 'git checkout <git treeish>'
41 See also https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftree-ishatree-ishalsotreeish .
42 "
Jeff Gaston043d21f2019-03-20 14:53:42 -040043 return 1
44}
45
Jeff Gastonfd450352020-01-31 16:39:32 -050046# Fills in a default repository path of "frameworks/support:" for any args that don't specify
47# their repository. Given an input of: "work^ prebuilts/androidx/external:HEAD^", should return
48# "frameworks/support:work^ prebuilts/androidx/external:HEAD^".
49function expandCommitArgs() {
50 inputSpecs="$@"
51 outputSpecs=""
52 for spec in $inputSpecs; do
53 if echo "$spec" | grep -v ":" >/dev/null; then
54 spec="frameworks/support:$spec"
55 fi
56 outputSpecs="$outputSpecs $spec"
57 done
58 echo $outputSpecs
59}
60
61# Given a list of paths like "frameworks/support prebuilts/androidx/external",
62# runs `git checkout -` in each
63function uncheckout() {
64 repositoryPaths="$@"
65 for repositoryPath in $repositoryPaths; do
66 echoAndDo git -C "$checkoutRoot/$repositoryPath" checkout -
67 done
68}
69# Given a list of version specs like "a/b:c d/e:f", returns just the paths: "a/b d/e"
70function getParticipatingProjectPaths() {
71 specs="$@"
72 result=""
73 for arg in $specs; do
74 echo parsing $arg >&2
75 repositoryPath="$(echo $arg | sed 's|\([^:]*\):\([^:]*\)|\1|')"
76 otherVersion="$(echo $arg | sed 's|\([^:]*\):\([^:]*\)|\2|')"
77 if [ "$otherVersion" != "HEAD" ]; then
78 result="$result $repositoryPath"
79 fi
80 done
81 echo $result
82}
83# Given a list of paths, returns a string containing the currently checked-out version of each
84function getCurrentCommits() {
85 repositoryPaths="$@"
86 result=""
87 for repositoryPath in $repositoryPaths; do
88 currentVersion="$(cd $checkoutRoot/$repositoryPath && git log -1 --format=%H)"
89 result="$result $repositoryPath:$currentVersion"
90 done
91 echo $result
92}
93function echoAndDo() {
94 echo "$*"
95 eval "$*"
96}
97# Given a list of version specs like "a/b:c d/e:f", checks out the appropriate version in each
98# In this example it would be `cd a/b && git checkout e` and `cd e/e && git checkout f`
99function checkout() {
100 versionSpecs="$1"
101 for versionSpec in $versionSpecs; do
102 project="$(echo $versionSpec | sed 's|\([^:]*\):\([^:]*\)|\1|')"
103 ref="$(echo $versionSpec | sed 's|\([^:]*\):\([^:]*\)|\2|')"
104 echo "checking out $ref in project $project"
105 echoAndDo git -C "$checkoutRoot/$project" checkout "$ref"
106 done
107}
Jeff Gaston90fed962022-11-30 13:59:54 -0500108function unzipInPlace() {
109 archiveName="$1"
110 echoAndDo unzip -q "$archiveName" -d "${archiveName}.unzipped"
111}
Jeff Gastonfd450352020-01-31 16:39:32 -0500112function doBuild() {
Jeff Gaston6c1c2ec2020-07-01 14:11:43 -0400113 # build androidx
Jeff Gaston90fed962022-11-30 13:59:54 -0500114 echoAndDo ./gradlew createArchive zipDocs --no-daemon --rerun-tasks --offline
Jeff Gastonf2c5b702020-01-31 16:57:31 -0500115 archiveName="top-of-tree-m2repository-all-0.zip"
Jeff Gaston90fed962022-11-30 13:59:54 -0500116 unzipInPlace "${tempOutPath}/dist/top-of-tree-m2repository-all-0.zip"
117 unzipInPlace "${tempOutPath}/dist/docs-tip-of-tree-0.zip"
118 unzipInPlace "${tempOutPath}/dist/docs-public-0.zip"
Jeff Gastonfd450352020-01-31 16:39:32 -0500119}
120
121oldCommits="$(expandCommitArgs $@)"
122projectPaths="$(getParticipatingProjectPaths $oldCommits)"
Jeff Gastonbcf56d62020-02-14 17:37:52 -0500123if echo $projectPaths | grep external/dokka >/dev/null; then
124 if [ "$BUILD_DOKKA" == "" ]; then
125 echo "It doesn't make sense to include the external/dokka project without also setting BUILD_DOKKA=true. Did you mean to set BUILD_DOKKA=true?"
126 exit 1
127 fi
128fi
Jeff Gastonfd450352020-01-31 16:39:32 -0500129echo old commits: $oldCommits
130if [ "$oldCommits" == "" ]; then
Jeff Gaston043d21f2019-03-20 14:53:42 -0400131 usage
132fi
Jeff Gastonfd450352020-01-31 16:39:32 -0500133newCommits="$(getCurrentCommits $projectPaths)"
Jeff Gaston6c1c2ec2020-07-01 14:11:43 -0400134cd "$supportRoot"
Jeff Gastonfd450352020-01-31 16:39:32 -0500135echo new commits: $newCommits
Jeff Gaston043d21f2019-03-20 14:53:42 -0400136
137oldOutPath="${checkoutRoot}/out-old"
138newOutPath="${checkoutRoot}/out-new"
139tempOutPath="${checkoutRoot}/out"
140
Jeff Gaston043d21f2019-03-20 14:53:42 -0400141
142rm -rf "$oldOutPath" "$newOutPath" "$tempOutPath"
143
144echo building new commit
Jeff Gaston043d21f2019-03-20 14:53:42 -0400145doBuild
146mv "$tempOutPath" "$newOutPath"
147
Jeff Gaston043d21f2019-03-20 14:53:42 -0400148echo building previous commit
Jeff Gastonfd450352020-01-31 16:39:32 -0500149
150checkout "$oldCommits"
Jeff Gaston043d21f2019-03-20 14:53:42 -0400151if doBuild; then
152 echo previous build succeeded
153else
154 echo previous build failed
Jeff Gastonfd450352020-01-31 16:39:32 -0500155 uncheckout "$projectPaths"
Jeff Gaston043d21f2019-03-20 14:53:42 -0400156 exit 1
157fi
Jeff Gastonfd450352020-01-31 16:39:32 -0500158uncheckout "$projectPaths"
Jeff Gaston043d21f2019-03-20 14:53:42 -0400159mv "$tempOutPath" "$oldOutPath"
160
161echo
162echo diffing results
163# Don't care about maven-metadata files because they have timestamps in them
164# 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
Jeff Gastonf2c5b702020-01-31 16:57:31 -0500165# We also don't care about several specific files, either
Aurimas Liutikasbc451c22022-09-29 13:12:59 -0700166echoAndDo diff -r -x "*.md5*" -x "*.sha*" -x "*maven-metadata.xml" -x buildSrc.jar -x jetpad-integration.jar -x "top-of-tree-m2repository-all-0.zip" -x noto-emoji-compat-java.jar -x versionedparcelable-annotation.jar -x dokkaTipOfTreeDocs-0.zip "$oldOutPath/dist" "$newOutPath/dist"
Jeff Gaston043d21f2019-03-20 14:53:42 -0400167echo end of difference