Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. README_FILES := $(shell find . -name '*README.md' | sort | tr '\n' ' ')
  18. .DEFAULT_GOAL := fmt-lint-vet-embedmd-test
  19. .PHONY: fmt-lint-vet-embedmd-test
  20. fmt-lint-vet-embedmd-test: fmt lint vet embedmd test
  21. # TODO enable test-with-coverage in tavis
  22. .PHONY: travis-ci
  23. travis-ci: fmt lint vet embedmd test test-386
  24. all-pkgs:
  25. @echo $(ALL_PKGS) | tr ' ' '\n' | sort
  26. all-srcs:
  27. @echo $(ALL_SRC) | tr ' ' '\n' | sort
  28. .PHONY: test
  29. test:
  30. $(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
  31. .PHONY: test-386
  32. test-386:
  33. GOARCH=386 $(GOTEST) -v -timeout 30s $(ALL_PKGS)
  34. .PHONY: test-with-coverage
  35. test-with-coverage:
  36. $(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
  37. .PHONY: fmt
  38. fmt:
  39. @FMTOUT=`$(GOFMT) -s -l $(ALL_SRC) 2>&1`; \
  40. if [ "$$FMTOUT" ]; then \
  41. echo "$(GOFMT) FAILED => gofmt the following files:\n"; \
  42. echo "$$FMTOUT\n"; \
  43. exit 1; \
  44. else \
  45. echo "Fmt finished successfully"; \
  46. fi
  47. .PHONY: lint
  48. lint:
  49. @LINTOUT=`$(GOLINT) $(ALL_PKGS) | grep -v $(TRACE_ID_LINT_EXCEPTION) | grep -v $(TRACE_OPTION_LINT_EXCEPTION) 2>&1`; \
  50. if [ "$$LINTOUT" ]; then \
  51. echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
  52. echo "$$LINTOUT\n"; \
  53. exit 1; \
  54. else \
  55. echo "Lint finished successfully"; \
  56. fi
  57. .PHONY: vet
  58. vet:
  59. # TODO: Understand why go vet downloads "github.com/google/go-cmp v0.2.0"
  60. @VETOUT=`$(GOVET) ./... | grep -v "go: downloading" 2>&1`; \
  61. if [ "$$VETOUT" ]; then \
  62. echo "$(GOVET) FAILED => go vet the following files:\n"; \
  63. echo "$$VETOUT\n"; \
  64. exit 1; \
  65. else \
  66. echo "Vet finished successfully"; \
  67. fi
  68. .PHONY: embedmd
  69. embedmd:
  70. @EMBEDMDOUT=`$(EMBEDMD) -d $(README_FILES) 2>&1`; \
  71. if [ "$$EMBEDMDOUT" ]; then \
  72. echo "$(EMBEDMD) FAILED => embedmd the following files:\n"; \
  73. echo "$$EMBEDMDOUT\n"; \
  74. exit 1; \
  75. else \
  76. echo "Embedmd finished successfully"; \
  77. fi
  78. .PHONY: install-tools
  79. install-tools:
  80. go get -u golang.org/x/tools/cmd/cover
  81. go get -u golang.org/x/lint/golint
  82. go get -u github.com/rakyll/embedmd