forked from bytesparadise/libasciidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (134 loc) · 5.18 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
# Makefile for the `libasciidoc` 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=\
github.com/mna/pigeon \
github.com/onsi/ginkgo/ginkgo \
github.com/sozorogami/gover
ifeq ($(OS),Windows_NT)
BINARY_PATH=$(INSTALL_PREFIX)/libasciidoc.exe
else
BINARY_PATH=$(INSTALL_PREFIX)/libasciidoc
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
@go install -v $(DEVTOOLS)
$(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..."
@pigeon ./pkg/parser/parser.peg > ./pkg/parser/parser.go
.PHONY: generate-optimized
## generate the .go file based on the asciidoc grammar
generate-optimized:
@echo "generating the parser (optimized)..."
@pigeon -optimize-parser \
-alternate-entrypoints AsciidocDocument,AsciidocDocumentWithinDelimitedBlock,TextDocument,DocumentBlock,InlineElementsWithoutSubtitution,FileLocation,IncludedFileLine,InlineLinks,LabeledListItemTerm \
-o ./pkg/parser/parser.go ./pkg/parser/parser.peg
.PHONY: test
## run all tests excluding fixtures and vendored packages
test: generate-optimized
@echo $(COVERPKGS)
@ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --trace --race --compilers=0
.PHONY: test-with-coverage
## run all tests excluding fixtures and vendored packages
test-with-coverage: generate-optimized
@echo $(COVERPKGS)
@ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --trace --race --compilers=0 --cover -coverpkg $(COVERPKGS)
.PHONY: test-fixtures
## run all fixtures tests
test-fixtures: generate-optimized
@ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --trace --race --compilers=2 -tags=fixtures --focus=fixtures
.PHONY: bench-parser
## run the benchmarks on the parser
bench-parser: generate-optimized
$(eval GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD))
go test -run="XXX" -bench=. -benchmem -count=10 \
github.com/bytesparadise/libasciidoc/pkg/parser | \
tee ./tmp/bench-$(GIT_BRANCH).txt
.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/bytesparadise/libasciidoc.BuildCommit=$(BUILD_COMMIT)\
-X github.com/bytesparadise/libasciidoc.BuildTag=$(BUILD_TAG) \
-X github.com/bytesparadise/libasciidoc.BuildTime=$(BUILD_TIME)" \
-o $(BINARY_PATH) \
cmd/libasciidoc/*.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/bytesparadise/libasciidoc.BuildCommit=$(BUILD_COMMIT)\
-X github.com/bytesparadise/libasciidoc.BuildTag=$(BUILD_TAG) \
-X github.com/bytesparadise/libasciidoc.BuildTime=$(BUILD_TIME)" \
-o $(BINARY_PATH) \
cmd/libasciidoc/*.go
@cp $(BINARY_PATH) $(GOPATH)/bin