Skip to content

Commit

Permalink
refactor(GoMod): Disable any GOPROXY
Browse files Browse the repository at this point in the history
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]: golang/go#44742 (comment)
[2]: golang/go#18387

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Feb 22, 2023
1 parent 9294ca1 commit ba43f6c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion analyzer/src/main/kotlin/managers/GoMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit ba43f6c

Please sign in to comment.