summaryrefslogtreecommitdiff
path: root/tcwg_aosp-build.sh
blob: c90eb78aece7bb470a45fdae902112b717e1ae0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash

set -euf -o pipefail

scripts=$(dirname $0)
# shellcheck source=jenkins-helpers.sh
. $scripts/jenkins-helpers.sh
# shellcheck source=round-robin.sh
. $scripts/round-robin.sh

convert_args_to_variables "$@"

obligatory_variables rr[ci_config]
declare -A rr

# Execution mode: build or bisect
rr[mode]="${rr[mode]-build}"

# Set custom revision for one of the projects, and use baseline revisions
# for all other projects.
rr[ci_project]="${rr[ci_project]-tcwg_aosp}"
rr[baseline_branch]="${rr[baseline_branch]-linaro-local/ci/${rr[ci_project]}/${rr[ci_config]}}"
rr[update_baseline]="${rr[update_baseline]-ignore}"
rr[top_artifacts]="${rr[top_artifacts]-$(pwd)/artifacts}"

# store date of the run
rr[run_date]="$(date +%s)"

# {toolchain}-{toolchain_ver}-{target}-{aosp_module}-{aosp_ver}
IFS=- read -a ci_config <<EOF
${rr[ci_config]}
EOF
rr[toolchain]=${rr[toolchain]-${ci_config[0]}}
rr[target]=${rr[target]-${ci_config[2]}}
aosp_module=${aosp_module-${ci_config[3]}}

rr[components]="llvm toolchain-manifest aosp-manifest"

# Use baseline branches by default.
for c in ${rr[components]}; do
    rr[${c}_git]=${rr[${c}_git]-baseline}
done

start_at="${start_at-default}"
finish_at="${finish_at-default}"
verbose="${verbose-true}"
verbose2="${verbose2-false}"

if $verbose2; then set -x; fi

trap print_traceback EXIT

# Set start and finish steps for different modes.
default_start_at=""
default_finish_at=""
case "${rr[mode]}" in
    "bisect")
	case "$(print_single_updated_component)" in
	    llvm) default_start_at="build_llvm_android" ;;
	    toolchain-manifest) default_start_at="build_llvm_android" ;;
	    aosp-manifest) default_start_at="build_aosp" ;;
	    *) assert false ;;
	esac
	;;
esac
if [ x"$start_at" = x"default" ]; then
    start_at="$default_start_at"
fi
if [ x"$finish_at" = x"default" ]; then
    finish_at="$default_finish_at"
fi

run_step_init "$start_at" "$finish_at" "${rr[top_artifacts]}" "$verbose"

# Build LLVM
build_llvm_android ()
{
    (
    set -euf -o pipefail

    clone_repo llvm

    clone_repo toolchain-manifest

    mkdir -p llvm-toolchain
    cd llvm-toolchain

    repo init --partial-clone --clone-filter=blob:limit=10M \
	 -u "$(get_current_git toolchain-manifest_url)" \
	 -b "$(get_current_git toolchain-manifest_rev)"

    repo sync -c -j"$(nproc --all)" -q

    python toolchain/llvm_android/build.py \
	   --no-build lldb,windows --skip-runtimes --skip-tests --skip-package

    local cc cxx ninja
    cc=$(cat out/stage2/cmake_invocation.sh \
	     | grep -e " -DCMAKE_C_COMPILER=" \
	     | sed -e "s/.* -DCMAKE_C_COMPILER=\([^ ]*\).*/\1/")
    cxx=$(cat out/stage2/cmake_invocation.sh \
	      | grep -e " -DCMAKE_CXX_COMPILER=" \
	      | sed -e "s/.* -DCMAKE_CXX_COMPILER=\([^ ]*\).*/\1/")
    ninja=$(cat out/stage2/cmake_invocation.sh \
	      | grep -e " -DCMAKE_MAKE_PROGRAM=" \
	      | sed -e "s/.* -DCMAKE_MAKE_PROGRAM=\([^ ]*\).*/\1/")
    cd ..

    local workspace
    workspace=$(pwd)

    rm -rf "${workspace:?}/bin"
    mkdir "$workspace/bin"

    cat > "$workspace/bin/cc" <<EOF
#!/bin/sh
CCACHE_BASEDIR=$workspace exec ccache $cc "\$@"
EOF
    chmod +x "$workspace/bin/cc"

    cat > "$workspace/bin/c++" <<EOF
#!/bin/sh
CCACHE_BASEDIR=$workspace exec ccache $cxx "\$@"
EOF
    chmod +x "$workspace/bin/c++"

    rm -rf llvm-install

    cd llvm-toolchain/out

    mkdir -p stage3
    cp stage2/cmake_invocation.sh stage3/

    cd stage3

    sed -i \
	-e "s#/llvm-toolchain/out/llvm-project/#/llvm/#" \
	-e "s#/llvm-toolchain/out/stage2-install#/llvm-install#" \
	-e "s# -DCMAKE_C_COMPILER=[^ ]* # -DCMAKE_C_COMPILER=$workspace/bin/cc #" \
	-e "s# -DCMAKE_CXX_COMPILER=[^ ]* # -DCMAKE_CXX_COMPILER=$workspace/bin/c++ #" \
	cmake_invocation.sh

    source ./cmake_invocation.sh
    ccache -z
    $ninja
    $ninja install
    ccache -s
    )
}

install_shadow_cc ()
{
    (
    set -euf -o pipefail

    )
}

# Build AOSP
build_aosp ()
{
    (
    set -euf -o pipefail

    clone_repo aosp-manifest

    mkdir -p aosp
    cd aosp

    repo init --partial-clone --clone-filter=blob:limit=10M \
	 -u "$(get_current_git aosp-manifest_url)" \
	 -b "$(get_current_git aosp-manifest_rev)"

    repo sync -c -j"$(nproc --all)" -q

    install_shadow_cc "aosp" "$(cd $scripts; pwd)/shadow-cc.sh"

    set -e +uf +o pipefail
    source build/envsetup.sh

    lunch aosp_arm64-user
    m clean
    m
    )
}

# Exit with code 0 if no regression compared to base-artifacts/results.
no_regression_p ()
{
    (
    set -euf -o pipefail

    local -a changed_components
    IFS=" " read -r -a changed_components <<< "$(print_changed_components)"

    case " ${changed_components[*]} " in
	*" llvm "*) ;;
	*)
	    # Builds without changed LLVM we declare as non-regressing.
	    return 0
	    ;;
    esac
    )
}

run_step stop_on_fail -10 reset_artifacts
run_step skip_on_fail 0 build_llvm_android
run_step skip_on_fail 1 build_aosp
run_step reset_on_fail x check_regression
run_step stop_on_fail x update_baseline

trap "" EXIT