-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake.sh
executable file
·594 lines (470 loc) · 14.6 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
#!/usr/bin/env bash
# NOTE(Jesse): These should be removed eventually.. but I'm leaving them here
# for the time-being since it should be harmless
#
# NOTE(Jesse): The following are switches for twiddling during development.
# Calling functions by name on the command line shouldn't be affected by these.
# RunPreemptivePoof=1
# BuildAllBinariesRunAllTests=1
# FetchBonsaiDebug=0
# BuildPoof=1
# RunPoof=1
# POOF_LOG_LEVEL="--log-level LogLevel_Debug"
# POOF_DEBUGGER="gdb --args"
# BuildPoofEmcc=0
# RollupEmcc=0
# BuildParserTests=1
# RunParserTests=1
# TEST_LOG_LEVEL="--log-level LogLevel_Debug"
# TEST_DEBUGGER="gdb --args"
# BuildAndRunAllExamples=1
# RunIntegrationTests=1
# INTEGRATION_TEST_INDEX=1
# INTEGRATION_TEST_LOG_LEVEL="--log-level LogLevel_Debug -c0"
# INTEGRATION_TEST_DEBUGGER="gdb --args"
# RunExtendedIntegrationTests=1
# OPTIMIZATION_LEVEL="-O2"
# BONSAI_INTERNAL="-D BONSAI_INTERNAL=0"
stdlib_build_scripts='include/bonsai_stdlib/scripts'
. $stdlib_build_scripts/preamble.sh
. $stdlib_build_scripts/setup_for_cxx.sh
. include/bonsai_debug/make.sh
if [ $# -gt 1 ]; then
echo "make.sh supports a maximum of 1 argument"
fi
# NOTE(Jesse): Can't do this cause it fucks with the paths poof outputs
# ROOT="$(pwd)"
ROOT="."
ABS_ROOT="$(pwd)"
SRC="$ROOT/poof"
BIN="$ROOT/bin"
BIN_TEST="$BIN/tests"
INCLUDE="include"
META_OUT="generated"
EXTENDED_INTEGRATION_TESTS_SRC="$ROOT/tests/integration_extended"
function RollupEmcc
{
if [ -x docs/node_modules/.bin/rollup ]; then
docs/node_modules/.bin/rollup \
docs/main.js \
-f iife \
-o docs/main.bundle.js \
-p @rollup/plugin-node-resolve
else
echo -e "$Error Rollup not found, try running './make.sh BootstrapWeb'"
fi
}
function BuildPoofEmcc
{
ColorizeTitle "Building Poof (emcc)"
which emcc > /dev/null
if [ $? -eq 0 ]; then
emcc \
poof/poof.cpp \
$OPTIMIZATION_LEVEL \
-msimd128 \
$CXX_OPTIONS \
$PLATFORM_CXX_OPTIONS \
\
-O0 \
-g \
\
-sALLOW_MEMORY_GROWTH \
-sEXPORTED_FUNCTIONS=_DoPoofForWeb \
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
-D "__SSE__" \
-D "__AVX__" \
-D "BONSAI_EMCC" \
-Wno-disabled-macro-expansion \
-Wno-reserved-identifier \
-Wno-limited-postlink-optimizations \
\
-sFORCE_FILESYSTEM \
--preload-file examples \
\
-sASSERTIONS=2 \
-sSAFE_HEAP=1 \
-sSTACK_OVERFLOW_CHECK=1 \
-fsanitize=undefined \
\
$BONSAI_INTERNAL \
$PLATFORM_INCLUDE_DIRS \
-I "$ROOT" \
-I "$ROOT/include" \
-I "$ROOT/poof" \
-o docs/poof_runtime.js
if [ $? -eq 0 ]; then
echo -e "$Success poof/poof.cpp -> poof.html"
else
echo -e "$Failed Error building poof, exiting."
exit 1
fi
if [ -d docs/node_modules ]; then
RollupEmcc
else
echo -e "$Info ./docs/node_modules could not be found! Attempting to bootstrap"
BootstrapWeb
if [ -d docs/node_modules ]; then
RollupEmcc
fi
fi
else
echo -e "$Warn No installation of emcc detected"
echo -e "$Info If you wish to target WASM, install emscriptend then run './make.sh BootstrapWeb'"
fi
echo -e ""
echo -e "$Delimeter"
echo -e ""
}
function BootstrapWeb
{
pushd docs > /dev/null 2>&1
which npm > /dev/null
if [ $? -eq 0 ]; then
npm install > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "$Success BootstrapWeb complete!"
else
echo -e "$Failed Bootstrapping docs"
fi
else
echo -e "$Error No installation of npm detected. To bootstrap docs, please install npm"
fi
popd > /dev/null 2>&1
}
function RunPoof {
ColorizeTitle "Poofing!"
# if [ -d $META_OUT ]; then
# rm -Rf $META_OUT
# fi
: "${POOF_EXECUTABLE:=./bin/poof}"
# --do-debug-window \
# POOF_LOG_LEVEL="--log-level LogLevel_Debug"
$POOF_DEBUGGER $POOF_EXECUTABLE \
\
$POOF_LOG_LEVEL \
poof/poof.cpp \
-D POOF_PREPROCESSOR \
-D BONSAI_PREPROCESSOR \
-D BONSAI_DEBUG_SYSTEM \
-d \
$PLATFORM_DEFINES \
-I "." \
-I "$ROOT/include" \
-o $META_OUT
if [ $? -eq 0 ]; then
echo -e "$Success Poofed"
else
echo -e "$Failed Poofing"
git checkout $META_OUT
fi
echo -e ""
echo -e "$Delimeter"
echo -e ""
}
function RunInstalledPoof {
old_poof_executable=$POOF_EXECUTABLE
POOF_EXECUTABLE=poof
old_poof_debugger=$POOF_DEBUGGER
POOF_DEBUGGER=
old_poof_log_level=$POOF_LOG_LEVEL
# POOF_LOG_LEVEL="--log-level LogLevel_Error"
RunPoof
POOF_LOG_LEVEL=$old_poof_log_level
POOF_DEBUGGER=$old_poof_debugger
POOF_EXECUTABLE=$old_poof_executable
}
function BuildPoof {
which clang++ > /dev/null
[ $? -ne 0 ] && echo -e "Please install clang++" && exit 1
ColorizeTitle "Building Poof"
source_file="$SRC/poof.cpp"
SetOutputBinaryPathBasename "$source_file" bin
echo -e "$Building $source_file"
clang++ \
$source_file \
$OPTIMIZATION_LEVEL \
$CXX_OPTIONS \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$BONSAI_INTERNAL \
$PLATFORM_INCLUDE_DIRS \
-I "$ROOT" \
-I "$ROOT/include" \
-I "$ROOT/poof" \
-o "$output_basename""$PLATFORM_EXE_EXTENSION"
if [ $? -eq 0 ]; then
echo -e "$Success $source_file -> $full_output_name"
echo -e ""
echo -e "$Delimeter"
echo -e ""
else
echo ""
echo -e "$Failed Error building poof, exiting."
exit 1
fi
}
function RunIntegrationTests()
{
ColorizeTitle "Running Integration Tests"
INTEGRATION_SRC_DIR=tests/integration/src
INTEGRATION_OUTPUT_DIR=tests/integration/generated
FILES_TO_POOF=$(find $INTEGRATION_SRC_DIR -type f | grep '\.h')
test_index=0
for filename in $FILES_TO_POOF; do
basename_stripped=$(basename $filename .h)
test_output_dir=$INTEGRATION_OUTPUT_DIR/$basename_stripped
# Each test file has a directory created under the output directory that
# we'll write all the poof() output to for that test file. We diff that
# whole directory to confirm the output is identical for that test file
run_test=1
if [[ -v INTEGRATION_TEST_INDEX ]]; then
if [[ $test_index != $INTEGRATION_TEST_INDEX ]]; then
run_test=0
fi
fi
if [[ $run_test == 1 ]]; then
if [ -d $test_output_dir ]; then
rm -Rf $test_output_dir
fi
mkdir -p $test_output_dir
echo -e "$Info TestIndex($test_index)"
echo -e "$Indent $INTEGRATION_TEST_DEBUGGER bin/poof $POOF_COLOR_FLAG $INTEGRATION_TEST_LOG_LEVEL $filename -o $test_output_dir"
$INTEGRATION_TEST_DEBUGGER bin/poof \
$POOF_COLOR_FLAG \
$INTEGRATION_TEST_LOG_LEVEL \
$filename \
-o $test_output_dir
if [[ $? == 0 ]]; then
DIFF_CMD="git diff --ignore-all-space --ignore-blank-lines ${test_output_dir} | wc -l"
echo -e "$Indent $DIFF_CMD == ($DIFF_CHANGED)"
DIFF_CHANGED=$(eval $DIFF_CMD)
if [[ $DIFF_CHANGED == 0 ]]; then
echo -e "$Success $filename"
else
echo -e "$Failed $filename"
fi
else
echo -e "$Failed $filename"
fi
fi
echo ""
((test_index++))
done
echo -e ""
echo -e "$Delimeter"
echo -e ""
}
function BuildParserTests
{
ColorizeTitle "Building Tests"
source_file=tests/parser/poof.cpp
SetOutputBinaryPathBasename "$source_file" bin/tests
echo -e "$Building $source_file"
clang++ \
$source_file \
$OPTIMIZATION_LEVEL \
$CXX_OPTIONS \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$PLATFORM_INCLUDE_DIRS \
$BONSAI_INTERNAL \
-I "." \
-I "$ROOT/include" \
-I "$ROOT/poof" \
-o "$output_basename""$PLATFORM_EXE_EXTENSION"
if [ $? -eq 0 ]; then
echo -e "$Success $source_file -> $full_output_name"
echo -e ""
echo -e "$Delimeter"
echo -e ""
else
echo ""
echo -e "$Failed Error building $source_file, exiting."
echo ""
exit 1
fi
}
function RunParserTests
{
ColorizeTitle "Running Parser Tests"
$TEST_DEBUGGER ./bin/tests/poof \
$TEST_LOG_LEVEL \
echo -e "$Delimeter"
echo -e ""
}
function RunSingleExtendedIntegrationTest
{
if [ -d $EXTENDED_INTEGRATION_TESTS_SRC/$test_name ]; then
pushd "$EXTENDED_INTEGRATION_TESTS_SRC/$test_name" > /dev/null
$1
if [ $? -eq 0 ]; then
echo -e "$Success $test_name parsed"
else
echo -e "$Failed $test_name didn't parse"
fi
popd > /dev/null
else
echo -e "$Warn $test_name not found. Try running './make.sh BootstrapExtendedIntegrationTests'"
fi
}
function RunExtendedIntegrationTests
{
ColorizeTitle "Running Extended Integration Tests"
test_name=uacme
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
-D USE_OPENSSL \
./uacme.c"
test_name=redis
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
--log-level LogLevel_Shush \
-D BYTE_ORDER \
-D LITTLE_ENDIAN \
\
-D __clang__ \
-D __i386 \
-D __x86_64__ \
-D linux \
-D __linux__ \
-D __GNUC__ \
src/server.c"
echo " - NOTE(Jesse): poof is known to not handle redis correctly yet. This failure is expected"
test_name=sqlite
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
-D __clang__ \
-D __i386 \
-D __x86_64__ \
-D linux \
-D __linux__ \
-D __GNUC__ \
src/test_server.c"
test_name=handmade_hero
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
code/handmade.cpp"
test_name=bonsai
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
-I src/ \
-I src/poof \
-I include/ \
-D BONSAI_LINUX \
-o src/generated \
src/game_loader.cpp"
test_name=hcc
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
-I src/ \
src/hcc.c"
test_name=gf
RunSingleExtendedIntegrationTest \
"$ABS_ROOT/bin/poof \
-I . \
gf2.cpp"
echo -e ""
echo -e "$Delimeter"
echo -e ""
}
function BootstrapSingleExtendedIntegrationTest
{
if [ -d $EXTENDED_INTEGRATION_TESTS_SRC/$test_name ]; then
echo -e "$Info $test_name exists, skipping"
else
echo -e "$Info Cloning $test_name"
git clone $1 $test_repo $EXTENDED_INTEGRATION_TESTS_SRC/$test_name
fi
}
function BootstrapExtendedIntegrationTests
{
ColorizeTitle "Bootstrapping Extended Integration Test Suite"
test_name=uacme
test_repo=git@github.com:ndilieto/uacme
BootstrapSingleExtendedIntegrationTest
test_name=redis
test_repo=git@github.com:$test_name/$test_name
BootstrapSingleExtendedIntegrationTest
test_name=sqlite
test_repo=git@github.com:$test_name/$test_name
BootstrapSingleExtendedIntegrationTest
test_name=handmade_hero
test_repo=git@github.com:HandmadeHero/cpp
BootstrapSingleExtendedIntegrationTest
test_name=bonsai
test_repo=git@github.com:scallyw4g/bonsai
BootstrapSingleExtendedIntegrationTest '--recursive'
test_name=hcc
test_repo=https://github.com/heroseh/hcc
BootstrapSingleExtendedIntegrationTest
test_name=gf
test_repo=https://github.com/nakst/gf
BootstrapSingleExtendedIntegrationTest
}
function BuildAndRunAllExamples
{
ColorizeTitle "Building and Running examples"
pushd examples > /dev/null
./make_all_examples.sh > /dev/null
if [ $? -eq 0 ]; then
echo -e "$Success Examples built and ran"
else
echo -e "$Failed Examples didn't build, or hit runtime errors"
fi
popd > /dev/null
echo -e ""
echo -e "$Delimeter"
echo -e ""
}
function FetchBonsaiDebug
{
[ -d lib_bonsai_debug ] && rm -Rf lib_bonsai_debug
cp -R ../bonsai/releases/debug_lib lib_bonsai_debug
}
function BuildAllBinaries
{
BuildPoof
# BuildPoofEmcc
BuildParserTests
}
function RunAllTests
{
RunParserTests
RunIntegrationTests
RunExtendedIntegrationTests
}
function BuildAllBinariesRunAllTests
{
BuildAllBinaries
RunAllTests
BuildAndRunAllExamples
}
if [ ! -d "$BIN" ]; then
mkdir "$BIN"
fi
if [ ! -d "$BIN_TEST" ]; then
mkdir "$BIN_TEST"
fi
echo -e ""
echo -e "$Delimeter"
echo -e ""
: "${OPTIMIZATION_LEVEL:="-O0"}"
: "${BONSAI_INTERNAL:="-D BONSAI_INTERNAL=1"}"
# If someone supplied a command line argument, call the function, otherwise
# respect the 'runflags'
if [ $# -eq 1 ]; then
# If someone's just trying to run the build/tests from the CLI normally don't
# throw a bunch of garbage output
TEST_LOG_LEVEL="--log-level LogLevel_Error"
POOF_LOG_LEVEL="--log-level LogLevel_Error"
# If someone's just trying to run the build/tests from the CLI normally don't
# throw them into a debugging environment
POOF_DEBUGGER=""
TEST_DEBUGGER=""
"$@"
else
BuildAllBinariesRunAllTests
fi