Skip to content

Make Makefile more predictable by bootstrapping

Jacob Vosmaer requested to merge makefile-bootstrap into master

Dependencies in the current Makefile are confusing. Some variables at the top of the Makefile shell out to commands that fail unless some Make tasks have already run.

This MR adds an explicit bootstrap stage. We have a top-level Makefile that initiates the bootstrap and dispatches the commands. The inner _build/Makefile then runs in a known state where e.g. we are guaranteed to have a GOPATH.

Additionally, to replace Make magic with shelling out, we generate the inner Makefile with a Go template.

Example:

% make -w test
make: Entering directory `/Users/jacobvosmaer/Desktop/gitlab-development-kit/gitaly/src/gitlab.com/gitlab-org/gitaly'
mkdir -p _build/src/gitlab.com/gitlab-org
cd _build/src/gitlab.com/gitlab-org && rm -f gitaly && \
		ln -sf ../../../.. gitaly
touch _build/.ok
go build -o _build/makegen _support/makegen.go
cd _build && ./makegen > Makefile
cd _build && make test
make[1]: Entering directory `/Users/jacobvosmaer/Desktop/gitlab-development-kit/gitaly/src/gitlab.com/gitlab-org/gitaly/_build'
ok  	gitlab.com/gitlab-org/gitaly/auth	0.040s
ok  	gitlab.com/gitlab-org/gitaly/client	0.028s
# snip

What is nice about this is that if you are trying to debug how dynamic behavior in the build works (e.g. "make list of all go packages in the project") is that you can see the output in _build/Makefile. In the old situation, this list gets generated on the fly by Make and you need to add debug statements to see its contents. In the new situation the list is built by Go code, and you can see the resulting list by inspecting _build/Makefile.

Nothing should change for the users of the Makefile (devs, CI, build scripts). But this change will make it easier for us to maintain and improve the Makefile.

Edited by GitLab Release Tools Bot

Merge request reports