diff options
author | Colin Cross <ccross@android.com> | 2015-04-08 13:03:43 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2015-04-08 16:37:31 -0700 |
commit | c0b06f191f99379d3e8111f3bb149a53b1054422 (patch) | |
tree | cee2de58b5b3bfcca311766c91b24ea71deb4766 /java/java.go | |
parent | 6cbb1275648b76377764a96960b7fd206e1a4917 (diff) |
Add aidl file support to java builds
Add support for aidl files listed in srcs for java builds, and
an aidl_preprocess module type for framework and sdk aidls.
Change-Id: I3aa537f4483822e5b534c74d0b35f13a938f8947
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 87 |
1 files changed, 79 insertions, 8 deletions
diff --git a/java/java.go b/java/java.go index 448580ec4..ca3a4c757 100644 --- a/java/java.go +++ b/java/java.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/google/blueprint" + "github.com/google/blueprint/pathtools" "android/soong/common" ) @@ -85,6 +86,13 @@ type javaBase struct { // jarjar_rules: if not blank, run jarjar using the specified rules file Jarjar_rules string + + // aidl_includes: directories to pass to aidl tool + Aidl_includes []string + + // aidl_export_include_dirs: directories that should be added as include directories + // for any aidl sources of modules that depend on this module + Export_aidl_include_dirs []string } // output file suitable for inserting into the classpath of another compile @@ -96,6 +104,8 @@ type javaBase struct { // jarSpecs suitable for inserting resources from a static library into another jar resourceJarSpecs []jarSpec + exportAidlIncludeDirs []string + // installed file for binary dependency installFile string } @@ -108,6 +118,8 @@ type JavaDependency interface { ClasspathFile() string ClassJarSpecs() []jarSpec ResourceJarSpecs() []jarSpec + AidlIncludeDirs() []string + AidlPreprocessed() string } func NewJavaBase(base *javaBase, module JavaModuleType, hod common.HostOrDeviceSupported, @@ -126,6 +138,7 @@ func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string { return "core-libart" } else if j.properties.Sdk_version == "current" { // TODO: !TARGET_BUILD_APPS + // TODO: export preprocessed framework.aidl from android_stubs_current return "android_stubs_current" } else if j.properties.Sdk_version == "system_current" { return "android_system_stubs_current" @@ -156,8 +169,29 @@ func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerM return deps } +func (j *javaBase) aidlFlags(ctx common.AndroidModuleContext, aidlPreprocess string, + aidlIncludeDirs []string) string { + + localAidlIncludes := pathtools.PrefixPaths(j.properties.Aidl_includes, common.ModuleSrcDir(ctx)) + + var flags []string + if aidlPreprocess != "" { + flags = append(flags, "-p"+aidlPreprocess) + } else { + flags = append(flags, common.JoinWithPrefix(aidlIncludeDirs, "-I")) + } + + flags = append(flags, common.JoinWithPrefix(j.exportAidlIncludeDirs, "-I")) + flags = append(flags, common.JoinWithPrefix(localAidlIncludes, "-I")) + flags = append(flags, "-I"+common.ModuleSrcDir(ctx)) + flags = append(flags, "-I"+filepath.Join(common.ModuleSrcDir(ctx), "src")) + + return strings.Join(flags, " ") +} + func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []string, - bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec) { + bootClasspath string, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess string, + aidlIncludeDirs []string) { ctx.VisitDirectDeps(func(module blueprint.Module) { otherName := ctx.OtherModuleName(module) @@ -173,12 +207,21 @@ func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []str } else { panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) } + aidlIncludeDirs = append(aidlIncludeDirs, j.AidlIncludeDirs()...) + if j.AidlPreprocessed() != "" { + if aidlPreprocess != "" { + ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q", + aidlPreprocess, j.AidlPreprocessed()) + } else { + aidlPreprocess = j.AidlPreprocessed() + } + } } else { ctx.ModuleErrorf("unknown dependency module type for %q", otherName) } }) - return classpath, bootClasspath, classJarSpecs, resourceJarSpecs + return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, aidlIncludeDirs } func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { @@ -186,16 +229,20 @@ func (j *javaBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) } func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { + + j.exportAidlIncludeDirs = pathtools.PrefixPaths(j.properties.Export_aidl_include_dirs, + common.ModuleSrcDir(ctx)) + + classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, + aidlIncludeDirs := j.collectDeps(ctx) + flags := javaBuilderFlags{ javacFlags: strings.Join(j.properties.Javacflags, " "), + aidlFlags: j.aidlFlags(ctx, aidlPreprocess, aidlIncludeDirs), } var javacDeps []string - srcFiles := common.ExpandSources(ctx, j.properties.Srcs) - - classpath, bootClasspath, classJarSpecs, resourceJarSpecs := j.collectDeps(ctx) - if bootClasspath != "" { flags.bootClasspath = "-bootclasspath " + bootClasspath javacDeps = append(javacDeps, bootClasspath) @@ -206,6 +253,10 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) { javacDeps = append(javacDeps, classpath...) } + srcFiles := common.ExpandSources(ctx, j.properties.Srcs) + + srcFiles = genSources(ctx, srcFiles, flags) + // Compile java sources into .class files classes := TransformJavaToClasses(ctx, srcFiles, flags, javacDeps) if ctx.Failed() { @@ -296,6 +347,14 @@ func (j *javaBase) ResourceJarSpecs() []jarSpec { return j.resourceJarSpecs } +func (j *javaBase) AidlIncludeDirs() []string { + return j.exportAidlIncludeDirs +} + +func (j *javaBase) AidlPreprocessed() string { + return "" +} + // // Java libraries (.jar file) // @@ -362,9 +421,11 @@ type JavaPrebuilt struct { common.AndroidModuleBase properties struct { - Srcs []string + Srcs []string + Aidl_preprocessed string } + aidlPreprocessed string classpathFile string classJarSpecs, resourceJarSpecs []jarSpec } @@ -381,7 +442,9 @@ func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx common.AndroidModuleConte j.classpathFile = prebuilt j.classJarSpecs = []jarSpec{classJarSpec} j.resourceJarSpecs = []jarSpec{resourceJarSpec} - + if j.properties.Aidl_preprocessed != "" { + j.aidlPreprocessed = filepath.Join(common.ModuleSrcDir(ctx), j.properties.Aidl_preprocessed) + } ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.classpathFile) } @@ -399,6 +462,14 @@ func (j *JavaPrebuilt) ResourceJarSpecs() []jarSpec { return j.resourceJarSpecs } +func (j *JavaPrebuilt) AidlIncludeDirs() []string { + return nil +} + +func (j *JavaPrebuilt) AidlPreprocessed() string { + return j.aidlPreprocessed +} + func JavaPrebuiltFactory() (blueprint.Module, []interface{}) { module := &JavaPrebuilt{} |