Skip to content

Commit 88318cb

Browse files
authored
Merge pull request #555 from LukeShu/lukeshu/reproduce
Makefile: Make it easier to re-generate everything
2 parents 88af709 + 66d4a16 commit 88318cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1762
-1047
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/.idea/
66
/test/path
77
/golangci-lint
8+
/tools/

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ go:
44
- 1.11.x
55
- 1.12.x
66

7-
before_script:
8-
- go get github.com/valyala/quicktemplate
9-
107
script: make check_generated test
118

129
after_success:

Makefile

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
.DEFAULT_GOAL = test
2+
.PHONY: FORCE
3+
export GO111MODULE = on
4+
5+
# Build
6+
7+
build: golangci-lint
8+
clean:
9+
rm -f golangci-lint test/path
10+
rm -rf tools
11+
.PHONY: build clean
12+
13+
# Test
14+
115
test: build
216
GL_TEST_RUN=1 ./golangci-lint run -v
317
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v --skip-dirs 'test/testdata_etc,pkg/golinters/goanalysis/(checker|passes)'
@@ -6,34 +20,81 @@ test: build
620

721
build:
822
go build -o golangci-lint ./cmd/golangci-lint
23+
.PHONY: test
924

1025
test_race:
1126
go build -race -o golangci-lint ./cmd/golangci-lint
1227
GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m
28+
.PHONY: test_race
1329

1430
test_linters:
1531
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T
32+
.PHONY: test_linters
1633

17-
assets:
18-
svg-term --cast=183662 --out docs/demo.svg --window --width 110 --height 30 --from 2000 --to 20000 --profile Dracula --term iterm2
19-
20-
readme:
21-
go run ./scripts/gen_readme/main.go
34+
# Maintenance
2235

23-
gen:
24-
go generate ./...
36+
generate: docs/demo.svg README.md install.sh pkg/logutils/log_mock.go vendor
37+
maintainer-clean: clean
38+
rm -f docs/demo.svg README.md install.sh pkg/logutils/log_mock.go
39+
rm -rf vendor
40+
.PHONY: generate maintainer-clean
2541

2642
check_generated:
27-
make readme && git diff --exit-code # check no changes
43+
$(MAKE) --always-make generate
44+
git diff --exit-code # check no changes
45+
.PHONY: check_generated
2846

2947
release:
3048
rm -rf dist
3149
curl -sL https://git.io/goreleaser | bash
50+
.PHONY: release
3251

33-
update_deps:
34-
GO111MODULE=on go mod verify
35-
GO111MODULE=on go mod tidy
36-
rm -rf vendor
37-
GO111MODULE=on go mod vendor
52+
# Non-PHONY targets (real files)
3853

