java: modify base java rules for android app builds
Store the jar output file for the app build to use.
Allow module types built on top of javaBase to provide filelist files
containing source files.
Allow module types built on top of javaBase to insert dependencies through
JavaDynamicDependencies.
Allow any java module to depend on framework-res.apk.
Move the install rule from javaBase to JavaLibrary.
Change-Id: I46e7e80139845ef7cc89daf180bddbdf77125555
diff --git a/java/java.go b/java/java.go
index 6ad5307..292e258 100644
--- a/java/java.go
+++ b/java/java.go
@@ -97,6 +97,9 @@
// output file suitable for inserting into the classpath of another compile
classpathFile string
+ // output file suitable for installing or running
+ outputFile string
+
// jarSpecs suitable for inserting classes from a static library into another jar
classJarSpecs []jarSpec
@@ -107,12 +110,17 @@
logtagsSrcs []string
+ // filelists of extra source files that should be included in the javac command line,
+ // for example R.java generated by aapt for android apps
+ ExtraSrcLists []string
+
// installed file for binary dependency
installFile string
}
type JavaModuleType interface {
GenerateJavaBuildActions(ctx common.AndroidModuleContext)
+ JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
}
type JavaDependency interface {
@@ -157,6 +165,10 @@
var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
+ return j.module.JavaDynamicDependencies(ctx)
+}
+
+func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
var deps []string
if !j.properties.No_standard_libraries {
@@ -203,16 +215,20 @@
if javaDep, ok := module.(JavaDependency); ok {
if otherName == j.BootClasspath(ctx) {
bootClasspath = javaDep.ClasspathFile()
+ } else if inList(otherName, defaultJavaLibraries) {
+ classpath = append(classpath, javaDep.ClasspathFile())
} else if inList(otherName, j.properties.Java_libs) {
classpath = append(classpath, javaDep.ClasspathFile())
} else if inList(otherName, j.properties.Java_static_libs) {
classpath = append(classpath, javaDep.ClasspathFile())
classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
- } else if ctx.ModuleName() == "framework" && otherName == "framework-res" {
- // framework.jar has a one-off dependency on the R.java and Manifest.java files
- // generated by framework-res.apk
- srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).rJarSpec.fileList)
+ } else if otherName == "framework-res" {
+ if ctx.ModuleName() == "framework" {
+ // framework.jar has a one-off dependency on the R.java and Manifest.java files
+ // generated by framework-res.apk
+ srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
+ }
} else {
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
}
@@ -278,6 +294,8 @@
srcFiles = j.genSources(ctx, srcFiles, flags)
+ srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
+
if len(srcFiles) > 0 {
// Compile java sources into .class files
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
@@ -356,8 +374,8 @@
// Combine classes.dex + resources into javalib.jar
outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
}
-
- j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile)
+ ctx.CheckbuildFile(outputFile)
+ j.outputFile = outputFile
}
var _ JavaDependency = (*JavaLibrary)(nil)
@@ -392,6 +410,12 @@
javaBase
}
+func (j *JavaLibrary) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
+ j.javaBase.GenerateJavaBuildActions(ctx)
+
+ j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", j.outputFile)
+}
+
func JavaLibraryFactory() (blueprint.Module, []interface{}) {
module := &JavaLibrary{}