Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: prepend $GOROOT/bin to PATH for tests (Cherry pick of #16993) #16997

Merged
merged 1 commit into from Sep 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/python/pants/backend/go/goals/test.py
Expand Up @@ -33,6 +33,7 @@
FirstPartyPkgAnalysisRequest,
FirstPartyPkgDigestRequest,
)
from pants.backend.go.util_rules.goroot import GoRoot
from pants.backend.go.util_rules.import_analysis import ImportConfig, ImportConfigRequest
from pants.backend.go.util_rules.link import LinkedGoBinary, LinkGoBinaryRequest
from pants.backend.go.util_rules.tests_analysis import GeneratedTestMain, GenerateTestMainRequest
Expand Down Expand Up @@ -164,6 +165,7 @@ async def run_go_tests(
test_subsystem: TestSubsystem,
go_test_subsystem: GoTestSubsystem,
test_extra_env: TestExtraEnv,
goroot: GoRoot,
) -> TestResult:
maybe_pkg_analysis, maybe_pkg_digest, dependencies = await MultiGet(
Get(FallibleFirstPartyPkgAnalysis, FirstPartyPkgAnalysisRequest(field_set.address)),
Expand Down Expand Up @@ -370,6 +372,14 @@ def compilation_failure(exit_code: int, stdout: str | None, stderr: str | None)
**field_set_extra_env,
}

# Add $GOROOT/bin to the PATH just as `go test` does.
# See https://github.com/golang/go/blob/master/src/cmd/go/internal/test/test.go#L1384
goroot_bin_path = os.path.join(goroot.path, "bin")
if "PATH" in extra_env:
extra_env["PATH"] = f"{goroot_bin_path}:{extra_env['PATH']}"
else:
extra_env["PATH"] = goroot_bin_path

cache_scope = (
ProcessCacheScope.PER_SESSION if test_subsystem.force else ProcessCacheScope.SUCCESSFUL
)
Expand Down