本站源代码
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.

198 lines
6.4KB

  1. # MAKEFILE
  2. #
  3. # @author Nicola Asuni <info@tecnick.com>
  4. # @link https://github.com/willf/bitset
  5. # ------------------------------------------------------------------------------
  6. # List special make targets that are not associated with files
  7. .PHONY: help all test format fmtcheck vet lint coverage cyclo ineffassign misspell structcheck varcheck errcheck gosimple astscan qa deps clean nuke
  8. # Use bash as shell (Note: Ubuntu now uses dash which doesn't support PIPESTATUS).
  9. SHELL=/bin/bash
  10. # CVS path (path to the parent dir containing the project)
  11. CVSPATH=github.com/willf
  12. # Project owner
  13. OWNER=willf
  14. # Project vendor
  15. VENDOR=willf
  16. # Project name
  17. PROJECT=bitset
  18. # Project version
  19. VERSION=$(shell cat VERSION)
  20. # Name of RPM or DEB package
  21. PKGNAME=${VENDOR}-${PROJECT}
  22. # Current directory
  23. CURRENTDIR=$(shell pwd)
  24. # GO lang path
  25. ifneq ($(GOPATH),)
  26. ifeq ($(findstring $(GOPATH),$(CURRENTDIR)),)
  27. # the defined GOPATH is not valid
  28. GOPATH=
  29. endif
  30. endif
  31. ifeq ($(GOPATH),)
  32. # extract the GOPATH
  33. GOPATH=$(firstword $(subst /src/, ,$(CURRENTDIR)))
  34. endif
  35. # --- MAKE TARGETS ---
  36. # Display general help about this command
  37. help:
  38. @echo ""
  39. @echo "$(PROJECT) Makefile."
  40. @echo "GOPATH=$(GOPATH)"
  41. @echo "The following commands are available:"
  42. @echo ""
  43. @echo " make qa : Run all the tests"
  44. @echo " make test : Run the unit tests"
  45. @echo ""
  46. @echo " make format : Format the source code"
  47. @echo " make fmtcheck : Check if the source code has been formatted"
  48. @echo " make vet : Check for suspicious constructs"
  49. @echo " make lint : Check for style errors"
  50. @echo " make coverage : Generate the coverage report"
  51. @echo " make cyclo : Generate the cyclomatic complexity report"
  52. @echo " make ineffassign : Detect ineffectual assignments"
  53. @echo " make misspell : Detect commonly misspelled words in source files"
  54. @echo " make structcheck : Find unused struct fields"
  55. @echo " make varcheck : Find unused global variables and constants"
  56. @echo " make errcheck : Check that error return values are used"
  57. @echo " make gosimple : Suggest code simplifications"
  58. @echo " make astscan : GO AST scanner"
  59. @echo ""
  60. @echo " make docs : Generate source code documentation"
  61. @echo ""
  62. @echo " make deps : Get the dependencies"
  63. @echo " make clean : Remove any build artifact"
  64. @echo " make nuke : Deletes any intermediate file"
  65. @echo ""
  66. # Alias for help target
  67. all: help
  68. # Run the unit tests
  69. test:
  70. @mkdir -p target/test
  71. @mkdir -p target/report
  72. GOPATH=$(GOPATH) \
  73. go test \
  74. -covermode=atomic \
  75. -bench=. \
  76. -race \
  77. -cpuprofile=target/report/cpu.out \
  78. -memprofile=target/report/mem.out \
  79. -mutexprofile=target/report/mutex.out \
  80. -coverprofile=target/report/coverage.out \
  81. -v ./... | \
  82. tee >(PATH=$(GOPATH)/bin:$(PATH) go-junit-report > target/test/report.xml); \
  83. test $${PIPESTATUS[0]} -eq 0
  84. # Format the source code
  85. format:
  86. @find . -type f -name "*.go" -exec gofmt -s -w {} \;
  87. # Check if the source code has been formatted
  88. fmtcheck:
  89. @mkdir -p target
  90. @find . -type f -name "*.go" -exec gofmt -s -d {} \; | tee target/format.diff
  91. @test ! -s target/format.diff || { echo "ERROR: the source code has not been formatted - please use 'make format' or 'gofmt'"; exit 1; }
  92. # Check for syntax errors
  93. vet:
  94. GOPATH=$(GOPATH) go vet .
  95. # Check for style errors
  96. lint:
  97. GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) golint .
  98. # Generate the coverage report
  99. coverage:
  100. @mkdir -p target/report
  101. GOPATH=$(GOPATH) \
  102. go tool cover -html=target/report/coverage.out -o target/report/coverage.html
  103. # Report cyclomatic complexity
  104. cyclo:
  105. @mkdir -p target/report
  106. GOPATH=$(GOPATH) gocyclo -avg ./ | tee target/report/cyclo.txt ; test $${PIPESTATUS[0]} -eq 0
  107. # Detect ineffectual assignments
  108. ineffassign:
  109. @mkdir -p target/report
  110. GOPATH=$(GOPATH) ineffassign ./ | tee target/report/ineffassign.txt ; test $${PIPESTATUS[0]} -eq 0
  111. # Detect commonly misspelled words in source files
  112. misspell:
  113. @mkdir -p target/report
  114. GOPATH=$(GOPATH) misspell -error ./ | tee target/report/misspell.txt ; test $${PIPESTATUS[0]} -eq 0
  115. # Find unused struct fields
  116. structcheck:
  117. @mkdir -p target/report
  118. GOPATH=$(GOPATH) structcheck -a ./ | tee target/report/structcheck.txt
  119. # Find unused global variables and constants
  120. varcheck:
  121. @mkdir -p target/report
  122. GOPATH=$(GOPATH) varcheck -e ./ | tee target/report/varcheck.txt
  123. # Check that error return values are used
  124. errcheck:
  125. @mkdir -p target/report
  126. GOPATH=$(GOPATH) errcheck ./ | tee target/report/errcheck.txt
  127. # Suggest code simplifications
  128. gosimple:
  129. @mkdir -p target/report
  130. GOPATH=$(GOPATH) gosimple ./ | tee target/report/gosimple.txt
  131. # AST scanner
  132. astscan:
  133. @mkdir -p target/report
  134. GOPATH=$(GOPATH) gas .//*.go | tee target/report/astscan.txt ; test $${PIPESTATUS[0]} -eq 0
  135. # Generate source docs
  136. docs:
  137. @mkdir -p target/docs
  138. nohup sh -c 'GOPATH=$(GOPATH) godoc -http=127.0.0.1:6060' > target/godoc_server.log 2>&1 &
  139. wget --directory-prefix=target/docs/ --execute robots=off --retry-connrefused --recursive --no-parent --adjust-extension --page-requisites --convert-links http://127.0.0.1:6060/pkg/github.com/${VENDOR}/${PROJECT}/ ; kill -9 `lsof -ti :6060`
  140. @echo '<html><head><meta http-equiv="refresh" content="0;./127.0.0.1:6060/pkg/'${CVSPATH}'/'${PROJECT}'/index.html"/></head><a href="./127.0.0.1:6060/pkg/'${CVSPATH}'/'${PROJECT}'/index.html">'${PKGNAME}' Documentation ...</a></html>' > target/docs/index.html
  141. # Alias to run all quality-assurance checks
  142. qa: fmtcheck test vet lint coverage cyclo ineffassign misspell structcheck varcheck errcheck gosimple
  143. # --- INSTALL ---
  144. # Get the dependencies
  145. deps:
  146. GOPATH=$(GOPATH) go get ./...
  147. GOPATH=$(GOPATH) go get github.com/golang/lint/golint
  148. GOPATH=$(GOPATH) go get github.com/jstemmer/go-junit-report
  149. GOPATH=$(GOPATH) go get github.com/axw/gocov/gocov
  150. GOPATH=$(GOPATH) go get github.com/fzipp/gocyclo
  151. GOPATH=$(GOPATH) go get github.com/gordonklaus/ineffassign
  152. GOPATH=$(GOPATH) go get github.com/client9/misspell/cmd/misspell
  153. GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/structcheck
  154. GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/varcheck
  155. GOPATH=$(GOPATH) go get github.com/kisielk/errcheck
  156. GOPATH=$(GOPATH) go get honnef.co/go/tools/cmd/gosimple
  157. GOPATH=$(GOPATH) go get github.com/GoASTScanner/gas
  158. # Remove any build artifact
  159. clean:
  160. GOPATH=$(GOPATH) go clean ./...
  161. # Deletes any intermediate file
  162. nuke:
  163. rm -rf ./target
  164. GOPATH=$(GOPATH) go clean -i ./...
上海开阖软件有限公司 沪ICP备12045867号-1