|
1 |
| -#!/bin/sh -e |
| 1 | +#!/bin/bash -e |
2 | 2 |
|
3 |
| -# This is the second half of the process of building Courgette; the Dockerfile |
4 |
| -# sets up the environment and configures the build. Now we need to actually |
5 |
| -# perform the build and package the results. |
| 3 | +# This script builds the Courgette target from Chromium. It works on macOS and |
| 4 | +# Linux. Please see the accompanying README.md file. |
6 | 5 | #
|
7 |
| -# https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md |
| 6 | +# https://www.chromium.org/developers/how-tos/get-the-code |
8 | 7 |
|
9 |
| -cd /root/chromium/src |
10 |
| -GITHASH=$(git rev-parse --short HEAD) |
| 8 | +function status { |
| 9 | + printf '\E[33m' |
| 10 | + echo "$@" |
| 11 | + printf '\E[0m' |
| 12 | +} |
| 13 | + |
| 14 | +if [ "$#" -eq 0 ]; then |
| 15 | + echo "Usage: $0 workspace-dir [fetch-only|no-update]" >&2 |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Enter the workspace |
| 20 | +mkdir -p "$1" |
| 21 | +cd "$1" |
| 22 | + |
| 23 | +# Install depot_tools |
| 24 | +if [ ! -d depot_tools ]; then |
| 25 | + status "[*] Cloning depot_tools" |
| 26 | + git clone --depth 1 \ |
| 27 | + https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 28 | +elif [ "$2" != "no-update" ]; then |
| 29 | + status "[*] Updating depot_tools" |
| 30 | + pushd depot_tools |
| 31 | + git pull |
| 32 | + popd |
| 33 | +fi |
| 34 | + |
| 35 | +export PATH="$(pwd)/depot_tools:${PATH}" |
| 36 | + |
| 37 | +# Is this our first build? |
| 38 | +if [ ! -f .first-build-finished ]; then |
| 39 | + FIRST_BUILD=1 |
| 40 | +else |
| 41 | + FIRST_BUILD=0 |
| 42 | +fi |
| 43 | + |
| 44 | +# Get the code |
| 45 | +if [ ! -d chromium/src ]; then |
| 46 | + status "[*] Fetching Chromium sources" |
| 47 | + mkdir -p chromium |
| 48 | + pushd chromium |
| 49 | + git config --global core.precomposeUnicode true |
| 50 | + fetch --nohooks --no-history chromium |
| 51 | + popd |
| 52 | +elif [ "$2" != "no-update" ]; then |
| 53 | + status "[*] Updating Chromium sources" |
| 54 | + pushd chromium/src |
| 55 | + git rebase-update |
| 56 | + popd |
| 57 | +fi |
11 | 58 |
|
12 |
| -# Update the checkout and re-sync dependencies and hooks |
13 |
| -git rebase-update |
14 |
| -gclient sync |
| 59 | +# Stop here if we just wanted to fetch the code |
| 60 | +if [ "$2" = "fetch-only" ]; then |
| 61 | + exit 0 |
| 62 | +fi |
| 63 | + |
| 64 | +# Install additional build dependencies |
| 65 | +if [ $FIRST_BUILD -eq 1 ] && [ "$(uname -s)" = "Linux" ]; then |
| 66 | + status "[*] Installing build dependencies" |
| 67 | + pushd chromium/src |
| 68 | + ./build/install-build-deps.sh \ |
| 69 | + --no-arm --no-chromeos-fonts --no-nacl \ |
| 70 | + --no-prompt |
| 71 | + popd |
| 72 | +fi |
| 73 | + |
| 74 | +# Run the hooks |
| 75 | +pushd chromium/src |
| 76 | +if [ $FIRST_BUILD -eq 1 ]; then |
| 77 | + status "[*] Running hooks" |
| 78 | + gclient runhooks |
| 79 | +elif [ "$2" != "no-update" ]; then |
| 80 | + status "[*] Running hooks" |
| 81 | + gclient sync |
| 82 | +fi |
| 83 | +popd |
| 84 | + |
| 85 | +# Configure the build |
| 86 | +if [ ! -d chromium/src/out/Default ]; then |
| 87 | + status "[*] Configuring" |
| 88 | + pushd chromium/src |
| 89 | + mkdir -p out/Default |
| 90 | + (echo "enable_nacl = false"; echo "symbol_level = 0") > out/Default/args.gn |
| 91 | + gn gen out/Default |
| 92 | + popd |
| 93 | +fi |
15 | 94 |
|
16 | 95 | # Build Courgette
|
| 96 | +status "[*] Building Courgette" |
| 97 | +pushd chromium/src |
17 | 98 | autoninja -C out/Default courgette
|
| 99 | +popd |
| 100 | +touch .first-build-finished |
| 101 | + |
| 102 | +# Create the version string |
| 103 | +pushd chromium/src |
| 104 | +DATE=$(date +"%Y%m%d") |
| 105 | +GITHASH=$(git rev-parse --short HEAD) |
| 106 | +VERSION="1.0.0-${DATE}+${GITHASH}" |
| 107 | +popd |
| 108 | + |
| 109 | +# Build the Debian package on Linux |
| 110 | +if [ "$(uname -s)" = "Linux" ]; then |
| 111 | + status "[*] Creating Debian package" |
| 112 | + |
| 113 | + # Copy the packaging template into the workspace |
| 114 | + rm -rf courgette |
| 115 | + cp -r "$(dirname "$0")"/deb-package courgette |
| 116 | + |
| 117 | + # Copy the Courgette binary into the package |
| 118 | + mkdir -p courgette/usr/bin |
| 119 | + cp chromium/src/out/Default/courgette courgette/usr/bin |
| 120 | + |
| 121 | + # Copy all built libraries it depends on in as well |
| 122 | + mkdir -p courgette/usr/lib |
| 123 | + LIBDEPS=$(ldd chromium/src/out/Default/courgette \ |
| 124 | + | grep 'chromium' \ |
| 125 | + | awk '{ print $3 }') |
| 126 | + cp $LIBDEPS courgette/usr/lib |
| 127 | + |
| 128 | + # Patch up the control file |
| 129 | + ARCH=$(dpkg --print-architecture) |
| 130 | + sed -i \ |
| 131 | + -e "s/@VERSION@/$VERSION/g" \ |
| 132 | + -e "s/@ARCH@/$ARCH/g" \ |
| 133 | + courgette/DEBIAN/control |
| 134 | + |
| 135 | + # Build the package |
| 136 | + dpkg-deb --build courgette |
| 137 | + mv courgette.deb "courgette-linux_${VERSION}_${ARCH}.deb" |
| 138 | + rm -rf courgette |
| 139 | +fi |
18 | 140 |
|
19 |
| -# Build the Debian package |
20 |
| -mkdir -p /root/courgette/usr/bin /root/courgette/usr/lib |
21 |
| -cp out/Default/courgette /root/courgette/usr/bin |
22 |
| -cp $(ldd out/Default/courgette | grep '/root' | awk '{ print $3 }') \ |
23 |
| - /root/courgette/usr/lib |
24 |
| -sed -i "s/@GITHASH@/$GITHASH/g" \ |
25 |
| - /root/courgette/DEBIAN/control |
26 |
| -dpkg-deb --build /root/courgette |
27 |
| -mv /root/courgette.deb /root/out/courgette-${GITHASH}.deb |
28 |
| - |
29 |
| -# Install the Debian package and test it |
30 |
| -dpkg -i /root/out/courgette-*.deb |
31 |
| -courgette --help 2>&1 | grep -q 'genbsdiff' |
| 141 | +# Build a zip archive on macOS |
| 142 | +if [ "$(uname -s)" = "Darwin" ]; then |
| 143 | + status "[*] Creating archive" |
| 144 | + |
| 145 | + # Create the archive directory |
| 146 | + rm -rf courgette |
| 147 | + mkdir courgette |
| 148 | + |
| 149 | + # Copy the courgette binary into the directory |
| 150 | + cp chromium/src/out/Default/courgette courgette |
| 151 | + LIBDEPS=$(otool -L chromium/src/out/Default/courgette \ |
| 152 | + | grep '@rpath' \ |
| 153 | + | awk '{ print $1 }' \ |
| 154 | + | sed 's,@rpath/,chromium/src/out/Default/,g') |
| 155 | + cp $LIBDEPS courgette |
| 156 | + |
| 157 | + # Make the zip archive |
| 158 | + ARCH=$(uname -m) |
| 159 | + zip -r "courgette-mac_${VERSION}_${ARCH}.zip" courgette |
| 160 | + rm -rf courgette |
| 161 | +fi |
0 commit comments