mirror of
https://github.com/golang/go
synced 2024-11-26 04:58:00 -07:00
cmd/go: populate module info even if an error occurs in loading package
The existing implementation ignores module info if there is any error loading the package.
Fixes #44287
Change-Id: I24142e4c7256517292fc654e29d759871b80bc09
GitHub-Last-Rev: 28e9bf85e8
GitHub-Pull-Request: golang/go#45777
Reviewed-on: https://go-review.googlesource.com/c/go/+/313549
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
11052d77a3
commit
5c69cb2a5b
@ -1846,6 +1846,14 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
|
||||
stk.Push(path)
|
||||
defer stk.Pop()
|
||||
|
||||
pkgPath := p.ImportPath
|
||||
if p.Internal.CmdlineFiles {
|
||||
pkgPath = "command-line-arguments"
|
||||
}
|
||||
if cfg.ModulesEnabled {
|
||||
p.Module = modload.PackageModuleInfo(ctx, pkgPath)
|
||||
}
|
||||
|
||||
p.EmbedFiles, p.Internal.Embed, err = resolveEmbed(p.Dir, p.EmbedPatterns)
|
||||
if err != nil {
|
||||
p.Incomplete = true
|
||||
@ -1905,6 +1913,10 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
|
||||
p.Internal.Imports = imports
|
||||
p.collectDeps()
|
||||
|
||||
if cfg.ModulesEnabled && p.Error == nil && p.Name == "main" && len(p.DepsErrors) == 0 {
|
||||
p.Internal.BuildInfo = modload.PackageBuildInfo(pkgPath, p.Deps)
|
||||
}
|
||||
|
||||
// unsafe is a fake package.
|
||||
if p.Standard && (p.ImportPath == "unsafe" || cfg.BuildContext.Compiler == "gccgo") {
|
||||
p.Target = ""
|
||||
@ -1944,17 +1956,6 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
|
||||
setError(fmt.Errorf("Fortran source files not allowed when not using cgo or SWIG: %s", strings.Join(p.FFiles, " ")))
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.ModulesEnabled && p.Error == nil {
|
||||
mainPath := p.ImportPath
|
||||
if p.Internal.CmdlineFiles {
|
||||
mainPath = "command-line-arguments"
|
||||
}
|
||||
p.Module = modload.PackageModuleInfo(ctx, mainPath)
|
||||
if p.Name == "main" && len(p.DepsErrors) == 0 {
|
||||
p.Internal.BuildInfo = modload.PackageBuildInfo(mainPath, p.Deps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An EmbedError indicates a problem with a go:embed directive.
|
||||
|
19
src/cmd/go/testdata/script/list_module_when_error.txt
vendored
Normal file
19
src/cmd/go/testdata/script/list_module_when_error.txt
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# The Module field should be populated even if there is an error loading the package.
|
||||
|
||||
env GO111MODULE=on
|
||||
|
||||
go list -e -f {{.Module}}
|
||||
stdout '^mod.com$'
|
||||
|
||||
-- go.mod --
|
||||
module mod.com
|
||||
|
||||
go 1.16
|
||||
|
||||
-- blah.go --
|
||||
package blah
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed README.md
|
||||
var readme string
|
Loading…
Reference in New Issue
Block a user