forked from anz-bank/sysl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (69 loc) · 2.88 KB
/
Makefile
File metadata and controls
100 lines (69 loc) · 2.88 KB
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
PKGS := $(shell go list ./... | grep -v /vendor)
BIN_DIR := $(GOPATH)/bin
# Try to detect current branch if not provided from environment
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
# Commit hash from git
COMMIT=$(shell git rev-parse --short HEAD)
# Tag on this commit
TAG = $(shell git tag --points-at HEAD)
ifneq ("$(shell which gotestsum)", "")
TESTEXE := gotestsum --
else
TESTEXE := go test ./...
endif
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
VERSION := $(or $(TAG),$(COMMIT)-$(BRANCH)-$(BUILD_DATE))
LDFLAGS = -X main.Version=$(VERSION) -X main.GitCommit=$(COMMIT) -X main.BuildDate=$(BUILD_DATE)
all: test lint build coverage examples ## test, lint, build, coverage test run
TUTORIALS: $(wildcard ./demo/examples/*) $(wildcard ./demo/examples/*/*)
examples: TUTORIALS
cd demo/examples/ && go run generate_website.go && cd ../../
.PHONY: all deps install grammar antlr build lint test coverage clean
lint: ## Run golangci-lint
golangci-lint run
coverage: ## Verify the test coverage remains high
./scripts/check-coverage.sh 80
test: ## Run tests without coverage
rm -rf pkg/grammar/temp
$(TESTEXE)
BINARY := sysl
PLATFORMS := windows linux darwin
.PHONY: $(PLATFORMS)
$(PLATFORMS): build
mkdir -p release
GOOS=$@ GOARCH=amd64 \
go build -o release/$(BINARY)-$(VERSION)-$@$(shell test $@ = windows && echo .exe) \
-ldflags="$(LDFLAGS)" \
-v \
./cmd/sysl
build: ## Build sysl into the ./dist folder
go build -o ./dist/sysl -ldflags="$(LDFLAGS)" -v ./cmd/sysl
deps: ## Download the project dependencies with `go get`
go get -v -t -d ./...
.PHONY: release
release: $(PLATFORMS) ## Build release binaries for all supported platforms into ./release
install: build ## Install the sysl binary into $(GOPATH)/bin
cp ./dist/sysl $(GOPATH)/bin
clean: ## Clean temp and build files
rm -rf release dist pkg/grammar/temp
# Autogen rules
ANTLR = java -jar pkg/antlr-4.7-complete.jar
GRAMMARS = pkg/grammar/SyslParser.g4 \
pkg/grammar/SyslLexer.g4
antlr: $(GRAMMARS)
$(ANTLR) -Dlanguage=Go -lib pkg/grammar -o pkg/grammar/temp $^
pkg/grammar/sysl_parser.go: antlr
cp pkg/grammar/temp/pkg/grammar/sysl*parser*.go pkg/grammar
git apply pkg/grammar/antlr4-datarace-fix-parser.go.diff
pkg/grammar/sysl_lexer.go: antlr
cp pkg/grammar/temp/pkg/grammar/sysl*lexer*.go pkg/grammar
git apply pkg/grammar/antlr4-datarace-fix-lexer.go.diff
grammar: pkg/grammar/sysl_lexer.go pkg/grammar/sysl_parser.go pkg/parser/grammar.pb.go ## Regenerate the grammars
pkg/parser/grammar.pb.go: pkg/parser/grammar.proto
protoc -I pkg/parser -I $(GOPATH)/src --go_out=pkg/parser grammar.proto
pkg/proto_old/sysl.pb.go: pkg/proto_old/sysl.proto
protoc -I pkg/proto_old -I $(GOPATH)/src --go_out=pkg/proto_old/ sysl.proto
proto: pkg/sysl/sysl.pb.go
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'