Skip to content

Commit 7f2a6d5

Browse files
authored
chore: updates to make targets for building binaries (#1733)
* chore: do not automatically clean binaries before building Signed-off-by: Evans Mungai <[email protected]> * chore: detect if source files changed before building Signed-off-by: Evans Mungai <[email protected]> --------- Signed-off-by: Evans Mungai <[email protected]>
1 parent 7efdb2b commit 7f2a6d5

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Makefile

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ VERSION_PACKAGE = github.com/replicatedhq/troubleshoot/pkg/version
77
VERSION ?=`git describe --tags --dirty`
88
DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
99
RUN?=""
10-
GOLANGCI_LINT_VERSION ?= "v1.61.0"
1110

1211
GIT_TREE = $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
1312
ifneq "$(GIT_TREE)" ""
@@ -104,18 +103,33 @@ clean:
104103
tidy:
105104
go mod tidy
106105

107-
bin/support-bundle:
106+
# Only build when any of the files in SOURCES changes, or if bin/<file> is absent
107+
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
108+
SOURCES := $(shell find $(MAKEFILE_DIR) -type f \( -name "*.go" -o -name "go.mod" -o -name "go.sum" \))
109+
bin/support-bundle: $(SOURCES)
108110
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot
109111

110-
bin/preflight:
112+
bin/preflight: $(SOURCES)
111113
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight
112114

113-
bin/analyze:
115+
bin/analyze: $(SOURCES)
114116
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze
115117

116-
bin/collect:
118+
bin/collect: $(SOURCES)
117119
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect
118120

121+
.PHONY: support-bundle
122+
support-bundle: bin/support-bundle
123+
124+
.PHONY: preflight
125+
preflight: bin/preflight
126+
127+
.PHONY: analyze
128+
analyze: bin/analyze
129+
130+
.PHONY: collect
131+
collect: bin/collect
132+
119133
build-linux: tidy
120134
@echo "Build cli binaries for Linux"
121135
GOOS=linux GOARCH=amd64 $(MAKE) -j bin/support-bundle bin/preflight bin/analyze bin/collect
@@ -256,18 +270,6 @@ npm-install:
256270

257271
######## Lagacy make targets ###########
258272
# Deprecated: These can be removed
259-
.PHONY: support-bundle
260-
support-bundle: clean bin/support-bundle
261-
262-
.PHONY: preflight
263-
preflight: clean bin/preflight
264-
265-
.PHONY: analyze
266-
analyze: clean bin/analyze
267-
268-
.PHONY: collect
269-
collect: clean bin/collect
270-
271273
.PHONY: run-troubleshoot
272274
run-troubleshoot: run-support-bundle
273275

0 commit comments

Comments
 (0)