From 1adddd9d904dfe1a11d32e88df5a04ce6b5e228e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Fri, 19 Feb 2021 17:30:20 -0300 Subject: [PATCH] common/build-style: check if go_import_path matches go.mod. Without this check, calling `go install` with a wrong go_import_path might end up downloading the source code for said package (using git, for example), instead of building from the provided tarball. The first line of go.mod should be "module $go_import_path" for Go to not try and download source code instead of using what it has locally. Fixes #27690. --- common/build-style/go.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/build-style/go.sh b/common/build-style/go.sh index c9f476b95c7..fa45bd29b03 100644 --- a/common/build-style/go.sh +++ b/common/build-style/go.sh @@ -25,6 +25,11 @@ do_build() { go_package=${go_package:-$go_import_path} # Build using Go modules if there's a go.mod file if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then + # Check if go_import_path matches module + if [ "module $go_import_path" != "$(head -n1 go.mod)" ]; then + msg_error "\"\$go_import_path\" doesn't match the one defined in go.mod!\n" + fi + if [ -z "${go_mod_mode}" ] && [ -d vendor ]; then msg_normal "Using vendor dir for $pkgname Go dependencies.\n" go_mod_mode=vendor