aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2019-04-07 00:08:13 +0900
committerJiyong Park <jiyong@google.com>2019-04-08 19:44:55 +0900
commitf06bc62b24bc2c88032fd196941132eef60a98dc (patch)
tree410c7fc60ac0b1a115bbb29535932c941c59acee
parent081b90a81b3b6d7ccd740fd87faf16b9259f4dab (diff)
downloadaidl-f06bc62b24bc2c88032fd196941132eef60a98dc.tar.gz
Simplify paths for the generated source files
Previously, the generated source files of an aidl_interface were found under: out/soong/.intermediate/<path_to_module>/<module>-cpp-gen-<number>/gen , where <number> is assigned arbitrarily. This caused a problem when the paths are added to the source path of an IDE. The paths had to be updated whenever the assigned numbers are changed. Now, the paths get simpler: out/soong/.intermediate/<path_to_module>/<module>-cpp-source/gen This is done by building multiple source files using a single genrule module. Bug: 130011113 Test: m Test: system/tools/aidl/runtests.sh Merged-In: I308f3c3ced5b2f7ca3a95ea3fd8ab49d8dd9105b Change-Id: I308f3c3ced5b2f7ca3a95ea3fd8ab49d8dd9105b (cherry picked from commit b8dceed62c9383b50b4a1f2525c49d78d152b3cf)
-rw-r--r--build/aidl_interface.go160
1 files changed, 84 insertions, 76 deletions
diff --git a/build/aidl_interface.go b/build/aidl_interface.go
index 99e8a8cd..294d1f5e 100644
--- a/build/aidl_interface.go
+++ b/build/aidl_interface.go
@@ -43,9 +43,14 @@ var (
pctx = android.NewPackageContext("android/aidl")
+ aidlDirPrepareRule = pctx.StaticRule("aidlDirPrepareRule", blueprint.RuleParams{
+ Command: `rm -rf "${outDir}" && mkdir -p "${outDir}" && ` +
+ `touch ${out}`,
+ Description: "create ${out}",
+ }, "outDir")
+
aidlCppRule = pctx.StaticRule("aidlCppRule", blueprint.RuleParams{
- Command: `rm -rf "${outDir}" && ` +
- `mkdir -p "${outDir}" "${headerDir}" && ` +
+ Command: `mkdir -p "${headerDir}" && ` +
`${aidlCmd} --lang=${lang} ${optionalFlags} --structured --ninja -d ${out}.d ` +
`-h ${headerDir} -o ${outDir} ${imports} ${in}`,
Depfile: "${out}.d",
@@ -55,8 +60,7 @@ var (
}, "imports", "lang", "headerDir", "outDir", "optionalFlags")
aidlJavaRule = pctx.StaticRule("aidlJavaRule", blueprint.RuleParams{
- Command: `rm -rf "${outDir}" && mkdir -p "${outDir}" && ` +
- `${aidlCmd} --lang=java ${optionalFlags} --structured --ninja -d ${out}.d ` +
+ Command: `${aidlCmd} --lang=java ${optionalFlags} --structured --ninja -d ${out}.d ` +
`-o ${outDir} ${imports} ${in}`,
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
@@ -127,7 +131,7 @@ func isRelativePath(path string) bool {
}
type aidlGenProperties struct {
- Input string // a single aidl file
+ Srcs []string
AidlRoot string // base directory for the input aidl file
Imports []string
Lang string // target language [java|cpp|ndk]
@@ -141,6 +145,10 @@ type aidlGenRule struct {
properties aidlGenProperties
+ implicitInputs android.Paths
+ importFlags string
+
+ genOutDir android.ModuleGenPath
genHeaderDir android.ModuleGenPath
genOutputs android.WritablePaths
}
@@ -149,24 +157,10 @@ var _ android.SourceFileProducer = (*aidlGenRule)(nil)
var _ genrule.SourceFileGenerator = (*aidlGenRule)(nil)
func (g *aidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- // g.properties.Input = some_dir/pkg/to/IFoo.aidl
- // g.properties.AidlRoot = some_dir
- // input = <module_root>/some_dir/pkg/to/IFoo.aidl
- // outDir = out/soong/.intermediate/..../gen/
- // outFile = out/soong/.intermediates/..../gen/pkg/to/IFoo.{java|cpp}
- input := android.PathForModuleSrc(ctx, g.properties.Input)
- input = android.PathWithModuleSrcSubDir(ctx, input, g.properties.AidlRoot)
- outDir := android.PathForModuleGen(ctx)
- var outFile android.WritablePath
- if g.properties.Lang == langJava {
- outFile = android.PathForModuleGen(ctx, pathtools.ReplaceExtension(input.Rel(), "java"))
- } else {
- outFile = android.PathForModuleGen(ctx, pathtools.ReplaceExtension(input.Rel(), "cpp"))
- }
- g.genOutputs = []android.WritablePath{outFile}
+ genDirTimestamp := android.PathForModuleGen(ctx, "timestamp")
+ g.implicitInputs = append(g.implicitInputs, genDirTimestamp)
var importPaths []string
- var checkApiTimestamps android.Paths
ctx.VisitDirectDeps(func(dep android.Module) {
if importedAidl, ok := dep.(*aidlInterface); ok {
importPaths = append(importPaths, importedAidl.properties.Full_import_paths...)
@@ -174,12 +168,38 @@ func (g *aidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// When compiling an AIDL interface, also make sure that each
// version of the interface is compatible with its previous version
for _, path := range api.checkApiTimestamps {
- checkApiTimestamps = append(checkApiTimestamps, path)
+ g.implicitInputs = append(g.implicitInputs, path)
}
}
})
+ g.importFlags = strings.Join(wrap("-I", importPaths, ""), " ")
- imports := strings.Join(wrap("-I", importPaths, ""), " ")
+ srcs := android.PathsWithModuleSrcSubDir(ctx, android.PathsForModuleSrc(ctx, g.properties.Srcs), g.properties.AidlRoot)
+
+ g.genOutDir = android.PathForModuleGen(ctx)
+ g.genHeaderDir = android.PathForModuleGen(ctx, "include")
+ for _, src := range srcs {
+ g.genOutputs = append(g.genOutputs, g.generateBuildActionsForSingleAidl(ctx, src))
+ }
+
+ // This is to clean genOutDir before generating any file
+ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+ Rule: aidlDirPrepareRule,
+ Implicits: srcs,
+ Output: genDirTimestamp,
+ Args: map[string]string{
+ "outDir": g.genOutDir.String(),
+ },
+ })
+}
+
+func (g *aidlGenRule) generateBuildActionsForSingleAidl(ctx android.ModuleContext, src android.Path) android.WritablePath {
+ var outFile android.WritablePath
+ if g.properties.Lang == langJava {
+ outFile = android.PathForModuleGen(ctx, pathtools.ReplaceExtension(src.Rel(), "java"))
+ } else {
+ outFile = android.PathForModuleGen(ctx, pathtools.ReplaceExtension(src.Rel(), "cpp"))
+ }
var optionalFlags []string
if g.properties.Version != "" {
@@ -189,19 +209,18 @@ func (g *aidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if g.properties.Lang == langJava {
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: aidlJavaRule,
- Input: input,
- Implicits: checkApiTimestamps,
- Outputs: g.genOutputs,
+ Input: src,
+ Implicits: g.implicitInputs,
+ Output: outFile,
Args: map[string]string{
- "imports": imports,
- "outDir": outDir.String(),
+ "imports": g.importFlags,
+ "outDir": g.genOutDir.String(),
"optionalFlags": strings.Join(optionalFlags, " "),
},
})
} else {
- g.genHeaderDir = android.PathForModuleGen(ctx, "include")
- typeName := strings.TrimSuffix(filepath.Base(input.Rel()), ".aidl")
- packagePath := filepath.Dir(input.Rel())
+ typeName := strings.TrimSuffix(filepath.Base(src.Rel()), ".aidl")
+ packagePath := filepath.Dir(src.Rel())
baseName := typeName
// TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if
// an interface name has a leading I. Those same heuristics have been
@@ -235,19 +254,21 @@ func (g *aidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: aidlCppRule,
- Input: input,
- Implicits: checkApiTimestamps,
- Outputs: g.genOutputs,
+ Input: src,
+ Implicits: g.implicitInputs,
+ Output: outFile,
ImplicitOutputs: headers,
Args: map[string]string{
- "imports": imports,
+ "imports": g.importFlags,
"lang": aidlLang,
"headerDir": g.genHeaderDir.String(),
- "outDir": outDir.String(),
+ "outDir": g.genOutDir.String(),
"optionalFlags": strings.Join(optionalFlags, " "),
},
})
}
+
+ return outFile
}
func (g *aidlGenRule) GeneratedSourceFiles() android.Paths {
@@ -679,7 +700,7 @@ func aidlInterfaceHook(mctx android.LoadHookContext, i *aidlInterface) {
}
func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version string, lang string) string {
- cppSourceGen := i.versionedName(version) + "-" + lang + "-gen"
+ cppSourceGen := i.versionedName(version) + "-" + lang + "-source"
cppModuleGen := i.versionedName(version) + "-" + lang
srcs, base := i.srcsForVersion(mctx, version)
@@ -690,30 +711,22 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin
return ""
}
- var cppGeneratedSources []string
-
genLog := false
if lang == langCpp {
genLog = proptools.Bool(i.properties.Backend.Cpp.Gen_log)
}
- for idx, source := range srcs {
- // Use idx to distinguish genrule modules. typename is not appropriate
- // as it is possible to have identical type names in different packages.
- cppSourceGenName := cppSourceGen + "-" + strconv.Itoa(idx)
- mctx.CreateModule(android.ModuleFactoryAdaptor(aidlGenFactory), &nameProperties{
- Name: proptools.StringPtr(cppSourceGenName),
- }, &aidlGenProperties{
- Input: source,
- AidlRoot: base,
- Imports: concat(i.properties.Imports, []string{i.ModuleBase.Name()}),
- Lang: lang,
- BaseName: i.ModuleBase.Name(),
- GenLog: genLog,
- Version: version,
- })
- cppGeneratedSources = append(cppGeneratedSources, cppSourceGenName)
- }
+ mctx.CreateModule(android.ModuleFactoryAdaptor(aidlGenFactory), &nameProperties{
+ Name: proptools.StringPtr(cppSourceGen),
+ }, &aidlGenProperties{
+ Srcs: srcs,
+ AidlRoot: base,
+ Imports: concat(i.properties.Imports, []string{i.ModuleBase.Name()}),
+ Lang: lang,
+ BaseName: i.ModuleBase.Name(),
+ GenLog: genLog,
+ Version: version,
+ })
importExportDependencies := wrap("", i.properties.Imports, "-"+lang)
var libJSONCppDependency []string
@@ -745,9 +758,9 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin
Owner: i.properties.Owner,
Vendor_available: i.properties.Vendor_available,
Defaults: []string{"aidl-cpp-module-defaults"},
- Generated_sources: cppGeneratedSources,
- Generated_headers: cppGeneratedSources,
- Export_generated_headers: cppGeneratedSources,
+ Generated_sources: []string{cppSourceGen},
+ Generated_headers: []string{cppSourceGen},
+ Export_generated_headers: []string{cppSourceGen},
Static: staticLib{Whole_static_libs: libJSONCppDependency},
Shared: sharedLib{Shared_libs: libJSONCppDependency, Export_shared_lib_headers: libJSONCppDependency},
Shared_libs: importExportDependencies,
@@ -762,7 +775,7 @@ func addCppLibrary(mctx android.LoadHookContext, i *aidlInterface, version strin
}
func addJavaLibrary(mctx android.LoadHookContext, i *aidlInterface, version string) string {
- javaSourceGen := i.versionedName(version) + "-java-gen"
+ javaSourceGen := i.versionedName(version) + "-java-source"
javaModuleGen := i.versionedName(version) + "-java"
srcs, base := i.srcsForVersion(mctx, version)
@@ -773,23 +786,18 @@ func addJavaLibrary(mctx android.LoadHookContext, i *aidlInterface, version stri
return ""
}
- var javaGeneratedSources []string
sdkVersion := proptools.StringDefault(i.properties.Backend.Java.Sdk_version, "system_current")
- for idx, source := range srcs {
- javaSourceGenName := javaSourceGen + "-" + strconv.Itoa(idx)
- mctx.CreateModule(android.ModuleFactoryAdaptor(aidlGenFactory), &nameProperties{
- Name: proptools.StringPtr(javaSourceGenName),
- }, &aidlGenProperties{
- Input: source,
- AidlRoot: base,
- Imports: concat(i.properties.Imports, []string{i.ModuleBase.Name()}),
- Lang: langJava,
- BaseName: i.ModuleBase.Name(),
- Version: version,
- })
- javaGeneratedSources = append(javaGeneratedSources, javaSourceGenName)
- }
+ mctx.CreateModule(android.ModuleFactoryAdaptor(aidlGenFactory), &nameProperties{
+ Name: proptools.StringPtr(javaSourceGen),
+ }, &aidlGenProperties{
+ Srcs: srcs,
+ AidlRoot: base,
+ Imports: concat(i.properties.Imports, []string{i.ModuleBase.Name()}),
+ Lang: langJava,
+ BaseName: i.ModuleBase.Name(),
+ Version: version,
+ })
mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Name: proptools.StringPtr(javaModuleGen),
@@ -799,7 +807,7 @@ func addJavaLibrary(mctx android.LoadHookContext, i *aidlInterface, version stri
No_framework_libs: proptools.BoolPtr(true),
Sdk_version: proptools.StringPtr(sdkVersion),
Static_libs: wrap("", i.properties.Imports, "-java"),
- Srcs: wrap(":", javaGeneratedSources, ""),
+ Srcs: []string{":" + javaSourceGen},
})
return javaModuleGen