diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index 7bd27c92a3d..6d9497c3a93 100644 --- a/src/cmd/compile/internal/base/flag.go +++ b/src/cmd/compile/internal/base/flag.go @@ -98,6 +98,7 @@ type CmdFlags struct { DwarfLocationLists *bool "help:\"add location lists to DWARF in optimized mode\"" // &Ctxt.Flag_locationlists, set below Dynlink *bool "help:\"support references to Go symbols defined in other shared libraries\"" // &Ctxt.Flag_dynlink, set below EmbedCfg func(string) "help:\"read go:embed configuration from `file`\"" + Env func(string) "help:\"add `definition` of the form key=value to environment\"" GenDwarfInl int "help:\"generate DWARF inline info records\"" // 0=disabled, 1=funcs, 2=funcs+formals/locals GoVersion string "help:\"required version of the runtime\"" ImportCfg func(string) "help:\"read import configuration from `file`\"" @@ -143,6 +144,14 @@ type CmdFlags struct { } } +func addEnv(s string) { + i := strings.Index(s, "=") + if i < 0 { + log.Fatal("-env argument must be of the form key=value") + } + os.Setenv(s[:i], s[i+1:]) +} + // ParseFlags parses the command-line flags into Flag. func ParseFlags() { Flag.I = addImportDir @@ -158,6 +167,7 @@ func ParseFlags() { *Flag.DwarfLocationLists = true Flag.Dynlink = &Ctxt.Flag_dynlink Flag.EmbedCfg = readEmbedCfg + Flag.Env = addEnv Flag.GenDwarfInl = 2 Flag.ImportCfg = readImportCfg Flag.CoverageCfg = readCoverageCfg