Skip to content

proposal: x/tools/packages: populate Module field for package loads using Gopackagesdriver  #62601

@rastenis

Description

@rastenis

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:

  1. Module.Version
  2. Module.Dir
  3. 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

No one assigned

    Labels

    ProposalToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    Status

    Incoming

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions