Home | History | Annotate | Download | only in scripts
      1 #!/bin/sh
      2 
      3 # Copyright (C) 2017 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 # WHAT IT DOES
     18 # Grabs all the support libraries and runs them through a preprocessor
     19 # using the default Jetifier config to generate the final mappings.
     20 
     21 set -e
     22 
     23 ROOT_DIR=$(dirname $(readlink -f $0))
     24 OUT_DIR="$ROOT_DIR/out"
     25 TEMP_LOG="$OUT_DIR/tempLog"
     26 
     27 CHECKOUT_DIR="$ROOT_DIR/../../../../../.."
     28 JETIFIER_DIR="$ROOT_DIR/../.."
     29 BUILD_DIR="$ROOT_DIR/../../../../../../out/host/gradle/frameworks/support"
     30 DEFAULT_CONFIG="$JETIFIER_DIR/core/src/main/resources/default.config"
     31 GENERATED_CONFIG="$JETIFIER_DIR/core/src/main/resources/default.generated.config"
     32 PREPROCESSOR_DISTRO_PATH="$BUILD_DIR/jetifier-preprocessor/build/distributions/jetifier-preprocessor.zip"
     33 PREPROCESSOR_BIN_PATH="$OUT_DIR/jetifier-preprocessor/bin/jetifier-preprocessor"
     34 SUPPORT_LIBS_BUILD_NUMBER="4631572"
     35 APP_TOOLKIT_BUILD_NUMBER="4669041"
     36 SUPPORT_LIBS_DOWNLOADED="$OUT_DIR/supportLibs/downloaded"
     37 SUPPORT_LIBS_UNPACKED="$OUT_DIR/supportLibs/unpacked"
     38 
     39 GREEN='\033[0;32m'
     40 RED='\033[0;31m'
     41 NC='\033[0m' # No Color
     42 
     43 function die() {
     44 	echo "$@"
     45 	exit 1
     46 }
     47 
     48 function printSectionStart() {
     49 	echo ""
     50 	echo "======================================================"
     51 	echo "$1"
     52 	echo "======================================================"
     53 }
     54 
     55 function printSuccess() {
     56 	echo -e "${GREEN}SUCCESS${NC}"
     57 }
     58 
     59 function buildProjectUsingGradle() {
     60 	cd $1
     61 	sh gradlew :jetifier-preprocessor:clean :jetifier-preprocessor:uploadArchives $2 > $TEMP_LOG --stacktrace
     62 }
     63 
     64 rm -rf $OUT_DIR
     65 mkdir $OUT_DIR
     66 echo "OUT dir is at '$OUT_DIR'"
     67 
     68 function getPreRenamedSupportLib() {
     69 	printSectionStart "Downloading all affected support libraries"
     70 	mkdir -p "$SUPPORT_LIBS_DOWNLOADED"
     71 
     72 	if [ "$FETCH_ARTIFACT" == "" ]; then
     73 		if which fetch_artifact; then
     74 			FETCH_ARTIFACT="$(which fetch_artifact)"
     75 		fi
     76 	fi
     77 	if [ ! -f "$FETCH_ARTIFACT" ]; then
     78 		die "fetch_artifact not found. Please set the environment variable FETCH_ARTIFACT equal to the path of fetch_artifact and try again"
     79 	fi
     80 
     81 	cd "$SUPPORT_LIBS_DOWNLOADED"
     82 	"$FETCH_ARTIFACT" --bid "$SUPPORT_LIBS_BUILD_NUMBER" --target support_library "top-of-tree-m2repository-$SUPPORT_LIBS_BUILD_NUMBER.zip" "$SUPPORT_LIBS_DOWNLOADED/support-lib.zip"
     83 	"$FETCH_ARTIFACT" --bid "$APP_TOOLKIT_BUILD_NUMBER" --target support_library_app_toolkit "top-of-tree-m2repository-$APP_TOOLKIT_BUILD_NUMBER.zip" "$SUPPORT_LIBS_DOWNLOADED/arch.zip"
     84 	cd -
     85 
     86 
     87 	unzip -oj "$SUPPORT_LIBS_DOWNLOADED/support-lib.zip" -d "$SUPPORT_LIBS_UNPACKED"
     88 	unzip -oj "$SUPPORT_LIBS_DOWNLOADED/arch.zip" -d "$SUPPORT_LIBS_UNPACKED"
     89 	#find "$CHECKOUT_DIR/prebuilts/maven_repo/android/com/android/support/" -type f -name "*design-*28.0.0*.aar" -exec cp '{}' -t "$SUPPORT_LIBS_UNPACKED" \;
     90 	cp "$CHECKOUT_DIR/prebuilts/maven_repo/android/com/android/support/multidex/1.0.3/multidex-1.0.3.aar" "$SUPPORT_LIBS_UNPACKED/multidex.aar"
     91 	cp "$CHECKOUT_DIR/prebuilts/maven_repo/android/com/android/support/multidex-instrumentation/1.0.3/multidex-instrumentation-1.0.3.aar" "$SUPPORT_LIBS_UNPACKED/multidex-instrumentation.aar"
     92 	find "$SUPPORT_LIBS_UNPACKED" -type f -name "jetifier*" -exec rm -f {} \;
     93 }
     94 
     95 DATA_BINDING_VERSION=`curl https://dl.google.com/dl/android/maven2/com/android/databinding/baseLibrary/maven-metadata.xml|xmllint --format -|grep latest|awk '{split($NAME,a,"[><]"); print a[3]}'`
     96 function pullDataBinding() {
     97 	NAME=$1
     98 	TYPE=$2
     99 	curl "https://dl.google.com/dl/android/maven2/com/android/databinding/$NAME/$DATA_BINDING_VERSION/$NAME-$DATA_BINDING_VERSION.$TYPE" -o "$SUPPORT_LIBS_UNPACKED/databinding-$NAME.$TYPE"
    100 }
    101 
    102 function pullConstraint() {
    103 	NAME=$1
    104 	TYPE=$2
    105 	curl "https://dl.google.com/dl/android/maven2/com/android/support/constraint/$NAME/1.1.0/$NAME-1.1.0.$TYPE" -o "$SUPPORT_LIBS_UNPACKED/$NAME.$TYPE"
    106 }
    107 
    108 function pullTest() {
    109 	NAME=$1
    110 	curl "https://dl.google.com/dl/android/maven2/com/android/support/test/$NAME/1.0.2/$NAME-1.0.2.aar" -o "$SUPPORT_LIBS_UNPACKED/$NAME.aar"
    111 }
    112 # Unfortunately this doesn't make a coffee using a lever machine. It only downloads espresso artifacts.
    113 function pullEspresso() {
    114 	NAME=$1
    115 	curl "https://dl.google.com/dl/android/maven2/com/android/support/test/espresso/$NAME/3.0.2/$NAME-3.0.2.aar" -o "$SUPPORT_LIBS_UNPACKED/$NAME.aar"
    116 }
    117 function pullEspressoIdling() {
    118 	NAME=$1
    119 	curl "https://dl.google.com/dl/android/maven2/com/android/support/test/espresso/idling/$NAME/3.0.2/$NAME-3.0.2.aar" -o "$SUPPORT_LIBS_UNPACKED/$NAME.aar"
    120 }
    121 
    122 getPreRenamedSupportLib
    123 pullDataBinding "baseLibrary" "jar"
    124 pullDataBinding "adapters" "aar"
    125 pullDataBinding "library" "aar"
    126 pullConstraint "constraint-layout" "aar"
    127 pullConstraint "constraint-layout-solver" "jar"
    128 
    129 pullTest "monitor"
    130 pullTest "rules"
    131 pullTest "runner"
    132 # FYI: We skip orchestrator since it is apk
    133 pullEspresso "espresso-accessibility"
    134 pullEspresso "espresso-contrib"
    135 pullEspresso "espresso-core"
    136 pullEspresso "espresso-idling-resource"
    137 pullEspresso "espresso-intents"
    138 pullEspresso "espresso-remote"
    139 pullEspresso "espresso-web"
    140 pullEspressoIdling "idling-concurrent"
    141 pullEspressoIdling "idling-net"
    142 curl "https://dl.google.com/dl/android/maven2/com/android/support/test/janktesthelper/janktesthelper-v23/1.0.1/janktesthelper-v23-1.0.1.aar" -o "$SUPPORT_LIBS_UNPACKED/janktesthelper-v23.aar"
    143 curl "https://dl.google.com/dl/android/maven2/com/android/support/test/uiautomator/uiautomator-v18/2.1.3/uiautomator-v18-2.1.3.aar" -o "$SUPPORT_LIBS_UNPACKED/uiautomator-v18.aar"
    144 # FYI: We skip test-services since it is apk
    145 
    146 # exposed-instrumentation-api-publish skipped as it is deprecated
    147 # testing-support-lib skipped as it is deprecated
    148 
    149 printSectionStart "Preparing Jetifier"
    150 buildProjectUsingGradle $JETIFIER_DIR/../..
    151 echo "[OK] Clean build done"
    152 
    153 unzip $PREPROCESSOR_DISTRO_PATH -d $OUT_DIR > /dev/null
    154 echo "[OK] Copied & unziped jetifier preprocessor"
    155 
    156 printSectionStart "Preprocessing mappings on support libraries"
    157 sh $PREPROCESSOR_BIN_PATH -i "$SUPPORT_LIBS_UNPACKED" -o "$GENERATED_CONFIG" -c "$DEFAULT_CONFIG" -l verbose || die
    158 echo "[OK] Done, config generated into $GENERATED_CONFIG"
    159 
    160 printSuccess
    161