// 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 ( ) // TODO(adonovan): move back into go/packages. func ( context.Context, gocommand.Invocation, *gocommand.Runner) (string, string, error) { .Verb = "list" .Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"} , , , := .RunRaw(, ) var , string if != nil { := .Error() if 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 "", "", } = strings.TrimSpace(.String()) = "gc" } else if != nil { return "", "", } else { // This should be unreachable, but be defensive // in case RunRaw's error results are inconsistent. return "", "", } } else { := strings.Fields(.String()) if len() < 2 { return "", "", fmt.Errorf("could not parse GOARCH and Go compiler in format \"<GOARCH> <compiler>\":\nstdout: <<%s>>\nstderr: <<%s>>", .String(), .String()) } = [0] = [1] } return , , nil }