forked from cucumber/gherkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (84 loc) · 4.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
SHELL := /usr/bin/env bash
GOOD_FEATURE_FILES = $(shell find ../testdata/good -name "*.feature")
BAD_FEATURE_FILES = $(shell find ../testdata/bad -name "*.feature")
TOKENS = $(patsubst ../testdata/%.feature,acceptance/testdata/%.feature.tokens,$(GOOD_FEATURE_FILES))
ASTS = $(patsubst ../testdata/%.feature,acceptance/testdata/%.feature.ast.ndjson,$(GOOD_FEATURE_FILES))
PICKLES = $(patsubst ../testdata/%.feature,acceptance/testdata/%.feature.pickles.ndjson,$(GOOD_FEATURE_FILES))
SOURCES = $(patsubst ../testdata/%.feature,acceptance/testdata/%.feature.source.ndjson,$(GOOD_FEATURE_FILES))
ERRORS = $(patsubst ../testdata/%.feature,acceptance/testdata/%.feature.errors.ndjson,$(BAD_FEATURE_FILES))
SRC_FILES= $(shell find src -name "*.[ch]*")
ifeq ($(CC),i686-w64-mingw32-gcc)
GHERKIN=bin/gherkin.exe
RUN_GHERKIN=wine $(GHERKIN)
GHERKIN_GENERATE_TOKENS=bin/gherkin_generate_tokens.exe
RUN_GHERKIN_GENERATE_TOKENS=wine $(GHERKIN_GENERATE_TOKENS)
else
GHERKIN=bin/gherkin
RUN_GHERKIN=$(GHERKIN)
GHERKIN_GENERATE_TOKENS=bin/gherkin_generate_tokens
RUN_GHERKIN_GENERATE_TOKENS=$(GHERKIN_GENERATE_TOKENS)
endif
.DELETE_ON_ERROR:
default: .compared
.PHONY: default
acceptance: .compared ## Build acceptance test dir and compare results with reference
.compared: .built $(TOKENS) $(ASTS) $(PICKLES) $(ERRORS) $(SOURCES) .run
touch $@
generate: ./include/rule_type.h src/parser.c ## Generate gherkin parser files
clean-generate: ## Remove generated Gherkin parser files ## Generate gherkin parser files
rm -f ./include/rule_type.h src/parser.c
.PHONY: clean-generate
copy-gherkin-languages: src/dialect.c ## Copy gherkin-languages.json and/or generate derived files
echo "Nothing to do"
clean-gherkin-languages: ## Remove gherkin-languages.json and any derived files
rm -f src/dialect.c
.built: generate $(SRC_FILES) src/Makefile
$(CC) --version
cd src; $(MAKE)
touch $@
clean:
rm -rf .compared .built .run acceptance
cd src; $(MAKE) $@
.PHONY: clean
cli: ./include/rule_type.h src/parser.c src/dialect.c $(SRC_FILES) src/Makefile
cd src; $(MAKE) CC=$(CC) $@
.PHONY: libs
libs: ./include/rule_type.h src/parser.c src/dialect.c $(SRC_FILES) src/Makefile
cd src; $(MAKE) CC=$(CC) $@
.PHONY: libs
libs_so: ./include/rule_type.h src/parser.c src/dialect.c $(SRC_FILES) src/Makefile
cd src; $(MAKE) CC=$(CC) $@
.PHONY: libs_so
.run: cli $(GHERKIN) $(GOOD_FEATURE_FILES)
$(RUN_GHERKIN) $(GOOD_FEATURE_FILES) | jq . > /dev/null
touch $@
define berp-generate-parser =
berp -g ../gherkin.berp -t $< -o $@ --noBOM
endef
./include/rule_type.h: gherkin-c-rule-type.razor gherkin.berp
$(berp-generate-parser)
src/parser.c: gherkin-c-parser.razor gherkin.berp
$(berp-generate-parser)
src/dialect.c: ../gherkin-languages.json dialect.c.jq
cat $< | jq -f dialect.c.jq -r -c > $@
acceptance/testdata/%.feature.tokens: ../testdata/%.feature ../testdata/%.feature.tokens $(GHERKIN_GENERATE_TOKENS)
mkdir -p $(@D)
echo $(RUN_GHERKIN_GENERATE_TOKENS)
$(RUN_GHERKIN_GENERATE_TOKENS) $< > $@
diff --strip-trailing-cr --unified $<.tokens $@
acceptance/testdata/%.feature.ast.ndjson: ../testdata/%.feature ../testdata/%.feature.ast.ndjson $(GHERKIN)
mkdir -p $(@D)
$(RUN_GHERKIN) --no-source --no-pickles $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.ast.ndjson) <(jq "." $@)
acceptance/testdata/%.feature.errors.ndjson: ../testdata/%.feature ../testdata/%.feature.errors.ndjson $(GHERKIN)
mkdir -p $(@D)
$(RUN_GHERKIN) --no-source --no-pickles $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.errors.ndjson) <(jq "." $@)
acceptance/testdata/%.feature.pickles.ndjson: ../testdata/%.feature ../testdata/%.feature.pickles.ndjson $(GHERKIN)
mkdir -p $(@D)
$(RUN_GHERKIN) --no-source --no-ast $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.pickles.ndjson) <(jq "." $@)
acceptance/testdata/%.feature.source.ndjson: ../testdata/%.feature ../testdata/%.feature.source.ndjson .built
mkdir -p $(@D)
$(RUN_GHERKIN) --no-ast --no-pickles $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.source.ndjson) <(jq "." $@)