-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathbuild.bats
executable file
·426 lines (333 loc) · 9.81 KB
/
build.bats
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/usr/bin/env bats
load test_helper
export NODE_BUILD_CACHE_PATH="$BATS_TMPDIR/cache"
export MAKE=make
export MAKE_OPTS="-j 2"
export CC=cc
export -n NODE_CONFIGURE_OPTS
setup() {
mkdir -p "$INSTALL_ROOT"
stub sha1 false
stub curl false
}
executable() {
local file="$1"
mkdir -p "${file%/*}"
cat > "$file"
chmod +x "$file"
}
cached_tarball() {
mkdir -p "$NODE_BUILD_CACHE_PATH"
pushd "$NODE_BUILD_CACHE_PATH" >/dev/null
tarball "$@"
popd >/dev/null
}
tarball() {
local name="$1"
local path="$PWD/$name"
local configure="$path/configure"
shift 1
executable "$configure" <<OUT
#!$BASH
IFS=,
echo "$name: [\$*]" \${NODEOPT:+NODEOPT=\$NODEOPT} >> build.log
OUT
for file; do
mkdir -p "$(dirname "${path}/${file}")"
touch "${path}/${file}"
done
tar czf "${path}.tar.gz" -C "${path%/*}" "$name"
}
stub_make_install() {
stub "$MAKE" \
" : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log" \
"install : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
}
assert_build_log() {
run cat "$INSTALL_ROOT/build.log"
assert_output
}
@test "apply node patch before building" {
cached_tarball "node-v4.0.0"
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$BATS_TMPDIR" install_fixture --patch definitions/vanilla-node <<PATCH
diff -pU3 align.c align.c
--- align.c 2017-09-14 21:09:29.000000000 +0900
+++ align.c 2017-09-15 05:56:46.000000000 +0900
PATCH
assert_success
unstub make
unstub patch
assert_build_log <<OUT
patch -p0 --force -i $BATS_TMPDIR/node-patch.XXX
node-v4.0.0: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "striplevel node patch before building" {
cached_tarball "node-v4.0.0"
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$BATS_TMPDIR" install_fixture --patch definitions/vanilla-node <<PATCH
diff -pU3 a/configure b/configure
--- a/configure 2017-09-14 21:09:29.000000000 +0900
+++ b/configure 2017-09-15 05:56:46.000000000 +0900
PATCH
assert_success
unstub make
unstub patch
assert_build_log <<OUT
patch -p1 --force -i $BATS_TMPDIR/node-patch.XXX
node-v4.0.0: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "apply node patch from git diff before building" {
cached_tarball "node-v4.0.0"
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$BATS_TMPDIR" install_fixture --patch definitions/vanilla-node <<PATCH
diff --git a/test/build.bats b/test/build.bats
index 4760c31..66a237a 100755
--- a/test/build.bats
+++ b/test/build.bats
PATCH
assert_success
unstub make
unstub patch
assert_build_log <<OUT
patch -p1 --force -i $BATS_TMPDIR/node-patch.XXX
node-v4.0.0: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "forward extra command-line arguments as configure flags" {
cached_tarball "node-v4.0.0"
stub_make_install
cat > "$BATS_TMPDIR/build-definition" <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
# TODO: use configure flags meaningful to node
NODE_CONFIGURE_OPTS='--with-readline-dir=/custom' run node-build "$BATS_TMPDIR/build-definition" "$INSTALL_ROOT" -- cppflags="-DYJIT_FORCE_ENABLE -DRUBY_PATCHLEVEL_NAME=test" --with-openssl-dir=/path/to/openssl
assert_success
unstub make
assert_build_log <<OUT
node-v4.0.0: [--prefix=$INSTALL_ROOT,cppflags=-DYJIT_FORCE_ENABLE -DRUBY_PATCHLEVEL_NAME=test,--with-openssl-dir=/path/to/openssl,--with-readline-dir=/custom]
make -j 2
make install
OUT
}
@test "number of CPU cores defaults to 2" {
cached_tarball "node-v4.0.0"
stub_repeated uname '-s : echo Darwin'
stub sysctl false
stub_make_install
export -n MAKE_OPTS
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
assert_success
unstub uname
unstub make
assert_build_log <<OUT
node-v4.0.0: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "number of CPU cores is detected on Mac" {
cached_tarball "node-v4.0.0"
stub_repeated uname '-s : echo Darwin'
stub sysctl '-n hw.ncpu : echo 4'
stub_make_install
export -n MAKE_OPTS
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
assert_success
unstub uname
unstub sysctl
unstub make
assert_build_log <<OUT
node-v4.0.0: --prefix=$INSTALL_ROOT
make -j 4
make install
OUT
}
@test "number of CPU cores is detected on FreeBSD" {
cached_tarball "node-v4.0.0"
stub_repeated uname '-s : echo FreeBSD'
stub sysctl '-n hw.ncpu : echo 1'
stub_make_install
export -n MAKE_OPTS
export NODE_CONFIGURE_OPTS="--with-openssl-dir=/test"
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
assert_success
unstub uname
unstub sysctl
unstub make
assert_build_log <<OUT
node-v4.0.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=/test]
make -j 1
make install
OUT
}
@test "using MAKE_INSTALL_OPTS" {
cached_tarball "node-v4.0.0"
stub_repeated uname '-s : echo Linux'
stub_make_install
export MAKE_INSTALL_OPTS="--globalmake"
export NODE_MAKE_INSTALL_OPTS="NODEMAKE=true with spaces"
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
assert_success
unstub make
assert_build_log <<OUT
node-v4.0.0: --prefix=$INSTALL_ROOT
make -j 2
make install --globalmake RUBYMAKE=true with spaces
OUT
}
@test "custom relative install destination" {
export NODE_BUILD_CACHE_PATH="$FIXTURE_ROOT"
cd "$BATS_TMPDIR"
install_fixture definitions/without-checksum ./here
assert_success
assert [ -x ./here/bin/package ]
}
@test "make on FreeBSD defaults to gmake" {
cached_tarball "node-v4.0.0"
stub_repeated uname "-s : echo FreeBSD"
MAKE=gmake stub_make_install
MAKE= install_fixture definitions/vanilla-node
assert_success
unstub gmake
unstub uname
}
@test "can use NODE_CONFIGURE to apply a patch" {
cached_tarball "node-v4.0.0"
executable "${BATS_TMPDIR}/custom-configure" <<CONF
#!$BASH
apply -p1 -i /my/patch.diff
exec ./configure "\$@"
CONF
stub_repeated uname '-s : echo Linux'
stub apply 'echo apply "$@" >> build.log'
stub_make_install
export NODE_CONFIGURE="${BATS_TMPDIR}/custom-configure"
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz"
DEF
assert_success
unstub make
unstub apply
assert_build_log <<OUT
apply -p1 -i /my/patch.diff
node-v4.0.0: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "copy strategy forces overwrite" {
export NODE_BUILD_CACHE_PATH="$FIXTURE_ROOT"
mkdir -p "$INSTALL_ROOT/bin"
touch "$INSTALL_ROOT/bin/package"
chmod -w "$INSTALL_ROOT/bin/package"
install_fixture definitions/without-checksum
assert_success
run "$INSTALL_ROOT/bin/package" "world"
assert_success
assert_output "hello world"
}
@test "non-writable TMPDIR aborts build" {
export TMPDIR="${BATS_TMPDIR}/build"
mkdir -p "$TMPDIR"
chmod -w "$TMPDIR"
touch "${BATS_TMPDIR}/build-definition"
run node-build "${BATS_TMPDIR}/build-definition" "$INSTALL_ROOT"
assert_failure
assert_output "node-build: TMPDIR=$TMPDIR is set to a non-accessible location"
}
@test "non-executable TMPDIR aborts build" {
export TMPDIR="${BATS_TMPDIR}/build"
mkdir -p "$TMPDIR"
chmod -x "$TMPDIR"
touch "${BATS_TMPDIR}/build-definition"
run node-build "${BATS_TMPDIR}/build-definition" "$INSTALL_ROOT"
assert_failure
assert_output "node-build: TMPDIR=$TMPDIR is set to a non-accessible location"
}
@test "initializes LDFLAGS directories" {
cached_tarball "node-v4.0.0"
export LDFLAGS="-L ${BATS_TEST_DIRNAME}/what/evs"
run_inline_definition <<DEF
install_package "node-v4.0.0" "http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz" ldflags_dirs
DEF
assert_success
assert [ -d "${INSTALL_ROOT}/lib" ]
assert [ -d "${BATS_TEST_DIRNAME}/what/evs" ]
}
@test "directory structure is fixed for jxcore source builds" {
export NODE_BUILD_CACHE_PATH="$FIXTURE_ROOT"
stub_make_install
install_fixture --compile definitions/jxcore
assert_success
assert [ -d "${INSTALL_ROOT}/bin" ]
assert [ -L "${INSTALL_ROOT}/bin/node" ]
}
@test "directory structure is fixed for jxcore binary builds" {
export NODE_BUILD_CACHE_PATH="$FIXTURE_ROOT"
stub_make_install
install_fixture definitions/jxcore
assert_success
refute [ -e "${INSTALL_ROOT}/jx" ]
assert [ -d "${INSTALL_ROOT}/bin" ]
assert [ -x "${INSTALL_ROOT}/bin/jx" ]
assert [ -L "${INSTALL_ROOT}/bin/npm" ]
assert [ -L "${INSTALL_ROOT}/bin/node" ]
}
@test "jxcore's custom npm is installed and configured" {
export NODE_BUILD_CACHE_PATH="$FIXTURE_ROOT"
stub_make_install
install_fixture definitions/jxcore
assert_success
assert [ -e "${INSTALL_ROOT}/bin/jx.config" ]
assert [ -d "${INSTALL_ROOT}/libexec/.jx/npm" ]
assert [ -e "${INSTALL_ROOT}/libexec/.jx/v 0.3.0.7" ]
assert grep "\"npmjxPath\": \"${INSTALL_ROOT}/libexec\"" "${INSTALL_ROOT}/bin/jx.config"
}
@test "jxcore can specify spidermonkey engine" {
cached_tarball "jxcore-sm-1.0.0"
stub_make_install
run_inline_definition <<DEF
install_package "jxcore-sm-1.0.0" "http://jxcore.s3.amazonaws.com/jxcore-sm-1.0.0.tar.gz" jxcore_spidermonkey standard
DEF
assert_success
unstub make
assert_build_log <<OUT
jxcore-sm-1.0.0: --prefix=$INSTALL_ROOT --engine-mozilla
make -j 2
make install
OUT
}
@test "jxcore can specify v8 3.28 engine" {
cached_tarball "jxcore-v8-1.0.0"
stub_make_install
run_inline_definition <<DEF
install_package "jxcore-v8-1.0.0" "http://jxcore.s3.amazonaws.com/jxcore-v8-1.0.0.tar.gz" jxcore_v8_328 standard
DEF
assert_success
unstub make
assert_build_log <<OUT
jxcore-v8-1.0.0: --prefix=$INSTALL_ROOT --engine-v8-3-28
make -j 2
make install
OUT
}