setup.sh revision 19e119b46c14f57988ba3504369e815d3aab0122
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
45ANDROID_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
53DEVICE_ID=${ANDROID_SERIAL:+"export ANDROID_SERIAL=${ANDROID_SERIAL} "}
54
55NUM_JOBS=${NUM_JOBS:-"1"}
56BISECT_ANDROID_DIR=${BISECT_DIR:-~/ANDROID_BISECT}
57
58#
59# Set up basic variables.
60#
61
62GOOD_BUILD=${BISECT_ANDROID_DIR}/good
63BAD_BUILD=${BISECT_ANDROID_DIR}/bad
64WORK_BUILD=${ANDROID_SRC}
65
66#
67# Verify that the necessary directories exist.
68#
69
70if [[ ! -d ${GOOD_BUILD} ]] ; then
71  echo "Error:  ${GOOD_BUILD} does not exist."
72  exit 1
73fi
74
75if [[ ! -d ${BAD_BUILD} ]] ; then
76  echo "Error:  ${BAD_BUILD} does not exist."
77  exit 1
78fi
79
80if [[ ! -d ${WORK_BUILD} ]] ; then
81  echo "Error:  ${WORK_BUILD} does not exist."
82  exit 1
83fi
84
85#
86# Verify that good/bad object lists are the same
87#
88
89good_list=`mktemp`
90bad_list=`mktemp`
91sort ${GOOD_BUILD}/_LIST > good_list
92sort ${BAD_BUILD}/_LIST > bad_list
93
94diff good_list bad_list
95diff_result=$?
96rm good_list bad_list
97
98if [ ${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
102fi
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
111if [ -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
117fi
118
119#
120# Create common.sh file, containing appropriate environment variables.
121#
122
123COMMON_FILE="android/common.sh"
124
125cat <<-EOF > ${COMMON_FILE}
126
127BISECT_ANDROID_DIR=${BISECT_ANDROID_DIR}
128
129BISECT_ANDROID_SRC=${ANDROID_SRC}
130BISECT_NUM_JOBS=${NUM_JOBS}
131
132BISECT_GOOD_BUILD=${GOOD_BUILD}
133BISECT_BAD_BUILD=${BAD_BUILD}
134BISECT_WORK_BUILD=${WORK_BUILD}
135
136${DEVICE_ID}
137
138export BISECT_STAGE="TRIAGE"
139
140EOF
141
142chmod 755 ${COMMON_FILE}
143
144exit 0
145