-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·254 lines (213 loc) · 6.45 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
# V8 Library Build Script
### docker run -it -v $(pwd):/usr/src/libv8-packaging/ debian:bookworm bash -c "cd /usr/src/libv8-packaging/ && bash"
### ./build.sh --install-deps --setup-pyenv
### ./build.sh --build-number 42 --output-dir /root/DEB/
### shfmt -w -s -ci -sr -kp -fn build.sh
echo "Preparing environment..."
handle_error()
{
echo "Error occurred at line $1"
if [ -n "$BUILD_DIR" ] && [[ $BUILD_DIR == /tmp/* ]]; then
echo "Cleaning up temporary build directory: $BUILD_DIR"
rm -rf "$BUILD_DIR"
fi
exit 1
}
set -e
set -o pipefail
trap 'handle_error $LINENO' ERR
if [ "$(id -u)" -ne 0 ]; then
echo "WARNING: This script may require root privileges to install packages and modify system files."
echo "Consider running with sudo if you encounter permission errors."
echo ""
fi
usage()
{
echo "Usage: $0 [--build-number <num>] [--source-dir <dir>] [--pyenv-root <dir>] [--output-dir <dir>] [--install-deps] [--setup-pyenv] [--debug]"
echo " --build-number : Build number for package versioning (required for V8 build)"
echo " --source-dir : Source directory containing libv8-packaging (defaults to script directory)"
echo " --pyenv-root : Path for pyenv installation (defaults to /opt/pyenv)"
echo " --output-dir : Output directory for deb packages (defaults to $HOME/DEB)"
echo " --install-deps : Install dependencies"
echo " --setup-pyenv : Setup pyenv and install the required Python version"
echo " --debug : Enable verbose debugging output"
echo " --help : Show this help message"
echo ""
echo "Note: When --build-number is not specified, the script will only perform the"
echo " environment setup steps (install dependencies and/or setup pyenv) if requested."
exit 1
}
create_temp_build_dir()
{
BUILD_DIR=$(mktemp -d /tmp/v8-build.XXXXXX)
if [ $? -ne 0 ]; then
echo "Failed to create temporary build directory"
exit 1
fi
echo "Created temporary build directory: $BUILD_DIR"
trap 'rm -rf "$BUILD_DIR"' EXIT
}
install_dependencies()
{
echo "Installing dependencies..."
apt-get update
apt-get -y install \
build-essential \
cmake \
devscripts \
docbook-xsl \
libbz2-dev \
libffi-dev \
libglib2.0-dev \
liblzma-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libtinfo5 \
llvm \
lsb-release \
ninja-build \
pkg-config \
tk-dev \
zlib1g-dev
echo "Dependencies installed successfully."
}
setup_pyenv()
{
echo "Setting up pyenv..."
if [ ! -d "$PYENV_ROOT" ]; then
git clone --depth 1 --branch "$PYENV_VERSION_TAG" https://github.com/pyenv/pyenv.git "$PYENV_ROOT"
sed -i 's|PATH="/|PATH="$PYENV_ROOT/bin/:/|g' /etc/profile
"$PYENV_ROOT/bin/pyenv" init - | tee -a /etc/profile
if [ -n "$BUILD_DIR" ]; then
echo "export PATH=\"$BUILD_DIR/depot_tools:\${PATH}\"" | tee -a /etc/profile
fi
fi
echo "Installing Python $PYTHON_VERSION..."
pyenv install -s $PYTHON_VERSION
pyenv global $PYTHON_VERSION
echo "Pyenv setup completed successfully."
}
build_v8()
{
echo "Starting V8 build process..."
create_temp_build_dir
cd "$SOURCE_DIR"
cp "$SOURCE_DIR/stub-gclient-spec" "$BUILD_DIR/.gclient"
cp -av "$SOURCE_DIR/debian/" "$BUILD_DIR/"
cd "$BUILD_DIR"
echo "Setting up depot_tools and syncing v8..."
if [ ! -d "$BUILD_DIR/depot_tools" ]; then
git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git "$BUILD_DIR/depot_tools"
fi
export PATH="$BUILD_DIR/depot_tools:$PATH"
echo "Sync to specific v8 version..."
gclient sync --verbose -r $V8_GIT_VERSION
echo "Building v8..."
cd v8
gn gen out.gn --args="is_debug=true symbol_level=2 blink_symbol_level=1 v8_symbol_level=1 v8_static_library=true is_component_build=false v8_enable_i18n_support=false v8_use_external_startup_data=false"
gn args out.gn --list | tee out.gn/gn_args.txt
ninja -v d8 -C out.gn
echo "Updating debian packaging..."
cd "$BUILD_DIR"
sed -i -e "s/GIT_VERSION/$V8_GIT_VERSION/g" "$BUILD_DIR/debian/v8-6.1_static.pc"
sed -i -e "s/GIT_VERSION/$V8_GIT_VERSION/g" "$BUILD_DIR/debian/changelog"
sed -i -e "s/DATE/$(env LC_ALL=en_US.utf8 date '+%a, %d %b %Y %H:%M:%S %z')/g" "$BUILD_DIR/debian/changelog"
sed -i -e "s/DISTRO/$(lsb_release -sc | tr -d '\n')/g" "$BUILD_DIR/debian/changelog"
sed -i -e "s/BUILD_NUMBER/$BUILD_NUMBER/g" "$BUILD_DIR/debian/changelog"
echo "Building debian package..."
debuild -b -us -uc
echo "Moving output files..."
mkdir -p "$OUTPUT_DIR"
mv -v "$BUILD_DIR"/../*.deb "$OUTPUT_DIR"/
echo "Build completed successfully!"
echo "Output packages are available in $OUTPUT_DIR"
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$SCRIPT_DIR"
BUILD_NUMBER=""
PYENV_ROOT="/opt/pyenv"
OUTPUT_DIR="$HOME/DEB"
INSTALL_DEPS=false
SETUP_PYENV=false
DEBUG=false
while [[ $# -gt 0 ]]; do
case "$1" in
--source-dir)
SOURCE_DIR="$2"
shift 2
;;
--build-number)
BUILD_NUMBER="$2"
shift 2
;;
--pyenv-root)
PYENV_ROOT="$2"
shift 2
;;
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
--install-deps)
INSTALL_DEPS=true
shift
;;
--setup-pyenv)
SETUP_PYENV=true
shift
;;
--debug)
DEBUG=true
shift
;;
--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
SOURCE_DIR=$(realpath "$SOURCE_DIR")
echo "Using source directory: $SOURCE_DIR"
if [ "$DEBUG" = true ]; then
echo "Debug mode enabled - verbose output will be shown"
set -x
fi
export DEBIAN_FRONTEND=noninteractive
if [ "$INSTALL_DEPS" = true ]; then
install_dependencies
fi
if ! git config --global --get-all safe.directory | grep -q '\*'; then
git config --global --add safe.directory '*'
fi
export BUILD_NUMBER="$BUILD_NUMBER"
export CODENAME=$(lsb_release -sc)
export PYENV_VERSION_TAG=v2.4.0
export PYTHON_VERSION=2.7.18
export V8_GIT_VERSION=6.1.298
export PYENV_ROOT="$PYENV_ROOT"
export BUILD_DIR="$BUILD_DIR"
export PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
if [ "$SETUP_PYENV" = true ]; then
setup_pyenv
fi
if [ -n "$BUILD_NUMBER" ]; then
build_v8
else
if [ "$INSTALL_DEPS" = false ] && [ "$SETUP_PYENV" = false ]; then
echo "No operations requested. Please specify at least one action."
echo "Use --install-deps to install dependencies or --setup-pyenv to set up Python environment."
echo "Add --build-number <num> to build V8 library."
usage
else
echo "Environment setup completed. Skipping V8 build as no build number was specified."
echo "To build V8, run again with --build-number <num>"
fi
fi
echo "Script execution completed."