diff options
author | Colin Cross <ccross@android.com> | 2018-02-21 14:07:48 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-02-21 14:55:34 -0800 |
commit | baccf5b984dad86af5fab06bc43a32f663fc4722 (patch) | |
tree | cd24ac70d218b1b8e2991320f98185761a57be49 /genrule | |
parent | 52226ad920fc848927070561a96a931157764d5b (diff) | |
download | build_soong-baccf5b984dad86af5fab06bc43a32f663fc4722.tar.gz build_soong-baccf5b984dad86af5fab06bc43a32f663fc4722.tar.bz2 build_soong-baccf5b984dad86af5fab06bc43a32f663fc4722.zip |
Use __SBOX_OUT_DIR__ in sbox output file list
The path to the output directory may be arbitrarily long, use
__SBOX_OUT_DIR__ in the list of output files passed to sbox
to avoid expanding it multiple times in the command line.
Fixes:
ninja: fatal: posix_spawn: Argument list too long
09:40:14 ninja failed with: exit status 1
when building libchrome with a long OUT or OUT_DIR_COMMON_BASE.
Bug: 73726635
Test: m checkbuild
Change-Id: I59024b2164287c8e531711afd9273b692ce9c28a
Diffstat (limited to 'genrule')
-rw-r--r-- | genrule/genrule.go | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go index 4f3ba93b..e423ebcc 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -112,9 +112,10 @@ type Module struct { type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask type generateTask struct { - in android.Paths - out android.WritablePaths - cmd string + in android.Paths + out android.WritablePaths + sandboxOuts []string + cmd string } func (g *Module) GeneratedSourceFiles() android.Paths { @@ -320,7 +321,7 @@ func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask Inputs: task.in, Implicits: g.deps, Args: map[string]string{ - "allouts": strings.Join(task.out.Strings(), " "), + "allouts": strings.Join(task.sandboxOuts, " "), }, } if Bool(g.properties.Depfile) { @@ -346,23 +347,31 @@ func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module { return module } +// replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>" +func pathToSandboxOut(path android.Path, genDir android.Path) string { + relOut, err := filepath.Rel(genDir.String(), path.String()) + if err != nil { + panic(fmt.Sprintf("Could not make ${out} relative: %v", err)) + } + return filepath.Join("__SBOX_OUT_DIR__", relOut) + +} + func NewGenSrcs() *Module { properties := &genSrcsProperties{} taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask { commands := []string{} outFiles := android.WritablePaths{} - genPath := android.PathForModuleGen(ctx).String() + genDir := android.PathForModuleGen(ctx) + sandboxOuts := []string{} for _, in := range srcFiles { outFile := android.GenPathWithExt(ctx, "", in, String(properties.Output_extension)) outFiles = append(outFiles, outFile) - // replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>" - relOut, err := filepath.Rel(genPath, outFile.String()) - if err != nil { - panic(fmt.Sprintf("Could not make ${out} relative: %v", err)) - } - sandboxOutfile := filepath.Join("__SBOX_OUT_DIR__", relOut) + sandboxOutfile := pathToSandboxOut(outFile, genDir) + sandboxOuts = append(sandboxOuts, sandboxOutfile) + command, err := android.Expand(rawCommand, func(name string) (string, error) { switch name { case "in": @@ -384,9 +393,10 @@ func NewGenSrcs() *Module { fullCommand := strings.Join(commands, " && ") return generateTask{ - in: srcFiles, - out: outFiles, - cmd: fullCommand, + in: srcFiles, + out: outFiles, + sandboxOuts: sandboxOuts, + cmd: fullCommand, } } @@ -409,13 +419,17 @@ func NewGenRule() *Module { taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask { outs := make(android.WritablePaths, len(properties.Out)) + sandboxOuts := make([]string, len(properties.Out)) + genDir := android.PathForModuleGen(ctx) for i, out := range properties.Out { outs[i] = android.PathForModuleGen(ctx, out) + sandboxOuts[i] = pathToSandboxOut(outs[i], genDir) } return generateTask{ - in: srcFiles, - out: outs, - cmd: rawCommand, + in: srcFiles, + out: outs, + sandboxOuts: sandboxOuts, + cmd: rawCommand, } } |