// GetSizes returns the sizes used by the underlying driver with the given parameters.
GetSizes returns the sizes used by the underlying driver with the given parameters.
// GetSizes returns the sizes used by the underlying driver with the given parameters .
func GetSizes(ctx context.Context, buildFlags, env []string, dir string, usesExportData bool) (types.Sizes, error) {
	const toolPrefix = "GOPACKAGESDRIVER="
	tool := ""
	for _, env := range env {
		if val := strings.TrimPrefix(env, toolPrefix); val != env {
			tool = val
		}
	}
	if tool == "" {
		var err error
		tool, err = exec.LookPath("gopackagesdriver")
		if err != nil {
			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"`
		BuildFlags []string `json:"build_flags"`
	}{
		Command:    "sizes",
		Env:        env,
		BuildFlags: buildFlags,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to encode message to driver tool: %v", err)
	}
	buf := new(bytes.Buffer)
	cmd := exec.CommandContext(ctx, tool)
	cmd.Dir = dir
	cmd.Env = env
	cmd.Stdin = bytes.NewReader(req)
	cmd.Stdout = buf
	cmd.Stderr = new(bytes.Buffer)
	if err := cmd.Run(); err != nil {
		return nil, fmt.Errorf("%v: %v: %s", tool, err, cmd.Stderr)
	}
	var response struct {
		Sizes *types.StdSizes
	}
	if err := json.Unmarshal(buf.Bytes(), &response); err != nil {
		return nil, err
	}
	return response.Sizes, nil
}
func GetSizes ( ctx context . Context , buildFlags , env [ ] string , dir string , usesExportData bool ) ( types . Sizes , error ) { const toolPrefix = " " tool := " " for _ , env := range env { if val := strings . TrimPrefix ( env , toolPrefix ) ; val != env { tool = val } } if tool == " " { var err error tool , err = exec . LookPath ( " " ) if err != nil { tool = " " } } if tool == " " { return GetSizesGolist ( ctx , buildFlags , env , dir , usesExportData ) } req , err := json . Marshal ( struct { Command string `json:"command"` Env [ ] string `json:"env"` BuildFlags [ ] string `json:"build_flags"` } { Command : " " , Env : env , BuildFlags : buildFlags , } ) if err != nil { return nil , fmt . Errorf ( " " , err ) } buf := new ( bytes . Buffer ) cmd := exec . CommandContext ( ctx , tool ) cmd . Dir = dir cmd . Env = env cmd . Stdin = bytes . NewReader ( req ) cmd . Stdout = buf cmd . Stderr = new ( bytes . Buffer ) if err := cmd . Run ( ) ; err != nil { return nil , fmt . Errorf ( " " , tool , err , cmd . Stderr ) } var response struct { Sizes * types . StdSizes } if err := json . Unmarshal ( buf . Bytes ( ) , & response ) ; err != nil { return nil , err } return response . Sizes , nil }
GetSizes returns the sizes used by the underlying driver with the given parameters.
GetSizes returns the sizes used by the underlying driver with the given parameters .
// TODO(matloob): Clean this up. This code is mostly a copy of packages.findExternalDriver. // We did not find the driver, so use "go list". // Sizes, if not nil, is the types.Sizes to use when type checking.