Closed nickbruun closed 1 month ago
Sorry for the trouble and thanks for the reproducer and test case!
Is this something you're interested in trying to fix?
I'll likely give it a swing some evening when I have a minute, but if someone has any quick pointers as to why duplicate libraries are being built, I'm all ears!
Great. Maybe @tdyas or @tgolsson might have a hint or two? (I'm not personally familiar with the Go backend or Go in general.)
What version of Go are you using?
@tdyas I reproduced this in 1.21, 1.22 and now 1.23.
Given the test is an external test (xtest), I wonder if Pants is generating the package archives for the package under test and the external test package at the same location with each digest.
I added some debugging to https://github.com/pantsbuild/pants/blob/1d1e93edcdf617c651c3eb1d1cbadd29d99172b2/src/python/pants/backend/go/util_rules/build_pkg.py#L518 and found that the foo
package is showing up multiple times in the dependencies. The difference is that one version is built with coverage and the other version is built without coverage.
This change fixes this bug (although I still need to test if it has consequences for other parts of the Go backend):
diff --git a/src/python/pants/backend/go/util_rules/build_pkg_target.py b/src/python/pants/backend/go/util_rules/build_pkg_target.py
index fccc4290b7..6f7aa29cae 100644
--- a/src/python/pants/backend/go/util_rules/build_pkg_target.py
+++ b/src/python/pants/backend/go/util_rules/build_pkg_target.py
@@ -458,7 +458,7 @@ async def setup_build_go_package_target_request(
maybe_base_pkg_dep = await Get(
FallibleBuildGoPackageRequest,
BuildGoPackageTargetRequest(
- request.address, for_tests=True, build_opts=request.build_opts
+ request.address, for_tests=True, with_coverage=request.with_coverage, build_opts=request.build_opts
),
)
if maybe_base_pkg_dep.request is None:
https://github.com/pantsbuild/pants/pull/21452 has the fix. I will also back-port the fix back to v2.2[1-3].x.
@tdyas I lost track of this one for a second. Thanks a million for debugging and fixing this :)
Describe the bug When
use_coverage
is enabled, Go packages that have<package>_test
packaged test files (ie. for the packagefoo
, the tests are in the same folder but are in thefoo_test
package and importfoo
, see reproduction repository for an example) causes anIntrinsicError
of the following shape when thetest
goal is run:A simple reproduction case can be found at nickbruun/pants-use-coverage-repro. The repository has two commits:
use_coverage
enabled. Failure can be seen in GitHub Actions loguse_coverage
disabled. The successful test run can be seen in GitHub Actions log.Pants version 2.21.1, but confirmed at least as far back as 2.17 (I just hadn't gotten around to reporting it until now -- sorry!)
OS Reproduced on Linux and MacOS.
Additional info See https://github.com/nickbruun/pants-use-coverage-repro/pull/1 for evidence that if the test has the non-
_test
package, the test goal succeeds.The following addition to
src/python/pants/backend/go/goals/test_test.py
will reproduce the issue in tests: