Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / utils / ci / macos-ci-setup
blobfc3a6f007ece13eab93a82acb39515f98d781e0d
1 #!/usr/bin/env bash
3 # This simple script can be used to set up a CI node running MacOS.
4 # An additional requirement that is *not* handled by this script is the
5 # installation of Xcode, which requires manual intervention.
7 # This script should first be run from an administrator account to install
8 # the dependencies necessary for running CI. It can be run without having
9 # to clone the LLVM repository with:
11 # $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)"
13 # If you perform system updates, you should re-run the script from the
14 # administrator account -- this allows updating the packages used for
15 # CI and the BuildKite agent tags.
17 # Once the necessary dependencies have been installed, you can switch
18 # to a non-administrator account and run the script again, passing the
19 # --setup-launchd argument. That will install a Launchd agent to run the
20 # BuildKite agent whenever the current user is logged in. You should enable
21 # automatic login for that user, so that if the CI node goes down, the user
22 # is logged back in automatically when the node goes up again, and the
23 # BuildKite agent starts automatically.
25 # Alternatively, you can simply run the BuildKite agent by hand using:
27 # $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds
29 set -e
31 # Install a Launchd agent that will automatically start the BuildKite agent at login
32 if [[ ${1} == "--setup-launchd" ]]; then
33 HOMEBREW_PREFIX="$(brew --prefix)"
34 mkdir -p ~/Library/LaunchAgents
35 cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
36 <?xml version="1.0" encoding="UTF-8"?>
37 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
38 <plist version="1.0">
39 <dict>
40 <key>Label</key>
41 <string>libcxx.buildkite-agent</string>
43 <key>ProgramArguments</key>
44 <array>
45 <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string>
46 <string>start</string>
47 <string>--build-path</string>
48 <string>${HOME}/libcxx.buildkite-agent/builds</string>
49 </array>
51 <key>EnvironmentVariables</key>
52 <dict>
53 <key>PATH</key>
54 <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
55 </dict>
57 <key>RunAtLoad</key>
58 <true/>
60 <key>KeepAlive</key>
61 <dict>
62 <key>SuccessfulExit</key>
63 <false/>
64 </dict>
66 <key>ProcessType</key>
67 <string>Interactive</string>
69 <key>ThrottleInterval</key>
70 <integer>30</integer>
72 <key>StandardOutPath</key>
73 <string>${HOME}/libcxx.buildkite-agent/stdout.log</string>
75 <key>StandardErrorPath</key>
76 <string>${HOME}/libcxx.buildkite-agent/stderr.log</string>
77 </dict>
78 </plist>
79 EOF
81 echo "Starting BuildKite agent"
82 launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
84 else
85 echo "Installing CI dependencies for macOS"
87 if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then
88 echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script."
89 exit 1
92 # Install Homebrew
93 if ! which -s brew; then
94 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
97 # Install the required tools to run CI
98 brew update
99 for package in sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent; do
100 if brew ls --versions "${package}" >/dev/null; then
101 brew upgrade "${package}"
102 else
103 brew install "${package}"
105 done
106 python3 -m pip install --upgrade psutil
108 echo "Setting up BuildKite Agent config"
109 version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')"
110 arch="$(uname -m)"
111 cat <<EOF > "$(brew --prefix)/etc/buildkite-agent/buildkite-agent.cfg"
112 token="${BUILDKITE_AGENT_TOKEN}"
113 tags="queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}"
114 build-path=/tmp/buildkite-builds # Note that this is actually overwritten when starting the agent with launchd