You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
2.5 KiB

  1. # TODO: Fix this on windows.
  2. ALL_SRC := $(shell find . -name '*.go' \
  3. -not -path './vendor/*' \
  4. -not -path '*/gen-go/*' \
  5. -type f | sort)
  6. ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
  7. GOTEST_OPT?=-v -race -timeout 30s
  8. GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
  9. GOTEST=go test
  10. GOFMT=gofmt
  11. GOLINT=golint
  12. GOVET=go vet
  13. EMBEDMD=embedmd
  14. # TODO decide if we need to change these names.
  15. TRACE_ID_LINT_EXCEPTION="type name will be used as trace.TraceID by other packages"
  16. TRACE_OPTION_LINT_EXCEPTION="type name will be used as trace.TraceOptions by other packages"
  17. .DEFAULT_GOAL := fmt-lint-vet-embedmd-test
  18. .PHONY: fmt-lint-vet-embedmd-test
  19. fmt-lint-vet-embedmd-test: fmt lint vet embedmd test
  20. # TODO enable test-with-coverage in tavis
  21. .PHONY: travis-ci
  22. travis-ci: fmt lint vet embedmd test test-386
  23. all-pkgs:
  24. @echo $(ALL_PKGS) | tr ' ' '\n' | sort
  25. all-srcs:
  26. @echo $(ALL_SRC) | tr ' ' '\n' | sort
  27. .PHONY: test
  28. test:
  29. $(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
  30. .PHONY: test-386
  31. test-386:
  32. GOARCH=386 $(GOTEST) -v -timeout 30s $(ALL_PKGS)
  33. .PHONY: test-with-coverage
  34. test-with-coverage:
  35. $(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
  36. .PHONY: fmt
  37. fmt:
  38. @FMTOUT=`$(GOFMT) -s -l $(ALL_SRC) 2>&1`; \
  39. if [ "$$FMTOUT" ]; then \
  40. echo "$(GOFMT) FAILED => gofmt the following files:\n"; \
  41. echo "$$FMTOUT\n"; \
  42. exit 1; \
  43. else \
  44. echo "Fmt finished successfully"; \
  45. fi
  46. .PHONY: lint
  47. lint:
  48. @LINTOUT=`$(GOLINT) $(ALL_PKGS) | grep -v $(TRACE_ID_LINT_EXCEPTION) | grep -v $(TRACE_OPTION_LINT_EXCEPTION) 2>&1`; \
  49. if [ "$$LINTOUT" ]; then \
  50. echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
  51. echo "$$LINTOUT\n"; \
  52. exit 1; \
  53. else \
  54. echo "Lint finished successfully"; \
  55. fi
  56. .PHONY: vet
  57. vet:
  58. # TODO: Understand why go vet downloads "github.com/google/go-cmp v0.2.0"
  59. @VETOUT=`$(GOVET) ./... | grep -v "go: downloading" 2>&1`; \
  60. if [ "$$VETOUT" ]; then \
  61. echo "$(GOVET) FAILED => go vet the following files:\n"; \
  62. echo "$$VETOUT\n"; \
  63. exit 1; \
  64. else \
  65. echo "Vet finished successfully"; \
  66. fi
  67. .PHONY: embedmd
  68. embedmd:
  69. @EMBEDMDOUT=`$(EMBEDMD) -d README.md 2>&1`; \
  70. if [ "$$EMBEDMDOUT" ]; then \
  71. echo "$(EMBEDMD) FAILED => embedmd the following files:\n"; \
  72. echo "$$EMBEDMDOUT\n"; \
  73. exit 1; \
  74. else \
  75. echo "Embedmd finished successfully"; \
  76. fi
  77. .PHONY: install-tools
  78. install-tools:
  79. go get -u golang.org/x/tools/cmd/cover
  80. go get -u golang.org/x/lint/golint
  81. go get -u github.com/rakyll/embedmd