-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Description
packages.Load uses either the goListDriver or an external driver (Gopackagesdriver) to retrieve information about packages. However, the goListDriver response returns data that is missing in the Gopackagesdriver response.
Currently, the Module field is not parsed from the external driver response, implemented as an UnmarshalJSON override in packages.go:
*p = Package{
ID: flat.ID,
Name: flat.Name,
PkgPath: flat.PkgPath,
Errors: flat.Errors,
GoFiles: flat.GoFiles,
CompiledGoFiles: flat.CompiledGoFiles,
OtherFiles: flat.OtherFiles,
EmbedFiles: flat.EmbedFiles,
EmbedPatterns: flat.EmbedPatterns,
ExportFile: flat.ExportFile,
// Module is not parsed
}However, it is parsed from the goListDriver response, in golist.go:
pkg := &Package{
Name: p.Name,
ID: p.ImportPath,
GoFiles: absJoin(p.Dir, p.GoFiles, p.CgoFiles),
CompiledGoFiles: absJoin(p.Dir, p.CompiledGoFiles),
OtherFiles: absJoin(p.Dir, otherFiles(p)...),
EmbedFiles: absJoin(p.Dir, p.EmbedFiles),
EmbedPatterns: absJoin(p.Dir, p.EmbedPatterns),
IgnoredFiles: absJoin(p.Dir, p.IgnoredGoFiles, p.IgnoredOtherFiles),
forTest: p.ForTest,
depsErrors: p.DepsErrors,
Module: p.Module, // Module is parsed
}The proposal is to add the Module field to the UnmarshalJSON override in packages.go, so that packages.Load returns Module data when using either driver. This also involves adding the field to the flatPackage struct.
The fields required in the Module field for our usecase is as follows:
- Module.Version
- Module.Dir
- Module.Path
Let me know if this sounds good, or if there are any alternatives to consider or suggestions about this approach.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status