Skip to content

Commit 64d8dcb

Browse files
authored
Faster make v2 (#3724)
* Don’t use simply expanded variables for constants Signed-off-by: David Gageot <[email protected]> * Eval only when needed This makes the Makefile faster for other targets. Signed-off-by: David Gageot <[email protected]> * Use built-in variable for current path Signed-off-by: David Gageot <[email protected]> * Simplify `make` and `make install` We don’t need a target to go build for every GOOS since this done by `make cross`. Signed-off-by: David Gageot <[email protected]> * Not useful for local dev and not used at release time. At release time, we build in a Docker container so the path is predictable. Signed-off-by: David Gageot <[email protected]> * Generate statik files only when needed Signed-off-by: David Gageot <[email protected]> * These variables can be deferred Signed-off-by: David Gageot <[email protected]>
1 parent 7ee0c0b commit 64d8dcb

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

Diff for: Makefile

+27-29
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
GOOS ?= $(shell go env GOOS)
1515
GOARCH = amd64
1616
BUILD_DIR ?= ./out
17-
ORG := github.com/GoogleContainerTools
18-
PROJECT := skaffold
17+
ORG = github.com/GoogleContainerTools
18+
PROJECT = skaffold
1919
REPOPATH ?= $(ORG)/$(PROJECT)
2020
RELEASE_BUCKET ?= $(PROJECT)
2121
GSC_BUILD_PATH ?= gs://$(RELEASE_BUCKET)/builds/$(COMMIT)
@@ -28,10 +28,11 @@ GCP_PROJECT ?= k8s-skaffold
2828
GKE_CLUSTER_NAME ?= integration-tests
2929
GKE_ZONE ?= us-central1-a
3030

31-
SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe
31+
SUPPORTED_PLATFORMS = linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe
3232
BUILD_PACKAGE = $(REPOPATH)/cmd/skaffold
3333

34-
SKAFFOLD_TEST_PACKAGES := $(shell go list ./... | grep -v diag)
34+
SKAFFOLD_TEST_PACKAGES = $(shell go list ./... | grep -v diag)
35+
GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*")
3536

3637
VERSION_PACKAGE = $(REPOPATH)/pkg/skaffold/version
3738
COMMIT = $(shell git rev-parse HEAD)
@@ -45,16 +46,13 @@ endif
4546
export GO111MODULE = on
4647
export GOFLAGS = -mod=vendor
4748

48-
GO_GCFLAGS := "all=-trimpath=${PWD}"
49-
GO_ASMFLAGS := "all=-trimpath=${PWD}"
50-
5149
LDFLAGS_linux = -static
5250
LDFLAGS_darwin =
5351
LDFLAGS_windows =
5452

55-
GO_BUILD_TAGS_linux := "osusergo netgo static_build release"
56-
GO_BUILD_TAGS_darwin := "release"
57-
GO_BUILD_TAGS_windows := "release"
53+
GO_BUILD_TAGS_linux = "osusergo netgo static_build release"
54+
GO_BUILD_TAGS_darwin = "release"
55+
GO_BUILD_TAGS_windows = "release"
5856

5957
GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION)
6058
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
@@ -66,16 +64,23 @@ GO_LDFLAGS_windows =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_windows)\""
6664
GO_LDFLAGS_darwin =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_darwin)\""
6765
GO_LDFLAGS_linux =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_linux)\""
6866

69-
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*")
70-
DEPS_DIGEST := $(shell ./hack/skaffold-deps-sha1.sh)
67+
STATIK_FILES = cmd/skaffold/app/cmd/statik/statik.go
68+
69+
# Build for local development.
70+
$(BUILD_DIR)/$(PROJECT): $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR)
71+
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -o $@ $(BUILD_PACKAGE)
72+
73+
.PHONY: install
74+
install: $(BUILD_DIR)/$(PROJECT)
75+
cp $(BUILD_DIR)/$(PROJECT) $(GOPATH)/bin/$(PROJECT)
7176

72-
$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
73-
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@
77+
# Build for a release.
78+
.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
7479

75-
$(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH): generate-statik $(GO_FILES) $(BUILD_DIR)
76-
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -o $@ $(BUILD_PACKAGE)
80+
.PHONY: cross
81+
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)
7782

78-
$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): generate-statik $(GO_FILES) $(BUILD_DIR)
83+
$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR)
7984
docker build \
8085
--build-arg PROJECT=$(REPOPATH) \
8186
--build-arg TARGETS=$*/$(GOARCH) \
@@ -99,11 +104,6 @@ $(BUILD_DIR)/VERSION: $(BUILD_DIR)
99104
$(BUILD_DIR):
100105
mkdir -p $(BUILD_DIR)
101106

102-
.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
103-
104-
.PHONY: cross
105-
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)
106-
107107
.PHONY: test
108108
test: $(BUILD_DIR)
109109
@ ./hack/gotest.sh -count=1 -race -short -timeout=90s $(SKAFFOLD_TEST_PACKAGES)
@@ -122,12 +122,8 @@ checks: $(BUILD_DIR)
122122
quicktest:
123123
@ ./hack/gotest.sh -short -timeout=60s $(SKAFFOLD_TEST_PACKAGES)
124124

125-
.PHONY: install
126-
install: $(GO_FILES) $(BUILD_DIR)
127-
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go install -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) $(BUILD_PACKAGE)
128-
129125
.PHONY: integration
130-
integration: generate-statik install
126+
integration: install
131127
ifeq ($(GCP_ONLY),true)
132128
gcloud container clusters get-credentials \
133129
$(GKE_CLUSTER_NAME) \
@@ -166,6 +162,7 @@ clean:
166162

167163
.PHONY: build_deps
168164
build_deps:
165+
$(eval DEPS_DIGEST := $(shell ./hack/skaffold-deps-sha1.sh))
169166
docker build \
170167
-f deploy/skaffold/Dockerfile.deps \
171168
-t gcr.io/$(GCP_PROJECT)/build_deps:$(DEPS_DIGEST) \
@@ -243,6 +240,7 @@ build-docs-preview:
243240
generate-schemas:
244241
go run hack/schemas/main.go
245242

246-
.PHONY: generate-statik
247-
generate-statik:
243+
# static files
244+
245+
$(STATIK_FILES): go.mod docs/content/en/schemas/*
248246
hack/generate-statik.sh

Diff for: deploy/skaffold/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ COPY . .
1919

2020
FROM builder as release
2121
ARG VERSION
22-
RUN make clean && make out/skaffold-linux-amd64 VERSION=$VERSION && mv out/skaffold-linux-amd64 /usr/bin/skaffold
22+
RUN make clean out/skaffold VERSION=$VERSION && mv out/skaffold /usr/bin/skaffold
2323
RUN skaffold credits -d /THIRD_PARTY_NOTICES

0 commit comments

Comments
 (0)