blob: d5e962ccff662d2e8aa06e548ba77f0a6b1c8a0a [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001PROJECT_ROOT=github.com/uber/jaeger-client-go
2PACKAGES := . $(shell go list ./... | awk -F/ 'NR>1 {print "./"$$4"/..."}' | grep -v -e ./thrift-gen/... -e ./thrift/... | sort -u)
3# all .go files that don't exist in hidden directories
4ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e ./thrift/ \
5 -e ".*/\..*" \
6 -e ".*/_.*" \
7 -e ".*/mocks.*")
8
9USE_DEP := true
10
11-include crossdock/rules.mk
12
13RACE=-race
14GOTEST=go test -v $(RACE)
15GOLINT=golint
16GOVET=go vet
17GOFMT=gofmt
18FMT_LOG=fmt.log
19LINT_LOG=lint.log
20
21THRIFT_VER=0.9.3
22THRIFT_IMG=thrift:$(THRIFT_VER)
23THRIFT=docker run -v "${PWD}:/data" $(THRIFT_IMG) thrift
24THRIFT_GO_ARGS=thrift_import="github.com/apache/thrift/lib/go/thrift"
25THRIFT_GEN_DIR=thrift-gen
26
27PASS=$(shell printf "\033[32mPASS\033[0m")
28FAIL=$(shell printf "\033[31mFAIL\033[0m")
29COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/''
30
31.DEFAULT_GOAL := test-and-lint
32
33.PHONY: test-and-lint
34test-and-lint: test fmt lint
35
36.PHONY: test
37test:
38ifeq ($(USE_DEP),true)
39 dep check
40endif
41 bash -c "set -e; set -o pipefail; $(GOTEST) $(PACKAGES) | $(COLORIZE)"
42
43.PHONY: fmt
44fmt:
45 $(GOFMT) -e -s -l -w $(ALL_SRC)
46 ./scripts/updateLicenses.sh
47
48.PHONY: lint
49lint:
50 $(GOVET) $(PACKAGES)
51 @cat /dev/null > $(LINT_LOG)
52 @$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift >> $(LINT_LOG) || true;)
53 @[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false)
54 @$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG)
55 ./scripts/updateLicenses.sh >> $(FMT_LOG)
56 @[ ! -s "$(FMT_LOG)" ] || (echo "go fmt or license check failures, run 'make fmt'" | cat - $(FMT_LOG) && false)
57
58
59.PHONY: install
60install:
61 @echo install: USE_DEP=$(USE_DEP) USE_GLIDE=$(USE_GLIDE)
62ifeq ($(USE_DEP),true)
63 dep version || make install-dep
64 dep ensure
65endif
66ifeq ($(USE_GLIDE),true)
67 glide --version || go get github.com/Masterminds/glide
68 glide install
69endif
70
71
72.PHONY: cover
73cover:
74 $(GOTEST) -cover -coverprofile cover.out $(PACKAGES)
75
76.PHONY: cover-html
77cover-html: cover
78 go tool cover -html=cover.out -o cover.html
79
80# This is not part of the regular test target because we don't want to slow it
81# down.
82.PHONY: test-examples
83test-examples:
84 make -C examples
85
86.PHONY: thrift
87thrift: idl-submodule thrift-compile
88
89# TODO at the moment we're not generating tchan_*.go files
90.PHONY: thrift-compile
91thrift-compile: thrift-image
92 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/agent.thrift
93 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/sampling.thrift
94 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/jaeger.thrift
95 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/zipkincore.thrift
96 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/baggage.thrift
97 $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/crossdock/thrift/ /data/idl/thrift/crossdock/tracetest.thrift
98 sed -i '' 's|"zipkincore"|"$(PROJECT_ROOT)/thrift-gen/zipkincore"|g' $(THRIFT_GEN_DIR)/agent/*.go
99 sed -i '' 's|"jaeger"|"$(PROJECT_ROOT)/thrift-gen/jaeger"|g' $(THRIFT_GEN_DIR)/agent/*.go
100 sed -i '' 's|"github.com/apache/thrift/lib/go/thrift"|"github.com/uber/jaeger-client-go/thrift"|g' \
101 $(THRIFT_GEN_DIR)/*/*.go crossdock/thrift/tracetest/*.go
102 rm -rf thrift-gen/*/*-remote
103 rm -rf crossdock/thrift/*/*-remote
104 rm -rf thrift-gen/jaeger/collector.go
105
106.PHONY: idl-submodule
107idl-submodule:
108 git submodule init
109 git submodule update
110
111.PHONY: thrift-image
112thrift-image:
113 $(THRIFT) -version
114
115.PHONY: install-dep
116install-dep:
117 - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $$GOPATH/bin/dep
118 - chmod +x $$GOPATH/bin/dep
119
120.PHONY: install-ci
121install-ci: install
122 go get github.com/wadey/gocovmerge
123 go get github.com/mattn/goveralls
124 go get golang.org/x/tools/cmd/cover
125 go get golang.org/x/lint/golint
126
127.PHONY: test-ci
128test-ci: cover
129ifeq ($(CI_SKIP_LINT),true)
130 echo 'skipping lint'
131else
132 make lint
133endif
134