Skip to content

Commit 54c0754

Browse files
committed
Replace full binary paths with $TOOL_BIN variables
This just makes more sense to me by being DRY. Signed-off-by: Manuel Mendez <[email protected]>
1 parent d6a5039 commit 54c0754

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,46 @@ ifeq ($(LINT_OS),Darwin)
1818
endif
1919

2020
SHELLCHECK_VERSION ?= v0.7.2
21-
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH):
21+
SHELLCHECK_BIN := out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)
22+
$(SHELLCHECK_BIN):
2223
mkdir -p out/linters
2324
rm -rf out/linters/shellcheck-*
2425
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_OS_LOWER).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
2526
mv out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck $@
2627
rm -rf out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck
2728
HADOLINT_VERSION ?= v2.7.0
28-
out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH):
29+
HADOLINT_BIN := out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH)
30+
$(HADOLINT_BIN):
2931
mkdir -p out/linters
3032
rm -rf out/linters/hadolint-*
3133
curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > $@
3234
chmod u+x $@
3335
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
3436
GOLANGCI_LINT_VERSION ?= v1.42.1
35-
out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH):
37+
GOLANGCI_LINT_BIN := out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
38+
$(GOLANGCI_LINT_BIN):
3639
mkdir -p out/linters
3740
rm -rf out/linters/golangci-lint-*
3841
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLANGCI_LINT_VERSION)
3942
mv out/linters/golangci-lint $@
4043
YAMLLINT_VERSION ?= 1.26.3
4144
YAMLLINT_ROOT := out/linters/yamllint-$(YAMLLINT_VERSION)
42-
$(YAMLLINT_ROOT)/dist/bin/yamllint:
45+
YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint
46+
$(YAMLLINT_BIN):
4347
mkdir -p out/linters
4448
rm -rf out/linters/yamllint-*
4549
curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C out/linters -zxf -
4650
cd $(YAMLLINT_ROOT) && pip3 install --target dist .
4751
.PHONY: _lint
48-
_lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) $(YAMLLINT_ROOT)/dist/bin/yamllint
49-
out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) run
50-
out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) $(shell find . -name "*Dockerfile")
51-
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) $(shell find . -name "*.sh")
52+
_lint: $(SHELLCHECK_BIN) $(HADOLINT_BIN) $(GOLANGCI_LINT_BIN) $(YAMLLINT_BIN)
53+
$(GOLANGCI_LINT_BIN) run
54+
$(HADOLINT_BIN) $(shell find . -name "*Dockerfile")
55+
$(SHELLCHECK_BIN) $(shell find . -name "*.sh")
5256
PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint .
5357

5458
.PHONY: fix
55-
fix: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
56-
out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) run --fix
57-
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) $(shell find . -name "*.sh") -f diff | { read -t 1 line || exit 0; { echo "$$line" && cat; } | git apply -p2; }
59+
fix: $(SHELLCHECK_BIN) $(GOLANGCI_LINT_BIN)
60+
$(GOLANGCI_LINT_BIN) run --fix
61+
$(SHELLCHECK_BIN) $(shell find . -name "*.sh") -f diff | { read -t 1 line || exit 0; { echo "$$line" && cat; } | git apply -p2; }
5862

5963
# END: lint-install .

Makefile.tmpl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ endif
1919

2020
{{ if .Shell -}}
2121
SHELLCHECK_VERSION ?= v0.7.2
22-
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH):
22+
SHELLCHECK_BIN := out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)
23+
$(SHELLCHECK_BIN):
2324
mkdir -p out/linters
2425
rm -rf out/linters/shellcheck-*
2526
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_OS_LOWER).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
@@ -29,7 +30,8 @@ out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH):
2930

