-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(host/go): Download external plugins even if they're not imported #13455
Conversation
Changelog[uncommitted] (2023-07-11)Bug Fixes
|
84f1930
to
201efec
Compare
Repro: https://github.com/pulumi/pulumi/actions/runs/5525559114/jobs/10079407337?pr=13455
|
6160ec5
to
0d9aee0
Compare
Adds a regression of the bug using code provided by @phillipedwards. The reproduction is a bit complicated because of the very specific scenario we need to replicate here. Additionally, we need an untidy go.mod file for this, so we need to teach scripts/tidy.sh how to ignore files.
We previously changed how the Go language host retrieves information about a Go module: before: go list -m -json -mod=mod all after: go list -m -json $importPath1 $importPath1 This change made it possible for us to supprot running in vendored mode which allowed for use of private plugins that are not go-get-able. This uncovered a corner case in the `go` command's behavior when running in module mode: If a package is listed in the go.mod but it's not imported by the current module, `go list -m -json $importPath` will not list its Dir in the output even if it's present in the module cache. For example, given a go.mod file that declares a dependency but code that doesn't import it, as of Go 1.20.5, export GOMODCACHE=$(mktemp -d) go mod download -json go list -m -json $importPath The output of `go mod download` will include information about the dependency and the `Dir` where it was downloaded, but `go list -m` will not. Unfortunately, we can't just use `go mod download` because that breaks vendoring: vendored dependencies cannot always be redownloaded. To resolve this issue, we switch to a two-pass variant to gather this information: - Run `go list -m` to get whatever information we can locally. This will be sufficient for the majority of use cases. - For the handful of cases where the dependency isn't imported, we'll use `go mod download -json` to download them on-demand and get their location from that instead. The `go mod download` step will take place only if we're in module mode. In vendor mode, we'll work with what we have. Resolves #13301
0d9aee0
to
a244de9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
We previously changed how the Go language host retrieves information
about a Go module:
This change made it possible for us to supprot running in vendored mode
which allowed for use of private plugins that are not go-get-able.
This uncovered a corner case in the
go
command's behaviorwhen running in module mode:
If a package is listed in the go.mod
but it's not imported by the current module,
go list -m -json $importPath
will not list its Dir in the outputeven if it's present in the module cache.
For example, given a go.mod file that declares a dependency
but code that doesn't import it, as of Go 1.20.5,
The output of
go mod download
will include informationabout the dependency and the
Dir
where it was downloaded,but
go list -m
will not.Unfortunately, we can't just use
go mod download
because that breaks vendoring:
vendored dependencies cannot always be redownloaded.
To resolve this issue,
we switch to a two-pass variant to gather this information:
go list -m
to get whatever information we can locally.This will be sufficient for the majority of use cases.
we'll use
go mod download -json
to download them on-demandand get their location from that instead.
The
go mod download
step will take place only if we're in module mode.In vendor mode, we'll work with what we have.
Resolves #13301