Skip to content

x/tools/go/packages: publish DriverRequest, DriverResponse #64608

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

Closed
adonovan opened this issue Dec 7, 2023 · 4 comments
Closed

x/tools/go/packages: publish DriverRequest, DriverResponse #64608

adonovan opened this issue Dec 7, 2023 · 4 comments
Assignees
Labels
FrozenDueToAge Proposal Proposal-Accepted Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Dec 7, 2023

Proposal Details

According to #34341 (comment), the lack of public documentation on GOPACKAGESDRIVER is merely an oversight, that I plan to fix in https://go.dev/cl/547977. Internal documentation was added in CL https://go.dev/cl/184943, but the Go types that define the JSON protocol are unexported, meaning users must copy them (e.g. here https://github.com/bazelbuild/rules_go/wiki/Editor-and-tool-integration)

I propose to export them by capitalizing their names and tidying their documentation:

// The Driver Protocol
//
// The driver, given the inputs to a call to Load, returns metadata about the packages specified.
// This allows for different build systems to support go/packages by telling go/packages how the
// packages' source is organized.
// The driver is an executable specified by the GOPACKAGESDRIVER environment variable.
// It's given the inputs to load in its argv. See the package
// documentation in doc.go for the full description of the patterns that need to be supported.
// A driver receives as a JSON-serialized driverRequest struct in standard input and will
// produce a JSON-serialized driverResponse (see definition in packages.go) in its standard output.

// DriverRequest is used to provide the portion of Load's Config that is needed by a driver.
type DriverRequest struct {
	Mode LoadMode `json:"mode"`
	// Env specifies the environment the underlying build system should be run in.
	Env []string `json:"env"`
	// BuildFlags are flags that should be passed to the underlying build system.
	BuildFlags []string `json:"build_flags"`
	// Tests specifies whether the patterns should also return test packages.
	Tests bool `json:"tests"`
	// Overlay maps file paths (relative to the driver's working directory) to the byte contents
	// of overlay files.
	Overlay map[string][]byte `json:"overlay"`
}

// DriverResponse contains the results for a driver query.
type DriverResponse struct {
	// NotHandled is returned if the request can't be handled by the current
	// driver. If an external driver returns a response with NotHandled, the
	// rest of the driverResponse is ignored, and go/packages will fallback
	// to the next driver. If go/packages is extended in the future to support
	// lists of multiple drivers, go/packages will fall back to the next driver.
	NotHandled bool

	// Compiler and Arch are the arguments pass of types.SizesFor
	// to get a types.Sizes to use when type checking.
	Compiler string
	Arch     string

	// Roots is the set of package IDs that make up the root packages.
	// We have to encode this separately because when we encode a single package
	// we cannot know if it is one of the roots as that requires knowledge of the
	// graph it is part of.
	Roots []string `json:",omitempty"`

	// Packages is the full set of packages in the graph.
	// The packages are not connected into a graph.
	// The Imports if populated will be stubs that only have their ID set.
	// Imports will be connected and then type and syntax information added in a
	// later pass (see refine).
	Packages []*Package

	// GoVersion is the minor version number used by the driver
	// (e.g. the go command on the PATH) when selecting .go files.
	// Zero means unknown.
	GoVersion int
}

Note: the current internal documentation and behavior support both os.Getenv("GOPACKAGESDRIVER") and os.LookPath("gopackagesdriver") as ways of locating the driver. I'm not convinced that the latter mechanism is desirable (though it may be in current use within Google for Blaze; I should check) and I propose that we drop it.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 7, 2023
@gopherbot gopherbot added this to the Unreleased milestone Dec 7, 2023
@adonovan adonovan moved this to Incoming in Proposals Dec 7, 2023
@adonovan adonovan changed the title x/tools/go/packages: publish Driver{Request,Response} proposal: x/tools/go/packages: publish Driver{Request,Response} Dec 7, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/547977 mentions this issue: go/packages: improve docs of 'go list' and GOPACKAGESDRIVER

gopherbot pushed a commit to golang/tools that referenced this issue Dec 8, 2023
Fixes golang/go#34341
Updates golang/go#64608

Change-Id: I3b41660c12942fdb15b8ea6f1f3c0b77ae91b897
Reviewed-on: https://go-review.googlesource.com/c/tools/+/547977
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
@rsc rsc changed the title proposal: x/tools/go/packages: publish Driver{Request,Response} proposal: x/tools/go/packages: publish DriverRequest, DriverResponse Jan 10, 2024
@rsc
Copy link
Contributor

rsc commented Jan 10, 2024

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

Details: Export the DriverRequest and DriverResponse structs that already exist (unexported) in the package and are the definition of the wire format.

@rsc rsc moved this from Incoming to Likely Accept in Proposals Jan 10, 2024
@rsc
Copy link
Contributor

rsc commented Jan 19, 2024

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

Details: Export the DriverRequest and DriverResponse structs that already exist (unexported) in the package and are the definition of the wire format.

@rsc rsc moved this from Likely Accept to Accepted in Proposals Jan 19, 2024
@rsc rsc changed the title proposal: x/tools/go/packages: publish DriverRequest, DriverResponse x/tools/go/packages: publish DriverRequest, DriverResponse Jan 19, 2024
@adonovan adonovan self-assigned this Jan 19, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/557056 mentions this issue: go/packages: publish Driver{Request,Response}

@golang golang locked and limited conversation to collaborators Jan 21, 2025
@aclements aclements removed this from Proposals Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal Proposal-Accepted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants