blob: 55f4ddd26b10bc135785a53007ec0f823acf71b4 [file] [log] [blame]
Colin Cross0ffa5a02016-04-01 16:45:40 -07001#!/bin/bash -ex
2
3if [ -z "${OUT_DIR}" ]; then
4 echo Must set OUT_DIR
5 exit 1
6fi
7
8TOP=$(pwd)
9
10UNAME="$(uname)"
11case "$UNAME" in
12Linux)
13 OS='linux'
14 ;;
15Darwin)
16 OS='darwin'
17 ;;
18*)
19 exit 1
20 ;;
21esac
22
23build_soong=1
24if [ -d ${TOP}/toolchain/go ]; then
25 build_go=1
26fi
Colin Cross0ffa5a02016-04-01 16:45:40 -070027
28if [ -n ${build_soong} ]; then
29 # ckati and makeparallel (Soong)
30 SOONG_OUT=${OUT_DIR}/soong
31 SOONG_HOST_OUT=${OUT_DIR}/soong/host/${OS}-x86
32 rm -rf ${SOONG_OUT}
33 mkdir -p ${SOONG_OUT}
34 cat > ${SOONG_OUT}/soong.variables << EOF
35{
36 "Allow_missing_dependencies": true,
Dan Willemsen0455a262018-08-28 17:50:21 -070037 "HostArch":"x86_64"
Colin Cross0ffa5a02016-04-01 16:45:40 -070038}
39EOF
Colin Crossc5042c72017-06-20 17:22:32 -070040 SOONG_BINARIES=(
41 acp
Dan Willemsen52503bb2017-11-17 10:11:03 -080042 aidl
Dan Willemsen10aabfe2018-01-08 17:12:38 -080043 bison
Colin Crossc5042c72017-06-20 17:22:32 -070044 bpfmt
45 ckati
46 ckati_stamp_dump
Dan Willemsen77ad4b92018-05-22 16:38:31 -070047 flex
Dan Willemsenc4e38f52018-10-04 17:41:49 -070048 make
Colin Crossc5042c72017-06-20 17:22:32 -070049 makeparallel
Colin Crossc5042c72017-06-20 17:22:32 -070050 ninja
51 soong_zip
Dan Willemsen9672d7a2018-03-09 01:00:47 -080052 xz
Colin Crossc5042c72017-06-20 17:22:32 -070053 zip2zip
Dan Willemsen52503bb2017-11-17 10:11:03 -080054 zipalign
Colin Crossc5042c72017-06-20 17:22:32 -070055 ziptime
56 )
Colin Cross14cd25f2017-09-22 14:27:44 -070057 SOONG_ASAN_BINARIES=(
58 acp
Dan Willemsen52503bb2017-11-17 10:11:03 -080059 aidl
Colin Cross14cd25f2017-09-22 14:27:44 -070060 ckati
61 makeparallel
62 ninja
Dan Willemsen52503bb2017-11-17 10:11:03 -080063 zipalign
Colin Cross14cd25f2017-09-22 14:27:44 -070064 ziptime
65 )
66 SOONG_JAVA_LIBRARIES=(
67 desugar
68 dx
Nan Zhangac1bdea2017-10-24 14:46:58 -070069 turbine
Colin Cross14cd25f2017-09-22 14:27:44 -070070 )
71 SOONG_JAVA_WRAPPERS=(
72 dx
Colin Cross14cd25f2017-09-22 14:27:44 -070073 )
Dan Willemsen7c8949f2018-10-29 11:00:43 -070074 if [[ $OS == "linux" ]]; then
75 SOONG_BINARIES+=(
76 toybox
77 )
78 SOONG_ASAN_BINARIES+=(
79 toybox
80 )
81 fi
Colin Cross14cd25f2017-09-22 14:27:44 -070082
83 binaries=$(for i in "${SOONG_BINARIES[@]}"; do echo ${SOONG_HOST_OUT}/bin/${i}; done)
Dan Willemsend4475082017-10-04 15:40:35 -070084 asan_binaries=$(for i in "${SOONG_ASAN_BINARIES[@]}"; do echo ${SOONG_HOST_OUT}/bin/${i}; done)
Colin Cross14cd25f2017-09-22 14:27:44 -070085 jars=$(for i in "${SOONG_JAVA_LIBRARIES[@]}"; do echo ${SOONG_HOST_OUT}/framework/${i}.jar; done)
86 wrappers=$(for i in "${SOONG_JAVA_WRAPPERS[@]}"; do echo ${SOONG_HOST_OUT}/bin/${i}; done)
87
88 # Build everything
89 build/soong/soong_ui.bash --make-mode --skip-make \
90 ${binaries} \
91 ${wrappers} \
92 ${jars} \
Colin Crossacad53f2017-12-12 10:59:25 -080093 ${SOONG_HOST_OUT}/nativetest64/ninja_test/ninja_test \
Dan Willemsenfe85be02018-02-15 13:59:35 -080094 ${SOONG_HOST_OUT}/nativetest64/ckati_test/find_test \
Colin Crossacad53f2017-12-12 10:59:25 -080095 soong_docs
Colin Cross14cd25f2017-09-22 14:27:44 -070096
97 # Run ninja tests
Dan Willemsen76748492016-04-21 12:40:04 -070098 ${SOONG_HOST_OUT}/nativetest64/ninja_test/ninja_test
Colin Cross14cd25f2017-09-22 14:27:44 -070099
Dan Willemsenfe85be02018-02-15 13:59:35 -0800100 # Run ckati tests
101 ${SOONG_HOST_OUT}/nativetest64/ckati_test/find_test
102
Colin Cross14cd25f2017-09-22 14:27:44 -0700103 # Copy arch-specific binaries
Dan Willemsen6adbc362016-10-05 22:41:25 -0700104 mkdir -p ${SOONG_OUT}/dist/bin
Colin Cross14cd25f2017-09-22 14:27:44 -0700105 cp ${binaries} ${SOONG_OUT}/dist/bin/
Dan Willemsen6adbc362016-10-05 22:41:25 -0700106 cp -R ${SOONG_HOST_OUT}/lib* ${SOONG_OUT}/dist/
107
Colin Cross14cd25f2017-09-22 14:27:44 -0700108 # Copy jars and wrappers
109 mkdir -p ${SOONG_OUT}/dist-common/bin ${SOONG_OUT}/dist-common/framework
110 cp ${wrappers} ${SOONG_OUT}/dist-common/bin
111 cp ${jars} ${SOONG_OUT}/dist-common/framework
112
Dan Willemsen10aabfe2018-01-08 17:12:38 -0800113 cp -r external/bison/data ${SOONG_OUT}/dist-common/bison
114
Dan Willemsen6adbc362016-10-05 22:41:25 -0700115 if [[ $OS == "linux" ]]; then
116 # Build ASAN versions
117 export ASAN_OPTIONS=detect_leaks=0
118 cat > ${SOONG_OUT}/soong.variables << EOF
119{
120 "Allow_missing_dependencies": true,
121 "HostArch":"x86_64",
Dan Willemsen6adbc362016-10-05 22:41:25 -0700122 "SanitizeHost": ["address"]
123}
124EOF
Colin Cross14cd25f2017-09-22 14:27:44 -0700125
126 # Clean up non-ASAN installed versions
Colin Cross85c2d922017-05-09 20:30:40 -0700127 rm -rf ${SOONG_HOST_OUT}
Colin Cross14cd25f2017-09-22 14:27:44 -0700128
129 # Build everything with ASAN
130 build/soong/soong_ui.bash --make-mode --skip-make \
Dan Willemsend4475082017-10-04 15:40:35 -0700131 ${asan_binaries} \
Dan Willemsenfe85be02018-02-15 13:59:35 -0800132 ${SOONG_HOST_OUT}/nativetest64/ninja_test/ninja_test \
133 ${SOONG_HOST_OUT}/nativetest64/ckati_test/find_test
Colin Cross14cd25f2017-09-22 14:27:44 -0700134
135 # Run ninja tests
Dan Willemsen6adbc362016-10-05 22:41:25 -0700136 ${SOONG_HOST_OUT}/nativetest64/ninja_test/ninja_test
Colin Cross14cd25f2017-09-22 14:27:44 -0700137
Dan Willemsenfe85be02018-02-15 13:59:35 -0800138 # Run ckati tests
139 ${SOONG_HOST_OUT}/nativetest64/ckati_test/find_test
140
Colin Cross14cd25f2017-09-22 14:27:44 -0700141 # Copy arch-specific binaries
Dan Willemsen6adbc362016-10-05 22:41:25 -0700142 mkdir -p ${SOONG_OUT}/dist/asan/bin
Dan Willemsend4475082017-10-04 15:40:35 -0700143 cp ${asan_binaries} ${SOONG_OUT}/dist/asan/bin/
Dan Willemsen6adbc362016-10-05 22:41:25 -0700144 cp -R ${SOONG_HOST_OUT}/lib* ${SOONG_OUT}/dist/asan/
145 fi
146
Colin Cross14cd25f2017-09-22 14:27:44 -0700147 # Package arch-specific prebuilts
Dan Willemsen6adbc362016-10-05 22:41:25 -0700148 (
149 cd ${SOONG_OUT}/dist
150 zip -qryX build-prebuilts.zip *
151 )
Colin Cross14cd25f2017-09-22 14:27:44 -0700152
153 # Package common prebuilts
154 (
155 cd ${SOONG_OUT}/dist-common
156 zip -qryX build-common-prebuilts.zip *
157 )
Colin Cross0ffa5a02016-04-01 16:45:40 -0700158fi
159
160# Go
161if [ -n ${build_go} ]; then
162 GO_OUT=${OUT_DIR}/obj/go
163 rm -rf ${GO_OUT}
164 mkdir -p ${GO_OUT}
165 cp -a ${TOP}/toolchain/go/* ${GO_OUT}/
166 (
167 cd ${GO_OUT}/src
168 export GOROOT_BOOTSTRAP=${TOP}/prebuilts/go/${OS}-x86
Colin Cross42f43d92016-04-18 12:31:06 -0700169 export GOROOT_FINAL=./prebuilts/go/${OS}-x86
Colin Cross0ffa5a02016-04-01 16:45:40 -0700170 export GO_TEST_TIMEOUT_SCALE=100
171 ./make.bash
Dan Willemsen817bd2e2017-02-21 14:37:36 -0800172 rm -rf ../pkg/bootstrap
Dan Willemsen77ba5532018-07-23 10:48:27 -0700173 rm -rf ../pkg/obj
Colin Cross0ffa5a02016-04-01 16:45:40 -0700174 GOROOT=$(pwd)/.. ../bin/go install -race std
175 )
176 (
177 cd ${GO_OUT}
178 zip -qryX go.zip *
179 )
180fi
181
182if [ -n "${DIST_DIR}" ]; then
183 mkdir -p ${DIST_DIR} || true
184
185 if [ -n ${build_soong} ]; then
Dan Willemsen6adbc362016-10-05 22:41:25 -0700186 cp ${SOONG_OUT}/dist/build-prebuilts.zip ${DIST_DIR}/
Colin Cross14cd25f2017-09-22 14:27:44 -0700187 cp ${SOONG_OUT}/dist-common/build-common-prebuilts.zip ${DIST_DIR}/
Colin Crossacad53f2017-12-12 10:59:25 -0800188 cp ${SOONG_OUT}/docs/soong_build.html ${DIST_DIR}/
Colin Cross0ffa5a02016-04-01 16:45:40 -0700189 fi
Colin Cross0ffa5a02016-04-01 16:45:40 -0700190 if [ -n ${build_go} ]; then
191 cp ${GO_OUT}/go.zip ${DIST_DIR}/
192 fi
193fi