blob: 7d14aed355d42d60dd701359331fc6deddd369b1 [file] [log] [blame]
Louis Dionne298f2072023-07-12 12:55:071#!/usr/bin/env bash
2#===----------------------------------------------------------------------===##
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8#===----------------------------------------------------------------------===##
9
10#
11# This file generates a Buildkite pipeline that triggers the various CI jobs for
12# the LLVM project during pre-commit CI (each time a Phabricator diff is uploaded).
13#
14# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format.
15#
Mikhail Goncharovc81ab622023-08-31 14:18:2716# As this outputs a yaml file, it's possible to log messages to stderr or
17# prefix with "#".
18
19
20set -eu
21set -o pipefail
22
23# Environment variables script works with:
24# List of files affected by this commit
25: ${MODIFIED_FILES:=$(git diff --name-only HEAD~1)}
26# Filter rules for generic windows tests
27: ${WINDOWS_AGENTS:='{"queue": "windows"}'}
28# Filter rules for generic linux tests
29: ${LINUX_AGENTS:='{"queue": "linux"}'}
30# Service agents, for interacting with Phabricator.
31: ${SERVICE_AGENTS:='{"queue": "service"}'}
32# Set by buildkite
33: ${BUILDKITE_COMMIT:=}
34: ${BUILDKITE_BRANCH:=}
Louis Dionne298f2072023-07-12 12:55:0735
Louis Dionne298f2072023-07-12 12:55:0736reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')"
37if [[ "${reviewID}" != "" ]]; then
38 buildMessage="https://llvm.org/${reviewID}"
39else
40 buildMessage="Push to branch ${BUILDKITE_BRANCH}"
41fi
42
43cat <<EOF
44steps:
45EOF
46
Mikhail Goncharovc81ab622023-08-31 14:18:2747echo "Files modified:" >&2
48echo "$MODIFIED_FILES" >&2
49modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u)
50echo "Directories modified:" >&2
51echo "$modified_dirs" >&2
Louis Dionne298f2072023-07-12 12:55:0752
Louis Dionnecf1a3d92023-06-12 21:45:4853function compute-projects-to-test() {
54 projects=${@}
55 for project in ${projects}; do
56 echo "${project}"
57 case ${project} in
58 lld)
59 for p in bolt cross-project-tests; do
60 echo $p
61 done
62 ;;
63 llvm)
64 for p in bolt clang clang-tools-extra flang lld lldb mlir polly; do
65 echo $p
66 done
67 ;;
68 clang)
69 for p in clang-tools-extra compiler-rt flang libc lldb openmp cross-project-tests; do
70 echo $p
71 done
72 ;;
73 clang-tools-extra)
74 echo libc
75 ;;
76 mlir)
77 echo flang
78 ;;
79 *)
80 # Nothing to do
81 ;;
82 esac
83 done
84}
85
86function add-dependencies() {
87 projects=${@}
88 for project in ${projects}; do
89 echo "${project}"
90 case ${project} in
91 bolt)
92 for p in lld llvm; do
93 echo $p
94 done
95 ;;
96 cross-project-tests)
97 for p in lld clang; do
98 echo $p
99 done
100 ;;
101 clang-tools-extra)
102 for p in llvm clang; do
103 echo $p
104 done
105 ;;
106 compiler-rt|libc|openmp)
107 echo clang
108 ;;
109 flang|lldb)
110 for p in llvm clang; do
111 echo $p
112 done
113 ;;
114 lld|mlir|polly)
115 echo llvm
116 ;;
117 *)
118 # Nothing to do
119 ;;
120 esac
121 done
122}
123
124function exclude-linux() {
125 projects=${@}
126 for project in ${projects}; do
127 case ${project} in
128 cross-project-tests) ;; # tests failing
129 lldb) ;; # tests failing
130 openmp) ;; # https://github.com/google/llvm-premerge-checks/issues/410
131 *)
132 echo "${project}"
133 ;;
134 esac
135 done
136}
137
138function exclude-windows() {
139 projects=${@}
140 for project in ${projects}; do
141 case ${project} in
142 cross-project-tests) ;; # tests failing
143 compiler-rt) ;; # tests taking too long
144 openmp) ;; # TODO: having trouble with the Perl installation
145 libc) ;; # no Windows support
146 lldb) ;; # tests failing
147 bolt) ;; # tests are not supported yet
148 *)
149 echo "${project}"
150 ;;
151 esac
152 done
153}
154
Mikhail Goncharovc81ab622023-08-31 14:18:27155# Prints only projects that are both present in $modified_dirs and the passed
156# list.
Louis Dionnecf1a3d92023-06-12 21:45:48157function keep-modified-projects() {
158 projects=${@}
Louis Dionnecf1a3d92023-06-12 21:45:48159 for project in ${projects}; do
Mikhail Goncharovc81ab622023-08-31 14:18:27160 if echo "$modified_dirs" | grep -q -E "^${project}$"; then
Louis Dionnecf1a3d92023-06-12 21:45:48161 echo "${project}"
162 fi
163 done
164}
165
166function check-targets() {
167 projects=${@}
168 for project in ${projects}; do
169 case ${project} in
170 clang-tools-extra)
171 echo "check-clang-tools"
172 ;;
173 compiler-rt)
174 echo "check-all"
175 ;;
176 cross-project-tests)
177 echo "check-cross-project"
178 ;;
179 lldb)
180 echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
181 ;;
182 pstl)
183 echo "check-all"
184 ;;
185 libclc)
186 echo "check-all"
187 ;;
188 *)
189 echo "check-${project}"
190 ;;
191 esac
192 done
193}
194
Mikhail Goncharovc81ab622023-08-31 14:18:27195# Project specific pipelines.
196
197# If libc++ or one of the runtimes directories changed.
198if echo "$modified_dirs" | grep -q -E "^(libcxx|libcxxabi|libunwind|runtimes|cmake)$"; then
199 cat <<EOF
200- trigger: "libcxx-ci"
201 build:
202 message: "${buildMessage}"
203 commit: "${BUILDKITE_COMMIT}"
204 branch: "${BUILDKITE_BRANCH}"
205EOF
206fi
207
208# If clang changed.
209if echo "$modified_dirs" | grep -q -E "^(clang)$"; then
210 cat <<EOF
211- trigger: "clang-ci"
212 build:
213 message: "${buildMessage}"
214 commit: "${BUILDKITE_COMMIT}"
215 branch: "${BUILDKITE_BRANCH}"
216EOF
217fi
218
219# Generic pipeline for projects that have not defined custom steps.
220#
221# Individual projects should instead define the pre-commit CI tests that suits their
222# needs while letting them run on the infrastructure provided by LLVM.
223
Louis Dionnecf1a3d92023-06-12 21:45:48224# Figure out which projects need to be built on each platform
225all_projects="bolt clang-tools-extra compiler-rt cross-project-tests flang libc libclc lld lldb llvm mlir openmp polly pstl"
226modified_projects="$(keep-modified-projects ${all_projects})"
227
228linux_projects_to_test=$(exclude-linux $(compute-projects-to-test ${modified_projects}))
229linux_check_targets=$(check-targets ${linux_projects_to_test} | sort | uniq)
230linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq)
231
232windows_projects_to_test=$(exclude-windows $(compute-projects-to-test ${modified_projects}))
233windows_check_targets=$(check-targets ${windows_projects_to_test} | sort | uniq)
234windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq)
235
236# Generate the appropriate pipeline
237if [[ "${linux_projects}" != "" ]]; then
238 cat <<EOF
Mikhail Goncharovc81ab622023-08-31 14:18:27239- label: ':linux: Linux x64'
Louis Dionnecf1a3d92023-06-12 21:45:48240 artifact_paths:
Mikhail Goncharovc81ab622023-08-31 14:18:27241 - artifacts/**/*
Mikhail Goncharov24846782023-09-11 11:20:34242 - *_result.json
243 - build/test-results.xml
Mikhail Goncharovc81ab622023-08-31 14:18:27244 agents: ${LINUX_AGENTS}
Louis Dionnecf1a3d92023-06-12 21:45:48245 retry:
246 automatic:
247 - exit_status: -1 # Agent was lost
248 limit: 2
Mikhail Goncharovc81ab622023-08-31 14:18:27249 - exit_status: 255 # Forced agent shutdown
250 limit: 2
Louis Dionnecf1a3d92023-06-12 21:45:48251 timeout_in_minutes: 120
252 env:
253 CC: 'clang'
254 CXX: 'clang++'
255 commands:
Mikhail Goncharovc81ab622023-08-31 14:18:27256 - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" "$(echo ${linux_check_targets})"'
Louis Dionnecf1a3d92023-06-12 21:45:48257EOF
258fi
259
260if [[ "${windows_projects}" != "" ]]; then
261 cat <<EOF
Mikhail Goncharovc81ab622023-08-31 14:18:27262- label: ':windows: Windows x64'
Louis Dionnecf1a3d92023-06-12 21:45:48263 artifact_paths:
Mikhail Goncharovc81ab622023-08-31 14:18:27264 - artifacts/**/*
Mikhail Goncharov24846782023-09-11 11:20:34265 - *_result.json
266 - build/test-results.xml
Mikhail Goncharovc81ab622023-08-31 14:18:27267 agents: ${WINDOWS_AGENTS}
Louis Dionnecf1a3d92023-06-12 21:45:48268 retry:
269 automatic:
270 - exit_status: -1 # Agent was lost
271 limit: 2
Mikhail Goncharovc81ab622023-08-31 14:18:27272 - exit_status: 255 # Forced agent shutdown
273 limit: 2
Louis Dionnecf1a3d92023-06-12 21:45:48274 timeout_in_minutes: 150
275 env:
276 CC: 'cl'
277 CXX: 'cl'
278 LD: 'link'
279 commands:
Mikhail Goncharovc81ab622023-08-31 14:18:27280 - 'C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 -host_arch=amd64'
281 - 'bash .ci/monolithic-windows.sh "$(echo ${windows_projects} | tr ' ' ';')" "$(echo ${windows_check_targets})"'
282EOF
283fi
284
285# If build was triggered from a Phabricator review - send an update back.
286if [[ -n "${ph_target_phid:-}" ]]; then
287 cat << EOF
288- continue_on_failure: true
289 wait: '~'
290- label: ':phabricator: update build status on Phabricator'
291 agents: ${SERVICE_AGENTS}
292 artifact_paths:
293 - artifacts/**/*
Mikhail Goncharovc81ab622023-08-31 14:18:27294 commands:
295 - export SRC=\$\${BUILDKITE_BUILD_PATH}/llvm-premerge-checks
296 - rm -rf \$\${SRC}
297 - git clone --depth 1 https://github.com/google/llvm-premerge-checks.git "\$\${SRC}"
298 - cd \$\${SRC}
299 - git fetch origin "main":x
300 - git checkout x
301 - echo "llvm-premerge-checks commit"
302 - git rev-parse HEAD
303 - pip install -q -r \$\${SRC}/scripts/requirements.txt
304 - cd "\$\$BUILDKITE_BUILD_CHECKOUT_PATH"
305 - \$\${SRC}/scripts/summary.py
306 timeout_in_minutes: 10
Louis Dionnecf1a3d92023-06-12 21:45:48307EOF
308fi