// 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 ( ) var debug = false func ( context.Context, gocommand.Invocation, *gocommand.Runner) (types.Sizes, error) { .Verb = "list" .Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"} , , , := .RunRaw(, ) var , string if != nil { if := .Error(); strings.Contains(, "cannot find main module") || strings.Contains(, "go.mod file not found") { // User's running outside of a module. All bets are off. Get GOARCH and guess compiler is gc. // TODO(matloob): Is this a problem in practice? .Verb = "env" .Args = []string{"GOARCH"} , := .Run(, ) if != nil { return nil, } = strings.TrimSpace(.String()) = "gc" } else { return nil, } } else { := strings.Fields(.String()) if len() < 2 { return nil, fmt.Errorf("could not parse GOARCH and Go compiler in format \"<GOARCH> <compiler>\":\nstdout: <<%s>>\nstderr: <<%s>>", .String(), .String()) } = [0] = [1] } return types.SizesFor(, ), nil }