aboutsummaryrefslogtreecommitdiff
path: root/go/packages/packages.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2020-05-15 17:13:55 -0400
committerMichael Matloob <matloob@golang.org>2020-05-19 14:27:18 +0000
commit10921354bc51183e227c71db59a380315ddf871a (patch)
treefdf7502940b3cda9bb0fec8078894fc284a28bfd /go/packages/packages.go
parent0d0afa43d58a135bb43bdf085a31bfc166c92143 (diff)
downloadgolang-x-tools-10921354bc51183e227c71db59a380315ddf871a.tar.gz
go/packages: add a Module field to the Package struct
This change introduces Module and ModuleError struct types to the packages package with the same types as defined in the cmd/go documentation for module information output by go list (with the exception of the Module type's Versions and Update fields). go/packages will fill the module struct with the module information output by go list. Drivers that support modules can also provide module information by filling the Module fields in the packages in their driverResponses. Fixes golang/go#35921 Change-Id: Icbdf79869f09d26f6a01c3670146ace4f6ffa25e Reviewed-on: https://go-review.googlesource.com/c/tools/+/234219 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Diffstat (limited to 'go/packages/packages.go')
-rw-r--r--go/packages/packages.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/go/packages/packages.go b/go/packages/packages.go
index 68039d3a9..1e6f9a467 100644
--- a/go/packages/packages.go
+++ b/go/packages/packages.go
@@ -22,6 +22,7 @@ import (
"reflect"
"strings"
"sync"
+ "time"
"golang.org/x/tools/go/gcexportdata"
"golang.org/x/tools/internal/gocommand"
@@ -75,6 +76,9 @@ const (
// TypecheckCgo enables full support for type checking cgo. Requires Go 1.15+.
// Modifies CompiledGoFiles and Types, and has no effect on its own.
TypecheckCgo
+
+ // NeedModule adds Module.
+ NeedModule
)
const (
@@ -310,16 +314,32 @@ type Package struct {
forTest string
// module is the module information for the package if it exists.
- module *packagesinternal.Module
+ Module *Module
+}
+
+// Module provides module information for a package.
+type Module struct {
+ Path string // module path
+ Version string // module version
+ Replace *Module // replaced by this module
+ Time *time.Time // time version was created
+ Main bool // is this the main module?
+ Indirect bool // is this module only an indirect dependency of main module?
+ Dir string // directory holding files for this module, if any
+ GoMod string // path to go.mod file used when loading this module, if any
+ GoVersion string // go version used in module
+ Error *ModuleError // error loading module
+}
+
+// ModuleError holds errors loading a module.
+type ModuleError struct {
+ Err string // the error itself
}
func init() {
packagesinternal.GetForTest = func(p interface{}) string {
return p.(*Package).forTest
}
- packagesinternal.GetModule = func(p interface{}) *packagesinternal.Module {
- return p.(*Package).module
- }
packagesinternal.GetGoCmdRunner = func(config interface{}) *gocommand.Runner {
return config.(*Config).gocmdRunner
}
@@ -708,6 +728,9 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
if ld.requestedMode&NeedTypesSizes == 0 {
ld.pkgs[i].TypesSizes = nil
}
+ if ld.requestedMode&NeedModule == 0 {
+ ld.pkgs[i].Module = nil
+ }
}
return result, nil