Skip to content

proposal: cmd/go: add GOCMD environment variable #28043

Closed
@jimmyfrasche

Description

@jimmyfrasche

Tools for interacting with go code need to exec the go command. Sometimes there are multiple versions of the go command available, rarely themselves named "go": go, vgo, go1.1xbetax, go1.1x, etc.

Tools that exec "go" cannot use these without $PATH manipulation and shell scripts named "go" that forward to the desired go command. Possible, but awkward.

This should be the convention:

goBin := os.Getenv("GOCMD")
if goBin == "" {
  goBin = "go"
}
// exec goBin

If this environment variable were not known to the go command itself, this would be required: GOCMD=go1.12beta1 go1.12beta1 generate But the go command can always set GOCMD to itself.

By showing up in $GOCMD env and $GOCMD help environment, the convention is official, encouraging all tools that need to exec go to follow the convention.

If it is official, go/packages can use it making the majority of tooling just work (once ported over to using go/packages, at least) since it greatly reduces the need to manually exec the go command.

Previous discussion in #26845

cc: @rsc @bcmills @alandonovan @ianthehat @marwan-at-work

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions