Skip to content

Commit

Permalink
Add makefile goal to verify the generated parser (#126)
Browse files Browse the repository at this point in the history
goal will fail if the `git diff` command exists with a non-0
return code.
the goal is called during the build on travis-ci.

Fixes #126

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jun 12, 2018
1 parent 8f08511 commit ac33738
Show file tree
Hide file tree
Showing 3 changed files with 5,719 additions and 42,194 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ matrix:
allow_failures:
- go: tip
script:
- make generate
- make test
# verify that the commit code for the parser was optimized during the code generation
- make verify-parser
# verify that the library builds completly
- make build
# run the tests
- make test

after_success:
- gover . coverage.txt
Expand Down
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $(TMP_PATH):

.PHONY: prebuild-checks
prebuild-checks: $(TMP_PATH) $(INSTALL_PREFIX)
# Check that all tools where found
## Check that all tools where found
ifndef GIT_BIN
$(error The "$(GIT_BIN_NAME)" executable could not be found in your PATH)
endif
Expand All @@ -89,17 +89,17 @@ ifndef GO_BIN
endif

.PHONY: generate
## generates the .go file based on the asciidoc grammar
generate:
## generate the .go file based on the asciidoc grammar
generate: prebuild-checks
@echo "generating the parser..."
@pigeon ./pkg/parser/asciidoc-grammar.peg > ./pkg/parser/asciidoc_parser.go

.PHONY: generate-optimized
## generates the .go file based on the asciidoc grammar
## generate the .go file based on the asciidoc grammar
generate-optimized:
@echo "generating the parser..."
## @pigeon -optimize-parser ./pkg/parser/asciidoc-grammar.peg > ./pkg/parser/asciidoc_parser.go
@pigeon -optimize-grammar ./pkg/parser/asciidoc-grammar.peg > ./pkg/parser/asciidoc_parser.go
# @pigeon -optimize-parser ./pkg/parser/asciidoc-grammar.peg > ./pkg/parser/asciidoc_parser.go


.PHONY: test
Expand All @@ -109,7 +109,7 @@ test: deps generate
@ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --trace --race --compilers=2 --cover -coverpkg $(COVERPKGS)

.PHONY: build
## builds the binary executable from CLI
## build the binary executable from CLI
build: $(INSTALL_PREFIX) deps generate-optimized
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))
$(eval BUILD_TAG:=$(shell git tag --contains $(BUILD_COMMIT)))
Expand All @@ -122,6 +122,19 @@ build: $(INSTALL_PREFIX) deps generate-optimized
-o $(BINARY_PATH) \
cmd/libasciidoc/*.go


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/asciidoc_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: build
Expand Down
Loading

0 comments on commit ac33738

Please sign in to comment.