-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (139 loc) · 5.48 KB
/
Makefile
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
ifeq ($(OS),Windows_NT)
UNAME_S := Windows
EXE := .\\zig-out\\bin\\main.exe
else
UNAME_S := $(shell uname -s)
EXE := ./zig-out/bin/main
endif
define generate_sources
$(wildcard src/*.zig)
endef # or use `$(shell find src -name '*.zig')`
# the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small
RELEASE_FLAGS := --release=fast
TEST_FILE := test.lox
TRACE_FLAGS := -freference-trace
VALGRIND := valgrind --leak-check=full --show-leak-kinds=all -s --track-origins=yes
ZIG_FILES := $(call generate_sources)
ZIG_SRCS := $(shell find src -name '*.zig' -not -name 'test_*.zig')
ZIG_TEST_FILES := $(shell find src -name 'test_*.zig')
.PHONY: clean
clean:
@date && echo $(UNAME_S)
rm -rf zig-out .zig-cache vgcore.*
echo $$?
.PHONY: bench
bench:
hyperfine --shell=none --warmup=25 --ignore-failure './zig-out/bin/main run test.lox' './zig-out/bin/main run test.lox'
.PHONY: build
build: $(ZIG_SRCS)
# Debug
@zig build --summary all $(TRACE_FLAGS) # $(RELEASE_FLAGS)
# @$(foreach src,$(call generate_sources), \
# # echo "Running ast-check on $(src)"; \
# zig ast-check $(src); \
# )
ast-check: $(ZIG_FILES)
@echo "Running ast-check in parallel on $(ZIG_FILES)"
@echo $(ZIG_FILES) | tr ' ' '\n' | parallel -j $(shell nproc) --halt-on-error 1 'zig ast-check {};'
# @$(foreach src,$(ZIG_SRCS), \
# echo "Running zig test on $(src)"; \
# zig ast-check $(src); \
# zig test $(src) $(TRACE_FLAGS); \
# )
.PHONY: test-zig-srcs
test-zig-srcs: $(ZIG_SRCS) ./.zig-cache/o
@make ast-check
@echo "Running zig tests in parallel on $(ZIG_SRCS)"
@echo $(ZIG_SRCS) | tr ' ' '\n' | parallel -j $(shell nproc) --halt soon,fail=3% 'echo "Running zig test on {}"; zig ast-check {}; zig test {} $(TRACE_FLAGS) 2>&1'
.PHONY: test-zig-srcs
SUPPRESS_STDERR_FLAGS := 2>&1 | head
SUPPRESS_STDERR_FLAGS =
# : echo $(ZIG_TEST_FILES) | tr ' ' '\n' | parallel -j $(shell nproc) --halt-on-error 1 'echo "Running zig test on {}"; zig ast-check {}; zig test {} $(TRACE_FLAGS);'
test-zig-test-files: $(ZIG_TEST_FILES)
@make ast-check
@echo "Running zig tests in parallel on $(ZIG_TEST_FILES)"
echo $(ZIG_TEST_FILES) | tr ' ' '\n' | parallel -j $(shell nproc) 'echo "Running zig test on {}"; zig ast-check {}; zig test {} $(TRACE_FLAGS) $(SUPPRESS_STDERR_FLAGS);'
.PHONY: test
test: $(ZIG_SRCS)
@date && echo $(UNAME_S)
# capture both stdout and stderr
zig test src/test_statements_and_state.zig $(TRACE_FLAGS) 2>&1 | head &
zig test src/test_expressions_evaluate.zig $(TRACE_FLAGS) 2>&1 | head &
zig test src/test_expressions_parse.zig $(TRACE_FLAGS) 2>&1 | head &
zig test src/test_scanning.zig $(TRACE_FLAGS) 2>&1 | head &
wait
#
# COMMANDS
#
.PHONY: tokenize parse evaluate run
tokenize:
@make ast-check
@make build
$(EXE) tokenize test.lox $(TRACE_FLAGS) && echo
parse:
@make ast-check
@make build
$(EXE) parse test.lox $(TRACE_FLAGS) && echo
evaluate:
@make ast-check
@make build
$(EXE) evaluate test.lox $(TRACE_FLAGS) && echo
run:
@make ast-check
@make build
$(EXE) run test.lox $(TRACE_FLAGS) && echo
.PHONY: valgrind-tokenize valgrind-parse valgrind-evaluate valgrind-run
# @for src in $(ZIG_FILES); do echo "Running ast-check on $$src"; zig ast-check $$src; done
pre-valgrind:
make ast-check
@echo "Building project from build.zig"
@make build
valgrind-tokenize:
make -j4 pre-valgrind
$(VALGRIND) $(EXE) tokenize $(TEST_FILE) $(TRACE_FLAGS)
valgrind-parse:
make -j4 pre-valgrind
$(VALGRIND) $(EXE) parse $(TEST_FILE) $(TRACE_FLAGS)
valgrind-evaluate:
make -j4 pre-valgrind
$(VALGRIND) $(EXE) evaluate $(TEST_FILE) $(TRACE_FLAGS)
valgrind-run:
make -j4 pre-valgrind
$(VALGRIND) $(EXE) run $(TEST_FILE) $(TRACE_FLAGS)
#
# EXAMPLES
#
define generate_example_sources
$(wildcard examples/*.lox)
endef # or use `$(shell find src/examples -name '*.lox')`
EXAMPLE_FILES := $(call generate_example_sources)
# @printf "Running command 'run' on examples\n└─\x1b[37m$(EXAMPLE_FILES)\x1b[0m\n"
# @$(foreach src,$(EXAMPLE_FILES), \
# printf "\x1b[37mInterpreting file\n└─ $(src)\x1b[0m\n"; \
# $(VALGRIND) $(EXE) run $(src) $(TRACE_FLAGS); \
# )
.PHONY: run-examples
run-examples: $(EXAMPLE_FILES)
make ast-check
@echo "Building project from build.zig"
@make build
@printf "Running command 'run' on examples\n└─\x1b[37m$(EXAMPLE_FILES)\x1b[0m\n"
: "NOTE: halt on error is disabled. e.g: " parallel -j $(shell nproc) --halt-on-error 1 'printf ...'
@echo $(EXAMPLE_FILES) | tr ' ' '\n' | parallel -j $(shell nproc) 'printf "\x1b[37mInterpreting file\n└─ {} \x1b[0m\n"; $(EXE) run {} $(TRACE_FLAGS);'
.PHONY: valgrind-run-examples
valgrind-run-examples: $(EXAMPLE_FILES)
make -j4 pre-valgrind
@printf "Running command 'run' on examples\n└─\x1b[37m$(EXAMPLE_FILES)\x1b[0m\n"
: "NOTE: halt on error is disabled. e.g: " parallel -j $(shell nproc) --halt-on-error 1 'printf ...'
@echo $(EXAMPLE_FILES) | tr ' ' '\n' | parallel -j $(shell nproc) 'printf "\x1b[37mInterpreting file\n└─ {} \x1b[0m\n"; $(VALGRIND) $(EXE) run {} $(TRACE_FLAGS);'
.PHONY: all
# // Usage:
# //
# // $ ./your_program.sh tokenize test.lox
# // $ ./zig-out/bin/main tokenize test.lox
# // $ zig test src/main.zig
# // $ find . -name '*.zig' | entr -crs 'date; zig test src/main.zig; echo exit status $?'
# // $ find . -name '*.lox' | entr -crs 'date; make parse; echo exit code: $?'
# // $ find . -name '*.lox' | entr -crs 'date; make tokenize; echo exit code: $?'
# // $ find . -name '*.lox' | entr -crs 'date; make evaluate; echo exit code: $?'
# //