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
This commit is contained in:
Colin Cross
2015-04-16 14:09:14 -07:00
parent efb9ebe14f
commit b7a63247ed

View File

@@ -97,6 +97,9 @@ type javaBase struct {
// output file suitable for inserting into the classpath of another compile // output file suitable for inserting into the classpath of another compile
classpathFile string classpathFile string
// output file suitable for installing or running
outputFile string
// jarSpecs suitable for inserting classes from a static library into another jar // jarSpecs suitable for inserting classes from a static library into another jar
classJarSpecs []jarSpec classJarSpecs []jarSpec
@@ -107,12 +110,17 @@ type javaBase struct {
logtagsSrcs []string 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 // installed file for binary dependency
installFile string installFile string
} }
type JavaModuleType interface { type JavaModuleType interface {
GenerateJavaBuildActions(ctx common.AndroidModuleContext) GenerateJavaBuildActions(ctx common.AndroidModuleContext)
JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string
} }
type JavaDependency interface { type JavaDependency interface {
@@ -157,6 +165,10 @@ func (j *javaBase) BootClasspath(ctx common.AndroidBaseContext) string {
var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"} var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { func (j *javaBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
return j.module.JavaDynamicDependencies(ctx)
}
func (j *javaBase) JavaDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
var deps []string var deps []string
if !j.properties.No_standard_libraries { if !j.properties.No_standard_libraries {
@@ -203,16 +215,20 @@ func (j *javaBase) collectDeps(ctx common.AndroidModuleContext) (classpath []str
if javaDep, ok := module.(JavaDependency); ok { if javaDep, ok := module.(JavaDependency); ok {
if otherName == j.BootClasspath(ctx) { if otherName == j.BootClasspath(ctx) {
bootClasspath = javaDep.ClasspathFile() bootClasspath = javaDep.ClasspathFile()
} else if inList(otherName, defaultJavaLibraries) {
classpath = append(classpath, javaDep.ClasspathFile())
} else if inList(otherName, j.properties.Java_libs) { } else if inList(otherName, j.properties.Java_libs) {
classpath = append(classpath, javaDep.ClasspathFile()) classpath = append(classpath, javaDep.ClasspathFile())
} else if inList(otherName, j.properties.Java_static_libs) { } else if inList(otherName, j.properties.Java_static_libs) {
classpath = append(classpath, javaDep.ClasspathFile()) classpath = append(classpath, javaDep.ClasspathFile())
classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...) classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...)
resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...) resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...)
} else if ctx.ModuleName() == "framework" && otherName == "framework-res" { } else if otherName == "framework-res" {
// framework.jar has a one-off dependency on the R.java and Manifest.java files if ctx.ModuleName() == "framework" {
// generated by framework-res.apk // framework.jar has a one-off dependency on the R.java and Manifest.java files
srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).rJarSpec.fileList) // generated by framework-res.apk
srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
}
} else { } else {
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
} }
@@ -278,6 +294,8 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
srcFiles = j.genSources(ctx, srcFiles, flags) srcFiles = j.genSources(ctx, srcFiles, flags)
srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
if len(srcFiles) > 0 { if len(srcFiles) > 0 {
// Compile java sources into .class files // Compile java sources into .class files
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps) classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, javacDeps)
@@ -356,8 +374,8 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
// Combine classes.dex + resources into javalib.jar // Combine classes.dex + resources into javalib.jar
outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec) outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
} }
ctx.CheckbuildFile(outputFile)
j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile) j.outputFile = outputFile
} }
var _ JavaDependency = (*JavaLibrary)(nil) var _ JavaDependency = (*JavaLibrary)(nil)
@@ -392,6 +410,12 @@ type JavaLibrary struct {
javaBase 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{}) { func JavaLibraryFactory() (blueprint.Module, []interface{}) {
module := &JavaLibrary{} module := &JavaLibrary{}