Louis Dionne | 298f207 | 2023-07-12 12:55:07 | [diff] [blame] | 1 | #!/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 Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 16 | # As this outputs a yaml file, it's possible to log messages to stderr or |
| 17 | # prefix with "#". |
| 18 | |
| 19 | |
| 20 | set -eu |
| 21 | set -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 Dionne | 298f207 | 2023-07-12 12:55:07 | [diff] [blame] | 35 | |
Louis Dionne | 298f207 | 2023-07-12 12:55:07 | [diff] [blame] | 36 | reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" |
| 37 | if [[ "${reviewID}" != "" ]]; then |
| 38 | buildMessage="https://llvm.org/${reviewID}" |
| 39 | else |
| 40 | buildMessage="Push to branch ${BUILDKITE_BRANCH}" |
| 41 | fi |
| 42 | |
| 43 | cat <<EOF |
| 44 | steps: |
| 45 | EOF |
| 46 | |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 47 | echo "Files modified:" >&2 |
| 48 | echo "$MODIFIED_FILES" >&2 |
| 49 | modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u) |
| 50 | echo "Directories modified:" >&2 |
| 51 | echo "$modified_dirs" >&2 |
Louis Dionne | 298f207 | 2023-07-12 12:55:07 | [diff] [blame] | 52 | |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 53 | function 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 | |
| 86 | function 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 | |
| 124 | function 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 | |
| 138 | function 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 Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 155 | # Prints only projects that are both present in $modified_dirs and the passed |
| 156 | # list. |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 157 | function keep-modified-projects() { |
| 158 | projects=${@} |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 159 | for project in ${projects}; do |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 160 | if echo "$modified_dirs" | grep -q -E "^${project}$"; then |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 161 | echo "${project}" |
| 162 | fi |
| 163 | done |
| 164 | } |
| 165 | |
| 166 | function 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 Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 195 | # Project specific pipelines. |
| 196 | |
| 197 | # If libc++ or one of the runtimes directories changed. |
| 198 | if 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}" |
| 205 | EOF |
| 206 | fi |
| 207 | |
| 208 | # If clang changed. |
| 209 | if 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}" |
| 216 | EOF |
| 217 | fi |
| 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 Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 224 | # Figure out which projects need to be built on each platform |
| 225 | all_projects="bolt clang-tools-extra compiler-rt cross-project-tests flang libc libclc lld lldb llvm mlir openmp polly pstl" |
| 226 | modified_projects="$(keep-modified-projects ${all_projects})" |
| 227 | |
| 228 | linux_projects_to_test=$(exclude-linux $(compute-projects-to-test ${modified_projects})) |
| 229 | linux_check_targets=$(check-targets ${linux_projects_to_test} | sort | uniq) |
| 230 | linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq) |
| 231 | |
| 232 | windows_projects_to_test=$(exclude-windows $(compute-projects-to-test ${modified_projects})) |
| 233 | windows_check_targets=$(check-targets ${windows_projects_to_test} | sort | uniq) |
| 234 | windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq) |
| 235 | |
| 236 | # Generate the appropriate pipeline |
| 237 | if [[ "${linux_projects}" != "" ]]; then |
| 238 | cat <<EOF |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 239 | - label: ':linux: Linux x64' |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 240 | artifact_paths: |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 241 | - artifacts/**/* |
Mikhail Goncharov | 2484678 | 2023-09-11 11:20:34 | [diff] [blame] | 242 | - *_result.json |
| 243 | - build/test-results.xml |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 244 | agents: ${LINUX_AGENTS} |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 245 | retry: |
| 246 | automatic: |
| 247 | - exit_status: -1 # Agent was lost |
| 248 | limit: 2 |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 249 | - exit_status: 255 # Forced agent shutdown |
| 250 | limit: 2 |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 251 | timeout_in_minutes: 120 |
| 252 | env: |
| 253 | CC: 'clang' |
| 254 | CXX: 'clang++' |
| 255 | commands: |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 256 | - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" "$(echo ${linux_check_targets})"' |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 257 | EOF |
| 258 | fi |
| 259 | |
| 260 | if [[ "${windows_projects}" != "" ]]; then |
| 261 | cat <<EOF |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 262 | - label: ':windows: Windows x64' |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 263 | artifact_paths: |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 264 | - artifacts/**/* |
Mikhail Goncharov | 2484678 | 2023-09-11 11:20:34 | [diff] [blame] | 265 | - *_result.json |
| 266 | - build/test-results.xml |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 267 | agents: ${WINDOWS_AGENTS} |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 268 | retry: |
| 269 | automatic: |
| 270 | - exit_status: -1 # Agent was lost |
| 271 | limit: 2 |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 272 | - exit_status: 255 # Forced agent shutdown |
| 273 | limit: 2 |
Louis Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 274 | timeout_in_minutes: 150 |
| 275 | env: |
| 276 | CC: 'cl' |
| 277 | CXX: 'cl' |
| 278 | LD: 'link' |
| 279 | commands: |
Mikhail Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 280 | - '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})"' |
| 282 | EOF |
| 283 | fi |
| 284 | |
| 285 | # If build was triggered from a Phabricator review - send an update back. |
| 286 | if [[ -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 Goncharov | c81ab62 | 2023-08-31 14:18:27 | [diff] [blame] | 294 | 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 Dionne | cf1a3d9 | 2023-06-12 21:45:48 | [diff] [blame] | 307 | EOF |
| 308 | fi |