blob: 058d4f5441a76c9d75ac3f3d04ab827b888af0fb [file] [log] [blame]
Louis Dionnecc7d0842020-10-06 14:13:55 -04001#!/usr/bin/env bash
2
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.
Louis Dionne2c7a3b52021-07-13 13:07:45 -04006#
Louis Dionne51fc0b32021-07-16 11:37:16 -04007# 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:
Louis Dionne2c7a3b52021-07-13 13:07:45 -040010#
11# $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)"
12#
13# Once the necessary dependencies have been installed, you can switch
Louis Dionne51fc0b32021-07-16 11:37:16 -040014# to a non-administrator account and run the script again, passing the
15# --setup-launchd argument. That will install a Launchd agent to run the
16# BuildKite agent whenever the current user is logged in. You should enable
17# automatic login for that user, so that if the CI node goes down, the user
18# is logged back in automatically when the node goes up again, and the
19# BuildKite agent starts automatically.
20#
21# Alternatively, you can simply run the BuildKite agent by hand using:
Louis Dionne2c7a3b52021-07-13 13:07:45 -040022#
23# $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds
Louis Dionnecc7d0842020-10-06 14:13:55 -040024
Louis Dionneaf413c52021-07-12 15:44:28 -040025set -e
26
Louis Dionne51fc0b32021-07-16 11:37:16 -040027# Install a Launchd agent that will automatically start the BuildKite agent at login
28if [[ ${1} == "--setup-launchd" ]]; then
29 HOMEBREW_PREFIX="$(brew --prefix)"
30 cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
31<?xml version="1.0" encoding="UTF-8"?>
32<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33<plist version="1.0">
34<dict>
35 <key>Label</key>
36 <string>libcxx.buildkite-agent</string>
37
38 <key>ProgramArguments</key>
39 <array>
40 <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string>
41 <string>start</string>
42 <string>--build-path</string>
43 <string>${HOME}/libcxx.buildkite-agent/builds</string>
44 </array>
45
46 <key>EnvironmentVariables</key>
47 <dict>
48 <key>PATH</key>
49 <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
50 </dict>
51
52 <key>RunAtLoad</key>
53 <true/>
54
55 <key>KeepAlive</key>
56 <dict>
57 <key>SuccessfulExit</key>
58 <false/>
59 </dict>
60
61 <key>ProcessType</key>
62 <string>Interactive</string>
63
64 <key>ThrottleInterval</key>
65 <integer>30</integer>
66
67 <key>StandardOutPath</key>
68 <string>${HOME}/libcxx.buildkite-agent/stdout.log</string>
69
70 <key>StandardErrorPath</key>
71 <string>${HOME}/libcxx.buildkite-agent/stderr.log</string>
72</dict>
73</plist>
74EOF
75
76 echo "Starting BuildKite agent"
77 launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
78
79else
80 echo "Installing CI dependencies for macOS"
81
82 if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then
83 echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script."
84 exit 1
85 fi
86
87 # Install Homebrew
88 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
89 HOMEBREW_PREFIX="$(brew --prefix)"
90
91 # Install the required tools to run CI
92 brew install sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent
93
94 # Setup BuildKite Agent config
95 version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')"
96 arch="$(uname -m)"
97 sed -i '' "s/token=xxx/token=${BUILDKITE_AGENT_TOKEN}/g" "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg"
98 echo "tags=\"queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}\"" >> "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg"
Louis Dionne137daee2021-06-14 15:55:36 -040099fi