-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
101 lines (85 loc) · 2.48 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
#
# Intro
help:
@echo 'Usage:'
@echo ' make help'
@echo ' make test'
@echo ' make dlib.cov.html'
@echo ' make lint'
.PHONY: help
.SECONDARY:
.PHONY: FORCE
SHELL = bash
#
# Test
dlib.cov: test
test -e $@
touch $@
test:
GOCOVERDIR=. go test -count=1 -coverprofile=dlib.cov -coverpkg=./... -race ./...
.PHONY: test
%.cov.html: %.cov
go tool cover -html=$< -o=$@
#
# Generate
generate-clean:
rm -f dlog/convenience.go
.PHONY: generate-clean
generate:
go generate ./...
.PHONY: generate
#
# Lint
lint: .circleci/golangci-lint
GOOS=linux .circleci/golangci-lint run ./...
GOOS=darwin .circleci/golangci-lint run ./...
GOOS=windows .circleci/golangci-lint run ./...
.PHONY: lint
#
# Tools
.circleci/%: .circleci/%.d/go.mod .circleci/%.d/pin.go
cd $(<D) && go build -o ../$(@F) $$(sed -En 's,^import "(.*)"$$,\1,p' pin.go)
#
# Utilities for working with borrowed code
GOHOME ?= $(HOME)/src/github.com/golang/go
GOVERSION ?= 1.19.4
%.unmod: % .circleci/goimports FORCE
<$< \
sed \
-e '/MODIFIED: META:/d' \
-e '/MODIFIED: ADDED/d' \
-e 's,.*// MODIFIED: FROM:,,' | \
.circleci/goimports -local github.com/datawire/dlib \
>$@
borrowed.patch: FORCE
$(MAKE) $(addsuffix .unmod,$(shell git ls-files ':*borrowed_*'))
@for copy in $$(git ls-files ':*borrowed_*'); do \
orig=$$(sed <<<"$$copy" \
-e s,borrowed_,, \
-e s,^dexec/internal/,internal/, \
-e s,^dexec/,os/exec/, \
-e s,^dcontext/,context/, \
-e '/^dhttp/{ s,^dhttp/,net/http/internal/,; s,_test,,; }'); \
if grep -q 'MODIFIED: META: .* subset ' "$$copy"; then \
echo "diff -uw $(GOHOME)/src/$$orig $$copy.unmod | sed '3,\$${ /^-/d; }'" >&2; \
diff -uw $(GOHOME)/src/$$orig $$copy.unmod | sed '3,$${ /^-/d; }' || true; \
else \
echo "diff -uw $(GOHOME)/src/$$orig $$copy.unmod" >&2; \
diff -uw $(GOHOME)/src/$$orig $$copy.unmod || true; \
fi; \
done > $@
check-attribution:
for copy in $$(git ls-files ':*borrowed_*'); do \
orig=$$(sed <<<"$$copy" \
-e s,borrowed_,, \
-e s,^dexec/internal/,internal/, \
-e s,^dexec/,os/exec/, \
-e s,^dcontext/,context/, \
-e '/^dhttp/{ s,^dhttp/,net/http/internal/,; s,_test,,; }'); \
if grep -Fq "Go $(GOVERSION) $$orig" "$$copy" && grep -q 'Copyright .* The Go Authors' "$$copy"; then \
echo "$$copy : Looks OK"; \
else \
echo "$$copy : Doesn't claim copied from Go $(GOVERSION) $$orig or doesn't have the copyright statement"; \
fi; \
done
.PHONY: check-attribution