Skip to content

Commit b022182

Browse files
committed
fix: Remove excessive recursive variable expansions
Modern GNU make (version >= 4.4) has backward-incompatibile feature: > * WARNING: Backward-incompatibility! > Previously makefile variables marked as export were not exported to commands > started by the $(shell ...) function. Now, all exported variables are > exported to $(shell ...). If this leads to recursion during expansion, then > for backward-compatibility the value from the original environment is used. This makes any invocation of `make` command very costly. Compare the performance of make 4.3 vs. 4.4: ``` $ time ~/Sources/make-4.3/make smb ARCH=$(go env GOARCH) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:00:09Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin real 0m38.504s user 3m50.580s sys 0m23.502s $ time ~/Sources/make-4.4/make smb ARCH=$(go env GOARCH) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:04:04Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin real 16m59.851s user 13m16.490s sys 13m46.418s ``` The same variables are evaluated again and again millions times: ``` $ rpm -qf /usr/bin/make make-4.4.1-6.fc40.x86_64 $ /usr/bin/make -d smb ARCH=$(go env GOARCH) 2>&1 |grep "not recursively expanding.*to export to shell function" |wc -l 2171342 ``` The patch doesn't change user-visible behavior of Makefile, but makes `make` command as performant as it used to be in case of make 4.3.
1 parent ce19947 commit b022182

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ CMDS=smbplugin
1616
PKG = github.com/kubernetes-csi/csi-driver-smb
1717
GINKGO_FLAGS = -ginkgo.v -ginkgo.timeout=2h
1818
GO111MODULE = on
19-
GOPATH ?= $(shell go env GOPATH)
19+
ifndef GOPATH
20+
GOPATH := $(shell go env GOPATH)
21+
endif
2022
GOBIN ?= $(GOPATH)/bin
2123
DOCKER_CLI_EXPERIMENTAL = enabled
2224
IMAGENAME ?= smb-csi
2325
export GOPATH GOBIN GO111MODULE DOCKER_CLI_EXPERIMENTAL
2426

2527
include release-tools/build.make
2628

27-
GIT_COMMIT ?= $(shell git rev-parse HEAD)
29+
GIT_COMMIT := $(shell git rev-parse HEAD)
2830
REGISTRY ?= andyzhangx
29-
REGISTRY_NAME = $(shell echo $(REGISTRY) | sed "s/.azurecr.io//g")
31+
REGISTRY_NAME := $(shell echo $(REGISTRY) | sed "s/.azurecr.io//g")
3032
IMAGE_VERSION ?= v1.15.0
3133
VERSION ?= latest
3234
# Use a custom version for E2E tests if we are testing in CI
@@ -37,7 +39,9 @@ endif
3739
endif
3840
IMAGE_TAG = $(REGISTRY)/$(IMAGENAME):$(IMAGE_VERSION)
3941
IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGENAME):latest
40-
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
42+
ifndef BUILD_DATE
43+
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
44+
endif
4145
LDFLAGS = -X ${PKG}/pkg/smb.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/smb.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/smb.buildDate=${BUILD_DATE}
4246
EXT_LDFLAGS = -s -w -extldflags "-static"
4347
E2E_HELM_OPTIONS ?= --set image.smb.repository=$(REGISTRY)/$(IMAGENAME) --set image.smb.tag=$(IMAGE_VERSION)

0 commit comments

Comments
 (0)