-
Notifications
You must be signed in to change notification settings - Fork 42
/
Makefile
192 lines (144 loc) · 6.06 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
include ./scripts/version-report.mk
.PHONY: all install grammar antlr build lint test test-arrai coverage clean check-clean gen generate golden
GOPATH = $(shell go env GOPATH)
GOVERSION = $(shell go version | cut -d' ' -f3-4)
BIN_DIR := $(GOPATH)/bin
ARRAI = go run github.com/arr-ai/arrai/cmd/arrai
ifneq ("$(shell which gotestsum)", "")
TESTEXE := gotestsum --
else
TESTEXE := go test ./...
endif
all: lint build buildlsp install test coverage
lint: generate
golangci-lint run ./...
make -C docs lint
lint-docker: generate
docker run --rm \
-v $(CURDIR):/app \
-e GOCACHE=/cache/go \
-v ${GOPATH}/pkg:/go/pkg \
-w /app \
golangci/golangci-lint:v1.55.0 \
golangci-lint run -v
tidy:
go mod tidy
gofmt -s -w .
goimports -w .
make -C docs tidy
# Generates intermediate files for build.
generate: internal/bundles/bundles.go plugins bundled-proto
go generate ./pkg/lsp/...
gen: generate
test: test-arrai coverage
test-arrai: internal/bundles/bundles.go
$(ARRAI) test
coverage: generate
./scripts/test-with-coverage.sh 75
# Updates golden test files in pkg/parse.
golden: generate
go test ./pkg/parse ./pkg/exporter ./pkg/importer -update
# TODO: Extend the -update flag to work for all golden files
sysl pb --mode=textpb tests/args.sysl > tests/args.sysl.golden.textpb
sysl pb --mode=json tests/args.sysl > tests/args.sysl.golden.json
sysl pb --mode=textpb tests/type_merge1.sysl > tests/type_merge1.sysl.golden.textpb
sysl pb --mode=textpb tests/type_merge2.sysl > tests/type_merge2.sysl.golden.textpb
sysl pb --mode=textpb tests/file_merge.sysl > tests/file_merge.sysl.golden.textpb
sysl pb --mode=json tests/file_merge.sysl > tests/file_merge.sysl.golden.json
sysl pb --mode=textpb tests/namespace_merge.sysl > tests/namespace_merge.sysl.golden.textpb
check-clean: generate
git --no-pager diff HEAD && test -z "$$(git status --porcelain)"
build: generate internal/bundles/bundles.go
CGO_ENABLED=0 go build -o ./dist/sysl -ldflags=$(LDFLAGS) -v ./cmd/sysl
build-windows: generate internal/bundles/bundles.go
CGO_ENABLED=0 go build -o ./dist/sysl.exe -ldflags=$(LDFLAGS) -v ./cmd/sysl
buildlsp: generate
go build -o ./dist/sysllsp -ldflags=$(LDFLAGS) -v ./cmd/sysllsp
build-docker: generate
docker build -t sysl .
build-sysl-version-diff-docker: generate
docker build -t sysl-version-diff -f sysl-version-diff/Dockerfile .
BUNDLE = mkdir -p $(dir $@) && $(ARRAI) bundle $< > $@
# Assumes that every arr.ai script depends on every other arr.ai script.
%.arraiz: %.arrai $(shell find . -name '*.arrai') go.mod
$(BUNDLE)
.PHONY: plugins
plugins: \
pkg/plugins/integration_model_plugin.arraiz
internal/bundles/assets/transformer_cli.arraiz: pkg/importer/avro/transformer_cli.arrai go.mod
$(BUNDLE)
internal/bundles/assets/import_sql_cli.arraiz: \
pkg/importer/sql/import_sql_cli.arrai \
pkg/importer/sql/sql.arrai \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)
internal/bundles/assets/import_openapi_cli.arraiz: \
pkg/importer/openapi/import_openapi_cli.arrai \
pkg/importer/cli.arrai \
$(shell find pkg/importer/openapi -name '*.arrai') \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)
# There are many files that change the proto importer logic.
# Check all arrai files within the directory for changes before bundling.
internal/bundles/assets/import_proto_cli.arraiz: \
pkg/importer/proto/import_proto_cli.arrai \
$(shell find pkg/importer/proto -name '*.arrai') \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)
internal/bundles/exporters/proto/transform.arraiz: transforms/exporters/proto/transform.arrai $(shell find transforms/exporters/proto -name '*.arrai') go.mod
$(BUNDLE)
internal/bundles/exporters/spanner/transform.arraiz: transforms/exporters/spanner/transform.arrai $(shell find transforms/exporters/spanner -name '*.arrai') go.mod
$(BUNDLE)
internal/bundles/importers/%/transform.arraiz: transforms/importers/%/transform.arrai go.mod
$(BUNDLE)
internal/bundles/bundles.go: \
internal/bundles/assets/transformer_cli.arraiz \
internal/bundles/assets/import_sql_cli.arraiz \
internal/bundles/assets/import_openapi_cli.arraiz \
internal/bundles/assets/import_proto_cli.arraiz \
internal/bundles/exporters/proto/transform.arraiz \
internal/bundles/exporters/spanner/transform.arraiz \
internal/bundles/importers/jsonschema/transform.arraiz
touch $@
pkg/importer/proto/bundled_files/local_imports.arrai: pkg/importer/proto/bundled_files/bundler.arrai
$(ARRAI) run $< > pkg/importer/proto/bundled_files/tmp.arrai && \
mv -f pkg/importer/proto/bundled_files/tmp.arrai $@
.PHONY: bundled-proto
bundled-proto: pkg/importer/proto/bundled_files/local_imports.arrai
release:
GOVERSION="$(GOVERSION)" goreleaser build --clean --snapshot -f .goreleaser.yml
install: build ## Install the sysl binary into $(GOPATH)/bin. We don't use go install because we need to pass in LDFLAGS.
test -n "$(GOPATH)" # $$GOPATH
rm -f $(GOPATH)/bin/sysl
cp ./dist/sysl $(GOPATH)/bin
clean:
rm -rf dist
# Autogen rules
ANTLR = java -jar pkg/antlr-4.7-complete.jar
ANTLR_GO = $(ANTLR) -Dlanguage=Go -lib $(@D) $<
grammar: pkg/grammar/sysl_lexer.go pkg/grammar/sysl_parser.go ## Regenerate the grammars
pkg/grammar/sysl_parser.go: pkg/grammar/SyslParser.g4 pkg/grammar/SyslLexer.tokens
$(ANTLR_GO)
pkg/grammar/sysl_lexer.go pkg/grammar/SyslLexer.tokens &: pkg/grammar/SyslLexer.g4
$(ANTLR_GO)
pkg/sysl/sysl.pb.go: pkg/sysl/sysl.proto
protoc -I pkg/sysl -I $(GOPATH)/src --go_out=pkg/sysl/ sysl.proto
pkg/sysl/sysl.pb: pkg/sysl/sysl.proto
protoc -o $@ $<
proto: pkg/sysl/sysl.pb.go pkg/sysl/sysl.pb
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
test-grammar:
which wbnf || go install github.com/arr-ai/wbnf
./scripts/test-grammar-wbnf.sh . | diff ./scripts/grammar-out.txt -
update-grammar-result:
which wbnf || go install github.com/arr-ai/wbnf
./scripts/test-grammar-wbnf.sh . > ./scripts/grammar-out.txt
test_ts: install_ts
yarn --cwd ts test
install_ts:
yarn --cwd ts install