2019-11-22 04:06:57 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set +x
|
|
|
|
|
|
|
|
trap "cd $(pwd -P)" EXIT
|
|
|
|
cd "$(dirname "$0")"
|
2021-02-18 01:43:19 +03:00
|
|
|
SCRIPT_PATH=$(pwd -P)
|
2019-11-22 04:06:57 +03:00
|
|
|
|
2022-04-22 22:35:35 +03:00
|
|
|
source "${SCRIPT_PATH}/utils.sh"
|
|
|
|
|
2019-11-22 04:06:57 +03:00
|
|
|
REMOTE_BROWSER_UPSTREAM="browser_upstream"
|
|
|
|
BUILD_BRANCH="playwright-build"
|
|
|
|
|
|
|
|
if [[ ($1 == '--help') || ($1 == '-h') ]]; then
|
2021-08-07 15:32:18 +03:00
|
|
|
echo "usage: $(basename "$0") [firefox|firefox-beta|webkit] [custom_checkout_path]"
|
2019-11-22 04:06:57 +03:00
|
|
|
echo
|
|
|
|
echo "Prepares browser checkout. The checkout is a GIT repository that:"
|
|
|
|
echo "- has a '$REMOTE_BROWSER_UPSTREAM' remote pointing to a REMOTE_URL from UPSTREAM_CONFIG.sh"
|
|
|
|
echo "- has a '$BUILD_BRANCH' branch that is BASE_REVISION with all the patches applied."
|
|
|
|
echo
|
|
|
|
echo "You can optionally specify custom_checkout_path if you want to use some other browser checkout"
|
|
|
|
echo
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
echo "missing browser: 'firefox' or 'webkit'"
|
2021-08-07 15:32:18 +03:00
|
|
|
echo "try './$(basename "$0") --help' for more information"
|
2019-11-22 04:06:57 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-04-05 11:24:49 +03:00
|
|
|
function maybe_cmd {
|
2022-04-22 22:35:35 +03:00
|
|
|
if is_win; then
|
2022-04-05 11:24:49 +03:00
|
|
|
local args="$@"
|
|
|
|
/c/Windows/System32/cmd.exe "/c $args"
|
|
|
|
else
|
|
|
|
$@
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-02-18 01:43:19 +03:00
|
|
|
function prepare_chromium_checkout {
|
|
|
|
cd "${SCRIPT_PATH}"
|
2021-02-20 01:23:09 +03:00
|
|
|
|
2022-04-21 08:38:26 +03:00
|
|
|
if [[ $1 == "chromium" ]]; then
|
|
|
|
source "${SCRIPT_PATH}/chromium/UPSTREAM_CONFIG.sh"
|
|
|
|
elif [[ "$1" == "chromium-tot" ]]; then
|
|
|
|
source "${SCRIPT_PATH}/chromium-tip-of-tree/UPSTREAM_CONFIG.sh"
|
|
|
|
else
|
|
|
|
echo "ERROR: unknown type of checkout to prepare - $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-02-20 01:23:09 +03:00
|
|
|
source "${SCRIPT_PATH}/chromium/ensure_depot_tools.sh"
|
|
|
|
|
2021-02-18 01:43:19 +03:00
|
|
|
if [[ -z "${CR_CHECKOUT_PATH}" ]]; then
|
2021-10-28 21:48:57 +03:00
|
|
|
CR_CHECKOUT_PATH="$HOME/chromium"
|
2021-02-18 01:43:19 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Update Chromium checkout.
|
|
|
|
#
|
2021-11-12 21:23:22 +03:00
|
|
|
# This is based on https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md#get-the-code
|
2021-10-28 21:48:57 +03:00
|
|
|
if [[ ! -d "${CR_CHECKOUT_PATH}" ]]; then
|
2021-02-18 01:43:19 +03:00
|
|
|
rm -rf "${CR_CHECKOUT_PATH}"
|
|
|
|
mkdir -p "${CR_CHECKOUT_PATH}"
|
|
|
|
cd "${CR_CHECKOUT_PATH}"
|
2022-04-05 11:24:49 +03:00
|
|
|
maybe_cmd fetch --nohooks chromium
|
2021-02-18 01:43:19 +03:00
|
|
|
cd src
|
2022-04-22 22:35:35 +03:00
|
|
|
if is_linux; then
|
2021-11-02 13:23:15 +03:00
|
|
|
./build/install-build-deps.sh
|
2021-02-18 01:43:19 +03:00
|
|
|
fi
|
2022-04-05 11:24:49 +03:00
|
|
|
maybe_cmd gclient runhooks
|
2021-02-18 01:43:19 +03:00
|
|
|
fi
|
2021-10-28 21:48:57 +03:00
|
|
|
if [[ ! -d "${CR_CHECKOUT_PATH}/src" ]]; then
|
|
|
|
echo "ERROR: CR_CHECKOUT_PATH does not have src/ subfolder; is this a chromium checkout?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-02-18 01:43:19 +03:00
|
|
|
cd "${CR_CHECKOUT_PATH}/src"
|
2022-04-05 11:24:49 +03:00
|
|
|
maybe_cmd gclient sync --with_branch_heads
|
2022-04-05 00:33:23 +03:00
|
|
|
git fetch origin
|
|
|
|
git checkout "${BRANCH_COMMIT}"
|
2022-04-05 11:24:49 +03:00
|
|
|
maybe_cmd gclient sync -D --with_branch_heads
|
2021-02-18 01:43:19 +03:00
|
|
|
}
|
|
|
|
|
2019-11-22 04:06:57 +03:00
|
|
|
# FRIENDLY_CHECKOUT_PATH is used only for logging.
|
|
|
|
FRIENDLY_CHECKOUT_PATH="";
|
|
|
|
CHECKOUT_PATH=""
|
2019-11-24 03:22:04 +03:00
|
|
|
PATCHES_PATH=""
|
2019-12-10 00:16:27 +03:00
|
|
|
BUILD_NUMBER=""
|
2020-06-03 02:51:13 +03:00
|
|
|
WEBKIT_EXTRA_FOLDER_PATH=""
|
|
|
|
FIREFOX_EXTRA_FOLDER_PATH=""
|
2020-08-08 02:22:05 +03:00
|
|
|
if [[ ("$1" == "chromium") || ("$1" == "chromium/") || ("$1" == "cr") ]]; then
|
2022-04-21 08:38:26 +03:00
|
|
|
prepare_chromium_checkout chromium
|
|
|
|
exit 0
|
|
|
|
elif [[ ("$1" == "chromium-tip-of-tree") || ("$1" == "chromium-tot") || ("$1" == "cr-tot") ]]; then
|
|
|
|
prepare_chromium_checkout chromium-tot
|
2020-09-10 03:05:08 +03:00
|
|
|
exit 0
|
|
|
|
elif [[ ("$1" == "ffmpeg") || ("$1" == "ffmpeg/") ]]; then
|
|
|
|
echo "FYI: ffmpeg checkout is not supported. Use '//browser_patches/ffmpeg/build.sh' instead"
|
2020-08-08 02:22:05 +03:00
|
|
|
exit 0
|
2020-09-18 20:30:53 +03:00
|
|
|
elif [[ ("$1" == "winldd") || ("$1" == "winldd/") ]]; then
|
|
|
|
echo "FYI: winldd source code is available right away"
|
|
|
|
exit 0
|
2020-08-08 02:22:05 +03:00
|
|
|
elif [[ ("$1" == "firefox") || ("$1" == "firefox/") || ("$1" == "ff") ]]; then
|
2021-10-14 20:20:06 +03:00
|
|
|
if [[ -z "${FF_CHECKOUT_PATH}" ]]; then
|
|
|
|
FRIENDLY_CHECKOUT_PATH='$HOME/firefox';
|
|
|
|
CHECKOUT_PATH="$HOME/firefox"
|
|
|
|
else
|
|
|
|
echo "WARNING: using checkout path from FF_CHECKOUT_PATH env: ${FF_CHECKOUT_PATH}"
|
|
|
|
CHECKOUT_PATH="${FF_CHECKOUT_PATH}"
|
|
|
|
FRIENDLY_CHECKOUT_PATH="<FF_CHECKOUT_PATH>"
|
|
|
|
fi
|
|
|
|
|
2019-11-24 03:22:04 +03:00
|
|
|
PATCHES_PATH="$PWD/firefox/patches"
|
2020-06-03 02:51:13 +03:00
|
|
|
FIREFOX_EXTRA_FOLDER_PATH="$PWD/firefox/juggler"
|
2020-07-02 22:09:27 +03:00
|
|
|
BUILD_NUMBER=$(head -1 "$PWD/firefox/BUILD_NUMBER")
|
2019-11-22 04:06:57 +03:00
|
|
|
source "./firefox/UPSTREAM_CONFIG.sh"
|
2021-10-14 20:20:06 +03:00
|
|
|
elif [[ ("$1" == "firefox-beta") || ("$1" == "ff-beta") ]]; then
|
|
|
|
# NOTE: firefox-beta re-uses firefox checkout.
|
|
|
|
if [[ -z "${FF_CHECKOUT_PATH}" ]]; then
|
|
|
|
FRIENDLY_CHECKOUT_PATH='$HOME/firefox';
|
|
|
|
CHECKOUT_PATH="$HOME/firefox"
|
|
|
|
else
|
2020-12-05 05:46:20 +03:00
|
|
|
echo "WARNING: using checkout path from FF_CHECKOUT_PATH env: ${FF_CHECKOUT_PATH}"
|
|
|
|
CHECKOUT_PATH="${FF_CHECKOUT_PATH}"
|
|
|
|
FRIENDLY_CHECKOUT_PATH="<FF_CHECKOUT_PATH>"
|
|
|
|
fi
|
2021-05-05 03:46:24 +03:00
|
|
|
|
2021-06-08 03:05:51 +03:00
|
|
|
PATCHES_PATH="$PWD/firefox-beta/patches"
|
|
|
|
FIREFOX_EXTRA_FOLDER_PATH="$PWD/firefox-beta/juggler"
|
|
|
|
BUILD_NUMBER=$(head -1 "$PWD/firefox-beta/BUILD_NUMBER")
|
|
|
|
source "./firefox-beta/UPSTREAM_CONFIG.sh"
|
2020-03-24 23:22:46 +03:00
|
|
|
elif [[ ("$1" == "webkit") || ("$1" == "webkit/") || ("$1" == "wk") ]]; then
|
2021-10-14 20:20:06 +03:00
|
|
|
if [[ -z "${WK_CHECKOUT_PATH}" ]]; then
|
|
|
|
FRIENDLY_CHECKOUT_PATH='$HOME/webkit';
|
|
|
|
CHECKOUT_PATH="$HOME/webkit"
|
|
|
|
else
|
2020-12-07 19:42:20 +03:00
|
|
|
echo "WARNING: using checkout path from WK_CHECKOUT_PATH env: ${WK_CHECKOUT_PATH}"
|
|
|
|
CHECKOUT_PATH="${WK_CHECKOUT_PATH}"
|
|
|
|
FRIENDLY_CHECKOUT_PATH="<WK_CHECKOUT_PATH>"
|
|
|
|
fi
|
2021-10-14 20:20:06 +03:00
|
|
|
|
|
|
|
PATCHES_PATH="$PWD/webkit/patches"
|
|
|
|
WEBKIT_EXTRA_FOLDER_PATH="$PWD/webkit/embedder/Playwright"
|
|
|
|
BUILD_NUMBER=$(head -1 "$PWD/webkit/BUILD_NUMBER")
|
|
|
|
source "./webkit/UPSTREAM_CONFIG.sh"
|
2019-11-22 04:06:57 +03:00
|
|
|
else
|
|
|
|
echo ERROR: unknown browser - "$1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if there's no checkout folder - checkout one.
|
|
|
|
if ! [[ -d $CHECKOUT_PATH ]]; then
|
|
|
|
echo "-- $FRIENDLY_CHECKOUT_PATH is missing - checking out.."
|
2021-05-05 11:12:03 +03:00
|
|
|
if [[ -n "$CI" ]]; then
|
|
|
|
# In CI environment, we re-checkout constantly, so we do a shallow checkout to save time.
|
2021-08-07 15:32:18 +03:00
|
|
|
git clone --single-branch --depth 1 --branch "$BASE_BRANCH" "$REMOTE_URL" "$CHECKOUT_PATH"
|
2021-05-05 11:12:03 +03:00
|
|
|
else
|
|
|
|
# In non-CI environment, do a full checkout. This takes time,
|
|
|
|
# but liberates from the `git fetch --unshallow`.
|
2021-08-07 15:32:18 +03:00
|
|
|
git clone --single-branch --branch "$BASE_BRANCH" "$REMOTE_URL" "$CHECKOUT_PATH"
|
2021-05-05 11:12:03 +03:00
|
|
|
fi
|
2019-11-22 04:06:57 +03:00
|
|
|
else
|
|
|
|
echo "-- checking $FRIENDLY_CHECKOUT_PATH folder - OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if folder exists but not a git repository - bail out.
|
|
|
|
if ! [[ -d $CHECKOUT_PATH/.git ]]; then
|
|
|
|
echo "ERROR: $FRIENDLY_CHECKOUT_PATH is not a git repository! Remove it and re-run the script."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "-- checking $FRIENDLY_CHECKOUT_PATH is a git repo - OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ============== SETTING UP GIT REPOSITORY ==============
|
2021-08-07 15:32:18 +03:00
|
|
|
cd "$CHECKOUT_PATH"
|
2019-11-22 04:06:57 +03:00
|
|
|
|
|
|
|
# Bail out if git repo is dirty.
|
2019-12-02 23:58:44 +03:00
|
|
|
if [[ -n $(git status -s --untracked-files=no) ]]; then
|
2019-11-22 04:06:57 +03:00
|
|
|
echo "ERROR: $FRIENDLY_CHECKOUT_PATH has dirty GIT state - commit everything and re-run the script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Setting up |$REMOTE_BROWSER_UPSTREAM| remote and fetch the $BASE_BRANCH
|
|
|
|
if git remote get-url $REMOTE_BROWSER_UPSTREAM >/dev/null; then
|
|
|
|
echo "-- setting |$REMOTE_BROWSER_UPSTREAM| remote url to $REMOTE_URL"
|
2021-08-07 15:32:18 +03:00
|
|
|
git remote set-url $REMOTE_BROWSER_UPSTREAM "$REMOTE_URL"
|
2019-11-22 04:06:57 +03:00
|
|
|
else
|
|
|
|
echo "-- adding |$REMOTE_BROWSER_UPSTREAM| remote to $REMOTE_URL"
|
2021-08-06 22:01:41 +03:00
|
|
|
git remote rename origin $REMOTE_BROWSER_UPSTREAM
|
2019-11-22 04:06:57 +03:00
|
|
|
fi
|
|
|
|
|
2022-05-16 19:32:22 +03:00
|
|
|
# if our remote branch does not contains "BASE_REVISION" - then fetch more stuff.
|
|
|
|
if [[ -z $(git branch -r --contains "${BASE_REVISION}" --list "${REMOTE_BROWSER_UPSTREAM}/${BASE_BRANCH}") ]]; then
|
2020-11-05 13:04:06 +03:00
|
|
|
# Detach git head so that we can fetch into branch.
|
|
|
|
git checkout --detach >/dev/null 2>/dev/null
|
|
|
|
|
2021-10-28 21:07:22 +03:00
|
|
|
if [[ -z "$CI" ]]; then
|
|
|
|
# On non-CI, fetch everything.
|
|
|
|
git fetch "$REMOTE_BROWSER_UPSTREAM" "$BASE_BRANCH"
|
|
|
|
else
|
|
|
|
# On CI, fetch from REMOTE_BROWSER_UPSTREAM more and more commits
|
|
|
|
# until we find $BASE_REVISION.
|
|
|
|
# This technique allows us start with a shallow clone.
|
|
|
|
|
|
|
|
# Fetch 128 commits first, and then double the amount every iteration.
|
|
|
|
FETCH_DEPTH=128
|
|
|
|
SUCCESS="no"
|
|
|
|
while (( FETCH_DEPTH <= 8192 )); do
|
|
|
|
echo "Fetching ${FETCH_DEPTH} commits to find base revision..."
|
|
|
|
git fetch --depth "${FETCH_DEPTH}" "$REMOTE_BROWSER_UPSTREAM" "$BASE_BRANCH"
|
|
|
|
FETCH_DEPTH=$(( FETCH_DEPTH * 2 ));
|
|
|
|
if git cat-file -e "$BASE_REVISION"^{commit} >/dev/null; then
|
|
|
|
SUCCESS="yes"
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ "${SUCCESS}" == "no" ]]; then
|
|
|
|
echo "ERROR: $FRIENDLY_CHECKOUT_PATH/ does not include the BASE_REVISION (@$BASE_REVISION). Wrong revision number?"
|
|
|
|
exit 1
|
2020-11-05 13:04:06 +03:00
|
|
|
fi
|
|
|
|
fi
|
2019-11-22 04:06:57 +03:00
|
|
|
fi
|
2020-05-13 01:20:12 +03:00
|
|
|
|
2019-12-10 00:16:27 +03:00
|
|
|
echo "-- checking $FRIENDLY_CHECKOUT_PATH repo has BASE_REVISION (@$BASE_REVISION) commit - OK"
|
2019-11-22 04:06:57 +03:00
|
|
|
|
|
|
|
# Check out the $BASE_REVISION
|
2021-08-07 15:32:18 +03:00
|
|
|
git checkout "$BASE_REVISION"
|
2019-11-22 04:06:57 +03:00
|
|
|
|
|
|
|
# Create a playwright-build branch and apply all the patches to it.
|
|
|
|
if git show-ref --verify --quiet refs/heads/playwright-build; then
|
|
|
|
git branch -D playwright-build
|
|
|
|
fi
|
|
|
|
git checkout -b playwright-build
|
2019-12-10 00:16:27 +03:00
|
|
|
echo "-- applying patches"
|
2021-08-07 15:32:18 +03:00
|
|
|
git apply --index --whitespace=nowarn "$PATCHES_PATH"/*
|
2020-04-22 20:52:17 +03:00
|
|
|
|
2020-06-03 02:51:13 +03:00
|
|
|
if [[ ! -z "${WEBKIT_EXTRA_FOLDER_PATH}" ]]; then
|
|
|
|
echo "-- adding WebKit embedders"
|
2020-11-04 22:20:47 +03:00
|
|
|
EMBEDDER_DIR="$PWD/Tools/Playwright"
|
|
|
|
# git status does not show empty directories, check it separately.
|
2022-05-03 22:45:26 +03:00
|
|
|
# XCode 13 and WebKit build on MacOS 12 now create empty folder here:
|
|
|
|
# ./Tools/Playwright/Playwright.xcodeproj/project.xcworkspace/xcshareddata/swiftpm
|
|
|
|
# As an easy work-around, let's remove it.
|
2020-11-04 22:20:47 +03:00
|
|
|
if [[ -d $EMBEDDER_DIR ]]; then
|
2022-05-03 22:45:26 +03:00
|
|
|
rm -rf "$EMBEDDER_DIR"
|
2020-11-04 22:20:47 +03:00
|
|
|
fi
|
2021-08-07 15:32:18 +03:00
|
|
|
cp -r "${WEBKIT_EXTRA_FOLDER_PATH}" "$EMBEDDER_DIR"
|
|
|
|
git add "$EMBEDDER_DIR"
|
2020-06-03 02:51:13 +03:00
|
|
|
elif [[ ! -z "${FIREFOX_EXTRA_FOLDER_PATH}" ]]; then
|
|
|
|
echo "-- adding juggler"
|
2020-11-04 22:20:47 +03:00
|
|
|
EMBEDDER_DIR="$PWD/juggler"
|
|
|
|
# git status does not show empty directories, check it separately.
|
2022-05-03 22:45:26 +03:00
|
|
|
# Remove for good if its empty but exists.
|
2020-11-04 22:20:47 +03:00
|
|
|
if [[ -d $EMBEDDER_DIR ]]; then
|
2022-05-03 22:45:26 +03:00
|
|
|
rm -rf "$EMBEDDER_DIR"
|
2020-11-04 22:20:47 +03:00
|
|
|
fi
|
2021-08-07 15:32:18 +03:00
|
|
|
cp -r "${FIREFOX_EXTRA_FOLDER_PATH}" "$EMBEDDER_DIR"
|
|
|
|
git add "$EMBEDDER_DIR"
|
2020-04-22 20:52:17 +03:00
|
|
|
fi
|
|
|
|
|
2021-05-05 03:46:24 +03:00
|
|
|
git commit -a --author="playwright-devops <devops@playwright.dev>" -m "chore($1): bootstrap build #$BUILD_NUMBER"
|
2019-11-22 04:06:57 +03:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "DONE. Browser is ready to be built."
|