Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6ca407b

Browse files
committedDec 21, 2018
chore(Makefile): add checks to Makefile
1 parent 6bf2405 commit 6ca407b

File tree

13 files changed

+147
-42
lines changed

13 files changed

+147
-42
lines changed
 

‎.circleci/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ jobs:
2525
- flux-gomod- # Matches a new branch.
2626
# Run tests
2727
- run: make checkfmt
28+
- run: make checktidy
2829
- run: make vet
30+
- run: make staticcheck
2931
- run: make test
3032
- save_cache:
3133
name: Saving GOCACHE

‎Makefile

+31-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# * All recursive Makefiles must support the targets: all and clean.
1212
#
1313

14-
SUBDIRS = ast internal/scanner
14+
SUBDIRS = ast/asttest internal/scanner
1515

1616
GO_ARGS=-tags '$(GO_TAGS)'
1717

@@ -39,19 +39,23 @@ bin/$(GOOS)/cmpgen: ./ast/asttest/cmpgen/main.go
3939
$(GO_BUILD) -o $@ ./ast/asttest/cmpgen
4040

4141
fmt: $(SOURCES_NO_VENDOR)
42-
goimports -w $^
42+
go fmt ./...
4343

4444
checkfmt:
45+
./etc/checkfmt.sh
46+
47+
tidy:
4548
GO111MODULE=on go mod tidy
46-
@if ! git --no-pager diff --exit-code -- go.mod go.sum; then \
47-
>&2 echo "modules are not tidy, please run 'go mod tidy'"; \
48-
exit 1; \
49-
fi
50-
go fmt ./...
51-
@if ! git --no-pager diff --quiet; then \
52-
>&2 echo "files are not formatted, please run 'go fmt ./...'"; \
53-
exit 1; \
54-
fi
49+
50+
checktidy:
51+
./etc/checktidy.sh
52+
53+
checkgenerate:
54+
./etc/checkgenerate.sh
55+
56+
staticcheck:
57+
GO111MODULE=on go mod vendor # staticcheck looks in vendor for dependencies.
58+
GO111MODULE=on go run honnef.co/go/tools/cmd/staticcheck ./...
5559

5660
test:
5761
$(GO_TEST) ./...
@@ -70,5 +74,20 @@ release:
7074

7175

7276

73-
.PHONY: all clean fmt test test-race vet bench checkfmt release $(SUBDIRS)
77+
.PHONY: all \
78+
clean \
79+
fmt \
80+
checkfmt \
81+
tidy \
82+
checktidt \
83+
generate \
84+
checkgenerate \
85+
staticcheck \
86+
test \
87+
test-race \
88+
vet \
89+
bench \
90+
checkfmt \
91+
release \
92+
$(SUBDIRS)
7493

‎ast/Makefile

-13
This file was deleted.

‎ast/asttest/Makefile

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
all: cmpopts.go
1+
# List any generated files here
2+
TARGETS = cmpopts.go
3+
# List any source files used to generate the targets here
4+
SOURCES = ../ast.go gen.go ../../bin/$(GOOS)/cmpgen
5+
# List any directories that have their own Makefile here
6+
SUBDIRS =
27

3-
cmpopts.go: ../ast.go gen.go ../../bin/$(GOOS)/cmpgen
4-
PATH=../../bin/${GOOS}:${PATH} $(GO_GENERATE) -x ./...
8+
# Default target
9+
all: $(SUBDIRS) $(TARGETS)
510

6-
clean:
7-
rm -f cmpopts.go
11+
# Recurse into subdirs for same make goal
12+
$(SUBDIRS):
13+
$(MAKE) -C $@ $(MAKECMDGOALS)
814

9-
.PHONY: all clean
15+
# Clean all targets recursively
16+
clean: $(SUBDIRS)
17+
rm -f $(TARGETS)
18+
19+
# Define go generate if not already defined
20+
GO_GENERATE := go generate
21+
22+
# Run go generate for the targets
23+
$(TARGETS): $(SOURCES)
24+
PATH=../../bin/${GOOS}:${PATH} $(GO_GENERATE) -x
25+
26+
.PHONY: all clean $(SUBDIRS)

‎etc/checkfmt.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
HAS_FMT_ERR=0
4+
# For every Go file in the project, excluding vendor...
5+
for file in $(go list -f '{{$dir := .Dir}}{{range .GoFiles}}{{printf "%s/%s\n" $dir .}}{{end}}' ./...); do
6+
# ... if file does not contain standard generated code comment (https://golang.org/s/generatedcode)...
7+
if ! grep -Exq '^// Code generated .* DO NOT EDIT\.$' $file; then
8+
FMT_OUT="$(gofmt -l -d -e $file)" # gofmt exits 0 regardless of whether it's formatted.
9+
# ... and if gofmt had any output...
10+
if [[ -n "$FMT_OUT" ]]; then
11+
if [ "$HAS_FMT_ERR" -eq "0" ]; then
12+
# Only print this once.
13+
HAS_FMT_ERR=1
14+
echo 'Commit includes files that are not gofmt-ed' && \
15+
echo 'run "make fmt"' && \
16+
echo ''
17+
fi
18+
echo "$FMT_OUT" # Print output and continue, so developers don't fix one file at a t
19+
fi
20+
fi
21+
done
22+
23+
## print at the end too... sometimes it is nice to see what to do at the end.
24+
if [ "$HAS_FMT_ERR" -eq "1" ]; then
25+
echo 'Commit includes files that are not gofmt-ed' && \
26+
echo 'run "make fmt"' && \
27+
echo ''
28+
fi
29+
exit "$HAS_FMT_ERR"

