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