3031
{{ if .Dockerfile -}}
3132
HADOLINT_VERSION ?= v2.7.0
32-
out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH):
33+
HADOLINT_BIN := out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH)
34+
$(HADOLINT_BIN):
3335
mkdir -p out/linters
3436
rm -rf out/linters/hadolint-*
3537
curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > $@
@@ -39,7 +41,8 @@ out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH):
3941
{{ if .Go -}}
4042
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
4143
GOLANGCI_LINT_VERSION ?= v1.42.1
42-
out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH):
44+
GOLANGCI_LINT_BIN := out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
45+
$(GOLANGCI_LINT_BIN):
4346
mkdir -p out/linters
4447
rm -rf out/linters/golangci-lint-*
4548
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLANGCI_LINT_VERSION)
@@ -49,20 +52,21 @@ out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH):
4952
{{ if .YAML -}}
5053
YAMLLINT_VERSION ?= 1.26.3
5154
YAMLLINT_ROOT := out/linters/yamllint-$(YAMLLINT_VERSION)
52-
$(YAMLLINT_ROOT)/dist/bin/yamllint:
55+
YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint
56+
$(YAMLLINT_BIN):
5357
mkdir -p out/linters
5458
rm -rf out/linters/yamllint-*
5559
curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C out/linters -zxf -
5660
cd $(YAMLLINT_ROOT) && pip3 install --target dist .
5761
{{ end -}}
5862

5963
.PHONY: _lint
60-
_lint: {{ if .Shell }}out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) {{ end }}{{ if .Dockerfile }}out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH) {{ end }}{{ if .Go}}out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) {{ end }}{{ if .YAML}}$(YAMLLINT_ROOT)/dist/bin/yamllint{{ end }}
64+
_lint: {{ if .Shell }}$(SHELLCHECK_BIN) {{ end }}{{ if .Dockerfile }}$(HADOLINT_BIN) {{ end }}{{ if .Go}}$(GOLANGCI_LINT_BIN) {{ end }}{{ if .YAML}}$(YAMLLINT_BIN){{ end }}
6165
{{- range .LintCommands }}
6266
{{ .}}{{ end}}
6367

6468
.PHONY: fix
65-
fix: {{ if .Shell }}out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) {{ end }}{{ if .Go}}out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH){{ end }}
69+
fix: {{ if .Shell }}$(SHELLCHECK_BIN) {{ end }}{{ if .Go}}$(GOLANGCI_LINT_BIN){{ end }}
6670
{{- range .FixCommands }}
6771
{{ .}}{{ end}}
6872

lint-install.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ func goLintCmd(root string, level string, fix bool) string {
255255

256256
klog.Infof("found %d modules within %s: %s", len(found), root, found)
257257
if len(found) == 0 || (len(found) == 1 && found[0] == strings.Trim(root, "/")) {
258-
return fmt.Sprintf("out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH) run%s", suffix)
258+
return fmt.Sprintf("$(GOLANGCI_LINT_BIN) run%s", suffix)
259259
}
260260

261-
return fmt.Sprintf(`find . -name go.mod -execdir "$(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)" run -c "$(GOLINT_CONFIG)"%s \;`, suffix)
261+
return fmt.Sprintf(`find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLINT_CONFIG)"%s \;`, suffix)
262262
}
263263

264264
// shellLintCmd returns the appropriate shell lint command for a project.
@@ -276,7 +276,7 @@ func shellLintCmd(_ string, level string, fix bool) string {
276276
suffix = " || true"
277277
}
278278

279-
return fmt.Sprintf(`out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH) $(shell find . -name "*.sh")%s`, suffix)
279+
return fmt.Sprintf(`$(SHELLCHECK_BIN) $(shell find . -name "*.sh")%s`, suffix)
280280
}
281281

282282
// dockerLintCmd returns the appropriate docker lint command for a project.
@@ -286,7 +286,7 @@ func dockerLintCmd(_ string, level string) string {
286286
f = " --no-fail"
287287
}
288288

289-
return fmt.Sprintf(`out/linters/hadolint-$(HADOLINT_VERSION)-$(LINT_ARCH)%s $(shell find . -name "*Dockerfile")`, f)
289+
return fmt.Sprintf(`$(HADOLINT_BIN)%s $(shell find . -name "*Dockerfile")`, f)
290290
}
291291

292292
// yamlLintCmd returns the appropriate yamllint command for a project.

0 commit comments

Comments
 (0)