Support multiple outputs in genrules with depfile: true

am: 15e86d938b

Change-Id: If3c3ed7927ca8343077b9e053359a8f122cf7b86
This commit is contained in:
Colin Cross 2017-10-23 21:16:46 +00:00 committed by android-build-merger
commit d85ff2fa7a
2 changed files with 18 additions and 10 deletions

View File

@ -260,13 +260,13 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written,
// to be replaced later by ninja_strings.go
sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %q $out", sandboxPath, buildDir, rawCommand)
sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %q $allouts", sandboxPath, buildDir, rawCommand)
ruleParams := blueprint.RuleParams{
Command: sandboxCommand,
CommandDeps: []string{"$sboxCmd"},
}
var args []string
args := []string{"allouts"}
if g.properties.Depfile {
ruleParams.Deps = blueprint.DepsGCC
args = append(args, "depfile")
@ -281,16 +281,24 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask) {
desc := "generate"
if len(task.out) == 0 {
ctx.ModuleErrorf("must have at least one output file")
return
}
if len(task.out) == 1 {
desc += " " + task.out[0].Base()
}
params := android.ModuleBuildParams{
Rule: g.rule,
Description: "generate",
Outputs: task.out,
Inputs: task.in,
Implicits: g.deps,
Rule: g.rule,
Description: "generate",
Output: task.out[0],
ImplicitOutputs: task.out[1:],
Inputs: task.in,
Implicits: g.deps,
Args: map[string]string{
"allouts": strings.Join(task.out.Strings(), " "),
},
}
if g.properties.Depfile {
depfile := android.GenPathWithExt(ctx, "", task.out[0], task.out[0].Ext()+".d")

View File

@ -613,13 +613,13 @@ func TestGeneratedSources(t *testing.T) {
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
genrule := ctx.ModuleForTests("gen", "").Rule("generator")
if len(genrule.Outputs) != 1 || filepath.Base(genrule.Outputs[0].String()) != "gen.java" {
t.Fatalf(`gen output file %v is not [".../gen.java"]`, genrule.Outputs.Strings())
if filepath.Base(genrule.Output.String()) != "gen.java" {
t.Fatalf(`gen output file %v is not ".../gen.java"`, genrule.Output.String())
}
if len(javac.Inputs) != 3 ||
javac.Inputs[0].String() != "a.java" ||
javac.Inputs[1].String() != genrule.Outputs[0].String() ||
javac.Inputs[1].String() != genrule.Output.String() ||
javac.Inputs[2].String() != "b.java" {
t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs)
}