Repository navigation
Expand file tree
/
Copy pathdownload_v8.sh
More file actions
executable file
·159 lines (137 loc) · 5.42 KB
/
Copy pathdownload_v8.sh
File metadata and controls
executable file
·159 lines (137 loc) · 5.42 KB
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
#!/bin/bash
set -euo pipefail
#
# Installs the prebuilt V8 libraries and headers for the pinned release.
#
# The artifacts are built by NativeScript/v8-buildscripts and published as
# GitHub release assets; they are not committed here because two of the four
# monoliths exceed GitHub's 100 MiB per-file push limit, and because the full
# matrix cannot be produced on any single machine.
#
# Deliberately a standalone script rather than a Gradle task: it is a
# prerequisite you run once, trivial to skip when you already have the
# artifacts, and easy to override with a local V8 build.
#
# Set V8_SKIP_DOWNLOAD=1 to make it a no-op -- use that when you have built V8
# yourself and do not want a pinned release overwriting it.
#
# Usage: download_v8.sh [--release <tag>] [--abi <abi>]... [--force]
#
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
UPSTREAM="NativeScript/v8-buildscripts"
RELEASE_FILE="$REPO_ROOT/V8_RELEASE"
CACHE_DIR="${V8_PREBUILT_CACHE:-$REPO_ROOT/.v8-prebuilt}"
CPP_DIR="$REPO_ROOT/test-app/runtime/src/main/cpp"
LIBS_DIR="$REPO_ROOT/test-app/runtime/src/main/libs"
STAMP="$LIBS_DIR/.v8-release-stamp"
RELEASE=""
FORCE=0
ABIS=()
usage() {
cat <<EOF
Usage: $(basename "$0") [--release <tag>] [--abi <abi>]... [--force]
--release <tag> Release to install (default: contents of V8_RELEASE)
--abi <abi> Repeatable. armeabi-v7a, arm64-v8a, x86, x86_64
(default: all four)
--force Reinstall even if the pinned release is already in place
Downloads are cached in $CACHE_DIR (override with \$V8_PREBUILT_CACHE).
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--release) RELEASE="$2"; shift 2 ;;
--release=*) RELEASE="${1#*=}"; shift ;;
--abi) ABIS+=("$2"); shift 2 ;;
--abi=*) ABIS+=("${1#*=}"); shift ;;
--force) FORCE=1; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown argument: $1" >&2; usage >&2; exit 1 ;;
esac
done
if [ "${V8_SKIP_DOWNLOAD:-0}" != "0" ]; then
echo "V8_SKIP_DOWNLOAD is set; leaving the libraries and headers alone."
exit 0
fi
if [ -z "$RELEASE" ]; then
[ -f "$RELEASE_FILE" ] || { echo "Missing $RELEASE_FILE" >&2; exit 1; }
RELEASE="$(tr -d '[:space:]' < "$RELEASE_FILE")"
fi
[ ${#ABIS[@]} -gt 0 ] || ABIS=(arm64-v8a armeabi-v7a x86_64 x86)
# The stamp records which release was installed, not which ABIs were asked for,
# so a previous --abi run must not satisfy a later request for the full set.
# The installed files are the source of truth.
installed() {
[ -f "$STAMP" ] && [ "$(cat "$STAMP")" = "$RELEASE" ] || return 1
[ -f "$CPP_DIR/include/v8.h" ] && [ -d "$CPP_DIR/v8_inspector/src" ] || return 1
for abi in "${ABIS[@]}"; do
[ -f "$LIBS_DIR/$abi/libv8_monolith.a" ] || return 1
done
}
if [ "$FORCE" = "0" ] && installed; then
echo "V8 $RELEASE already installed for ${ABIS[*]}. Use --force to reinstall."
exit 0
fi
BASE_URL="https://github.com/$UPSTREAM/releases/download/$RELEASE"
DL="$CACHE_DIR/$RELEASE"
mkdir -p "$DL"
fetch() {
local name="$1"
if [ -f "$DL/$name" ]; then return 0; fi
echo " downloading $name"
curl -fSL --retry 3 -o "$DL/$name.part" "$BASE_URL/$name"
mv "$DL/$name.part" "$DL/$name"
}
echo "Installing V8 $RELEASE from $UPSTREAM"
fetch SHA256SUMS
ASSETS=()
for ABI in "${ABIS[@]}"; do
ASSETS+=("$(grep -oE "v8-[^ ]*-android-$ABI\.tar\.gz" "$DL/SHA256SUMS" | head -1)")
done
ASSETS+=("$(grep -oE 'v8-[^ ]*-src-headers\.tar\.gz' "$DL/SHA256SUMS" | head -1)")
for a in "${ASSETS[@]}"; do
[ -n "$a" ] || { echo "Release $RELEASE is missing an expected asset." >&2; exit 1; }
fetch "$a"
done
# Verify before unpacking anything. A release is only trustworthy because the
# archive matches the checksum published with it.
#
# Linux has sha256sum, macOS has shasum; neither has both reliably.
if command -v sha256sum > /dev/null 2>&1; then
SHA256_CHECK="sha256sum -c -"
else
SHA256_CHECK="shasum -a 256 -c -"
fi
echo "Verifying checksums"
( cd "$DL" && grep -E "$(printf '%s|' "${ASSETS[@]}" | sed 's/|$//')" SHA256SUMS | $SHA256_CHECK ) \
|| { echo "Checksum verification FAILED for $RELEASE" >&2; exit 1; }
STAGE="$(mktemp -d)"
trap 'rm -rf "$STAGE"' EXIT
for a in "${ASSETS[@]}"; do tar -xzf "$DL/$a" -C "$STAGE"; done
echo "Installing libraries"
for ABI in "${ABIS[@]}"; do
src="$STAGE/android-$ABI/lib/libv8_monolith.a"
[ -f "$src" ] || { echo "Archive for $ABI has no libv8_monolith.a" >&2; exit 1; }
mkdir -p "$LIBS_DIR/$ABI"
cp "$src" "$LIBS_DIR/$ABI/libv8_monolith.a"
done
echo "Installing public headers"
# zip.h/zipconf.h belong to libzip and live in the same directory, so the V8
# headers are replaced selectively rather than by wiping include/.
FIRST_ABI="${ABIS[0]}"
SRC_INC="$STAGE/android-$FIRST_ABI/include"
[ -d "$SRC_INC" ] || { echo "Archive has no include/" >&2; exit 1; }
for entry in cppgc libplatform inspector; do
rm -rf "${CPP_DIR:?}/include/$entry"
done
find "$CPP_DIR/include" -maxdepth 1 -type f \
! -name 'zip.h' ! -name 'zipconf.h' -delete
cp -R "$SRC_INC/." "$CPP_DIR/include/"
echo "Vendoring the inspector's V8 internals"
# The closure is computed here rather than shipped, because what the glue
# includes is this repo's business, not the build repo's.
python3 "$REPO_ROOT/tools/v8/vendor_inspector_sources.py" \
--v8-dir "$STAGE/src-headers" \
--gen-dir "$STAGE/src-headers" \
--dest "$CPP_DIR/v8_inspector"
echo "$RELEASE" > "$STAMP"
echo "Installed V8 $RELEASE"