playwright/browser_patches/webkit/archive.sh
Andrey Lushnikov d93abcbe42
devops: fix webkit builds (#15546)
This patch:
* removes "deterministic" argument from `rdfind` on Ubuntu 18.04.
  `rdfind` is a new addition, but it's nice to have since it saves 10%
  of the archive size.
* drops `stdc++fs` from dependencies. This doesn't seem to be necessary
  for JHBuild but breaks universal build.

Pretty diff: 256392e8c4
2022-07-11 14:40:23 -07:00

162 lines
4.9 KiB
Bash
Executable File

#!/bin/bash
set -e
set +x
if [[ ("$1" == "-h") || ("$1" == "--help") ]]; then
echo "usage: $(basename "$0") [output-absolute-path] [--universal]"
echo
echo "Generate distributable .zip archive from ./checkout folder that was previously built."
echo
exit 0
fi
ZIP_PATH=$1
if [[ $ZIP_PATH != /* ]]; then
echo "ERROR: path $ZIP_PATH is not absolute"
exit 1
fi
if [[ $ZIP_PATH != *.zip ]]; then
echo "ERROR: path $ZIP_PATH must have .zip extension"
exit 1
fi
if [[ -f $ZIP_PATH ]]; then
echo "ERROR: path $ZIP_PATH exists; can't do anything."
exit 1
fi
if ! [[ -d $(dirname "$ZIP_PATH") ]]; then
echo "ERROR: folder for path $($ZIP_PATH) does not exist."
exit 1
fi
IS_UNIVERSAL=""
if [[ $2 == "--universal" ]]; then
IS_UNIVERSAL=1
fi
main() {
if [[ ! -z "${WK_CHECKOUT_PATH}" ]]; then
cd "${WK_CHECKOUT_PATH}"
echo "WARNING: checkout path from WK_CHECKOUT_PATH env: ${WK_CHECKOUT_PATH}"
else
cd "$HOME/webkit"
fi
set -x
if is_mac; then
createZipForMac
elif is_linux; then
createZipForLinux
elif is_win; then
createZipForWindows
else
echo "ERROR: cannot upload on this platform!" 1>&2
exit 1;
fi
}
createZipForLinux() {
# create a TMP directory to copy all necessary files
local tmpdir=$(mktemp -d -p "$(pwd)/WebKitBuild" -t webkit-deploy-XXXXXXXXXX)
mkdir -p "$tmpdir"
# copy runner
cp -t "$tmpdir" "$SCRIPTS_DIR"/pw_run.sh
# copy protocol
node "$SCRIPTS_DIR"/concat_protocol.js > "$tmpdir"/protocol.json
# Generate and unpack MiniBrowser bundles for each port
for port in gtk wpe; do
if [[ -n "${IS_UNIVERSAL}" ]]; then
Tools/Scripts/generate-bundle \
--syslibs=bundle-all \
--bundle=MiniBrowser --release \
--platform=${port} --destination="${tmpdir}"
else
WEBKIT_OUTPUTDIR=$(pwd)/WebKitBuild/${port^^} \
Tools/Scripts/generate-bundle \
--bundle=MiniBrowser --release \
--platform=${port} --destination="${tmpdir}"
fi
unzip "${tmpdir}"/MiniBrowser_${port}_release.zip -d "${tmpdir}"/minibrowser-${port}
rm -f "${tmpdir}"/MiniBrowser_${port}_release.zip
done
cd "$tmpdir"
# De-duplicate common files: convert to relative symlinks identical files (same hash).
# Note: ubuntu 18.04 does not support "deterministic" argument.
local CURRENT_HOST_OS="$(bash -c 'source /etc/os-release && echo $NAME')"
local CURRENT_HOST_OS_VERSION="$(bash -c 'source /etc/os-release && echo $VERSION_ID')"
if [[ "${CURRENT_HOST_OS}" == "Ubuntu" && "${CURRENT_HOST_OS_VERSION}" == "18.04" ]]; then
rdfind -makesymlinks true -makehardlinks false -makeresultsfile false .
else
rdfind -deterministic true -makesymlinks true -makehardlinks false -makeresultsfile false .
fi
symlinks -rc .
# zip resulting directory and cleanup TMP.
zip --symlinks -r "$ZIP_PATH" ./
cd -
rm -rf "$tmpdir"
}
createZipForWindows() {
# create a TMP directory to copy all necessary files
local tmpdir="/tmp/webkit-deploy-$(date +%s)"
mkdir -p "$tmpdir"
cp -t "$tmpdir" ./WebKitLibraries/win/bin64/*.dll
cd WebKitBuild/Release/bin64
cp -r -t "$tmpdir" WebKit.resources
cp -t "$tmpdir" JavaScriptCore.dll PlaywrightLib.dll WTF.dll WebKit2.dll libEGL.dll libGLESv2.dll
cp -t "$tmpdir" Playwright.exe WebKitNetworkProcess.exe WebKitWebProcess.exe
cd -
cd "$(printMSVCRedistDir)"
cp -t "$tmpdir" msvcp140.dll vcruntime140.dll vcruntime140_1.dll msvcp140_2.dll
cd -
# copy protocol
node "$SCRIPTS_DIR"/concat_protocol.js > "$tmpdir"/protocol.json
# tar resulting directory and cleanup TMP.
cd "$tmpdir"
zip -r "$ZIP_PATH" ./
cd -
rm -rf "$tmpdir"
}
createZipForMac() {
# create a TMP directory to copy all necessary files
local tmpdir=$(mktemp -d)
# copy all relevant files
ditto {./WebKitBuild/Release,"$tmpdir"}/com.apple.WebKit.GPU.xpc
ditto {./WebKitBuild/Release,"$tmpdir"}/com.apple.WebKit.Networking.xpc
ditto {./WebKitBuild/Release,"$tmpdir"}/com.apple.WebKit.WebContent.xpc
ditto {./WebKitBuild/Release,"$tmpdir"}/JavaScriptCore.framework
ditto {./WebKitBuild/Release,"$tmpdir"}/libANGLE-shared.dylib
ditto {./WebKitBuild/Release,"$tmpdir"}/libwebrtc.dylib
ditto {./WebKitBuild/Release,"$tmpdir"}/Playwright.app
ditto {./WebKitBuild/Release,"$tmpdir"}/WebCore.framework
ditto {./WebKitBuild/Release,"$tmpdir"}/WebInspectorUI.framework
ditto {./WebKitBuild/Release,"$tmpdir"}/WebKit.framework
ditto {./WebKitBuild/Release,"$tmpdir"}/WebKitLegacy.framework
ditto {"$SCRIPTS_DIR","$tmpdir"}/pw_run.sh
# copy protocol
node "$SCRIPTS_DIR"/concat_protocol.js > "$tmpdir"/protocol.json
# Remove all broken symlinks. @see https://github.com/microsoft/playwright/issues/5472
find "${tmpdir}" -type l ! -exec test -e {} \; -print | xargs rm
# zip resulting directory and cleanup TMP.
ditto -c -k "$tmpdir" "$ZIP_PATH"
rm -rf "$tmpdir"
}
trap "cd $(pwd -P)" EXIT
cd "$(dirname "$0")"
SCRIPTS_DIR="$(pwd -P)"
source "${SCRIPTS_DIR}/../utils.sh"
main "$@"