Colin Cross | 6ca8d25 | 2024-01-18 10:38:47 -0800 | [diff] [blame] | 1 | #!/bin/bash -ex |
| 2 | |
| 3 | : "${OUT_DIR:?Must set OUT_DIR}" |
| 4 | TOP=$(cd $(dirname $0)/../../..; pwd) |
| 5 | cd ${TOP} |
| 6 | |
| 7 | UNAME="$(uname)" |
| 8 | case "$UNAME" in |
| 9 | Linux) |
| 10 | OS='linux' |
| 11 | ;; |
| 12 | Darwin) |
| 13 | OS='darwin' |
| 14 | ;; |
| 15 | *) |
| 16 | exit 1 |
| 17 | ;; |
| 18 | esac |
| 19 | |
| 20 | # Verify that go test and go build work on all the same projects that are parsed by |
| 21 | # build/soong/build_kzip.bash |
| 22 | declare -ar go_modules=(build/blueprint build/soong |
| 23 | build/make/tools/canoninja build/make/tools/compliance build/make/tools/rbcrun) |
| 24 | export GOROOT=${TOP}/prebuilts/go/${OS}-x86 |
| 25 | export GOENV=off |
| 26 | export GOPROXY=off |
| 27 | abs_out_dir=$(cd ${OUT_DIR}; pwd) |
| 28 | export GOPATH=${abs_out_dir}/gopath |
| 29 | export GOCACHE=${abs_out_dir}/gocache |
| 30 | export GOMODCACHE=${abs_out_dir}/gomodcache |
| 31 | export TMPDIR=${abs_out_dir}/gotemp |
| 32 | mkdir -p ${TMPDIR} |
| 33 | ${GOROOT}/bin/go env |
| 34 | |
Colin Cross | 84caaef | 2024-01-19 19:32:54 +0000 | [diff] [blame] | 35 | if [[ ${OS} = linux ]]; then |
| 36 | # Building with the race detector enabled uses the host linker, set the |
| 37 | # path to use the hermetic one. |
| 38 | CLANG_VERSION=$(build/soong/scripts/get_clang_version.py) |
| 39 | export CC="${TOP}/prebuilts/clang/host/${OS}-x86/${CLANG_VERSION}/bin/clang" |
| 40 | export CXX="${TOP}/prebuilts/clang/host/${OS}-x86/${CLANG_VERSION}/bin/clang++" |
| 41 | fi |
Colin Cross | ec78a46 | 2024-01-18 10:44:06 -0800 | [diff] [blame] | 42 | |
Colin Cross | 6ca8d25 | 2024-01-18 10:38:47 -0800 | [diff] [blame] | 43 | # androidmk_test.go gets confused if ANDROID_BUILD_TOP is set. |
| 44 | unset ANDROID_BUILD_TOP |
| 45 | |
| 46 | network_jail="" |
| 47 | if [[ ${OS} = linux ]]; then |
| 48 | # The go tools often try to fetch dependencies from the network, |
| 49 | # wrap them in an nsjail to prevent network access. |
| 50 | network_jail=${TOP}/prebuilts/build-tools/linux-x86/bin/nsjail |
| 51 | # Quiet |
| 52 | network_jail="${network_jail} -q" |
| 53 | # No timeout |
| 54 | network_jail="${network_jail} -t 0" |
| 55 | # Set working directory |
| 56 | network_jail="${network_jail} --cwd=\$PWD" |
| 57 | # Pass environment variables through |
| 58 | network_jail="${network_jail} -e" |
| 59 | # Allow read-only access to everything |
| 60 | network_jail="${network_jail} -R /" |
| 61 | # Allow write access to the out directory |
| 62 | network_jail="${network_jail} -B ${abs_out_dir}" |
| 63 | # Allow write access to the /tmp directory |
| 64 | network_jail="${network_jail} -B /tmp" |
| 65 | # Set high values, as network_jail uses low defaults. |
| 66 | network_jail="${network_jail} --rlimit_as soft" |
| 67 | network_jail="${network_jail} --rlimit_core soft" |
| 68 | network_jail="${network_jail} --rlimit_cpu soft" |
| 69 | network_jail="${network_jail} --rlimit_fsize soft" |
| 70 | network_jail="${network_jail} --rlimit_nofile soft" |
| 71 | fi |
| 72 | |
| 73 | for dir in "${go_modules[@]}"; do |
| 74 | (cd "$dir"; |
| 75 | eval ${network_jail} -- ${GOROOT}/bin/go build ./... |
| 76 | eval ${network_jail} -- ${GOROOT}/bin/go test ./... |
Colin Cross | 55f169a | 2024-04-30 11:19:25 -0700 | [diff] [blame] | 77 | eval ${network_jail} -- ${GOROOT}/bin/go test -race -timeout 20m -short ./... |
Colin Cross | 6ca8d25 | 2024-01-18 10:38:47 -0800 | [diff] [blame] | 78 | ) |
| 79 | done |