-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
142 lines (121 loc) · 4.13 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
# Makefile for the `tsgo` project
# tools
CUR_DIR=$(shell pwd)
INSTALL_PREFIX=$(CUR_DIR)/bin
VENDOR_DIR=vendor
SOURCE_DIR ?= .
COVERPKGS := $(shell go list ./... | grep -v vendor | paste -sd "," -)
DEVTOOLS=
ifeq ($(OS),Windows_NT)
BINARY_PATH=$(INSTALL_PREFIX)/tsgo.exe
else
BINARY_PATH=$(INSTALL_PREFIX)/tsgo
endif
# Call this function with $(call log-info,"Your message")
define log-info =
@echo "INFO: $(1)"
endef
.PHONY: help
# Based on https://gist.github.com/rcmachado/af3db315e31383502660
## Display this help text.
help:/
$(info Available targets)
$(info -----------------)
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
if (helpMessage) { \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub(/##/, "\n ", helpMessage); \
} else { \
helpMessage = "(No documentation)"; \
} \
printf "%-35s - %s\n", helpCommand, helpMessage; \
lastLine = "" \
} \
{ hasComment = match(lastLine, /^## (.*)/); \
if(hasComment) { \
lastLine=lastLine$$0; \
} \
else { \
lastLine = $$0 \
} \
}' $(MAKEFILE_LIST)
.PHONY: install-devtools
## Install development tools.
install-devtools:
@go mod download
$(INSTALL_PREFIX):
# Build artifacts dir
@mkdir -p $(INSTALL_PREFIX)
.PHONY: prebuild-checks
## Check that all tools where found
prebuild-checks: $(INSTALL_PREFIX)
.PHONY: generate
## generate the .go file based on the asciidoc grammar
generate: prebuild-checks
@echo "generating the parser..."
.PHONY: generate-optimized
## generate the .go file based on the asciidoc grammar
generate-optimized:
@echo "generating the parser (optimized)..."
.PHONY: test
## run all tests excluding fixtures and vendored packages
test: generate-optimized
@echo $(COVERPKGS)
.PHONY: test-with-coverage
## run all tests excluding fixtures and vendored packages
test-with-coverage: generate-optimized
@echo $(COVERPKGS)
.PHONY: test-fixtures
## run all fixtures tests
test-fixtures: generate-optimized
@echo "run all fixtures tests"
.PHONY: bench-parser
## run the benchmarks on the parser
bench-parser: generate-optimized
@echo "run the benchmarks on the parser"
.PHONY: build
## build the binary executable from CLI
build: $(INSTALL_PREFIX) generate-optimized
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))
$(eval BUILD_TAG:=$(shell git tag --contains $(BUILD_COMMIT)))
$(eval BUILD_TIME:=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ'))
@echo "building $(BINARY_PATH) (commit:$(BUILD_COMMIT) / tag:$(BUILD_TAG) / time:$(BUILD_TIME))"
@go build -ldflags \
" -X github.com/saycv/tsgo.BuildCommit=$(BUILD_COMMIT)\
-X github.com/saycv/tsgo.BuildTag=$(BUILD_TAG) \
-X github.com/saycv/tsgo.BuildTime=$(BUILD_TIME)" \
-o $(BINARY_PATH) \
cmd/tsgo/*.go
.PHONY: lint
## run golangci-lint against project
lint:
@golangci-lint run -E gofmt,golint,megacheck,misspell ./...
PARSER_DIFF_STATUS :=
.PHONY: verify-parser
## verify that the parser was built with the latest version of pigeon, using the `optimize-grammar` option
verify-parser: prebuild-checks
ifneq ($(shell git diff --quiet pkg/parser/parser.go; echo $$?), 0)
$(error "parser was generated with an older version of 'mna/pigeon' or without the '-optimize' option(s).")
else
@echo "parser is ok"
endif
.PHONY: install
## installs the binary executable in the $GOPATH/bin directory
install: install-devtools build
@cp $(BINARY_PATH) $(GOPATH)/bin
.PHONY: quick-install
## installs the binary executable in the $GOPATH/bin directory without prior tools setup and parser generation
quick-install:
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))
$(eval BUILD_TAG:=$(shell git tag --contains $(BUILD_COMMIT)))
$(eval BUILD_TIME:=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ'))
@echo "building $(BINARY_PATH) (commit:$(BUILD_COMMIT) / tag:$(BUILD_TAG) / time:$(BUILD_TIME))"
@go build -ldflags \
" -X github.com/saycv/tsgo.BuildCommit=$(BUILD_COMMIT)\
-X github.com/saycv/tsgo.BuildTag=$(BUILD_TAG) \
-X github.com/saycv/tsgo.BuildTime=$(BUILD_TIME)" \
-o $(BINARY_PATH) \
cmd/tsgo/*.go
@cp $(BINARY_PATH) $(GOPATH)/bin