1 #!/bin/bash -u 2 # 3 # Copyright 2016 Google Inc. All Rights Reserved. 4 # 5 # This script is part of the Android binary search triage process. 6 # It should be the first script called by the user, after the user has set up 7 # the two necessary build tree directories (see the prerequisites section of 8 # README.android). 9 # 10 # WARNING: 11 # Before running this script make sure you have setup the Android build 12 # environment in this shell (i.e. successfully run 'lunch'). 13 # 14 # This script takes three arguments. The first argument must be the path of 15 # the android source tree being tested. The second (optional) argument is the 16 # device ID for fastboot/adb so the test device can be uniquely indentified in 17 # case multiple phones are plugged in. The final (optional) argument is the 18 # number of jobs that various programs can use for parallelism 19 # (make, xargs, etc.). There is also the argument for bisection directory, but 20 # this is not strictly an argument for just this script (as it should be set 21 # during the POPULATE_GOOD and POPULATE_BAD steps, see README.android for 22 # details). 23 # 24 # Example call: 25 # ANDROID_SERIAL=002ee16b1558a3d3 NUM_JOBS=10 android/setup.sh ~/android 26 # 27 # This will setup the bisector for Nexus5X, using 10 jobs, where the android 28 # source lives at ~/android. 29 # 30 # NOTE: ANDROID_SERIAL is actually an option used by ADB. You can also simply 31 # do 'export ANDROID_SERIAL=<device_id>' and the bisector will still work. 32 # Furthermore, if your device is the only Android device plugged in you can 33 # ignore ANDROID_SERIAL. 34 # 35 # This script sets all necessary environment variables, and ensures the 36 # environment for the binary search triage process is setup properly. In 37 # addition, this script generates common.sh, which generates enviroment 38 # variables used by the other scripts in the package binary search triage process. 39 # 40 41 # 42 # Positional arguments 43 # 44 45 ANDROID_SRC=$1 46 47 # 48 # Optional arguments 49 # 50 51 # If DEVICE_ID is not null export this as ANDROID_SERIAL for use by adb 52 # If DEVICE_ID is null then leave null 53 DEVICE_ID=${ANDROID_SERIAL:+"export ANDROID_SERIAL=${ANDROID_SERIAL} "} 54 55 NUM_JOBS=${NUM_JOBS:-"1"} 56 BISECT_ANDROID_DIR=${BISECT_DIR:-~/ANDROID_BISECT} 57 58 # 59 # Set up basic variables. 60 # 61 62 GOOD_BUILD=${BISECT_ANDROID_DIR}/good 63 BAD_BUILD=${BISECT_ANDROID_DIR}/bad 64 WORK_BUILD=${ANDROID_SRC} 65 66 # 67 # Verify that the necessary directories exist. 68 # 69 70 if [[ ! -d ${GOOD_BUILD} ]] ; then 71 echo "Error: ${GOOD_BUILD} does not exist." 72 exit 1 73 fi 74 75 if [[ ! -d ${BAD_BUILD} ]] ; then 76 echo "Error: ${BAD_BUILD} does not exist." 77 exit 1 78 fi 79 80 if [[ ! -d ${WORK_BUILD} ]] ; then 81 echo "Error: ${WORK_BUILD} does not exist." 82 exit 1 83 fi 84 85 # 86 # Verify that good/bad object lists are the same 87 # 88 89 good_list=`mktemp` 90 bad_list=`mktemp` 91 sort ${GOOD_BUILD}/_LIST > good_list 92 sort ${BAD_BUILD}/_LIST > bad_list 93 94 diff good_list bad_list 95 diff_result=$? 96 rm good_list bad_list 97 98 if [ ${diff_result} -ne 0 ]; then 99 echo "Error: good and bad object lists differ." 100 echo "diff exited with non-zero status: ${diff_result}" 101 exit 1 102 fi 103 104 # 105 # Ensure android build environment is setup 106 # 107 # ANDROID_PRODUCT_OUT is only set once lunch is successfully executed. Fail if 108 # ANDROID_PRODUCT_OUT is unset. 109 # 110 111 if [ -z ${ANDROID_PRODUCT_OUT+0} ]; then 112 echo "Error: Android build environment is not setup." 113 echo "cd to ${ANDROID_SRC} and do the following:" 114 echo " source build/envsetup.sh" 115 echo " lunch <device_lunch_combo>" 116 exit 1 117 fi 118 119 # 120 # Create common.sh file, containing appropriate environment variables. 121 # 122 123 COMMON_FILE="android/common.sh" 124 125 cat <<-EOF > ${COMMON_FILE} 126 127 BISECT_ANDROID_DIR=${BISECT_ANDROID_DIR} 128 129 BISECT_ANDROID_SRC=${ANDROID_SRC} 130 BISECT_NUM_JOBS=${NUM_JOBS} 131 132 BISECT_GOOD_BUILD=${GOOD_BUILD} 133 BISECT_BAD_BUILD=${BAD_BUILD} 134 BISECT_WORK_BUILD=${WORK_BUILD} 135 136 BISECT_GOOD_SET=${GOOD_BUILD}/_LIST 137 BISECT_BAD_SET=${BAD_BUILD}/_LIST 138 139 ${DEVICE_ID} 140 141 export BISECT_STAGE="TRIAGE" 142 143 EOF 144 145 chmod 755 ${COMMON_FILE} 146 147 exit 0 148