diff options
author | Toon Claes <toon@gitlab.com> | 2022-03-25 16:29:22 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-03-25 19:06:06 +0300 |
commit | 77ba618cdd27e9ad3874039271fda8f2176a3be0 (patch) | |
tree | dcc1e94509045e7ffc6098ba900dbf3060e7626f | |
parent | c63b16f7b9a41d37e3e68ee69c798feb099282bc (diff) |
Makefile: Simplify build targettc-makefile-improve
When building Gitaly binaries there are two ways to do this, with or
without build-id. How this was implemented was hard to understand.
This change streamlines how Gitaly binaries are built when not using
build-ids. This makes compilation a lot faster when there are no changes
made.
-rw-r--r-- | Makefile | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -256,6 +256,7 @@ BENCHMARK_REPO := ${TEST_REPO_DIR}/benchmark.git # Find all Gitaly commands. gitaly_commands := $(notdir $(shell find ${SOURCE_DIR}/cmd -mindepth 1 -maxdepth 1 -type d -print)) +gitaly_binaries := $(addprefix ${BUILD_DIR}/bin/, $(gitaly_commands)) # Find all binaries, including Gitaly's and Git's find_command_binaries = $(wildcard ${BUILD_DIR}/bin/*) # Find all Go source files. @@ -314,27 +315,27 @@ help: .PHONY: build ## Build Go binaries and install required Ruby Gems. -build: ${SOURCE_DIR}/.ruby-bundle libgit2 +build: ${SOURCE_DIR}/.ruby-bundle libgit2 $(gitaly_binaries) +$(gitaly_binaries): $(find_go_sources) ifdef WITHOUT_BUILD_ID + @ # Build all commands at once, which is a lot faster than one-by-one go install -ldflags '${GO_LDFLAGS}' -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, $(gitaly_commands)) -endif - -ifndef WITHOUT_BUILD_ID -build: $(gitaly_commands) - -.PHONY: $(gitaly_commands) -$(gitaly_commands): - ${Q}go install -ldflags '${GO_LDFLAGS}' -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, $@) +else + @ # Because each command will get a unique build-id, build each command separately + ${Q}go install -ldflags '${GO_LDFLAGS}' -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, ${@F}) @ # 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 @ # comparably unique and deterministic GNU build-id to inject into the final binary. @ # If we cannot extract a Go build-id, we punt and fallback to using a random 32-byte hex string. @ # This fallback is unique but non-deterministic, making it sufficient to avoid generating the @ # GNU build-id from the empty string and causing guaranteed collisions. - GO_BUILD_ID=$$( go tool buildid $(addprefix ${BUILD_DIR}/bin/, $@) || openssl rand -hex 32 ) && \ + GO_BUILD_ID=$$( go tool buildid $@ || openssl rand -hex 32 ) && \ GNU_BUILD_ID=$$( echo $$GO_BUILD_ID | sha1sum | cut -d' ' -f1 ) && \ - go install -ldflags '${GO_LDFLAGS}'" -B 0x$$GNU_BUILD_ID" -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, $@) + go install -ldflags '${GO_LDFLAGS}'" -B 0x$$GNU_BUILD_ID" -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, ${@F}) + +# Ensure binaries get a new build-id on every run of `make build` +.PHONY: $(gitaly_binaries) endif .PHONY: install |