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 /Makefile.build.mk | |
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
Diffstat (limited to 'Makefile.build.mk')
-rw-r--r-- | Makefile.build.mk | 18 |
1 files changed, 15 insertions, 3 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 . |