Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: Make it easier to re-generate everything #555

Merged
merged 5 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.idea/
/test/path
/golangci-lint
/tools/
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ go:
- 1.11.x
- 1.12.x

before_script:
- go get github.com/valyala/quicktemplate

script: make check_generated test

after_success:
Expand Down
89 changes: 75 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
.DEFAULT_GOAL = test
.PHONY: FORCE
export GO111MODULE = on

# Build

build: golangci-lint
clean:
rm -f golangci-lint test/path
rm -rf tools
.PHONY: build clean

# Test

test: build
GL_TEST_RUN=1 ./golangci-lint run -v
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v --skip-dirs 'test/testdata_etc,pkg/golinters/goanalysis/(checker|passes)'
Expand All @@ -6,34 +20,81 @@ test: build

build:
go build -o golangci-lint ./cmd/golangci-lint
.PHONY: test

test_race:
go build -race -o golangci-lint ./cmd/golangci-lint
GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m
.PHONY: test_race

test_linters:
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T
.PHONY: test_linters

assets:
svg-term --cast=183662 --out docs/demo.svg --window --width 110 --height 30 --from 2000 --to 20000 --profile Dracula --term iterm2

readme:
go run ./scripts/gen_readme/main.go
# Maintenance

gen:
go generate ./...
generate: docs/demo.svg README.md install.sh pkg/logutils/log_mock.go vendor
maintainer-clean: clean
rm -f docs/demo.svg README.md install.sh pkg/logutils/log_mock.go
rm -rf vendor
.PHONY: generate maintainer-clean

check_generated:
make readme && git diff --exit-code # check no changes
$(MAKE) --always-make generate
git diff --exit-code # check no changes
.PHONY: check_generated

release:
rm -rf dist
curl -sL https://git.io/goreleaser | bash
.PHONY: release

update_deps:
GO111MODULE=on go mod verify
GO111MODULE=on go mod tidy
rm -rf vendor
GO111MODULE=on go mod vendor
# Non-PHONY targets (real files)

.PHONY: test
golangci-lint: FORCE pkg/logutils/log_mock.go
go build -o $@ ./cmd/golangci-lint

tools/mockgen: go.mod go.sum
GOBIN=$(CURDIR)/tools go install github.com/golang/mock/mockgen

tools/goimports: go.mod go.sum
GOBIN=$(CURDIR)/tools go install golang.org/x/tools/cmd/goimports

tools/go.mod:
@mkdir -p tools
@rm -f $@
cd tools && go mod init local-tools

tools/godownloader: Makefile tools/go.mod
cd tools && GOBIN=$(CURDIR)/tools go get github.com/goreleaser/godownloader@3b90d248ba30307915288f08ab3f2fc2d9f6710c

tools/svg-term:
@mkdir -p tools
cd tools && npm install svg-term-cli
ln -sf node_modules/.bin/svg-term $@

tools/Dracula.itermcolors:
@mkdir -p tools
curl -fL -o $@ https://raw.githubusercontent.com/dracula/iterm/master/Dracula.itermcolors

docs/demo.svg: tools/svg-term tools/Dracula.itermcolors
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

install.sh: tools/godownloader .goreleaser.yml
PATH=$(CURDIR)/tools:$${PATH} tools/godownloader .goreleaser.yml | sed '/DO NOT EDIT/s/ on [0-9TZ:-]*//' > $@

README.md: FORCE golangci-lint
go run ./scripts/gen_readme/main.go

pkg/logutils/log_mock.go: tools/mockgen tools/goimports pkg/logutils/log.go
@rm -f $@
PATH=$(CURDIR)/tools:$${PATH} go generate ./...

go.mod: FORCE
go mod verify
go mod tidy
go.sum: go.mod

