forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
291 lines (242 loc) · 9.44 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
##
## This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain
## Dedication license. Its contents can be found at:
## http://creativecommons.org/publicdomain/zero/1.0
##
.PHONY: all build
.PHONY: lint lint-all
.PHONY: test coverbrowse test-cmd
.PHONY: clean distclean
CMD_DIR :=./go-bindata
TESTDATA_DIR :=./testdata
TESTDATA_IN_DIR :=./testdata/in
TESTDATA_OUT_DIR :=./testdata/out
SRC :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .GoFiles }} {{ $$dir }}/{{.}} {{end}}' ./...)
TEST :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .TestGoFiles }} {{ $$dir }}/{{.}} {{end}}' ./...)
TEST_COVER_ALL :=cover.out
TARGET_CMD :=$(shell go list -f '{{ .Target }}' $(CMD_DIR))
CMD_SRC :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .GoFiles }} {{ $$dir }}/{{.}} {{end}}' $(CMD_DIR))
CMD_TEST :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .TestGoFiles }} {{ $$dir }}/{{.}} {{end}}' $(CMD_DIR))
CMD_COVER_OUT :=$(CMD_DIR)/cover.out
TARGET_LIB :=$(shell go list -f '{{ .Target }}' ./)
LIB_SRC :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .GoFiles }} {{ $$dir }}/{{.}} {{end}}' ./)
LIB_TEST :=$(shell go list -f '{{ $$dir := .Dir }}{{ range .TestGoFiles }} {{ $$dir }}/{{.}} {{end}}' ./)
LIB_COVER_OUT :=lib.cover.out
TEST_COVER_OUT :=$(TEST_COVER_ALL) $(LIB_COVER_OUT) $(CMD_COVER_OUT)
TEST_COVER_HTML :=cover.html
POST_TEST_FILES := \
./assert_test.go \
$(TESTDATA_DIR)/_bindata_test.go \
$(TESTDATA_DIR)/_out_default_single.go
TEST_OUT := \
$(TESTDATA_OUT_DIR)/opt/no-output/bindata.go \
$(TESTDATA_OUT_DIR)/default/single/bindata.go \
$(TESTDATA_OUT_DIR)/compress/memcopy/bindata.go \
$(TESTDATA_OUT_DIR)/compress/nomemcopy/bindata.go \
$(TESTDATA_OUT_DIR)/debug/bindata.go \
$(TESTDATA_OUT_DIR)/nocompress/memcopy/bindata.go \
$(TESTDATA_OUT_DIR)/nocompress/nomemcopy/bindata.go \
$(TESTDATA_OUT_DIR)/split/bindata.go \
$(TESTDATA_OUT_DIR)/symlinkFile/bindata.go \
$(TESTDATA_OUT_DIR)/symlinkParent/bindata.go \
$(TESTDATA_OUT_DIR)/symlinkRecursiveParent/bindata.go
VENDOR_DIR :=$(PWD)/vendor
VENDOR_BIN :=$(VENDOR_DIR)/bin
LINTER_OUT :=.lint.out
LINTER_CMD :=$(VENDOR_BIN)/gometalinter
LINTER_OPTS =\
--vendor --concurrency=1 --deadline=240s --enable-gc --sort=path \
--skip=testdata \
--disable=gotype
LINTER =GOBIN=$(VENDOR_BIN) $(VENDOR_BIN)/gometalinter $(LINTER_OPTS)
##
## MAIN TARGET
##
all: build test-cmd
##
## CLEAN
##
clean:
rm -rf $(TEST_COVER_OUT) $(TEST_COVER_HTML) $(TESTDATA_OUT_DIR) \
$(LINTER_OUT)
distclean: clean
rm -rf $(TARGET_CMD) $(TARGET_LIB) $(VENDOR_DIR)
##
## LINT
##
$(VENDOR_DIR): vendor.deps
@echo ">>> Installing vendor dependencies ..."
@./.scripts/deps.sh $<
@touch $@
$(LINTER_CMD): $(VENDOR_DIR)
$(LINTER_OUT): $(LINTER_CMD) $(CMD_SRC) $(CMD_TEST) $(LIB_SRC) $(LIB_TEST)
@echo ">>> Linting ..."
-$(LINTER) ./... > $@
@cat $@
lint: $(LINTER_OUT)
lint-all: LINTER_OPTS+=--enable-all --disable=gotype --disable=nakedret
lint-all: $(LINTER_OUT)
##
## TEST
##
$(LIB_COVER_OUT): $(LIB_SRC) $(LIB_TEST)
@echo ""
@echo ">>> Testing library ..."
@go test -v ./ && \
go test -coverprofile=$@ ./ &>/dev/null && \
go tool cover -func=$@
$(CMD_COVER_OUT): $(CMD_SRC) $(CMD_TEST)
@echo ""
@echo ">>> Testing cmd ..."
@go test -v $(CMD_DIR) && \
go test -coverprofile=$@ $(CMD_DIR) &>/dev/null && \
go tool cover -func=$@
$(TEST_COVER_ALL): $(LIB_COVER_OUT) $(CMD_COVER_OUT)
@echo ""
@echo ">>> Generate single coverage '$@' ..."
@cat $^ | sed '/mode: set/d' | sed '1s/^/mode: set\n/' > $@
$(TEST_COVER_HTML): $(TEST_COVER_ALL)
@echo ">>> Generate HTML coverage '$@' ..."
@go tool cover -html=$< -o $@
test: lint $(TEST_COVER_HTML)
coverbrowse: test
@xdg-open $(TEST_COVER_HTML)
##
## BUILD
##
$(TARGET_LIB): $(LIB_SRC)
go install ./
$(TARGET_CMD): $(CMD_SRC) $(TARGET_LIB)
go install $(CMD_DIR)
build: test $(TARGET_CMD)
##
## TEST POST BUILD
##
$(TESTDATA_OUT_DIR)/opt/no-output/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/opt/no-output
$(TESTDATA_OUT_DIR)/opt/no-output/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing without '-o' flag"
mkdir -p $(OUT_DIR)
cd $(OUT_DIR) \
&& $(TARGET_CMD) -pkg bindata -prefix=".*/testdata/" \
-ignore="split/" ../../../../$(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/compress/memcopy/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/compress/memcopy
$(TESTDATA_OUT_DIR)/compress/memcopy/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing default option (compress, memcopy)"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" $(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/default/single/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/default/single
$(TESTDATA_OUT_DIR)/default/single/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing default option with single input file"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" $(TESTDATA_IN_DIR)/test.asset
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_out_default_single.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR) || rm -f $(OUT_DIR)/*
go test -v $(OUT_DIR) || rm -f $(OUT_DIR)/*
$(TESTDATA_OUT_DIR)/compress/nomemcopy/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/compress/nomemcopy
$(TESTDATA_OUT_DIR)/compress/nomemcopy/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing with '-nomemcopy'"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" -nomemcopy $(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/debug/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/debug
$(TESTDATA_OUT_DIR)/debug/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing opt 'debug'"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" -debug $(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/nocompress/memcopy/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/nocompress/memcopy
$(TESTDATA_OUT_DIR)/nocompress/memcopy/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing opt '-nocompress'"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" -nocompress $(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/nocompress/nomemcopy/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/nocompress/nomemcopy
$(TESTDATA_OUT_DIR)/nocompress/nomemcopy/bindata.go: $(TESTDATA_IN_DIR)/*
@echo ""
@echo ">>> Testing opt '-nocompress -nomemcopy'"
mkdir -p $(OUT_DIR)
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
-ignore="split/" -nocompress -nomemcopy $(TESTDATA_IN_DIR)/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_bindata_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/split/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/split
$(TESTDATA_OUT_DIR)/split/bindata.go: $(TESTDATA_DIR)/_split_test.go $(TESTDATA_IN_DIR)/split/*
@echo ""
@echo ">>> Testing opt '-split'"
mkdir -p $(OUT_DIR)
rm -f $(OUT_DIR)/*
$(TARGET_CMD) -o $(OUT_DIR) -pkg bindata -prefix=".*testdata/" \
-split $(TESTDATA_IN_DIR)/split/...
cp ./assert_test.go $(OUT_DIR)
cp $< $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/symlinkFile/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/symlinkFile
$(TESTDATA_OUT_DIR)/symlinkFile/bindata.go: $(TESTDATA_DIR)/symlinkFile $(TESTDATA_DIR)/_symlinkFile_test.go
@echo ""
@echo ">>> Testing symlink to file"
mkdir -p $(OUT_DIR)
rm -f $(OUT_DIR)/*
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
$(TESTDATA_DIR)/symlinkFile/...
cp ./assert_test.go $(OUT_DIR)
cp $(TESTDATA_DIR)/_symlinkFile_test.go $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/symlinkParent/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/symlinkParent
$(TESTDATA_OUT_DIR)/symlinkParent/bindata.go: $(TESTDATA_DIR)/_symlinkParent_test.go $(TESTDATA_DIR)/symlinkParent
@echo ""
@echo ">>> Testing symlink to directory"
mkdir -p $(OUT_DIR)
rm -f $(OUT_DIR)/*
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
$(TESTDATA_DIR)/symlinkParent/...
cp ./assert_test.go $(OUT_DIR)
cp $< $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TESTDATA_OUT_DIR)/symlinkRecursiveParent/bindata.go: OUT_DIR=$(TESTDATA_OUT_DIR)/symlinkRecursiveParent
$(TESTDATA_OUT_DIR)/symlinkRecursiveParent/bindata.go: $(TESTDATA_DIR)/_symlinkRecursiveParent_test.go $(TESTDATA_DIR)/symlinkRecursiveParent
@echo ""
@echo ">>> Testing symlink recursive directory"
mkdir -p $(OUT_DIR)
rm -f $(OUT_DIR)/*
$(TARGET_CMD) -o $@ -pkg bindata -prefix=".*testdata/" \
$(TESTDATA_DIR)/symlinkRecursiveParent/...
cp ./assert_test.go $(OUT_DIR)
cp $< $(OUT_DIR)/bindata_test.go
$(LINTER) $(OUT_DIR)
go test -v $(OUT_DIR)
$(TEST_OUT): $(LINTER_CMD) $(TARGET_CMD) $(POST_TEST_FILES)
test-cmd: $(TEST_OUT)