Skip to content

Commit 3b2afdd

Browse files
authored
Makefile refactor (#119)
1 parent f48d46c commit 3b2afdd

File tree

6 files changed

+177
-103
lines changed

6 files changed

+177
-103
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
bin
2-
doc/repl/glj.wasm
1+
/bin
2+
/doc/repl/glj.wasm
3+
/report.html
34
.direnv
45

56
# useful to symlink in for context

Makefile

Lines changed: 128 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
2-
CLOJURE_STDLIB_VERSION := clojure-1.12.1
3-
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
4-
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
5-
STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
6-
STDLIB_ORIGINALS := $(addprefix scripts/rewrite-core/originals/,$(STDLIB))
7-
STDLIB_TARGETS := $(addprefix pkg/stdlib/clojure/,$(STDLIB:.clj=.glj))
1+
# Usage:
2+
# make clean all test GO-VERSION=1.25.1
3+
4+
SHELL := bash
5+
6+
GO-VERSION ?= 1.19.3
7+
CLOJURE-VERSION ?= 1.12.1
8+
9+
CLOJURE-STDLIB-VERSION := clojure-$(CLOJURE-VERSION)
10+
STDLIB-ORIGINALS-DIR := scripts/rewrite-core/originals
11+
STDLIB-ORIGINALS := $(wildcard $(STDLIB-ORIGINALS-DIR)/*.clj)
12+
STDLIB-NAMES := $(STDLIB-ORIGINALS:scripts/rewrite-core/originals/%=%)
13+
STDLIB-ORIGINALS := $(STDLIB-NAMES:%=scripts/rewrite-core/originals/,%)
14+
STDLIB-TARGETS := $(addprefix pkg/stdlib/clojure/,$(STDLIB-NAMES:.clj=.glj))
15+
16+
AOT-NAMESPACES := \
17+
clojure.core \
18+
clojure.core.async \
19+
clojure.string \
20+
clojure.template \
21+
clojure.test \
22+
clojure.uuid \
23+
clojure.walk \
24+
glojure.go.io \
25+
glojure.go.types \
26+
$(EXTRA-AOT-NAMESPACES)
827

928
OS-TYPE := $(shell bash -c 'echo $$OSTYPE')
1029
OS-NAME := \
@@ -23,88 +42,142 @@ OA-linux-arm64 := linux_arm64
2342
OA-linux-int64 := linux_amd64
2443
OA-macos-arm64 := darwin_arm64
2544
OA-macos-int64 := darwin_amd64
26-
OA := $(OA-$(OS-ARCH))
27-
GLJ := bin/$(OA)/glj
45+
GLJ-CMD := bin/$(OA-$(OS-ARCH))/glj
2846
endif
2947
endif
3048

31-
TEST_FILES := $(shell find ./test -name '*.glj' | sort)
32-
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))
49+
TEST-GLJ-DIR := test/glojure
50+
TEST-GLJ-FILES := $(shell find $(TEST-GLJ-DIR) -name '*.glj' | sort)
51+
TEST-GLJ-TARGETS := $(addsuffix .test,$(TEST-GLJ-FILES))
52+
TEST-SUITE-DIR := test/clojure-test-suite
53+
TEST-SUITE-FILE := test-glojure.glj
54+
55+
GO-PLATFORMS := \
56+
darwin_arm64 \
57+
darwin_amd64 \
58+
linux_arm64 \
59+
linux_amd64 \
60+
windows_arm \
61+
windows_amd64 \
62+
js_wasm \
63+
$(EXTRA-GO-PLATFORMS)
64+
65+
GLJ-IMPORTS=$(foreach platform,$(GO-PLATFORMS) \
66+
,pkg/gen/gljimports/gljimports_$(platform).go)
3367

34-
GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
35-
GLJIMPORTS=$(foreach platform,$(GOPLATFORMS),pkg/gen/gljimports/gljimports_$(platform).go)
3668
# wasm should have .wasm suffix; others should not
37-
BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
69+
GLJ-BINS=$(foreach platform,$(GO-PLATFORMS) \
70+
,bin/$(platform)/glj$(if $(findstring wasm,$(platform)),.wasm,))
71+
72+
GO-CMD := go$(GO-VERSION)
73+
74+
ALL-TARGETS := \
75+
$(if $(force),update-clojure-sources) \
76+
stdlib-targets \
77+
generate \
78+
aot \
79+
glj-imports \
80+
glj-bins \
3881

39-
# eventually, support multiple minor versions
40-
GO_VERSION := 1.19.3
41-
GO_CMD := go$(GO_VERSION)
82+
#-------------------------------------------------------------------------------
83+
default: all
4284

43-
.PHONY: all
44-
all: gocmd $(STDLIB_TARGETS) go-generate aot $(GLJIMPORTS) $(BINS)
85+
# Dummy target for commands like:
86+
# make all force=1
87+
# make stdlib-targets force=1
88+
force:
89+
90+
all: $(ALL-TARGETS)
4591

46-
.PHONY: gocmd
4792
gocmd:
48-
@$(GO_CMD) version 2>&1 > /dev/null || \
49-
(go install "golang.org/dl/$(GO_CMD)@latest" && \
50-
$(GO_CMD) download > /dev/null && $(GO_CMD) version > /dev/null)
93+
@$(GO-CMD) version &> /dev/null || { \
94+
(go install "golang.org/dl/$(GO-CMD)@latest" && \
95+
$(GO-CMD) download > /dev/null && \
96+
$(GO-CMD) version > /dev/null); }
97+
98+
stdlib-targets: $(STDLIB-TARGETS)
5199

52-
.PHONY: go-generate
53100
generate:
54-
@go generate ./...
101+
go generate ./...
55102

56-
.PHONY: aot
57-
aot: gocmd $(STDLIB_TARGETS)
58-
@echo "(map compile '[clojure.core clojure.core.async clojure.string clojure.template clojure.test clojure.uuid clojure.walk glojure.go.types glojure.go.io])" | \
59-
GLOJURE_USE_AOT=false GLOJURE_STDLIB_PATH=./pkg/stdlib $(GO_CMD) run -tags glj_no_aot_stdlib ./cmd/glj
103+
aot: gocmd $(STDLIB-TARGETS)
104+
GLOJURE_USE_AOT=false \
105+
GLOJURE_STDLIB_PATH=./pkg/stdlib \
106+
$(GO-CMD) run -tags glj_no_aot_stdlib ./cmd/glj \
107+
<<<"(map compile '[$(AOT-NAMESPACES)])"
60108

61-
.PHONY: build
62-
build: $(GLJ)
109+
glj-imports: $(GLJ-IMPORTS)
63110

64-
.PHONY: clean
65-
clean:
66-
$(RM) -r bin/
111+
glj-bins: $(GLJ-BINS)
67112

68-
pkg/gen/gljimports/gljimports_%.go: ./scripts/gen-gljimports.sh ./cmd/gen-import-interop/main.go ./internal/genpkg/genpkg.go \
69-
$(wildcard ./pkg/lang/*.go) $(wildcard ./pkg/runtime/*.go)
113+
build: $(GLJ-CMD)
114+
115+
clean:
116+
$(RM) report.html
117+
$(RM) -r bin/ scripts/rewrite-core/.cpcache/
118+
119+
pkg/gen/gljimports/gljimports_%.go: \
120+
./scripts/gen-gljimports.sh \
121+
./cmd/gen-import-interop/main.go \
122+
./internal/genpkg/genpkg.go \
123+
$(wildcard ./pkg/lang/*.go) \
124+
$(wildcard ./pkg/runtime/*.go) \
125+
$(if $(force),force)
70126
@echo "Generating $@"
71-
@./scripts/gen-gljimports.sh $@ $* $(GO_CMD)
127+
./scripts/gen-gljimports.sh $@ $* $(GO-CMD)
72128

73-
pkg/stdlib/clojure/%.glj: scripts/rewrite-core/originals/%.clj scripts/rewrite-core/run.sh scripts/rewrite-core/rewrite.clj
129+
pkg/stdlib/clojure/%.glj: \
130+
scripts/rewrite-core/originals/%.clj \
131+
scripts/rewrite-core/run.sh \
132+
scripts/rewrite-core/rewrite.clj \
133+
$(if $(force),force)
74134
@echo "Rewriting $< to $@"
75135
@mkdir -p $(dir $@)
76-
@scripts/rewrite-core/run.sh $< > $@
136+
scripts/rewrite-core/run.sh $< > $@
77137

78-
bin/%/glj: generate $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
138+
bin/%/glj: generate \
139+
$(wildcard ./cmd/glj/*.go) \
140+
$(wildcard ./pkg/**/*.go) \
141+
$(wildcard ./internal/**/*.go) \
142+
$(if $(force),force)
79143
@echo "Building $@"
80144
@mkdir -p $(dir $@)
81-
@scripts/build-glj.sh $@ $*
145+
scripts/build-glj.sh $@ $*
82146

83-
bin/%/glj.wasm: $(wildcard ./cmd/glj/*.go) $(wildcard ./pkg/**/*.go) $(wildcard ./internal/**/*.go)
147+
bin/%/glj.wasm: \
148+
$(wildcard ./cmd/glj/*.go) \
149+
$(wildcard ./pkg/**/*.go) \
150+
$(wildcard ./internal/**/*.go) \
151+
$(if $(force),force)
84152
@echo "Building $@"
85153
@mkdir -p $(dir $@)
86-
@scripts/build-glj.sh $@ $*
154+
scripts/build-glj.sh $@ $*
87155

88-
.PHONY: vet
89156
vet:
90-
@go vet ./...
91-
92-
.PHONY: $(TEST_TARGETS)
93-
$(TEST_TARGETS): gocmd $(GLJ)
94-
@$(GLJ) $(basename $@)
157+
go vet ./...
95158

96159
.PHONY: test
97-
test: $(TEST_TARGETS) # vet - vet is disabled until we fix errors in generated code
98-
@cd test/clojure-test-suite && \
99-
../../$(GLJ) test-glojure.glj --expect-failures 38 --expect-errors 151 2>/dev/null
160+
# vet is disabled until we fix errors in generated code
161+
test: test-glj test-suite # vet
162+
163+
test-glj: $(TEST-GLJ-TARGETS)
164+
165+
test-suite: $(GLJ-CMD)
166+
cd $(TEST-SUITE-DIR) && \
167+
$(abspath $<) $(TEST-SUITE-FILE) \
168+
--expect-failures 38 \
169+
--expect-errors 151 \
170+
2>/dev/null
171+
172+
$(TEST-GLJ-TARGETS): $(GLJ-CMD)
173+
$< $(basename $@)
100174

101-
.PHONY: format
102175
format:
103176
@if go fmt ./... | grep -q ''; then \
104177
echo "Files were formatted. Please commit the changes."; \
105178
exit 1; \
106179
fi
107180

108-
.PHONY: update-clojure-sources
109181
update-clojure-sources:
110-
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE_STDLIB_VERSION)
182+
scripts/rewrite-core/update-clojure-sources.sh \
183+
$(CLOJURE-STDLIB-VERSION)