vendor: go.mod go.sum
rm -rf vendor
go mod vendor
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-lintpack/lintpack v0.5.2
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/mock v1.1.1
github.com/golang/mock v1.0.0
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6
Expand Down Expand Up @@ -49,6 +49,7 @@ require (
github.com/spf13/pflag v1.0.1
github.com/spf13/viper v1.0.2
github.com/stretchr/testify v1.2.2
github.com/valyala/quicktemplate v1.1.1
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a // indirect
golang.org/x/net v0.0.0-20190313220215-9f648a60d977 // indirect
Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.0.0 h1:HzcpUG60pfl43n9d2qbdi/3l1uKpAmxlfWEPWtV/QxM=
github.com/golang/mock v1.0.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0=
Expand Down Expand Up @@ -88,6 +88,10 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/kisielk/gotool v0.0.0-20161130080628-0de1eaf82fa3/go.mod h1:jxZFDH7ILpTPQTk+E2s+z4CUas9lVNjIuKR4c5/zKgM=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down Expand Up @@ -152,6 +156,12 @@ github.com/spf13/viper v1.0.2 h1:Ncr3ZIuJn322w2k1qmzXDnkLAdQMlJqBa9kfAH+irso=
github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
github.com/valyala/quicktemplate v1.1.1 h1:C58y/wN0FMTi2PR0n3onltemfFabany53j7M6SDDB8k=
github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb h1:lI9ufgFfvuqRctP9Ny8lDDLbSWCMxBPletcSqrnyFYM=
github.com/timakin/bodyclose v0.0.0-20190407043127-4a873e97b2bb/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -160,6 +170,7 @@ golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACk
golang.org/x/net v0.0.0-20170915142106-8351a756f30f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977 h1:actzWV6iWn3GLqN8dZjzsB+CLt+gaV2+wsxroxiQI8I=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-06-05T12:04:55Z. DO NOT EDIT.
# Code generated by godownloader. DO NOT EDIT.
#

usage() {
Expand Down
1 change: 1 addition & 0 deletions pkg/logutils/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logutils

//go:generate mockgen -package logutils -source log.go -destination log_mock.go
//go:generate goimports -w log_mock.go

type Log interface {
Fatalf(format string, args ...interface{})
Expand Down
6 changes: 3 additions & 3 deletions scripts/gen_readme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ func buildTemplateContext() (map[string]interface{}, error) {
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
}

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

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

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

helpCmd := exec.Command("golangci-lint", "run", "-h")
helpCmd := exec.Command("./golangci-lint", "run", "-h")
helpCmd.Env = append(helpCmd.Env, os.Environ()...)
helpCmd.Env = append(helpCmd.Env, "HELP_RUN=1") // make default concurrency stable: don't depend on machine CPU number
help, err := helpCmd.Output()
Expand Down
2 changes: 1 addition & 1 deletion test/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import "path/filepath"

const testdataDir = "testdata"
const binName = "golangci-lint"
const binName = "../golangci-lint"

func getProjectRoot() string {
return filepath.Join("..", "...")
Expand Down
6 changes: 4 additions & 2 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/golangci/golangci-lint/test/testshared"

"github.com/golangci/golangci-lint/pkg/exitcodes"

_ "github.com/valyala/quicktemplate"
)

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

func TestEmptyDirRun(t *testing.T) {
testshared.NewLintRunner(t).Run(getTestDataDir("nogofiles")).
testshared.NewLintRunner(t, "GO111MODULE=off").Run(getTestDataDir("nogofiles")).
ExpectExitCode(exitcodes.NoGoFiles).
ExpectOutputContains(": no go files to analyze")
}

func TestNotExistingDirRun(t *testing.T) {
testshared.NewLintRunner(t).Run(getTestDataDir("no_such_dir")).
testshared.NewLintRunner(t, "GO111MODULE=off").Run(getTestDataDir("no_such_dir")).
ExpectExitCode(exitcodes.Failure).
ExpectOutputContains(`cannot find package \"./testdata/no_such_dir\"`)
}
Expand Down
15 changes: 7 additions & 8 deletions test/testshared/testshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"

Expand All @@ -17,27 +16,26 @@ import (
type LintRunner struct {
t assert.TestingT
log logutils.Log

installed bool
env []string
}

func NewLintRunner(t assert.TestingT) *LintRunner {
func NewLintRunner(t assert.TestingT, environ ...string) *LintRunner {
log := logutils.NewStderrLog("test")
log.SetLevel(logutils.LogLevelInfo)
return &LintRunner{
t: t,
log: log,
env: environ,
}
}

func (r *LintRunner) Install() {
if r.installed {
if _, err := os.Stat("../golangci-lint"); err == nil {
return
}

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

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

runArgs := append([]string{"run"}, args...)
r.log.Infof("golangci-lint %s", strings.Join(runArgs, " "))
cmd := exec.Command("golangci-lint", runArgs...)
cmd := exec.Command("../golangci-lint", runArgs...)
cmd.Env = append(os.Environ(), r.env...)
out, err := cmd.CombinedOutput()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
Expand Down
Loading