Allow soong_ui to set env vars for soong_build .

This is used to make GODEBUG=asyncpreemptoff=1 only be set in debug mode
so that production is not affected.

Test: Presubmits.
Change-Id: Idb15ad20bb74ba3f896699715e3208c1287a5e82
This commit is contained in:
Lukacs T. Berki 2022-01-05 10:26:53 +01:00
parent 1a1ec4b59c
commit a67610a75f
2 changed files with 11 additions and 19 deletions

View file

@ -124,27 +124,10 @@ var (
// better to not to touch that while Blueprint and Soong are separate // better to not to touch that while Blueprint and Soong are separate
// NOTE: The spaces at EOL are important because otherwise Ninja would // NOTE: The spaces at EOL are important because otherwise Ninja would
// omit all spaces between the different options. // omit all spaces between the different options.
// GODEBUG=asyncpreemptoff=1 disables the preemption of goroutines. This
// is useful because the preemption happens by sending SIGURG to the OS
// thread hosting the goroutine in question and each signal results in
// work that needs to be done by Delve; it uses ptrace to debug the Go
// process and the tracer process must deal with every signal (it is not
// possible to selectively ignore SIGURG). This makes debugging slower,
// sometimes by an order of magnitude depending on luck.
//
// According to measurements, this does not result in any performance loss
// (or gain), but if it becomes necessary for some reason, it should be
// possible to set asyncpreemptoff=1 only if debugging is enabled by
// plumbing that information through PrimaryBuilderInvocation just like
// --delve_path and --delve_listen.
//
// The original reason for adding async preemption to Go is here:
// https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md
Command: `cd "$$(dirname "$builder")" && ` + Command: `cd "$$(dirname "$builder")" && ` +
`BUILDER="$$PWD/$$(basename "$builder")" && ` + `BUILDER="$$PWD/$$(basename "$builder")" && ` +
`cd / && ` + `cd / && ` +
`env -i GODEBUG=asyncpreemptoff=1 "$$BUILDER" ` + `env -i $env "$$BUILDER" ` +
` --top "$$TOP" ` + ` --top "$$TOP" ` +
` --soong_out "$soongOutDir" ` + ` --soong_out "$soongOutDir" ` +
` --out "$outDir" ` + ` --out "$outDir" ` +
@ -155,7 +138,7 @@ var (
Depfile: "$out.d", Depfile: "$out.d",
Restat: true, Restat: true,
}, },
"builder", "extra", "pool") "builder", "env", "extra", "pool")
// Work around a Ninja issue. See https://github.com/martine/ninja/pull/634 // Work around a Ninja issue. See https://github.com/martine/ninja/pull/634
phony = pctx.StaticRule("phony", phony = pctx.StaticRule("phony",
@ -701,6 +684,13 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
pool = "console" pool = "console"
} }
envAssignments := ""
for k, v := range i.Env {
// NB: This is rife with quoting issues but we don't care because we trust
// soong_ui to not abuse this facility too much
envAssignments += k + "=" + v + " "
}
// Build the main build.ninja // Build the main build.ninja
ctx.Build(pctx, blueprint.BuildParams{ ctx.Build(pctx, blueprint.BuildParams{
Rule: generateBuildNinja, Rule: generateBuildNinja,
@ -708,6 +698,7 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
Inputs: i.Inputs, Inputs: i.Inputs,
Args: map[string]string{ Args: map[string]string{
"builder": primaryBuilderFile, "builder": primaryBuilderFile,
"env": envAssignments,
"extra": strings.Join(flags, " "), "extra": strings.Join(flags, " "),
"pool": pool, "pool": pool,
}, },

View file

@ -110,4 +110,5 @@ type PrimaryBuilderInvocation struct {
Args []string Args []string
Console bool Console bool
Description string Description string
Env map[string]string
} }