39-
.PHONY: test
54+
golangci-lint: FORCE pkg/logutils/log_mock.go
55+
go build -o $@ ./cmd/golangci-lint
56+
57+
tools/mockgen: go.mod go.sum
58+
GOBIN=$(CURDIR)/tools go install github.com/golang/mock/mockgen
59+
60+
tools/goimports: go.mod go.sum
61+
GOBIN=$(CURDIR)/tools go install golang.org/x/tools/cmd/goimports
62+
63+
tools/go.mod:
64+
@mkdir -p tools
65+
@rm -f $@
66+
cd tools && go mod init local-tools
67+
68+
tools/godownloader: Makefile tools/go.mod
69+
cd tools && GOBIN=$(CURDIR)/tools go get github.com/goreleaser/godownloader@3b90d248ba30307915288f08ab3f2fc2d9f6710c
70+
71+
tools/svg-term:
72+
@mkdir -p tools
73+
cd tools && npm install svg-term-cli
74+
ln -sf node_modules/.bin/svg-term $@
75+
76+
tools/Dracula.itermcolors:
77+
@mkdir -p tools
78+
curl -fL -o $@ https://raw.githubusercontent.com/dracula/iterm/master/Dracula.itermcolors
79+
80+
docs/demo.svg: tools/svg-term tools/Dracula.itermcolors
81+
PATH=$(CURDIR)/tools:$${PATH} svg-term --cast=183662 --out docs/demo.svg --window --width 110 --height 30 --from 2000 --to 20000 --profile ./tools/Dracula.itermcolors --term iterm2
82+
83+
install.sh: tools/godownloader .goreleaser.yml
84+
PATH=$(CURDIR)/tools:$${PATH} tools/godownloader .goreleaser.yml | sed '/DO NOT EDIT/s/ on [0-9TZ:-]*//' > $@
85+
86+
README.md: FORCE golangci-lint
87+
go run ./scripts/gen_readme/main.go
88+
89+
pkg/logutils/log_mock.go: tools/mockgen tools/goimports pkg/logutils/log.go
90+
@rm -f $@
91+
PATH=$(CURDIR)/tools:$${PATH} go generate ./...
92+
93+
go.mod: FORCE
94+
go mod verify
95+
go mod tidy
96+
go.sum: go.mod
97+
98+
vendor: go.mod go.sum
99+
rm -rf vendor
100+
go mod vendor

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/go-lintpack/lintpack v0.5.2
1010
github.com/go-ole/go-ole v1.2.1 // indirect
1111
github.com/gobwas/glob v0.2.3 // indirect
12-
github.com/golang/mock v1.1.1
12+
github.com/golang/mock v1.0.0
1313
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
1414
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
1515
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6
@@ -49,6 +49,7 @@ require (
4949
github.com/spf13/pflag v1.0.1
5050
github.com/spf13/viper v1.0.2
5151
github.com/stretchr/testify v1.2.2
52+
github.com/valyala/quicktemplate v1.1.1
5253
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb
5354
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a // indirect
5455
golang.org/x/net v0.0.0-20190313220215-9f648a60d977 // indirect

go.sum

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
3838
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
3939
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
4040
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
41-
github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=
42-
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
41+
github.com/golang/mock v1.0.0 h1:HzcpUG60pfl43n9d2qbdi/3l1uKpAmxlfWEPWtV/QxM=
42+
github.com/golang/mock v1.0.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
4343
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
4444
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
4545
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0=
@@ -88,6 +88,10 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
8888
github.com/kisielk/gotool v0.0.0-20161130080628-0de1eaf82fa3/go.mod h1:jxZFDH7ILpTPQTk+E2s+z4CUas9lVNjIuKR4c5/zKgM=
8989
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
9090
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
91+
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
92+
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
93+
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
94+
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
9195
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
9296
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
9397
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -152,6 +156,12 @@ github.com/spf13/viper v1.0.2 h1:Ncr3ZIuJn322w2k1qmzXDnkLAdQMlJqBa9kfAH+irso=
152156
github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
153157
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
154158
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
159+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
160+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
161+
github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
162+
github.com/valyala/quicktemplate v1.1.1 h1:C58y/wN0FMTi2PR0n3onltemfFabany53j7M6SDDB8k=
163+
github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4=
164+
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
155165
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb h1:lI9ufgFfvuqRctP9Ny8lDDLbSWCMxBPletcSqrnyFYM=
156166
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
157167
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -160,6 +170,7 @@ golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACk
160170
golang.org/x/net v0.0.0-20170915142106-8351a756f30f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
161171
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
162172
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
173+
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
163174
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
164175
golang.org/x/net v0.0.0-20190313220215-9f648a60d977 h1:actzWV6iWn3GLqN8dZjzsB+CLt+gaV2+wsxroxiQI8I=
165176
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
set -e
3-
# Code generated by godownloader on 2018-06-05T12:04:55Z. DO NOT EDIT.
3+
# Code generated by godownloader. DO NOT EDIT.
44
#
55

66
usage() {

pkg/logutils/log.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package logutils
22

33
//go:generate mockgen -package logutils -source log.go -destination log_mock.go
4+
//go:generate goimports -w log_mock.go
45

56
type Log interface {
67
Fatalf(format string, args ...interface{})

scripts/gen_readme/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ func buildTemplateContext() (map[string]interface{}, error) {
5353
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
5454
}
5555

56-
if err = exec.Command("go", "install", "./cmd/...").Run(); err != nil {
56+
if err = exec.Command("make", "build").Run(); err != nil {
5757
return nil, fmt.Errorf("can't run go install: %s", err)
5858
}
5959

60-
lintersOut, err := exec.Command("golangci-lint", "help", "linters").Output()
60+
lintersOut, err := exec.Command("./golangci-lint", "help", "linters").Output()
6161
if err != nil {
6262
return nil, fmt.Errorf("can't run linters cmd: %s", err)
6363
}
6464

6565
lintersOutParts := bytes.Split(lintersOut, []byte("\n\n"))
6666

67-
helpCmd := exec.Command("golangci-lint", "run", "-h")
67+
helpCmd := exec.Command("./golangci-lint", "run", "-h")
6868
helpCmd.Env = append(helpCmd.Env, os.Environ()...)
6969
helpCmd.Env = append(helpCmd.Env, "HELP_RUN=1") // make default concurrency stable: don't depend on machine CPU number
7070
help, err := helpCmd.Output()

test/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package test
33
import "path/filepath"
44

55
const testdataDir = "testdata"
6-
const binName = "golangci-lint"
6+
const binName = "../golangci-lint"
77

88
func getProjectRoot() string {
99
return filepath.Join("..", "...")

test/run_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/golangci/golangci-lint/test/testshared"
1111

1212
"github.com/golangci/golangci-lint/pkg/exitcodes"
13+
14+
_ "github.com/valyala/quicktemplate"
1315
)
1416

1517
func getCommonRunArgs() []string {
@@ -25,13 +27,13 @@ func TestAutogeneratedNoIssues(t *testing.T) {
2527
}
2628

2729
func TestEmptyDirRun(t *testing.T) {
28-
testshared.NewLintRunner(t).Run(getTestDataDir("nogofiles")).
30+
testshared.NewLintRunner(t, "GO111MODULE=off").Run(getTestDataDir("nogofiles")).
2931
ExpectExitCode(exitcodes.NoGoFiles).
3032
ExpectOutputContains(": no go files to analyze")
3133
}
3234

3335
func TestNotExistingDirRun(t *testing.T) {
34-
testshared.NewLintRunner(t).Run(getTestDataDir("no_such_dir")).
36+
testshared.NewLintRunner(t, "GO111MODULE=off").Run(getTestDataDir("no_such_dir")).
3537
ExpectExitCode(exitcodes.Failure).
3638
ExpectOutputContains(`cannot find package \"./testdata/no_such_dir\"`)
3739
}

test/testshared/testshared.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"io/ioutil"
55
"os"
66
"os/exec"
7-
"path/filepath"
87
"strings"
98
"syscall"
109

@@ -17,27 +16,26 @@ import (
1716
type LintRunner struct {
1817
t assert.TestingT
1918
log logutils.Log
20-
21-
installed bool
19+
env []string
2220
}
2321

24-
func NewLintRunner(t assert.TestingT) *LintRunner {
22+
func NewLintRunner(t assert.TestingT, environ ...string) *LintRunner {
2523
log := logutils.NewStderrLog("test")
2624
log.SetLevel(logutils.LogLevelInfo)
2725
return &LintRunner{
2826
t: t,
2927
log: log,
28+
env: environ,
3029
}
3130
}
3231

3332
func (r *LintRunner) Install() {
34-
if r.installed {
33+
if _, err := os.Stat("../golangci-lint"); err == nil {
3534
return
3635
}
3736

38-
cmd := exec.Command("go", "install", filepath.Join("..", "cmd", "golangci-lint"))
37+
cmd := exec.Command("make", "-C", "..", "build")
3938
assert.NoError(r.t, cmd.Run(), "Can't go install golangci-lint")
40-
r.installed = true
4139
}
4240

4341
type RunResult struct {
@@ -82,7 +80,8 @@ func (r *LintRunner) Run(args ...string) *RunResult {
8280

8381
runArgs := append([]string{"run"}, args...)
8482
r.log.Infof("golangci-lint %s", strings.Join(runArgs, " "))
85-
cmd := exec.Command("golangci-lint", runArgs...)
83+
cmd := exec.Command("../golangci-lint", runArgs...)
84+
cmd.Env = append(os.Environ(), r.env...)
8685
out, err := cmd.CombinedOutput()
8786
if err != nil {
8887
if exitError, ok := err.(*exec.ExitError); ok {

0 commit comments

Comments
 (0)