From ba43f6c1364518a9c933c2ebcfb9edfc2dc308e7 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Tue, 21 Feb 2023 14:21:52 +0100 Subject: [PATCH] refactor(GoMod): Disable any GOPROXY This ensures that the `.info` files for all modules, which get created by the Go command line tools under '$GOPATH/pkg/mod', contain the VCS info. When using a Go proxy this is not guaranteed and depends on the actual proxy instance, see [1]. This comes at the price of increased execution time. As the user's environment may likely be configured to use a GOPROXY, which is the default, use an empty directory to not mix-up newly cached files with already existing ones which might have been created using a Go proxy and therefore may lack the VCS info. This prepares for using the Go tooling to determine the VCS info instead of using ORT's partial reimplementation of that. [1]: https://github.com/golang/go/issues/44742#issuecomment-1210986778 [2]: https://github.com/golang/go/issues/18387 Signed-off-by: Frank Viernau --- analyzer/src/main/kotlin/managers/GoMod.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/analyzer/src/main/kotlin/managers/GoMod.kt b/analyzer/src/main/kotlin/managers/GoMod.kt index 5a36eb12a473..eb4638bd9994 100644 --- a/analyzer/src/main/kotlin/managers/GoMod.kt +++ b/analyzer/src/main/kotlin/managers/GoMod.kt @@ -54,6 +54,7 @@ import org.ossreviewtoolkit.utils.common.Os import org.ossreviewtoolkit.utils.common.splitOnWhitespace import org.ossreviewtoolkit.utils.common.stashDirectories import org.ossreviewtoolkit.utils.common.withoutSuffix +import org.ossreviewtoolkit.utils.ort.createOrtTempDir /** * The [Go Modules](https://github.com/golang/go/wiki/Modules) package manager for Go. @@ -81,6 +82,15 @@ class GoMod( ) = GoMod(type, analysisRoot, analyzerConfig, repoConfig) } + private val goPath by lazy { createOrtTempDir() } + + private val environment by lazy { + mapOf( + "GOPROXY" to "direct", + "GOPATH" to goPath.absolutePath + ) + } + override fun command(workingDir: File?) = "go" override fun getVersionArguments() = "version" @@ -339,7 +349,8 @@ class GoMod( return firstProxy.ifBlank { DEFAULT_GO_PROXY } } - private fun runGo(vararg args: CharSequence, workingDir: File? = null) = run(args = args, workingDir = workingDir) + private fun runGo(vararg args: CharSequence, workingDir: File? = null) = + run(args = args, workingDir = workingDir, environment = environment) } /**