Skip to content

Change dir to SOURCE_DIR prior to go build

John McDonnell requested to merge jmd-fix-make-go-build-from-symlink into master

As Unable to build gitaly in /tmp on macOS (#4645 - closed) identifies, in some corner cases, we may attempt to run a make from a directory which is a symlink.
This causes issues for go build, as when it attempts to run a go build for a full path, the path/build_path are different which appears to cause issues for go modules.

Using the reproduction steps as listed in #4645 (comment 1183865947) it seems that in the Makefile we're in the directory /Users/john/tmp/test-symlink/gitaly whereas the build is attempting to build /Users/john/tmp/test/gitaly/cmd/gitaly-blackbox which causes the error.

As https://go.dev/ref/mod#commands-outside outlines Module-aware Go commands normally run in the context of a main module defined by a go.mod file in the working directory or a parent directory. so perhaps the easiest fix here is to just cd into the SOURCE_DIR as defined at Makefile#L27, prior to running go build, which should have already handled the symlink which avoids this situation from occurring.

Edited by John McDonnell

Merge request reports