pkg/ast/ast.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,21 @@ type (
190190
}
191191

192192
CaseNode struct {
193-
Test *Node // The expression to test
194-
Shift int64 // Bit shift for hash compaction
195-
Mask int64 // Bit mask for hash compaction
196-
TestType interface{} // Keyword: :int, :hash-identity, or :hash-equiv
197-
SwitchType interface{} // Keyword: :compact or :sparse
198-
Default *Node // Default expression
199-
Entries []CaseEntry // Case entries
200-
SkipCheck map[int64]bool // Set of keys with collisions
193+
Test *Node // The expression to test
194+
Shift int64 // Bit shift for hash compaction
195+
Mask int64 // Bit mask for hash compaction
196+
TestType interface{} // Keyword: :int, :hash-identity, or :hash-equiv
197+
SwitchType interface{} // Keyword: :compact or :sparse
198+
Default *Node // Default expression
199+
Entries []CaseEntry // Case entries
200+
SkipCheck map[int64]bool // Set of keys with collisions
201201
}
202202

203203
CaseEntry struct {
204-
Key int64 // Map key (int value or shifted/masked hash)
205-
TestConstant *Node // Original test constant (nil for collisions)
206-
ResultExpr *Node // Result expression or condp for collisions
207-
HasCollision bool // Whether this is a collision case
204+
Key int64 // Map key (int value or shifted/masked hash)
205+
TestConstant *Node // Original test constant (nil for collisions)
206+
ResultExpr *Node // Result expression or condp for collisions
207+
HasCollision bool // Whether this is a collision case
208208
}
209209

210210
TheVarNode struct {

pkg/stdlib/clojure/walk/loader.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)