Debian Codegraph @

Makefile

raw symbols SCIP
1 # MAKEFILE
2 #
3 # @author Nicola Asuni <[email protected]>
4 # @link https://github.com/dgryski/go-farm
5 #
6 # This file is intended to be executed in a Linux-compatible system.
7 # It also assumes that the project has been cloned in the right path under GOPATH:
8 # $GOPATH/src/github.com/dgryski/go-farm
9 #
10 # ------------------------------------------------------------------------------
11
12 # List special make targets that are not associated with files
13 .PHONY: help all test format fmtcheck vet lint coverage cyclo misspell errcheck staticcheck astscan qa deps clean nuke
14
15 # Use bash as shell (Note: Ubuntu now uses dash which doesn't support PIPESTATUS).
16 SHELL=/bin/bash
17
18 # CVS path (path to the parent dir containing the project)
19 CVSPATH=github.com/dgryski
20
21 # Project owner
22 OWNER=dgryski
23
24 # Project vendor
25 VENDOR=dgryski
26
27 # Project name
28 PROJECT=go-farm
29
30 # Project version
31 VERSION=$(shell cat VERSION)
32
33 # Name of RPM or DEB package
34 PKGNAME=${VENDOR}-${PROJECT}
35
36 # Current directory
37 CURRENTDIR=$(shell pwd)
38
39 # GO lang path
40 ifneq ($(GOPATH),)
41 ifeq ($(findstring $(GOPATH),$(CURRENTDIR)),)
42 # the defined GOPATH is not valid
43 GOPATH=
44 endif
45 endif
46 ifeq ($(GOPATH),)
47 # extract the GOPATH
48 GOPATH=$(firstword $(subst /src/, ,$(CURRENTDIR)))
49 endif
50
51 # --- MAKE TARGETS ---
52
53 # Display general help about this command
54 help:
55 @echo ""
56 @echo "$(PROJECT) Makefile."
57 @echo "GOPATH=$(GOPATH)"
58 @echo "The following commands are available:"
59 @echo ""
60 @echo " make qa : Run all the tests"
61 @echo " make test : Run the unit tests"
62 @echo ""
63 @echo " make format : Format the source code"
64 @echo " make fmtcheck : Check if the source code has been formatted"
65 @echo " make vet : Check for suspicious constructs"
66 @echo " make lint : Check for style errors"
67 @echo " make coverage : Generate the coverage report"
68 @echo " make cyclo : Generate the cyclomatic complexity report"
69 @echo " make misspell : Detect commonly misspelled words in source files"
70 @echo " make staticcheck : Run staticcheck
71 @echo " make errcheck : Check that error return values are used"
72 @echo " make astscan : GO AST scanner"
73 @echo ""
74 @echo " make docs : Generate source code documentation"
75 @echo ""
76 @echo " make deps : Get the dependencies"
77 @echo " make clean : Remove any build artifact"
78 @echo " make nuke : Deletes any intermediate file"
79 @echo ""
80
81
82 # Alias for help target
83 all: help
84
85 # Run the unit tests
86 test:
87 @mkdir -p target/test
88 @mkdir -p target/report
89 GOPATH=$(GOPATH) \
90 go test \
91 -covermode=atomic \
92 -bench=. \
93 -race \
94 -cpuprofile=target/report/cpu.out \
95 -memprofile=target/report/mem.out \
96 -mutexprofile=target/report/mutex.out \
97 -coverprofile=target/report/coverage.out \
98 -v ./... | \
99 tee >(PATH=$(GOPATH)/bin:$(PATH) go-junit-report > target/test/report.xml); \
100 test $${PIPESTATUS[0]} -eq 0
101
102 # Format the source code
103 format:
104 @find . -type f -name "*.go" -exec gofmt -s -w {} \;
105
106 # Check if the source code has been formatted
107 fmtcheck:
108 @mkdir -p target
109 @find . -type f -name "*.go" -exec gofmt -s -d {} \; | tee target/format.diff
110 @test ! -s target/format.diff || { echo "ERROR: the source code has not been formatted - please use 'make format' or 'gofmt'"; exit 1; }
111
112 # Check for syntax errors
113 vet:
114 GOPATH=$(GOPATH) go vet .
115
116 # Check for style errors
117 lint:
118 GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) golint .
119
120 # Generate the coverage report
121 coverage:
122 @mkdir -p target/report
123 GOPATH=$(GOPATH) \
124 go tool cover -html=target/report/coverage.out -o target/report/coverage.html
125
126 # Report cyclomatic complexity
127 cyclo:
128 @mkdir -p target/report
129 GOPATH=$(GOPATH) gocyclo -avg ./ | tee target/report/cyclo.txt ; test $${PIPESTATUS[0]} -eq 0
130
131 # Detect commonly misspelled words in source files
132 misspell:
133 @mkdir -p target/report
134 GOPATH=$(GOPATH) misspell -error ./ | tee target/report/misspell.txt ; test $${PIPESTATUS[0]} -eq 0
135
136 # Check that error return values are used
137 errcheck:
138 @mkdir -p target/report
139 GOPATH=$(GOPATH) errcheck ./ | tee target/report/errcheck.txt
140
141
142 # staticcheck
143 staticcheck:
144 @mkdir -p target/report
145 GOPATH=$(GOPATH) staticcheck ./... | tee target/report/staticcheck.txt
146
147
148 # AST scanner
149 astscan:
150 @mkdir -p target/report
151 GOPATH=$(GOPATH) gas .//*.go | tee target/report/astscan.txt
152
153 # Generate source docs
154 docs:
155 @mkdir -p target/docs
156 nohup sh -c 'GOPATH=$(GOPATH) godoc -http=127.0.0.1:6060' > target/godoc_server.log 2>&1 &
157 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`
158 @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
159
160 # Alias to run all quality-assurance checks
161 qa: fmtcheck test vet lint coverage cyclo misspell errcheck astscan
162
163 # --- INSTALL ---
164
165 # Get the dependencies
166 deps:
167 GOPATH=$(GOPATH) go get ./...
168 GOPATH=$(GOPATH) go get golang.org/x/lint/golint
169 GOPATH=$(GOPATH) go get github.com/jstemmer/go-junit-report
170 GOPATH=$(GOPATH) go get github.com/axw/gocov/gocov
171 GOPATH=$(GOPATH) go get github.com/fzipp/gocyclo
172 GOPATH=$(GOPATH) go get github.com/gordonklaus/ineffassign
173 GOPATH=$(GOPATH) go get github.com/client9/misspell/cmd/misspell
174 GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/structcheck
175 GOPATH=$(GOPATH) go get github.com/opennota/check/cmd/varcheck
176 GOPATH=$(GOPATH) go get github.com/kisielk/errcheck
177 GOPATH=$(GOPATH) go get honnef.co/go/tools/cmd/staticcheck
178 GOPATH=$(GOPATH) go get github.com/GoASTScanner/gas
179
180 # Remove any build artifact
181 clean:
182 GOPATH=$(GOPATH) go clean ./...
183
184 # Deletes any intermediate file
185 nuke:
186 rm -rf ./target
187 GOPATH=$(GOPATH) go clean -i ./...