Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame^] | 1 | PROJECT_ROOT=github.com/uber/jaeger-client-go |
| 2 | PACKAGES := . $(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 |
| 4 | ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e ./thrift/ \ |
| 5 | -e ".*/\..*" \ |
| 6 | -e ".*/_.*" \ |
| 7 | -e ".*/mocks.*") |
| 8 | |
| 9 | USE_DEP := true |
| 10 | |
| 11 | -include crossdock/rules.mk |
| 12 | |
| 13 | RACE=-race |
| 14 | GOTEST=go test -v $(RACE) |
| 15 | GOLINT=golint |
| 16 | GOVET=go vet |
| 17 | GOFMT=gofmt |
| 18 | FMT_LOG=fmt.log |
| 19 | LINT_LOG=lint.log |
| 20 | |
| 21 | THRIFT_VER=0.9.3 |
| 22 | THRIFT_IMG=thrift:$(THRIFT_VER) |
| 23 | THRIFT=docker run -v "${PWD}:/data" $(THRIFT_IMG) thrift |
| 24 | THRIFT_GO_ARGS=thrift_import="github.com/apache/thrift/lib/go/thrift" |
| 25 | THRIFT_GEN_DIR=thrift-gen |
| 26 | |
| 27 | PASS=$(shell printf "\033[32mPASS\033[0m") |
| 28 | FAIL=$(shell printf "\033[31mFAIL\033[0m") |
| 29 | COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/'' |
| 30 | |
| 31 | .DEFAULT_GOAL := test-and-lint |
| 32 | |
| 33 | .PHONY: test-and-lint |
| 34 | test-and-lint: test fmt lint |
| 35 | |
| 36 | .PHONY: test |
| 37 | test: |
| 38 | ifeq ($(USE_DEP),true) |
| 39 | dep check |
| 40 | endif |
| 41 | bash -c "set -e; set -o pipefail; $(GOTEST) $(PACKAGES) | $(COLORIZE)" |
| 42 | |
| 43 | .PHONY: fmt |
| 44 | fmt: |
| 45 | $(GOFMT) -e -s -l -w $(ALL_SRC) |
| 46 | ./scripts/updateLicenses.sh |
| 47 | |
| 48 | .PHONY: lint |
| 49 | lint: |
| 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 |
| 60 | install: |
| 61 | @echo install: USE_DEP=$(USE_DEP) USE_GLIDE=$(USE_GLIDE) |
| 62 | ifeq ($(USE_DEP),true) |
| 63 | dep version || make install-dep |
| 64 | dep ensure |
| 65 | endif |
| 66 | ifeq ($(USE_GLIDE),true) |
| 67 | glide --version || go get github.com/Masterminds/glide |
| 68 | glide install |
| 69 | endif |
| 70 | |
| 71 | |
| 72 | .PHONY: cover |
| 73 | cover: |
| 74 | $(GOTEST) -cover -coverprofile cover.out $(PACKAGES) |
| 75 | |
| 76 | .PHONY: cover-html |
| 77 | cover-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 |
| 83 | test-examples: |
| 84 | make -C examples |
| 85 | |
| 86 | .PHONY: thrift |
| 87 | thrift: idl-submodule thrift-compile |
| 88 | |
| 89 | # TODO at the moment we're not generating tchan_*.go files |
| 90 | .PHONY: thrift-compile |
| 91 | thrift-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 |
| 107 | idl-submodule: |
| 108 | git submodule init |
| 109 | git submodule update |
| 110 | |
| 111 | .PHONY: thrift-image |
| 112 | thrift-image: |
| 113 | $(THRIFT) -version |
| 114 | |
| 115 | .PHONY: install-dep |
| 116 | install-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 |
| 121 | install-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 |
| 128 | test-ci: cover |
| 129 | ifeq ($(CI_SKIP_LINT),true) |
| 130 | echo 'skipping lint' |
| 131 | else |
| 132 | make lint |
| 133 | endif |
| 134 | |