summaryrefslogtreecommitdiff
path: root/cc
diff options
context:
space:
mode:
author Dan Willemsen <dwillemsen@google.com> 2019-06-04 17:10:41 -0700
committer Dan Willemsen <dwillemsen@google.com> 2019-06-06 08:23:53 -0700
commit1945a4b47d2e446133b6eecfa464637d9bc4ddcd (patch)
treeacdf29b26b202c4f89cb59ea542c2c72d7f14d36 /cc
parentc4253b0ac98916ae851855adabd41c3aa17baa41 (diff)
Convert cc aidl to rule builder
This fixes an incremental build issue where we didn't clean up old aidl header files (or necessarily notice that they were updated). We do this by declaring the header files as outputs in the build graph, but this means that the src file name needs to be convertible to the aidl package name, as that's how the header file paths are created. In many cases, filegroups can be used to strip path prefixes from the aidl files. Bug: 112114177 Test: treehugger Change-Id: If534ff3dbfac329dea9a7402e30be74495754160
Diffstat (limited to 'cc')
-rw-r--r--cc/gen.go65
-rw-r--r--cc/gen_test.go5
2 files changed, 45 insertions, 25 deletions
diff --git a/cc/gen.go b/cc/gen.go
index ae761d036..82669acc7 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -16,6 +16,7 @@ package cc
import (
"path/filepath"
+ "strings"
"github.com/google/blueprint"
@@ -36,15 +37,6 @@ var (
CommandDeps: []string{"$lexCmd"},
})
- aidl = pctx.AndroidStaticRule("aidl",
- blueprint.RuleParams{
- Command: "$aidlCmd -d${out}.d --ninja $aidlFlags $in $outDir $out",
- CommandDeps: []string{"$aidlCmd"},
- Depfile: "${out}.d",
- Deps: blueprint.DepsGCC,
- },
- "aidlFlags", "outDir")
-
sysprop = pctx.AndroidStaticRule("sysprop",
blueprint.RuleParams{
Command: "$syspropCmd --header-dir=$headerOutDir --system-header-dir=$systemOutDir " +
@@ -114,20 +106,37 @@ func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile andr
return ret
}
-func genAidl(ctx android.ModuleContext, aidlFile android.Path, outFile android.ModuleGenPath, aidlFlags string) android.Paths {
- ctx.Build(pctx, android.BuildParams{
- Rule: aidl,
- Description: "aidl " + aidlFile.Rel(),
- Output: outFile,
- Input: aidlFile,
- Args: map[string]string{
- "aidlFlags": aidlFlags,
- "outDir": android.PathForModuleGen(ctx, "aidl").String(),
- },
- })
+func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile android.Path,
+ outFile, depFile android.ModuleGenPath, aidlFlags string) android.Paths {
+
+ aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base())
+ baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext())
+ shortName := strings.TrimPrefix(baseName, "I")
- // TODO: This should return the generated headers, not the source file.
- return android.Paths{outFile}
+ outDir := android.PathForModuleGen(ctx, "aidl")
+ headerI := outDir.Join(ctx, aidlPackage, baseName+".h")
+ headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h")
+ headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h")
+
+ cmd := rule.Command()
+ cmd.Tool(ctx.Config().HostToolPath(ctx, "aidl-cpp")).
+ FlagWithDepFile("-d", depFile).
+ Flag("--ninja").
+ Flag(aidlFlags).
+ Input(aidlFile).
+ OutputDir().
+ Output(outFile).
+ ImplicitOutputs(android.WritablePaths{
+ headerI,
+ headerBn,
+ headerBp,
+ })
+
+ return android.Paths{
+ headerI,
+ headerBn,
+ headerBp,
+ }
}
func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
@@ -187,6 +196,8 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
var deps android.Paths
var rsFiles android.Paths
+ var aidlRule *android.RuleBuilder
+
var yaccRule_ *android.RuleBuilder
yaccRule := func() *android.RuleBuilder {
if yaccRule_ == nil {
@@ -218,9 +229,13 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
srcFiles[i] = ccFile
deps = append(deps, headerFile)
case ".aidl":
+ if aidlRule == nil {
+ aidlRule = android.NewRuleBuilder().Sbox(android.PathForModuleGen(ctx, "aidl"))
+ }
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
+ depFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp.d")
srcFiles[i] = cppFile
- deps = append(deps, genAidl(ctx, srcFile, cppFile, buildFlags.aidlFlags)...)
+ deps = append(deps, genAidl(ctx, aidlRule, srcFile, cppFile, depFile, buildFlags.aidlFlags)...)
case ".rs", ".fs":
cppFile := rsGeneratedCppFile(ctx, srcFile)
rsFiles = append(rsFiles, srcFiles[i])
@@ -236,6 +251,10 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
}
}
+ if aidlRule != nil {
+ aidlRule.Build(pctx, ctx, "aidl", "gen aidl")
+ }
+
if yaccRule_ != nil {
yaccRule_.Build(pctx, ctx, "yacc", "gen yacc")
}
diff --git a/cc/gen_test.go b/cc/gen_test.go
index a0f7308c2..e4219d999 100644
--- a/cc/gen_test.go
+++ b/cc/gen_test.go
@@ -15,6 +15,7 @@
package cc
import (
+ "path/filepath"
"testing"
)
@@ -32,7 +33,7 @@ func TestGen(t *testing.T) {
aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
- if !inList("-I"+aidl.Args["outDir"], libfoo.flags.GlobalFlags) {
+ if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) {
t.Errorf("missing aidl includes in global flags")
}
})
@@ -55,7 +56,7 @@ func TestGen(t *testing.T) {
aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
- if !inList("-I"+aidl.Args["outDir"], libfoo.flags.GlobalFlags) {
+ if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) {
t.Errorf("missing aidl includes in global flags")
}
})