https://pantsbuild.org/ logo
#development
Title
# development
f

fast-nail-55400

10/25/2021, 3:37 PM
@hundreds-father-404: thread for discussing the dependency issue with Go plugin and replace directives in transitive dependencies.
and for others: building helm results in this error:
Copy code
go: <http://github.com/hashicorp/consul/sdk@v0.3.0|github.com/hashicorp/consul/sdk@v0.3.0> (replaced by ../sdk): reading ../sdk/go.mod: open /private/var/folders/md/0q71p41n0rbgwhnc8npjjzg00000gn/T/sdk/go.mod: no such file or directory
the issue is probably the fact that the replace directive in the transitive dependency is being applied.
and it shouldn’t be applied only the replace directives in the main module should have effect.
https://golang.org/ref/mod#go-mod-file-replace:
replace
directives only apply in the main module’s
go.mod
file and are ignored in other modules. See Minimal version selection for details.
this probably occurs because the Go plugin currently extracts the third-party module metadata by constructing an input root with the third-party module treated as if it were first party by
go
since the command references the packages using
./…
. https://github.com/pantsbuild/pants/blob/a57985b22160ab717adcadf0ab07995f870e2c34/src/python/pants/backend/go/util_rules/third_party_pkg.py#L2[…]281
👍 1
thus
go list
thinks it should apply replace directives in in that instance
we should probably have the command be `go list -m -json FULL_IMPORT_PATH_TO_MODULE/…`and keep the source code in the input root in the original GOPATH location
💯 1
👀 1
h

hundreds-father-404

10/25/2021, 4:18 PM
Good idea! Will try when I get online in a few. Thanks!
Bummer, didn't work. Added a failing test at https://github.com/pantsbuild/pants/pull/13349
Hm @fast-nail-55400, I was only able to get
go list -json
working by having the chroot include
<http://github.com/hashicorp/consul/sdk@v0.3.0|github.com/hashicorp/consul/sdk@v0.3.0>
and renaming the folder to
sdk
w/o the version... That was really important for performance that running
go list
on a downloaded module uses a chroot with only that module, not sibling modules
f

fast-nail-55400

10/25/2021, 6:46 PM
any errors?
h

hundreds-father-404

10/25/2021, 6:47 PM
One idea I have is to still default to only including the requested module. But analyze the
go.mod
for replace directives and pull in the module in that case? Seems finicky
Yeah, so, we'd do something like
go mod edit -json
to find this:
Copy code
"Replace": [
		{
			"Old": {
				"Path": "<http://github.com/hashicorp/consul/sdk|github.com/hashicorp/consul/sdk>"
			},
			"New": {
				"Path": "../sdk"
			}
		}
	],
We know the import path is
<http://github.com/hashicorp/consul/api|github.com/hashicorp/consul/api>
, so we calculate it's trying to load
<http://github.com/hashicorp/consul/sdk|github.com/hashicorp/consul/sdk>
when you apply the
../sdk
. We see if there is that downloaded module. If so, the
Digest
for
consul/api
has to also include
consul/sdk
Huzzah! @fast-nail-55400 your approach works. See the experiment I put up at https://github.com/pantsbuild/pants/pull/13349/files
f

fast-nail-55400

10/25/2021, 8:29 PM
(context for other readers of this thread: Eric and I chatted on VC outside of this thread and came up with an approach using a different way of subsetting the Digest with the gopath)
and nice!
h

hundreds-father-404

10/25/2021, 8:34 PM
Hm wait still trying to confirm this...not confident in my result and if caching is messing with this
w

witty-crayon-22786

10/27/2021, 6:49 PM
is it looking like these changes will land today?
no pressure, just curious re: 2.8.0rc1
h

hundreds-father-404

10/27/2021, 6:55 PM
Yes, needs approval tho
It's ready to merge fwict
w

witty-crayon-22786

10/27/2021, 6:56 PM
ok, thanks. i was abstaining since it seemed like you and @fast-nail-55400 were figuring it out