-
Notifications
You must be signed in to change notification settings - Fork 3
/
make.sh
executable file
·1120 lines (1013 loc) · 37.1 KB
/
make.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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
export LC_ALL=C
export TZ=America/Los_Angeles
export PYTHONDONTWRITEBYTECODE=1
: ${NIX_SHELL:=/run/current-system/sw/bin/nix-shell}
: ${IN_MAKE_SH:=false}
: ${SILENT:=false}
#echo cc=$CC cxx=$CXX my_cc=$my_CC my_cxx=$my_CXX
exitcode=0
arch_sel=
bld_sel=
cc_sel=
phase_sel=
aphase_sel=
kontinue=false
xpcshell=false
nspr=false
enabledbg=false
oomCheck=false
deterministic=false
gczeal=false
tracelog=false
thm=false
ggc=false
cgc=false
asan=false
ubsan=false
msan=false
tsan=false
spew=true
fuzz=false
noion=false
logref=false
taskspooler=false
warning=false # Set to false aas frequently forgotten.
perf=false
wtest=false
fuzzing=false
bisect=
badexitcode=
nix=true
fhs=false
impure=false
nocl=false
nosm=false
telem=false
# mach --enable-application flags
firefox=false
js=false
arg=$1; shift;
oldarg=
# Record if this is a nix-shel context, otherwise this is a task argument.
ctx_p=false
task=""
while test "$arg" != "$oldarg"; do
ctx_p=false;
case ${arg%%-*} in
(x86|x64|arm|arm64|mips64|mips32|none|none32) arch_sel="$arch_sel ${arg%%-*}"; ctx_p=true;;
(dbg|odbg|pro|opt|oopt) bld_sel="$bld_sel ${arg%%-*}"; ctx_p=true;;
(gcc*|clang*) cc_sel="$cc_sel ${arg%%-*}"; ctx_p=true;;
(autoconf|cfg|make|chk|run|runf|runt|runi|chk?|chk??|chk???|chksimd|regen|mach|src_mach|machcfg|unagi|flame|octane|embenchen|ss|kk|aa|asmapps|asmubench|val|vgdb|rr|shell|clobber|format)
last="${arg%%-*}";
phase_sel="$phase_sel $last";;
(patch) aphase_sel="$aphase_sel ${arg%%-*}";;
(k) kontinue=true;;
(fuzzing) fuzzing=true;;
(fhs) fhs=true;;
(ts) taskspooler=true;;
(xpc) xpcshell=true;;
(nspr) nspr=true;;
(enabledbg) enabledbg=true;;
(oom) oomCheck=true;;
(dt) deterministic=true;;
(gcz) gczeal=true;;
(tr) tracelog=true;;
(thm) thm=true;;
(ggc) ggc=true;;
(cgc) cgc=true;;
(asan) asan=true;;
(ubsan) ubsan=true;;
(msan) msan=true;;
(tsan) tsan=true;;
(nospew) spew=false;;
(fuzz) fuzz=true;;
(noion) noion=true;;
(nowarn) warning=false;;
(warn) warning=true;;
(perf) perf=true;;
(wtest) wtest=true;;
(thm) thm=true;;
(logref) logref=true;;
(impure) impure=true;;
(nocl) nocl=true;;
(nosm) nosm=true;;
(telem) telem=true;;
(ff) firefox=true;;
(js) js=true;;
(bisect_segv_run) bisect=run; badexitcode=139; last=run; phase_sel="$phase_sel $last";;
(bisect_trap_run) bisect=run; badexitcode=133; last=run; phase_sel="$phase_sel $last";;
(bisect_success_run) bisect=run; badexitcode=0; last=run; phase_sel="$phase_sel $last";;
(*) echo 1>&2 "Unknown variation flag '$arg'.";
exit 1;;
esac
if test $ctx_p = false; then
task=${task}${task:+-}${arg%%-*}
fi
oldarg=$arg
arg=${arg#*-}
done
test -z "$arch_sel" && arch_sel="x64"
test -z "$bld_sel" && bld_sel="pro"
test -z "$cc_sel" && cc_sel="clang"
test -z "$phase_sel" && phase_sel="make"
phase_sel="$phase_sel $aphase_sel"
TS=""
if $taskspooler; then
if which ts 2>/dev/null; then
TS=$(which ts)
else
echo 1>2 "Unable to find the task spooler."
fi
fi
top_file(){
local filename=$1
local p=$2
while test ! -r "$p/$filename"; do
if test -z "$p"; then
break;
else
p=${p%/*}
fi
done
if test -r "$p/$filename"; then
echo "$p/$filename"
fi
}
failed=false
catch_failure() {
local exitcode=$1
reset='\e[0;0m'
highlight='\e[0;31m'
if ! $SILENT ; then
echo -e 1>&2 "error: ${highlight}Failed while building variant: $arch-$bld ($phase)${reset}"
fi
failed=true
# "git bisect" use exit code 125 to know when the code cannot be tested.
if test -n "$bisect"; then
echo $bisect : $badexitcode : $exitcode
test \! "$phase" = "$bisect" && exit 125
if test -n "$badexitcode"; then
test "$badexitcode" = "$exitcode" && exit 99
exit 0
fi
fi
# Continue in case of failures.
$kontinue || (printf '\a'; exit 1)
}
maybeExport() {
local name=$1
test -v $name && echo "export $name='$(eval echo \$$name)';";
}
maybeExportPrefix() {
local name=$1
env | env | gawk -F= '/^'"$name"'/ { printf "export %s=\"%s\";", $1, $2; }';
}
RELEASE_NIX=
run() {
reset='\e[0;0m'
highlight='\e[0;35m'
if ! $SILENT ; then
echo -e 1>&2 "${TS:+wait-&-}exec: ${highlight}$@${reset}"
fi
# mach try to parse the environment, and the fact that these are present cause troubles.
unset shellHook;
unset configurePhase;
if $IN_MAKE_SH ; then
eval "$@"
elif $nix ; then
# echo -e 1>&2 "${TS:+wait-&-}enter nix-shell:${reset}"
if test $nativeArch = x64; then
archAttr=x86_64-linux
elif test $nativeArch = x86; then
archAttr=i686-linux
elif test $nativeArch = aarch64; then
archAttr=aarch64-linux
else
echo 1>&2 "Unknown nativeArch ($nativeArch)"
exit 1
fi
hook="
export NIX_GCC_WRAPPER_EXEC_HOOK='$(top_file "rewrite-rpath-link.sh" $buildtmpl)';
export NIX_CC_WRAPPER_EXEC_HOOK='$(top_file "rewrite-rpath-link.sh" $buildtmpl)';
$(maybeExport MOZBUILD_STATE_PATH)
export MOZCONFIG_TEMPLATE=\$MOZCONFIG;
$(maybeExport MOZCONFIG)
$(maybeExport LC_ALL)
$(maybeExport TZ)
$(maybeExport DISPLAY)
$(maybeExport PYTHONDONTWRITEBYTECODE)
$(maybeExport NIX_STRIP_DEBUG)
$(maybeExport JS_CODE_COVERAGE_OUTPUT_DIR)
$(maybeExport IONFILTER)
$(maybeExport IONFLAGS)
$(maybeExport ENABLE_THM)
$(maybeExport TLOPTIONS)
$(maybeExport TLLOG)
$(maybeExport XRE_NO_WINDOWS_CRASH_DIALOG)
$(maybeExportPrefix MOZ_)
$(maybeExportPrefix JIT_)
$(maybeExportPrefix ION_)
$(maybeExportPrefix BP_)
$(maybeExportPrefix XPCOM_)
$(maybeExportPrefix FUZZ)
export SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt;
export IN_MAKE_SH=true;
$(maybeExport IN_EMACS)
export SHELL;
$(maybeExport LD_LIBRARY_PATH)
$(maybeExportPrefix RUST)
cd $PWD;
"
# Note: "cd $PWD;" is resolved with the path before the nix-shell, while
# the path set before running the nix-shell command is used for the
# shell hook.
command="$(echo "$@")"
pure="--pure"
if $fhs; then
fhsAttr=".fhs.env"
#pure=""
echo $command
else
fhsAttr=""
fi
if $impure; then
pure=""
fi
# MOZ_LOG MOZ_GDB_SLEEP
cd $topsrcdir;
export NIX_SHELL_HOOK="$hook"
# Clear previous cache roots, to avoid keeping old derivations. Compiled
# content remains addressable from the nix-store.
test -e $builddir/.nix-roots && rm -rf $builddir/.nix-roots
mkdir $builddir/.nix-roots
# Cache instantiation of the nix-shell.
# See https://fzakaria.com/2020/08/11/caching-your-nix-shell.html
IN_NIX_SHELL=1 nix-instantiate --show-trace "$RELEASE_NIX" \
-A "gecko.$archAttr.$cc$fhsAttr" \
--add-root $builddir/.nix-roots/drv --indirect | \
xargs nix-store --query --references | \
xargs nix-store --realise 1>/dev/null \
--add-root $builddir/.nix-roots/shell --indirect \
# Execute the nix-shell.
$NIX_SHELL --show-trace "$RELEASE_NIX" \
-A "gecko.$archAttr.$cc$fhsAttr" \
$pure --command "$command"
cd -
elif test -z "$TS"; then
"$@"
else
$TS -nf "$@"
fi
exitcode=$?
test $exitcode -gt 0 -o \( -n "$bisect" -a "$phase" = "$bisect" \) && \
catch_failure $exitcode
}
checkForBenchmarks() {
local governor=$(cat /sys/bus/cpu/devices/cpu0/cpufreq/scaling_governor)
if test $governor != performance; then
echo 1>&2 "Governor are set to \"$governor\", use the following command to change to performance:
echo performance | sudo tee /sys/bus/cpu/devices/cpu*/cpufreq/scaling_governor
"
exit 1
fi
# STOP all firefox
pkill -s 19 firefox
}
afterBenchmark() {
# CONT-inue the execution of all firefox
pkill -s 18 firefox
}
generate_patch() {
if git st | grep -c '\(.M\|M.\)'; then
echo 2>&1 "Please commit the changes and re-test."
exit 1
else
tg patch -r ~/mozilla
fi
}
gen_builddir() {
local arch="$arch"
if test \! -e "$builddir/../config.site" -a -e "$buildtmpl"; then
mkdir -p "$builddir"
cd "$builddir/.."
# cp $(top_file ".init" $buildtmpl) .
# cp $(top_file ".preinit" $buildtmpl) .
cp $(top_file "config.site" $buildtmpl) .
cd -
fi
}
get_srcdir() {
local source=$(top_file "mach" $(pwd -L))
source=$(dirname "$source")
echo $source
}
get_js_srcdir() {
local source=$(get_srcdir)
source=${source%/js/src}
echo ${source}/js/src
}
cond() {
eval "($1) && echo true || echo false"
}
generate_conf_args() {
shell=$(cond "! $firefox && ! $nspr")
if $fuzz; then
firefox=false;
nspr=false;
shell=false;
dbg=false
pro=false
odbg=false
opt=false
oopt=false
else
dbg=$(cond "test $bld = dbg")
pro=$(cond "test $bld = pro")
odbg=$(cond "test $bld = odbg")
opt=$(cond "test $bld = opt")
oopt=$(cond "test $bld = oopt")
fi
machine=$(uname -m)
case $arch in
(x86|arm|mips32|none32) is32b=true;;
(*) is32b=false;;
esac
sed -n '/true / { s/true //; p; }' <<EOF
true --prefix=$instdir
true --disable-bootstrap
$(cond "$js") --enable-nspr-build
$(cond "$fuzz") --enable-valgrind
$(cond "$fuzz") --enable-gczeal
$(cond "$fuzz") --disable-tests
$(cond "$fuzz") --disable-profiling
$(cond "$fuzz") --enable-debug
$(cond "$fuzz") --enable-optimize
# --with-system-jpeg --with-system-zlib --with-system-bz2 --disable-crashreporter --disable-necko-wifi --disable-installer --disable-updater"
$(cond "$firefox") --enable-application=browser
$(cond "$js") --enable-application=js
$(cond "$firefox") --disable-install-strip
$(cond "$firefox") --enable-js-shell
$(cond "$firefox || $shell") --disable-jemalloc
$(cond "$firefox || $shell") --enable-valgrind
$(cond "$fuzzing") --enable-fuzzing
$(for extra in $NIX_EXTRA_CONFIGURE_ARGS; do
# removed "&& test $machine = x86_64" to be able to run the configure
# command on arm64 native compilation.
# case $cc in
# (clang*)
# case $extra in
# (--with-clang-path=*) continue;;
# (*) ;;
# esac;;
# (*) ;;
# esac
echo "$(cond "$fuzz || $shell") $extra"
done)
# conf_args="$conf_args --disable-gstreamer --disable-pulseaudio"
$(cond "$firefox || $nspr") --disable-pulseaudio
$(cond "$oomCheck") --enable-oom-backtrace
$(cond "$deterministic") --enable-more-deterministic
$(cond "$gczeal") --enable-gczeal
$(cond "$tracelog") --enable-trace-logging
$(cond "$thm") --enable-thm
$(cond "$ggc") --enable-exact-rooting
$(cond "$ggc") --enable-gcgenerational
$(cond "$cgc") --enable-gccompacting
$(cond "$asan") --enable-address-sanitizer
$(cond "$ubsan") --enable-undefined-sanitizer
$(cond "$msan") --enable-memory-sanitizer
$(cond "$tsan") --enable-thread-sanitizer
$(cond "$spew") --enable-jitspew
false --disable-masm-verbose
$(cond "$noion") --disable-ion
$(cond "$logref") --enable-logrefcnt
$(cond "! $nspr") --enable-ctypes
$(cond "! $nspr") --enable-oom-breakpoint
$(cond "$nocl") --disable-cranelift
$(cond "! $nosm") --enable-smoosh
# TODO: Use -ggdb3 when not building firefox, as -ggdb3 still output macro definitions after pre-processing.
$(cond "$dbg || $pro || $enabledbg") --enable-debug=-ggdb2
$(cond "($opt || $oopt) && ! $enabledbg") --enable-debug-symbols=-ggdb2
$(cond "$odbg || (($opt || $oopt) && ! $enabledbg)") --disable-debug
$(cond "$dbg") --disable-optimize
$(cond "$pro || $opt || $oopt") --enable-optimize
$(cond "$odbg") --enable-optimize='-g -Og'
$(cond "$oopt || $perf") --enable-release
$(cond "! $nspr && $warning") --enable-warnings-as-errors
$(cond "! $nspr && $perf") --enable-perf
$(cond "$wtest") --enable-tests
$(cond "! $wtest") --disable-tests
$(cond "$nspr && test $arch = x64") --enable-64bit
$(cond "$is32b -a $machine = x86_64") --host=i686-unknown-linux-gnu
$(cond "$is32b -a $machine = x86_64") --target=i686-unknown-linux-gnu
$(cond "test $arch = arm -a $machine = x86_64") --enable-simulator=arm
$(cond "test $arch = arm64 -a $machine = x86_64") --enable-simulator=arm64
$(cond "test $arch = mips64") --enable-simulator=mips64
$(cond "test $arch = mips32") --enable-simulator=mips32
$(cond "test $arch = none") --disable-ion
$(cond "test $arch = none32") --disable-ion
$(cond "test $arch = arm64") --enable-arm64-fjcvtzs
# Generate a compile_commands.json file in addition to the usual makefiles.
# see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation#Developer_(debug)_build
$(cond "$shell && test $machine = x86_64") --enable-build-backends=CompileDB,FasterMake,RecursiveMake
EOF
}
# TODO use trap here !
for p in $phase_sel; do
if test $p = regen; then
PROFILE_NIX=/home/nicolas/mozilla/profile.nix
nix-store -r $( nix-instantiate --show-trace $PROFILE_NIX) | \
tee /dev/stderr | \
tail -n $(nix-instantiate $PROFILE_NIX 2>/dev/null | wc -l) | \
while read drv; do
sum=$(echo $drv | sed 's,.*-profile-\([^-]*\)-\([^-]*\),\1:\2,')
cc=${sum%:*}
arch=${sum#*:}
ln -sfT $drv /nix/var/nix/profiles/per-user/nicolas/mozilla/profile-$cc-$arch
done
exit 0
elif test $p = unagi; then
run sudo chroot ~/deb-chroot/ /bin/bash -c '. ~/.bashrc; . ~/.bashrc; ~/awsa/run-benchmark.sh ~/B2G '"$@"
exit 0
elif test $p = flame; then
run sudo chroot ~/deb-chroot/ /bin/bash -c '. ~/.bashrc; . ~/.bashrc; ~/awsa/run-benchmark.sh ~/flame '"$@"
exit 0
fi
done
# Infer the project directory based on the command line arguments.
if $firefox || $xpcshell; then
topsrcdir=$(get_srcdir)
srcdir=$topsrcdir
projectdir=firefox
elif $nspr; then
topsrcdir=$(get_srcdir)
srcdir=$topsrcdir/nsprpub
projectdir=nsprpub
else
topsrcdir=$(get_srcdir)
srcdir=$(get_js_srcdir)
projectdir=js
fi
# Infer the build and install directories, based on the location of the
# top-level source directory.
topbuilddir=$topsrcdir/../_build/
test -e $topbuilddir || mkdir -p $topbuilddir
topbuilddir=$(cd $topbuilddir; pwd -L)
topinstdir=$topsrcdir/../_inst/
test -e $topinstdir || mkdir -p $topinstdir
topinstdir=$(cd $topinstdir; pwd -L)
# Find the name of the current work-directory.
topsrcname=$(basename $topsrcdir)
configsum=$topbuilddir/$projectdir/repo/$topsrcname/config.sum
test -e $configsum || mkdir -p $(dirname $configsum)
# if we are building with Nix, look for the nearest release.nix file.
RELEASE_NIX=$(top_file release.nix $srcdir)
# Infer the branch name which would be used as part of the name of the build
# directory.
cd $srcdir
if test -n "$BRANCH"; then
branch=$BRANCH
elif branch=$(git symbolic-ref HEAD 2>/dev/null); then
branch=${branch#*/*/}
elif branch=$(git rev-parse --short HEAD 2>/dev/null); then
:
else
branch=
fi
cd -
arch_max=$(echo $arch_sel | wc -w)
arch_cnt=1
for arch in $arch_sel; do
bld_max=$(echo $bld_sel | wc -w)
bld_cnt=1
for bld in $bld_sel; do
bld_name=$bld
if $deterministic; then
bld_name=${bld_name}-dt
fi
if $thm; then
bld_name=${bld_name}-thm
fi
cc_max=$(echo $cc_sel | wc -w)
cc_cnt=1
for cc in $cc_sel; do
buildspec=$arch/$cc/$bld_name
nsprbuildspec=$arch/$cc/$bld
builddir=$topbuilddir/$projectdir/${branch+$branch/}$buildspec
instdir=$topinstdir/$projectdir/${branch+$branch/}$buildspec
shell=$topbuilddir/$projectdir/js${branch+-$(echo "$branch" | tr '/' '-')}-$bld_name-$arch-$cc
buildtmpl=$HOME/mozilla/_build_tmpl/$buildspec
# oldarch=$arch
# test $arch = arm && arch=x64
# Handle emulated architectures.
nativeArch=$arch
case $(uname -m) in
(x86_64)
if test $arch = "arm" -o $arch = "mips32" -o $arch = "none32"; then
nativeArch=x86
elif test $arch = "arm64" -o $arch = "mips64" -o $arch = "none"; then
nativeArch=x64
fi;;
(aarch64)
nativeArch=aarch64
;;
esac
export LD_LIBRARY_PATH=$builddir/dist/bin
export NIX_STRIP_DEBUG=0
# arch=$oldarch
## Recurse in make.sh such that we can run the configure phase and all other
## commands in the nix-shell.
if ! $IN_MAKE_SH; then
# SILENT=true;
run $0 $arch-$bld-$cc-$task "$@";
continue;
fi
gen_builddir
# export CONFIG_SITE=$builddir/../config.site;
#export CC;
#export CXX;
test -e "$builddir" || mkdir -p "$builddir"
touch $configsum
rm -f $builddir/.src || ln -sf $srcdir $builddir/.src
phase_sel_case="$phase_sel"
checkConfig=true
case $phase_sel in
(*shell*) checkConfig=false;;
(*runf*) checkConfig=false;;
(*mach*|*src_mach*|*format*)
export AUTOCONF=$(which autoconf)
export MOZBUILD_STATE_PATH=$builddir/.mozbuild;
export MOZCONFIG=$builddir/.mozconfig;
checkConfig=false;
if test \! -e $MOZBUILD_STATE_PATH -o \! -e $MOZCONFIG; then
test \! -e $MOZBUILD_STATE_PATH || echo "Reconfigure: Cannot find $MOZBUILD_STATE_PATH"
test \! -e $MOZCONFIG || echo "Reconfigure: Cannot find $MOZCONFIG"
phase_sel_case="machcfg $phase_sel_case";
fi;
;;
esac
if test -n "$BRANCH"; then
checkConfig=false
fi
config_in=$srcdir/old-configure.in
test -e $config_in || config_in=$srcdir/configure.in
if $checkConfig ; then
if test "$(md5sum "$config_in" | sed 's/ .*//')" != "$(cat "$configsum")" -o \! -x $srcdir/configure; then
phase_sel_case="autoconf cfg $phase_sel_case"
elif test "$(cat "$builddir/config.sum")" != "$(cat "$configsum")"; then
phase_sel_case="cfg $phase_sel_case"
elif test "$config_in" -nt "$srcdir/configure" -o "$srcdir/configure" -nt "$builddir/config.status"; then
touch "$srcdir/configure"
touch "$builddir/config.status"
fi
fi
for phase in $phase_sel_case; do
args=""
if test "$last" = "$phase"; then
args="$@"
fi
case $phase in
(autoconf)
# does that once for all builds.
cd $srcdir;
if $nspr; then
nix-build '<nixpkgs>' -A autoconf -o /tmp/autoconf-latest
run /tmp/autoconf-latest/bin/autoconf
rm -f /tmp/autoconf-latest
else
run autoconf
fi
md5sum "$config_in" | sed 's/ .*//' > "$configsum"
cd -
;;
(cfg)
conf_args=$(generate_conf_args | tr -s '\n' ' ')
phase="configure"
cd $builddir;
# export HOST_LDFLAGS="-rpath $builddir/dist/bin"
run "$srcdir/configure" $conf_args
cd -
cp "$configsum" "$builddir/config.sum"
;;
(machcfg)
echo "Enable telemetry in $MOZBUILD_STATE_PATH/machrc"
mkdir -p $MOZBUILD_STATE_PATH
cat >$MOZBUILD_STATE_PATH/machrc <<EOF
[build]
telemetry = true
EOF
echo "Generate MOZCONFIG: $MOZCONFIG"
cat >$MOZCONFIG <<EOF
# Do not source automation scripts, but read them to reverse engineer options
# that we want.
# . "\$topsrcdir/build/mozconfig.common"
# Content of \$MOZCONFIG_TEMPLATE provided by the shellHook of the derivation.
$(cat $MOZCONFIG_TEMPLATE)
# Content produced by make.sh generate_conf_args function
mk_add_options MOZ_SRC=$topsrcdir
mk_add_options MOZ_OBJDIR=$builddir
mk_add_options AUTOCLOBBER=1
$(generate_conf_args | sed 's/^/ac_add_options /')
EOF
run "$topsrcdir/mach" "create-mach-environment";
;;
(src_mach)
cd $topsrcdir;
run "$topsrcdir/mach" "$@";
;;
(mach)
cd $builddir;
if test -z $IN_EMACS; then
run "$topsrcdir/mach" "$@";
else
run "$topsrcdir/mach" --log-no-times "$@" | sed 's/^TIER: pre-export export compile misc libs tools //';
fi
set -x
if $firefox || $nspr; then
:;
else
if test -d "$builddir/js/src"; then
test -e "$shell" && rm -f "$shell"
ln -sf "$builddir/js/src/js" "$shell"
else
test -e "$shell" && rm -f "$shell"
ln -sf "$builddir/js" "$shell"
fi
fi
;;
(make)
export CXXFLAGS="--expensive-definedness-checks=yes"
if test -z "$args"; then
args="-skj8";
fi
if $ubsan; then
SANFLAGS=bool,bounds,vla-bound
export CXXFLAGS="-fsanitize=$SANFLAGS -fno-sanitize-recover=$SANFLAGS"
export CFLAGS="-fsanitize=$SANFLAGS -fno-sanitize-recover=$SANFLAGS"
fi
case $arch in
# (arm)
# export PATH=$PATH:$HOME/.nix-profile/bin
# archive="$builddir/src.tgz"
# run echo "git-archive ..."
# git archive -o "$archive" --prefix=src/ --remote "$srcdir/../../" HEAD || exit 1
# case $bld in
# (dbg)
# attr=jsBuild
# ;;
# (opt)
# attr=jsOptBuild
# ;;
# esac
# run echo "nix-instantiate ..."
# drv=$(echo '(import /home/nicolas/mozilla/sync-repos/release.nix { ionmonkeySrc = '"$builddir/src.tgz"'; }).'"$attr"' { system = "armv7l-linux"; }' | nix-instantiate -I /home/nicolas/mozilla - || exit 2)
# run echo "nix-store -r ..."
# store=$(nix-store -r $drv || exit 3)
# ln -sf $store "$builddir/result"
# run ln -sf "$builddir/result/bin/js" "$builddir/js"
# ;;
(*)
LC_ALL=C run make -C "$builddir" "$args"
;;
esac
if $firefox || $nspr; then
LC_ALL=C run make -C "$builddir" install "$args"
else
test -e "$shell" && rm -f "$shell"
if test -d "$builddir/js/src"; then
ln -sf "$builddir/js/src/js" "$shell"
else
ln -sf "$builddir/js" "$shell"
fi
fi
;;
(format)
clang_dir=$(grep exec $(which clang) | sed -ne '/exec/ { s/^.*exec //; s,/bin/clang.*,,; p; q; }')
rm -rf $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin || true;
mkdir -p $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/;
ln -s $clang_dir/bin $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin;
( echo "make.sh: Watch for file modification to replace clang-format files.";
stdbuf -oL -eL inotifywait -mre create --format '%w%f' $MOZBUILD_STATE_PATH |
while read file; do
## echo "make.sh: $file"
if test $file = $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin/run-clang-tidy ; then
set -x
echo "make.sh: Replacing clang-tools binaries."
while test \! -h $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin ; do
rm -rf $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin || true;
mkdir -p $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/;
ln -s $clang_dir/bin $MOZBUILD_STATE_PATH/clang-tools/clang-tidy/bin;
done
break
fi
done
)&
cd $topsrcdir;
run "$topsrcdir/mach" -v "clang-format" "$@";
;;
(chk)
LC_ALL=C run make -C "$builddir" check "$@"
;;
(chki)
# check ion test directory.
#LC_ALL=C run make -C "$builddir" check-ion-test "$@"
run python $srcdir/jit-test/jit_test.py --ion --no-slow "$shell" ion
;;
(chka)
# check ion test directory.
#LC_ALL=C run make -C "$builddir" check-ion-test "$@"
if $nosm; then thisChkaOpt=""
else thisChkaOpt="$chkaOpt --args=--smoosh"
fi
if $telem; then thisChkaOpt="$thisChkaOpt --args=--telemetry-dir=/tmp/"
fi
# chkaOpt="$chkaOpt --ion"
kontinue_save=$kontinue
kontinue=true
if $firefox ; then
: ${MOCHITEST=plain}
# TEST_PATH='/tests/MochiKit-1.4.2/tests/test_MochiKit-Style.html' EXTRA_TEST_ARGS='--debugger=gdb' make mochitest-plain
LC_ALL=C run make -C "$builddir" mochitest-$MOCHITEST
else
# disabled for ARM64 testing
run python $srcdir/tests/jstests.py $thisChkaOpt --wpt=disabled --jitflags=ion -F -t 10 "$@" $(readlink "$shell")
run python $srcdir/jit-test/jit_test.py $thisChkaOpt --no-slow "$@" "$shell"
fi
kontinue=$kontinue_save
;;
(chkv)
# check ion test directory.
#LC_ALL=C run make -C "$builddir" check-ion-test "$@"
if $nosm; then smooshOpt=""
else smooshOpt="$chkaOpt --args=--smoosh"
fi
# chkaOpt="$chkaOpt --ion"
kontinue_save=$kontinue
kontinue=true
run python $srcdir/tests/jstests.py $smooshOpt --wpt=disabled --valgrind --jitflags=ion -F "$@" $(readlink "$shell")
run python $srcdir/jit-test/jit_test.py $smooshOpt --valgrind $chkaOpt --no-slow "$@" "$shell"
kontinue=$kontinue_save
;;
(chksimd)
# check ion test directory.
#LC_ALL=C run make -C "$builddir" check-ion-test "$@"
chkaOpt="$chkaOpt --ion"
kontinue_save=$kontinue
kontinue=true
run python $srcdir/jit-test/jit_test.py $chkaOpt --args="--no-asmjs --ion-regalloc=backtracking" --no-slow "$@" "$shell" asm.js
kontinue=$kontinue_save
;;
(chkt)
if $nosm; then smooshOpt=""
else smooshOpt="$chkaOpt --args=--smoosh"
fi
testIon=false
if $testIon; then jstOpts="--jitflags=ion"; jitOpts="--ion";
else jstOpts=""; jitOpts="";
fi
if test $(cd $srcdir/tests; ls 2>/dev/null $(echo " $@" | sed 's/ -/ \\\\-/g') | wc -l) -gt 0; then
run python $srcdir/tests/jstests.py $smooshOpt $jstOpts --wpt=disabled -o -s --no-progress $(readlink "$shell") "$@"
else
run python $srcdir/jit-test/jit_test.py $smooshOpt $jitOpts -s -f -o "$shell" "$@"
fi
;;
(chkwc)
run python $srcdir/jit-test/jit_test.py --args=--wasm-compiler=cranelift "$shell" wasm
;;
(chkg)
if test $(cd $srcdir/tests; ls 2>/dev/null $(echo " $@" | sed 's/ -/ \\\\-/g') | wc -l) -gt 0; then
run python $srcdir/tests/jstests.py --wpt=disabled --jitflags=ion -o -s --no-progress -g $(readlink "$shell") "$@"
else
run python $srcdir/jit-test/jit_test.py --ion -s -f -o -g "$shell" "$@"
fi
;;
(chkrr)
if $nosm; then smooshOpt=""
else smooshOpt="$chkaOpt --args=--smoosh"
fi
if test $(cd $srcdir/tests; ls 2>/dev/null $(echo " $@" | sed 's/ -/ \\\\-/g') | wc -l) -gt 0; then
run python $srcdir/tests/jstests.py $smooshOpt --wpt=disabled --jitflags=ion -o -s --no-progress -g --debugger='rr record -h' $(readlink "$shell") "$@"
else
run python $srcdir/jit-test/jit_test.py $smooshOpt --ion -s -f -o -G "$shell" "$@"
fi
;;
(chktt)
if test $(cd $srcdir/tests; ls 2>/dev/null $(echo " $@" | sed 's/ -/ \\\\-/g') | wc -l) -gt 0; then
run python $srcdir/tests/jstests.py --wpt=disabled --jitflags=all -o -s --no-progress $(readlink "$shell") "$@"
else
run python $srcdir/jit-test/jit_test.py --tbpl -s -f -o "$shell" "$@"
fi
;;
(chkgdb)
cd $srcdir
run python $srcdir/gdb/run-tests.py --gdb=$(type -P gdb) --srcdir=$topsrcdir --builddir=$builddir/js/src/gdb --testdir=$srcdir/gdb/tests $builddir "$@"
cd -
;;
(chkxpc)
: ${MOCHITEST=plain}
# TEST_PATH='/tests/MochiKit-1.4.2/tests/test_MochiKit-Style.html' EXTRA_TEST_ARGS='--debugger=gdb' make mochitest-plain
if test -z "$TEST_PATH"; then
LC_ALL=C run make -C "$builddir" xpcshell-tests
else
XPCSHELL_TESTS=$(dirname "$TEST_PATH") relativesrcdir=. SOLO_FILE=$(basename "$TEST_PATH") \
LC_ALL=C run make -C "$builddir" check-one
fi
;;
(clobber)
run rm -rf "$builddir" "$shell"
;;
(shell)
export PATH=$PATH:~/.nix-profile/bin/:/var/run/current-system/sw/bin/
run "$@"
;;
(runf|run)
if $fuzzing; then
echo arguments 1: $1
echo arguments 2: $2
# FUZZER is a JS file which contains a top-level JS variable named
# `fuzzBuf` and a function named `JSFuzzIterate`.
: ${FUZZER=$1}
if test \! -f "$FUZZER"; then
echo "Set the script which should be used for fuzzing on the command line"
exit 1;
fi
export FUZZER
# FUZZ_DIR is the last argument of the command line and would be
# the directory / file where samples are added and checked.
: ${FUZZ_DIR=$2}
if test \! -d "$FUZZ_DIR"; then
FUZZ_DIR=$(mktemp /tmp/js-libFuzzer-XXXXXX)/
fi
: ${FUZZ_TIMEOUT=5}
: ${FUZZ_MAX_LEN=32}
: ${FUZZ_ONLY_ASCII=1}
run "$shell -- -use_value_profile=1 -print_pcs=1 -timeout=${FUZZ_TIMEOUT} -max_len=${FUZZ_MAX_LEN} -only_ascii=${FUZZ_ONLY_ASCII} $FUZZ_DIR"
# -dict=js.dict TODO: Create a js.dict file which contains all keywords.
else
if $firefox ; then
run "$builddir/dist/bin/firefox" "$@"
elif $xpcshell ; then
run "$builddir/dist/bin/xpcshell" "$@"
else
run "$shell" "$@"
fi
fi
;;
(val)
if $firefox ; then
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access --show-mismatched-frees=no --read-inline-info=yes -- "$builddir/dist/bin/firefox" "$@"
elif $xpcshell ; then
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access -- "$builddir/dist/bin/xpcshell" "$@"
else
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access -- "$shell" "$@"
fi
;;
(rr)
if $firefox ; then
run rr record -S "$builddir/dist/bin/firefox" "$@"
elif $xpcshell ; then
run rr record -S "$builddir/dist/bin/xpcshell" "$@"
else
run rr record -S "$shell" "$@"
fi
;;
(vgdb)
if $firefox ; then
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access --show-mismatched-frees=no --read-inline-info=yes --vgdb-error=0 -- "$builddir/dist/bin/firefox" "$@"
elif $xpcshell ; then
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access --vgdb-error=0 -- "$builddir/dist/bin/xpcshell" "$@"
else
run valgrind --smc-check=all-non-file --vex-iropt-register-updates=allregs-at-mem-access --vgdb-error=0 -- "$shell" "$@"
fi
;;
(runt)
args=""
tests=""
debug=""
for i in $@; do
case "$i" in
(-g) debug="-g";;
(-*) args="$args $i";;
(*) tests="$tests $i";;
esac
done
run python $srcdir/jit-test/jit_test.py -w /dev/null --no-progress --write-failure-output -o --jitflags="" --args="$args" "$shell" $tests $debug
;;
(runi)
phase="runi interp"
# run "$shell" "$@"
failed=false
kontinue_save=$kontinue
kontinue=true
empty_opt=
for mode in none eager; do
mode_opt=$empty_opt
test $mode = infer && mode_opt="$mode_opt"