Louis Pullen-Freilich | 248a4c5 | 2020-07-01 23:20:33 +0100 | [diff] [blame] | 1 | #!/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 | |
| 23 | supportRoot="$(cd $(dirname $0)/.. && pwd)" |
| 24 | checkoutRoot="$(cd ${supportRoot}/../.. && pwd)" |
| 25 | |
| 26 | function die() { |
| 27 | echo "$@" >&2 |
| 28 | exit 1 |
| 29 | } |
| 30 | |
| 31 | function 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 | |
| 48 | function echoAndDo() { |
| 49 | echo "$*" |
| 50 | eval "$*" |
| 51 | } |
| 52 | |
| 53 | function 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 |
| 60 | if (( $# < 2 )); then |
| 61 | usage |
| 62 | fi |
| 63 | |
| 64 | oldLibrary=$1 |
| 65 | newLibrary=$2 |
| 66 | shouldBuild=false |
| 67 | if [[ $3 == "--build" ]]; then |
| 68 | shouldBuild=true |
| 69 | fi |
| 70 | |
| 71 | echo old library = $oldLibrary |
| 72 | echo new library = $newLibrary |
| 73 | echo building = $shouldBuild |
| 74 | |
| 75 | # Replace . and : with / to build the output path from the artifact ID |
| 76 | oldLibraryRelativePath="${oldLibrary//.//}" |
| 77 | oldLibraryRelativePath="${oldLibraryRelativePath//://}" |
| 78 | |
| 79 | newLibraryRelativePath="${newLibrary//.//}" |
| 80 | newLibraryRelativePath="${newLibraryRelativePath//://}" |
| 81 | |
| 82 | oldOutPath="${checkoutRoot}/out-old" |
| 83 | newOutPath="${checkoutRoot}/out-new" |
| 84 | tempOutPath="${checkoutRoot}/out" |
| 85 | |
| 86 | if $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" |
| 100 | fi |
| 101 | |
| 102 | m2repositoryRelativePath="dist/ui/top-of-tree-m2repository-all-0.zip.unzipped/m2repository" |
| 103 | oldLibraryOutput="${oldOutPath}/${m2repositoryRelativePath}/${oldLibraryRelativePath}" |
| 104 | newLibraryOutput="${newOutPath}/${m2repositoryRelativePath}/${newLibraryRelativePath}" |
| 105 | |
| 106 | echo unzipping aars |
| 107 | find ${oldLibraryOutput} -name "*.aar" -exec sh -c 'unzip -o -d `dirname {}` {}' ';' |
| 108 | find ${newLibraryOutput} -name "*.aar" -exec sh -c 'unzip -o -d `dirname {}` {}' ';' |
| 109 | |
| 110 | oldClasses="$(find ${oldLibraryOutput} -name "classes.jar")" |
| 111 | newClasses="$(find ${newLibraryOutput} -name "classes.jar")" |
| 112 | |
| 113 | echo |
| 114 | echo old classes.jar |
| 115 | echo ${oldClasses} |
| 116 | echo |
| 117 | echo new classes.jar |
| 118 | echo ${newClasses} |
| 119 | echo |
| 120 | echo example japi-compliance-checker command |
| 121 | echo ./japi-compliance-checker.pl -lib ${newLibrary} ${oldClasses} ${newClasses} |
| 122 | |
| 123 | echo |
| 124 | echo diffing .module file |
| 125 | oldModuleFile="$(find ${oldLibraryOutput} -name "*.module")" |
| 126 | newModuleFile="$(find ${newLibraryOutput} -name "*.module")" |
| 127 | diff ${oldModuleFile} ${newModuleFile} |
| 128 | |
| 129 | echo |
| 130 | echo diffing .pom file |
| 131 | oldPomFile="$(find ${oldLibraryOutput} -name "*.pom")" |
| 132 | newPomFile="$(find ${newLibraryOutput} -name "*.pom")" |
| 133 | diff ${oldPomFile} ${newPomFile} |
| 134 | |
| 135 | echo |
| 136 | echo diffing overall directory |
| 137 | # Ignore checksums and classes.jar file |
| 138 | diff -r -x "*.md5*" -x "*.sha*" -x "classes.jar" ${oldLibraryOutput} ${newLibraryOutput} |