Skip to content

Commit

Permalink
go/tools/gopackagesdriver: pass Compiler and Arch in DriverResponse (#…
Browse files Browse the repository at this point in the history
…3657)

go/tools/gopackagesdriver: pass Compiler and Arch in DriverResponse

go/packages is being changed to expect Compiler and Arch in its
DriverResponse (see golang.org/cl/516917) because we can't expect the
type of the types.Sizes returned by types.Sizes to be types.StdSizes.
(The default it uses when Compiler and Arch aren't set is the set of
types for gc,amd64, so there's no change in behavior if those fields
aren't set, but we should set them.)
  • Loading branch information
matloob committed Aug 14, 2023
1 parent f5ae196 commit 6e10f8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions go/tools/gopackagesdriver/json_packages_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main

import (
"fmt"
"go/types"
"runtime"
)

type JSONPackagesDriver struct {
Expand Down Expand Up @@ -52,7 +52,8 @@ func (b *JSONPackagesDriver) GetResponse(labels []string) *driverResponse {

return &driverResponse{
NotHandled: false,
Sizes: types.SizesFor("gc", "amd64").(*types.StdSizes),
Compiler: "gc",
Arch: runtime.GOARCH,
Roots: rootPkgs,
Packages: packages,
}
Expand Down
11 changes: 7 additions & 4 deletions go/tools/gopackagesdriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"
"encoding/json"
"fmt"
"go/types"
"os"
"runtime"
"strings"
)

Expand All @@ -31,8 +31,10 @@ type driverResponse struct {
// lists of multiple drivers, go/packages will fall back to the next driver.
NotHandled bool

// Sizes, if not nil, is the types.Sizes to use when type checking.
Sizes *types.StdSizes
// 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
Expand Down Expand Up @@ -63,7 +65,8 @@ var (
additionalKinds = strings.Fields(os.Getenv("GOPACKAGESDRIVER_BAZEL_KINDS"))
emptyResponse = &driverResponse{
NotHandled: true,
Sizes: types.SizesFor("gc", "amd64").(*types.StdSizes),
Compiler: "gc",
Arch: runtime.GOARCH,
Roots: []string{},
Packages: []*FlatPackage{},
}
Expand Down

0 comments on commit 6e10f8c

Please sign in to comment.