blob: 5a4ece21fdb1d5d3143f08ecf5a005992e571959 [file] [log] [blame]
Louis Pullen-Freilich248a4c52020-07-01 23:20:33 +01001#!/bin/bash
2#
3# Copyright (C) 2020 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#
17
18# Temporary script to aid migration from androidx.ui to androidx.compose, by validating artifacts
19# are identical / compatible during the migration
20# Most of the logic here is taken from validateRefactor.sh, and cut down into a less generic script
21# This can be removed after b/160233169 is finished
22
23supportRoot="$(cd $(dirname $0)/.. && pwd)"
24checkoutRoot="$(cd ${supportRoot}/../.. && pwd)"
25
26function die() {
27 echo "$@" >&2
28 exit 1
29}
30
31function usage() {
32 violation="$1"
33 die "
34 Usage: $0 androidx.ui:ui-material androidx.compose.material:material --build
35
36 Builds artifacts for the current commit, and the previous commit, and diffs the output between
37 the old artifact and new artifact, to validate that refactoring a library in Compose has
38 expected changes (such as pom file changes). Also unzips and prints the location of the class
39 files inside the .aar, to facilitate comparing the classes with a tool such as
40 japi-compliance-checker.
41
42 Running without --build will just diff the expected outputs, for cases when you wish to verify
43 multiple artifacts in the same commits.
44 "
45 return 1
46}
47
48function echoAndDo() {
49 echo "$*"
50 eval "$*"
51}
52
53function doBuild() {
54 echoAndDo ./gradlew createArchive --no-daemon --rerun-tasks --offline
55 archiveName="top-of-tree-m2repository-all-0.zip"
56 echoAndDo unzip -q "${tempOutPath}/dist/ui/${archiveName}" -d "${tempOutPath}/dist/ui/${archiveName}.unzipped"
57}
58
59# Ensure at least 2 args
60if (( $# < 2 )); then
61 usage
62fi
63
64oldLibrary=$1
65newLibrary=$2
66shouldBuild=false
67if [[ $3 == "--build" ]]; then
68 shouldBuild=true
69fi
70
71echo old library = $oldLibrary
72echo new library = $newLibrary
73echo building = $shouldBuild
74
75# Replace . and : with / to build the output path from the artifact ID
76oldLibraryRelativePath="${oldLibrary//.//}"
77oldLibraryRelativePath="${oldLibraryRelativePath//://}"
78
79newLibraryRelativePath="${newLibrary//.//}"
80newLibraryRelativePath="${newLibraryRelativePath//://}"
81
82oldOutPath="${checkoutRoot}/out-old"
83newOutPath="${checkoutRoot}/out-new"
84tempOutPath="${checkoutRoot}/out"
85
86if $shouldBuild ; then
87 echo removing out/
88 rm -rf "$oldOutPath" "$newOutPath" "$tempOutPath"
89
90 echo building new commit
91 doBuild
92 mv "$tempOutPath" "$newOutPath"
93
94 echo building previous commit
95
96 echoAndDo git -C "${checkoutRoot}/frameworks/support/ui" checkout "HEAD^"
97 doBuild
98 echoAndDo git -C "${checkoutRoot}/frameworks/support/ui" checkout -
99 mv "$tempOutPath" "$oldOutPath"
100fi
101
102m2repositoryRelativePath="dist/ui/top-of-tree-m2repository-all-0.zip.unzipped/m2repository"
103oldLibraryOutput="${oldOutPath}/${m2repositoryRelativePath}/${oldLibraryRelativePath}"
104newLibraryOutput="${newOutPath}/${m2repositoryRelativePath}/${newLibraryRelativePath}"
105
106echo unzipping aars
107find ${oldLibraryOutput} -name "*.aar" -exec sh -c 'unzip -o -d `dirname {}` {}' ';'
108find ${newLibraryOutput} -name "*.aar" -exec sh -c 'unzip -o -d `dirname {}` {}' ';'
109
110oldClasses="$(find ${oldLibraryOutput} -name "classes.jar")"
111newClasses="$(find ${newLibraryOutput} -name "classes.jar")"
112
113echo
114echo old classes.jar
115echo ${oldClasses}
116echo
117echo new classes.jar
118echo ${newClasses}
119echo
120echo example japi-compliance-checker command
121echo ./japi-compliance-checker.pl -lib ${newLibrary} ${oldClasses} ${newClasses}
122
123echo
124echo diffing .module file
125oldModuleFile="$(find ${oldLibraryOutput} -name "*.module")"
126newModuleFile="$(find ${newLibraryOutput} -name "*.module")"
127diff ${oldModuleFile} ${newModuleFile}
128
129echo
130echo diffing .pom file
131oldPomFile="$(find ${oldLibraryOutput} -name "*.pom")"
132newPomFile="$(find ${newLibraryOutput} -name "*.pom")"
133diff ${oldPomFile} ${newPomFile}
134
135echo
136echo diffing overall directory
137# Ignore checksums and classes.jar file
138diff -r -x "*.md5*" -x "*.sha*" -x "classes.jar" ${oldLibraryOutput} ${newLibraryOutput}