-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
build.sh
executable file
·203 lines (180 loc) · 6.02 KB
/
build.sh
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
#!/bin/bash
set -e
set +x
trap "cd $(pwd -P)" EXIT
cd "$(dirname $0)"
USAGE=$(cat<<EOF
usage: $(basename $0) [--mirror|--mirror-linux|--mirror-win32|--mirror-win64|--mirror-mac|--compile-mac-arm64]
Either compiles chromium or mirrors it from Chromium Continuous Builds CDN.
EOF
)
SCRIPT_PATH=$(pwd -P)
CRREV=$(head -1 ./BUILD_NUMBER)
main() {
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "$USAGE"
exit 0
elif [[ $1 == "--mirror"* ]]; then
mirror_chromium $1
elif [[ $1 == "--compile"* ]]; then
compile_chromium $1
else
echo "ERROR: unknown first argument. Use --help for details."
exit 1
fi
}
compile_chromium() {
if [[ -z "${CR_CHECKOUT_PATH}" ]]; then
echo "ERROR: chromium compilation requires CR_CHECKOUT_PATH to be set to reuse checkout."
exit 1
fi
if ! command -v gclient >/dev/null; then
echo "ERROR: chromium compilation requires depot_tools to be installed!"
exit 1
fi
CHROMIUM_FOLDER_NAME=""
CHROMIUM_FILES_TO_ARCHIVE=()
if [[ $1 == "--compile-mac-arm64" ]]; then
# As of Jan, 2021 Chromium mac compilation requires Xcode12.2
if [[ ! -d /Applications/Xcode12.2.app ]]; then
echo "ERROR: chromium mac arm64 compilation requires XCode 12.2 to be available"
echo "in the Applications folder!"
exit 1
fi
export DEVELOPER_DIR=/Applications/Xcode12.2.app/Contents/Developer
# As of Jan, 2021 Chromium mac compilation is only possible on Intel macbooks.
# See https://chromium.googlesource.com/chromium/src.git/+/master/docs/mac_arm64.md
if [[ $(uname -m) != "x86_64" ]]; then
echo "ERROR: chromium mac arm64 compilation is (ironically) only supported on Intel Macbooks"
exit 1
fi
CHROMIUM_FOLDER_NAME="chrome-mac"
CHROMIUM_FILES_TO_ARCHIVE=("Chromium.app")
elif [[ $1 == "--compile-linux" ]]; then
CHROMIUM_FOLDER_NAME="chrome-linux"
CHROMIUM_FILES_TO_ARCHIVE=(
"chrome"
"chrome_100_percent.pak"
"chrome_200_percent.pak"
"chrome_sandbox"
"chrome-wrapper"
"ClearKeyCdm"
"crashpad_handler"
"icudtl.dat"
"libEGL.so"
"libGLESv2.so"
"locales"
"MEIPreload"
"nacl_helper"
"nacl_helper_bootstrap"
"nacl_helper_nonsfi"
"nacl_irt_x86_64.nexe"
"product_logo_48.png"
"resources"
"resources.pak"
"swiftshader"
"v8_context_snapshot.bin"
"xdg-mime"
"xdg-settings"
)
fi
# Get chromium SHA from the build revision.
# This will get us the last redirect URL from the crrev.com service.
REVISION_URL=$(curl -ILs -o /dev/null -w %{url_effective} "https://crrev.com/${CRREV}")
CRSHA="${REVISION_URL##*/}"
# Update Chromium checkout. One might think that this step should go to `prepare_checkout.sh`
# script, but the `prepare_checkout.sh` is in fact designed to prepare a fork checkout, whereas
# we don't fork Chromium.
#
# This is based on https://chromium.googlesource.com/chromium/src/+/master/docs/linux/build_instructions.md#get-the-code
if [[ ! -d "${CR_CHECKOUT_PATH}" ]]; then
mkdir "${CR_CHECKOUT_PATH}"
cd "${CR_CHECKOUT_PATH}"
fetch --no-hooks chromium
cd src
if [[ $(uname) == "Linux" ]]; then
./build/install-build-deps.sh
fi
gclient runhooks
fi
cd "${CR_CHECKOUT_PATH}/src"
git checkout master
git pull origin master
git checkout "${CRSHA}"
gclient sync
# Prepare build folder.
mkdir -p "./out/Default"
cat <<EOF>./out/Default/args.gn
is_debug = false
symbol_level = 0
EOF
if [[ $1 == "--compile-mac-arm64" ]]; then
echo 'target_cpu = "arm64"' >> ./out/Default/args.gn
fi
# Compile Chromium with correct Xcode version.
gn gen out/Default
autoninja -C out/Default chrome
# Prepare resulting archive.
cd "$SCRIPT_PATH"
rm -rf output
mkdir -p "output/${CHROMIUM_FOLDER_NAME}"
# On Mac, use 'ditto' to copy directories instead of 'cp'.
COPY_COMMAND="cp -R"
if [[ $(uname) == "Darwin" ]]; then
COPY_COMMAND="ditto"
fi
for file in ${CHROMIUM_FILES_TO_ARCHIVE[@]}; do
$COPY_COMMAND "${CR_CHECKOUT_PATH}/src/out/Default/${file}" "output/${CHROMIUM_FOLDER_NAME}/${file}"
done
cd output
zip --symlinks -r build.zip "${CHROMIUM_FOLDER_NAME}"
}
mirror_chromium() {
cd "$SCRIPT_PATH"
rm -rf output
mkdir -p output
cd output
CHROMIUM_URL=""
CHROMIUM_FOLDER_NAME=""
CHROMIUM_FILES_TO_REMOVE=()
PLATFORM="$1"
if [[ "${PLATFORM}" == "--mirror" ]]; then
CURRENT_HOST_OS="$(uname)"
if [[ "${CURRENT_HOST_OS}" == "Darwin" ]]; then
PLATFORM="--mirror-mac"
elif [[ "${CURRENT_HOST_OS}" == "Linux" ]]; then
PLATFORM="--mirror-linux"
elif [[ "${CURRENT_HOST_OS}" == MINGW* ]]; then
PLATFORM="--mirror-win64"
else
echo "ERROR: unsupported host platform - ${CURRENT_HOST_OS}"
exit 1
fi
fi
if [[ "${PLATFORM}" == "--mirror-win32" ]]; then
CHROMIUM_URL="https://storage.googleapis.com/chromium-browser-snapshots/Win/${CRREV}/chrome-win.zip"
CHROMIUM_FOLDER_NAME="chrome-win"
CHROMIUM_FILES_TO_REMOVE+=("chrome-win/interactive_ui_tests.exe")
elif [[ "${PLATFORM}" == "--mirror-win64" ]]; then
CHROMIUM_URL="https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/${CRREV}/chrome-win.zip"
CHROMIUM_FOLDER_NAME="chrome-win"
CHROMIUM_FILES_TO_REMOVE+=("chrome-win/interactive_ui_tests.exe")
elif [[ "${PLATFORM}" == "--mirror-mac" ]]; then
CHROMIUM_URL="https://storage.googleapis.com/chromium-browser-snapshots/Mac/${CRREV}/chrome-mac.zip"
CHROMIUM_FOLDER_NAME="chrome-mac"
elif [[ "${PLATFORM}" == "--mirror-linux" ]]; then
CHROMIUM_URL="https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/${CRREV}/chrome-linux.zip"
CHROMIUM_FOLDER_NAME="chrome-linux"
else
echo "ERROR: unknown platform to build: $1"
exit 1
fi
echo "--> Pulling Chromium ${CRREV} for ${PLATFORM#--}"
curl --output chromium-upstream.zip "${CHROMIUM_URL}"
unzip chromium-upstream.zip
for file in ${CHROMIUM_FILES_TO_REMOVE[@]}; do
rm -f "${file}"
done
zip --symlinks -r build.zip "${CHROMIUM_FOLDER_NAME}"
}
main $1