summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go97
1 files changed, 73 insertions, 24 deletions
diff --git a/java/java.go b/java/java.go
index d6c759b45..44830839d 100644
--- a/java/java.go
+++ b/java/java.go
@@ -221,6 +221,13 @@ type CompilerDeviceProperties struct {
// If true, export a copy of the module as a -hostdex module for host testing.
Hostdex *bool
+ Target struct {
+ Hostdex struct {
+ // Additional required dependencies to add to -hostdex modules.
+ Required []string
+ }
+ }
+
// If set to true, compile dex regardless of installable. Defaults to false.
Compile_dex *bool
@@ -283,6 +290,10 @@ type Module struct {
// jar file containing only resources including from static library dependencies
resourceJar android.Path
+ // args and dependencies to package source files into a srcjar
+ srcJarArgs []string
+ srcJarDeps android.Paths
+
// jar file containing implementation classes and resources including static library
// dependencies
implementationAndResourcesJar android.Path
@@ -333,6 +344,9 @@ type Module struct {
// list of additional targets for checkbuild
additionalCheckedModules android.Paths
+ // Extra files generated by the module type to be added as java resources.
+ extraResources android.Paths
+
hiddenAPI
dexpreopter
}
@@ -355,6 +369,7 @@ type Dependency interface {
DexJar() android.Path
AidlIncludeDirs() android.Paths
ExportedSdkLibs() []string
+ SrcJarArgs() ([]string, android.Paths)
}
type SdkLibraryDependency interface {
@@ -502,7 +517,8 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
if j.hasSrcExt(".kt") {
// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
// Kotlin files
- ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
+ ctx.AddVariationDependencies(nil, kotlinStdlibTag,
+ "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
if len(j.properties.Plugins) > 0 {
ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
}
@@ -624,7 +640,7 @@ func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
switch {
case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
name == "stub-annotations" || name == "private-stub-annotations-jar" ||
- name == "core-lambda-stubs":
+ name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
return javaCore, true
case ver == "core_current":
return javaCore, false
@@ -778,7 +794,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
}
case kotlinStdlibTag:
- deps.kotlinStdlib = dep.HeaderJars()
+ deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
case kotlinAnnotationsTag:
deps.kotlinAnnotations = dep.HeaderJars()
}
@@ -839,7 +855,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
ret = javaVersion
} else if ctx.Device() && sdk <= 23 {
ret = "1.7"
- } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
+ } else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() {
ret = "1.8"
} else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
@@ -947,7 +963,9 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
return flags
}
-func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
+func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
+
+ hasSrcs := false
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
@@ -963,10 +981,15 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
srcFiles = j.genSources(ctx, srcFiles, flags)
+ if len(srcFiles) > 0 {
+ hasSrcs = true
+ }
srcJars := srcFiles.FilterByExt(".srcjar")
srcJars = append(srcJars, deps.srcJars...)
- srcJars = append(srcJars, extraSrcJars...)
+ if aaptSrcJar != nil {
+ srcJars = append(srcJars, aaptSrcJar)
+ }
// Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
// that IDEInfo struct will use
@@ -1103,9 +1126,18 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
}
+ j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
+
+ var includeSrcJar android.WritablePath
+ if Bool(j.properties.Include_srcs) {
+ includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
+ TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
+ }
+
dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
+ extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
var resArgs []string
var resDeps android.Paths
@@ -1116,11 +1148,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
resArgs = append(resArgs, fileArgs...)
resDeps = append(resDeps, fileDeps...)
- if Bool(j.properties.Include_srcs) {
- srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
- resArgs = append(resArgs, srcArgs...)
- resDeps = append(resDeps, srcDeps...)
- }
+ resArgs = append(resArgs, extraArgs...)
+ resDeps = append(resDeps, extraDeps...)
if len(resArgs) > 0 {
resourceJar := android.PathForModuleOut(ctx, "res", jarName)
@@ -1131,20 +1160,28 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
}
- if len(deps.staticResourceJars) > 0 {
- var jars android.Paths
- if j.resourceJar != nil {
- jars = append(jars, j.resourceJar)
- }
- jars = append(jars, deps.staticResourceJars...)
+ var resourceJars android.Paths
+ if j.resourceJar != nil {
+ resourceJars = append(resourceJars, j.resourceJar)
+ }
+ if Bool(j.properties.Include_srcs) {
+ resourceJars = append(resourceJars, includeSrcJar)
+ }
+ resourceJars = append(resourceJars, deps.staticResourceJars...)
+ if len(resourceJars) > 1 {
combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
- TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
+ TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
false, nil, nil)
j.resourceJar = combinedJar
+ } else if len(resourceJars) == 1 {
+ j.resourceJar = resourceJars[0]
}
- jars = append(jars, deps.staticJars...)
+ if len(deps.staticJars) > 0 {
+ jars = append(jars, deps.staticJars...)
+ hasSrcs = true
+ }
manifest := j.overrideManifest
if !manifest.Valid() && j.properties.Manifest != nil {
@@ -1246,16 +1283,17 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
// merge implementation jar with resources if necessary
implementationAndResourcesJar := outputFile
if j.resourceJar != nil {
- jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
+ jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
- TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
+ TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
false, nil, nil)
implementationAndResourcesJar = combinedJar
}
j.implementationAndResourcesJar = implementationAndResourcesJar
- if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
+ if ctx.Device() && hasSrcs &&
+ (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
// Dex compilation
var dexOutputFile android.ModuleOutPath
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
@@ -1354,7 +1392,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
// since we have to strip META-INF/TRANSITIVE dir from turbine.jar
combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
- false, nil, []string{"META-INF"})
+ false, nil, []string{"META-INF/TRANSITIVE"})
headerJar = combinedJar
if j.expandJarjarRules != nil {
@@ -1429,6 +1467,10 @@ func (j *Module) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Module) SrcJarArgs() ([]string, android.Paths) {
+ return j.srcJarArgs, j.srcJarDeps
+}
+
var _ logtagsProducer = (*Module)(nil)
func (j *Module) logtags() android.Paths {
@@ -1484,7 +1526,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
- j.compile(ctx)
+ j.compile(ctx, nil)
if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
@@ -1632,6 +1674,9 @@ func TestHelperLibraryFactory() android.Module {
&module.Module.protoProperties,
&module.testHelperLibraryProperties)
+ module.Module.properties.Installable = proptools.BoolPtr(true)
+ module.Module.dexpreopter.isTest = true
+
InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -1903,6 +1948,10 @@ func (j *Import) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Import) SrcJarArgs() ([]string, android.Paths) {
+ return nil, nil
+}
+
// Add compile time check for interface implementation
var _ android.IDEInfo = (*Import)(nil)
var _ android.IDECustomizedModuleName = (*Import)(nil)