go/packages: use packagesdriver to fetch sizes for "go list"
Also fix packagesdriver to use "go list" if the gopackagesdriver program is not available, rather than returning nil with no error. Also fix some comments. Change-Id: I0457cfa4eab4294760af71c780c62c05ad841c85 Reviewed-on: https://go-review.googlesource.com/c/154757 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
88e3b261f2
commit
2240b23956
|
@ -1,3 +1,8 @@
|
|||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package packagesdriver fetches type sizes for go/packages and go/analysis.
|
||||
package packagesdriver
|
||||
|
||||
import (
|
||||
|
@ -25,18 +30,20 @@ func GetSizes(ctx context.Context, buildFlags, env []string, dir string, usesExp
|
|||
tool = val
|
||||
}
|
||||
}
|
||||
if tool != "" && tool == "off" {
|
||||
return GetSizesGolist(ctx, buildFlags, env, dir, usesExportData)
|
||||
}
|
||||
|
||||
if tool == "" {
|
||||
var err error
|
||||
tool, err = exec.LookPath("gopackagesdriver")
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
// We did not find the driver, so use "go list".
|
||||
tool = "off"
|
||||
}
|
||||
}
|
||||
|
||||
if tool == "off" {
|
||||
return GetSizesGolist(ctx, buildFlags, env, dir, usesExportData)
|
||||
}
|
||||
|
||||
req, err := json.Marshal(struct {
|
||||
Command string `json:"command"`
|
||||
Env []string `json:"env"`
|
||||
|
|
|
@ -26,7 +26,7 @@ type driverRequest struct {
|
|||
Overlay map[string][]byte `json:"overlay"`
|
||||
}
|
||||
|
||||
// findExternalTool returns the file path of a tool that supplies
|
||||
// findExternalDriver returns the file path of a tool that supplies
|
||||
// the build system package structure, or "" if not found."
|
||||
// If GOPACKAGESDRIVER is set in the environment findExternalTool returns its
|
||||
// value, otherwise it searches for a binary named gopackagesdriver on the PATH.
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/tools/go/internal/packagesdriver"
|
||||
"golang.org/x/tools/internal/gopathwalk"
|
||||
"golang.org/x/tools/internal/semver"
|
||||
)
|
||||
|
@ -390,15 +391,7 @@ func runNamedQueries(cfg *Config, driver driver, addPkg func(*Package), queries
|
|||
}
|
||||
|
||||
func getSizes(cfg *Config) (types.Sizes, error) {
|
||||
stdout, err := invokeGo(cfg, "env", "GOARCH")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
goarch := strings.TrimSpace(stdout.String())
|
||||
// Assume "gc" because SizesFor doesn't respond to other compilers.
|
||||
// TODO(matloob): add support for gccgo as needed.
|
||||
return types.SizesFor("gc", goarch), nil
|
||||
return packagesdriver.GetSizesGolist(cfg.Context, cfg.BuildFlags, cfg.Env, cfg.Dir, usesExportData(cfg))
|
||||
}
|
||||
|
||||
// roots selects the appropriate paths to walk based on the passed-in configuration,
|
||||
|
|
Loading…
Reference in New Issue