‎etc/checkgenerate.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
make clean
6+
make all
7+
8+
status=$(git status --porcelain)
9+
if [ -n "$status" ]; then
10+
>&2 echo "generated code is not accurate, please run make generate"
11+
>&2 echo -e "Files changed:\n$status"
12+
exit 1
13+
fi

‎etc/checktidy.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export GO111MODULE=on
6+
go mod tidy
7+
8+
if ! git --no-pager diff --exit-code -- go.mod go.sum; then
9+
>&2 echo "modules are not tidy, please run 'go mod tidy'"
10+
exit 1
11+
fi

‎go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/influxdata/flux
22

33
require (
4+
github.com/BurntSushi/toml v0.3.1 // indirect
45
github.com/Masterminds/semver v1.4.2
56
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
67
github.com/apache/arrow/go/arrow v0.0.0-20181031164735-a56c009257a7
@@ -36,6 +37,8 @@ require (
3637
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect
3738
golang.org/x/exp v0.0.0-20181112044915-a3060d491354
3839
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a // indirect
40+
golang.org/x/tools v0.0.0-20181221154417-3ad2d988d5e2 // indirect
3941
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca
4042
gopkg.in/src-d/go-git.v4 v4.8.1
43+
honnef.co/go/tools v0.0.0-20181108184350-ae8f1f9103cc
4144
)

‎go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
13
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
24
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
35
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
@@ -168,7 +170,10 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
168170
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
169171
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
170172
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
173+
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b h1:7tibmaEqrQYA+q6ri7NQjuxqSwechjtDHKq6/e85S38=
171174
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
175+
golang.org/x/tools v0.0.0-20181221154417-3ad2d988d5e2 h1:M7NLB69gFpUH4s6SJLwXiVs45aZfVjqGKynfNFKSGcI=
176+
golang.org/x/tools v0.0.0-20181221154417-3ad2d988d5e2/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
172177
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE=
173178
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
174179
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6 h1:4WsZyVtkthqrHTbDCJfiTs8IWNYE4uvsSDgaV6xpp+o=
@@ -188,3 +193,5 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
188193
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
189194
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
190195
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
196+
honnef.co/go/tools v0.0.0-20181108184350-ae8f1f9103cc h1:VdiEcF0DrrUbDdrLBceS0h7LE60ebD5yRYLLXi0ezIs=
197+
honnef.co/go/tools v0.0.0-20181108184350-ae8f1f9103cc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

‎internal/scanner/Makefile

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
GO_GENERATE := go generate $(GO_ARGS)
1+
# List any generated files here
2+
TARGETS = scanner.gen.go unicode.rl
3+
# List any source files used to generate the targets here
4+
SOURCES = gen.go scanner.rl unicode2ragel.rb
5+
# List any directories that have their own Makefile here
6+
SUBDIRS =
27

3-
all: scanner.gen.go
8+
# Default target
9+
all: $(SUBDIRS) $(TARGETS)
410

5-
scanner.gen.go: scanner.rl unicode2ragel.rb
6-
$(GO_GENERATE) -x
11+
# Recurse into subdirs for same make goal
12+
$(SUBDIRS):
13+
$(MAKE) -C $@ $(MAKECMDGOALS)
14+
15+
# Clean all targets recursively
16+
clean: $(SUBDIRS)
17+
rm -f $(TARGETS)
718

8-
clean:
9-
rm -f scanner.gen.go unicode.rl
19+
# Define go generate if not already defined
20+
GO_GENERATE := go generate
21+
22+
# Run go generate for the targets
23+
$(TARGETS): $(SOURCES)
24+
$(GO_GENERATE) -x
1025

11-
.PHONY: all clean
26+
.PHONY: all clean $(SUBDIRS)

‎internal/scanner/gen.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scanner
2+
3+
//go:generate ruby unicode2ragel.rb -e utf8 -o unicode.rl
4+
//go:generate ragel -I. -Z scanner.rl -o scanner.gen.go
5+
//go:generate sh -c "go fmt scanner.gen.go > /dev/null"

‎internal/scanner/scanner.go

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import (
77
"github.com/influxdata/flux/internal/token"
88
)
99

10-
//go:generate ruby unicode2ragel.rb -e utf8 -o unicode.rl
11-
//go:generate ragel -I. -Z scanner.rl -o scanner.gen.go
12-
//go:generate sh -c "go fmt scanner.gen.go > /dev/null"
13-
1410
// Scanner is used to tokenize a flux program.
1511
type Scanner struct {
1612
f *token.File

‎tools.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package flux
44

55
import (
66
_ "github.com/goreleaser/goreleaser"
7+
_ "honnef.co/go/tools/cmd/staticcheck"
78
)
89

910
// This package is a workaround for adding additional paths to the go.mod file

0 commit comments

Comments
 (0)
Failed to load comments.