Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. PROJECT_ROOT=github.com/uber/jaeger-client-go
  2. export GO111MODULE=off
  3. PACKAGES := . $(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
  5. ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e ./thrift/ \
  6. -e ".*/\..*" \
  7. -e ".*/_.*" \
  8. -e ".*/mocks.*")
  9. USE_DEP := true
  10. -include crossdock/rules.mk
  11. RACE=-race
  12. GOTEST=go test -v $(RACE)
  13. GOLINT=golint
  14. GOVET=go vet
  15. GOFMT=gofmt
  16. FMT_LOG=fmt.log
  17. LINT_LOG=lint.log
  18. THRIFT_VER=0.14
  19. THRIFT_IMG=jaegertracing/thrift:$(THRIFT_VER)
  20. THRIFT=docker run -v "${PWD}:/data" -u ${shell id -u}:${shell id -g} $(THRIFT_IMG) thrift
  21. PASS=$(shell printf "\033[32mPASS\033[0m")
  22. FAIL=$(shell printf "\033[31mFAIL\033[0m")
  23. COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/''
  24. .DEFAULT_GOAL := test-and-lint
  25. .PHONY: test-and-lint
  26. test-and-lint: test fmt lint
  27. .PHONY: test
  28. test:
  29. ifeq ($(USE_DEP),true)
  30. dep check
  31. endif
  32. bash -c "set -e; set -o pipefail; $(GOTEST) $(PACKAGES) | $(COLORIZE)"
  33. .PHONY: fmt
  34. fmt:
  35. $(GOFMT) -e -s -l -w $(ALL_SRC)
  36. ./scripts/updateLicenses.sh
  37. .PHONY: lint
  38. lint: vet golint lint-fmt lint-thrift-testing
  39. .PHONY: vet
  40. vet:
  41. $(GOVET) $(PACKAGES)
  42. .PHONY: golint
  43. golint:
  44. @cat /dev/null > $(LINT_LOG)
  45. @$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift >> $(LINT_LOG) || true;)
  46. @[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false)
  47. .PHONY: lint-fmt
  48. lint-fmt:
  49. @$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG)
  50. ./scripts/updateLicenses.sh >> $(FMT_LOG)
  51. @[ ! -s "$(FMT_LOG)" ] || (echo "go fmt or license check failures, run 'make fmt'" | cat - $(FMT_LOG) && false)
  52. # make sure thrift/ module does not import "testing"
  53. .PHONY: lint-thrift-testing
  54. lint-thrift-testing:
  55. @cat /dev/null > $(LINT_LOG)
  56. @(grep -rn '"testing"' thrift | grep -v README.md > $(LINT_LOG)) || true
  57. @[ ! -s "$(LINT_LOG)" ] || (echo '"thrift" module must not import "testing", see issue #585' | cat - $(LINT_LOG) && false)
  58. .PHONY: install
  59. install:
  60. @echo install: USE_DEP=$(USE_DEP) USE_GLIDE=$(USE_GLIDE)
  61. ifeq ($(USE_DEP),true)
  62. dep version || make install-dep
  63. dep ensure -vendor-only -v
  64. endif
  65. ifeq ($(USE_GLIDE),true)
  66. glide --version || go get github.com/Masterminds/glide
  67. glide install
  68. endif
  69. .PHONY: cover
  70. cover:
  71. $(GOTEST) -cover -coverprofile cover.out $(PACKAGES)
  72. .PHONY: cover-html
  73. cover-html: cover
  74. go tool cover -html=cover.out -o cover.html
  75. # This is not part of the regular test target because we don't want to slow it
  76. # down.
  77. .PHONY: test-examples
  78. test-examples:
  79. make -C examples
  80. .PHONY: thrift
  81. thrift: idl-submodule thrift-compile
  82. # TODO at the moment we're not generating tchan_*.go files
  83. .PHONY: thrift-compile
  84. thrift-compile: thrift-image
  85. docker run -v "${PWD}:/data" -u ${shell id -u}:${shell id -g} $(THRIFT_IMG) /data/scripts/gen-thrift.sh
  86. .PHONY: idl-submodule
  87. idl-submodule:
  88. git submodule init
  89. git submodule update
  90. .PHONY: thrift-image
  91. thrift-image:
  92. $(THRIFT) -version
  93. .PHONY: install-dep
  94. install-dep:
  95. - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $$GOPATH/bin/dep
  96. - chmod +x $$GOPATH/bin/dep
  97. .PHONY: install-ci
  98. install-ci: install
  99. go get github.com/wadey/gocovmerge
  100. go get github.com/mattn/goveralls
  101. go get golang.org/x/tools/cmd/cover
  102. go get golang.org/x/lint/golint
  103. .PHONY: test-ci
  104. test-ci: cover
  105. ifeq ($(CI_SKIP_LINT),true)
  106. echo 'skipping lint'
  107. else
  108. make lint
  109. endif