Skip to content

Commit 03831a0

Browse files
authored
Merge pull request #408 from shutter-network/schmir/speedup-generate
Speedup 'make generate' and the generate pre-commit hook
2 parents 0903a0e + 0ca59bd commit 03831a0

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

rolling-shutter/Makefile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TINYGO ?= tinygo
66
WASMOPT ?= wasm-opt
77
BINDIR ?= ./bin
88
EXECUTABLE ?= ${BINDIR}/rolling-shutter
9+
GOPATH ?= $(${GO} env GOPATH)
910

1011
build:
1112
${GO} build ${GOFLAGS} -o ${EXECUTABLE}
@@ -37,8 +38,8 @@ test: test-unit
3738
test-all: test-unit test-integration
3839

3940
generate: install-codegen-tools
40-
${GO} generate -skip="gendocs.go" -x ./...
41-
${GO} generate -run="gendocs.go" -x ./...
41+
${GO} generate -skip="make docs" -x ./...
42+
${GO} generate -run="make docs" -x ./...
4243

4344
coverage:
4445
${GO} test ${GOFLAGS} -covermode=count -coverprofile=coverage.out ./...
@@ -50,36 +51,41 @@ clean:
5051
install-tools: install-codegen-tools install-golangci-lint install-cobra install-gofumpt install-gci install-gotestsum
5152

5253
# code generation tools: pin version
53-
install-codegen-tools: install-npm install-abigen install-sqlc install-protoc-gen-go install-oapi-codegen install-stringer install-go-enum install-cobra
54+
install-codegen-tools: install-npm install-abigen install-sqlc install-protoc-gen-go install-oapi-codegen install-go-enum
5455

55-
install-npm:
56+
../contracts/node_modules/.mark-npm-install: ../contracts/package.json ../contracts/package-lock.json
5657
cd ../contracts && npm install
58+
@touch ../contracts/node_modules/.mark-npm-install
5759

58-
install-sqlc:
60+
install-npm: ../contracts/node_modules/.mark-npm-install
61+
62+
${GOPATH}/bin/sqlc:
5963
${GO} install github.com/kyleconroy/sqlc/cmd/[email protected]
64+
install-sqlc: ${GOPATH}/bin/sqlc
65+
6066

61-
install-go-enum:
67+
${GOPATH}/bin/go-enum:
6268
${GO} install github.com/abice/[email protected]
69+
install-go-enum: ${GOPATH}/bin/go-enum
6370

64-
install-abigen:
71+
${GOPATH}/bin/abigen:
6572
${GO} install github.com/ethereum/go-ethereum/cmd/[email protected]
73+
install-abigen: ${GOPATH}/bin/abigen
74+
6675

67-
install-protoc-gen-go:
76+
${GOPATH}/bin/protoc-gen-go:
6877
${GO} install google.golang.org/protobuf/cmd/[email protected]
78+
install-protoc-gen-go: ${GOPATH}/bin/protoc-gen-go
6979

70-
install-oapi-codegen:
71-
${GO} install github.com/deepmap/oapi-codegen/cmd/[email protected]
7280

73-
install-stringer:
74-
${GO} install golang.org/x/tools/cmd/[email protected]
81+
${GOPATH}/bin/oapi-codegen:
82+
${GO} install github.com/deepmap/oapi-codegen/cmd/[email protected]
83+
install-oapi-codegen: ${GOPATH}/bin/oapi-codegen
7584

7685
# non code generation tools
7786
install-golangci-lint:
7887
${GO} install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
7988

80-
install-cobra:
81-
${GO} install github.com/spf13/cobra-cli@latest
82-
8389
install-gofumpt:
8490
${GO} install mvdan.cc/gofumpt@latest
8591

rolling-shutter/docs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docs: rolling-shutter.md
2+
3+
rolling-shutter.md: ../medley/rootcmd/root.go $(shell find ../cmd -iname '*.go' ! -iname '*_test.go')
4+
go run gendocs.go

rolling-shutter/docs/docs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package docs
2+
3+
//go:generate make docs

rolling-shutter/docs/gendocs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd"
99
)
1010

11-
//go:generate go run gendocs.go
1211
func main() {
1312
err := doc.GenMarkdownTree(cmd.Command(), "./")
1413
if err != nil {

rolling-shutter/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/rootcmd"
66
)
77

8-
//go:generate go run -C docs gendocs.go
9-
108
func main() {
119
rootcmd.Main(cmd.Command())
1210
}

rolling-shutter/medley/rootcmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
ArgNameLogformat string = "logformat"
2626
logLevelArg string
2727
ArgNameLoglevel string = "loglevel"
28-
reLogLevelConfig = regexp.MustCompile("^(?:(?P<logger>[\\w/._-]+)?:(?P<level>debug|info|warn(?:ing)?|error|fatal|panic),?)+$")
28+
reLogLevelConfig = regexp.MustCompile(`^(?:([\w/.-]+)?:(debug|info|warn(?:ing)?|error|fatal|panic),?)+$`)
2929
)
3030

3131
func configureCaller(l zerolog.Logger, short bool) zerolog.Logger {
@@ -116,9 +116,9 @@ func setupLogging() (zerolog.Logger, error) {
116116
return l, errors.Wrapf(err, "flag '%s' value '%s' not recognized", ArgNameLoglevel, logLevel)
117117
}
118118
zerolog.SetGlobalLevel(level)
119-
golog.SetLogLevel("*", levelName)
119+
_ = golog.SetLogLevel("*", levelName)
120120
} else {
121-
golog.SetLogLevel(loggerName, levelName)
121+
_ = golog.SetLogLevel(loggerName, levelName)
122122
}
123123
}
124124
}

0 commit comments

Comments
 (0)