diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2022-01-27 14:10:10 +0300 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2022-01-27 14:10:10 +0300 |
commit | 008e2afc8d6de32a30696dbf813ebc0fdf5192c7 (patch) | |
tree | 7ae2949de008fce0148719747d074459ce209e6e | |
parent | be24d56738e008301b467a02996e23b33f590c17 (diff) | |
parent | 783ec4e5328ac4106fc1f1e931e5fde7c9bc95af (diff) |
Merge branch 'bvl-add-gnu-build-id' into 'master'
Add a Gnu build-id to gitlab-pages binary
See merge request gitlab-org/gitlab-pages!669
-rw-r--r-- | Makefile.build.mk | 18 | ||||
-rw-r--r-- | Makefile.internal.mk | 2 |
2 files changed, 16 insertions, 4 deletions
diff --git a/Makefile.build.mk b/Makefile.build.mk index 2474ccbb..350a7b99 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -1,5 +1,12 @@ +BINDIR := $(CURDIR)/bin GO_BUILD_TAGS := continuous_profiler_stackdriver +# To compute a unique and deterministic value for GNU build-id, we build the Go binary a second time. +# From the first build, we extract its unique and deterministic Go build-id, and use that to derive +# a comparably unique and deterministic GNU build-id to inject into the final binary. +## Skip generation of the GNU build ID if set to speed up builds. +WITHOUT_BUILD_ID ?= + .PHONY: all setup generate-mocks build clean all: gitlab-pages @@ -21,10 +28,15 @@ generate-mocks: .GOPATH/.ok $Q bin/mockgen -source=internal/domain/resolver.go -destination=internal/mocks/resolver.go -package=mocks build: .GOPATH/.ok - $Q GOBIN=$(CURDIR)/bin go install $(if $V,-v) $(VERSION_FLAGS) -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) + $Q GOBIN=$(BINDIR) go install $(if $V,-v) -ldflags="$(VERSION_FLAGS)" -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) +ifndef WITHOUT_BUILD_ID + GO_BUILD_ID=$$( go tool buildid $(BINDIR)/gitlab-pages ) && \ + GNU_BUILD_ID=$$( echo $$GO_BUILD_ID | sha1sum | cut -d' ' -f1 ) && \ + $Q GOBIN=$(BINDIR) go install $(if $V,-v) -ldflags="$(VERSION_FLAGS) -B 0x$$GNU_BUILD_ID" -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) +endif clean: - $Q GOBIN=$(CURDIR)/bin go clean -i -modcache -x + $Q GOBIN=$(BINDIR) go clean -i -modcache -x gitlab-pages: build - $Q cp -f ./bin/gitlab-pages . + $Q cp -f $(BINDIR)/gitlab-pages . diff --git a/Makefile.internal.mk b/Makefile.internal.mk index e1454db8..d2340855 100644 --- a/Makefile.internal.mk +++ b/Makefile.internal.mk @@ -8,7 +8,7 @@ ifneq (v$(VERSION),$(LAST_TAG)) VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION)) endif -VERSION_FLAGS := -ldflags='-X "main.VERSION=$(VERSION)" -X "main.REVISION=$(REVISION)"' +VERSION_FLAGS :=-X "main.VERSION=$(VERSION)" -X "main.REVISION=$(REVISION)" _allpackages = $(shell (go list ./... | \ grep -v $(addprefix -e ,$(IGNORED_DIRS)))) |