summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go139
1 files changed, 95 insertions, 44 deletions
diff --git a/java/java.go b/java/java.go
index a23835bb8..230e8f2b8 100644
--- a/java/java.go
+++ b/java/java.go
@@ -115,10 +115,7 @@ type CompilerProperties struct {
Include_srcs *bool
// List of modules to use as annotation processors
- Annotation_processors []string
-
- // List of classes to pass to javac to use as annotation processors
- Annotation_processor_classes []string
+ Plugins []string
// The number of Java source entries each Javac instance can process
Javac_shard_size *int64
@@ -313,6 +310,9 @@ type Module struct {
// filter out Exclude_srcs, will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs []string
+ // expanded Jarjar_rules
+ expandJarjarRules android.Path
+
dexpreopter
}
@@ -336,8 +336,8 @@ type Dependency interface {
}
type SdkLibraryDependency interface {
- HeaderJars(linkType linkType) android.Paths
- ImplementationJars(linkType linkType) android.Paths
+ HeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
+ ImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
}
type SrcDependency interface {
@@ -373,12 +373,13 @@ type jniDependencyTag struct {
var (
staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib"}
- annoTag = dependencyTag{name: "annotation processor"}
+ pluginTag = dependencyTag{name: "plugin"}
bootClasspathTag = dependencyTag{name: "bootclasspath"}
systemModulesTag = dependencyTag{name: "system modules"}
frameworkResTag = dependencyTag{name: "framework-res"}
frameworkApkTag = dependencyTag{name: "framework-apk"}
kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
+ kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
certificateTag = dependencyTag{name: "certificate"}
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
@@ -466,14 +467,16 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
+
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
- }, annoTag, j.properties.Annotation_processors...)
+ }, pluginTag, j.properties.Plugins...)
android.ExtractSourcesDeps(ctx, j.properties.Srcs)
android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
android.ExtractSourceDeps(ctx, j.properties.Manifest)
+ android.ExtractSourceDeps(ctx, j.properties.Jarjar_rules)
if j.hasSrcExt(".proto") {
protoDeps(ctx, &j.protoProperties)
@@ -483,6 +486,9 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
// Kotlin files
ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
+ if len(j.properties.Plugins) > 0 {
+ ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
+ }
}
if j.shouldInstrumentStatic(ctx) {
@@ -555,6 +561,7 @@ type deps struct {
classpath classpath
bootClasspath classpath
processorPath classpath
+ processorClasses []string
staticJars android.Paths
staticHeaderJars android.Paths
staticResourceJars android.Paths
@@ -564,6 +571,9 @@ type deps struct {
systemModules android.Path
aidlPreprocess android.OptionalPath
kotlinStdlib android.Paths
+ kotlinAnnotations android.Paths
+
+ disableTurbine bool
}
func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
@@ -701,8 +711,16 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
- case annoTag:
- deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
+ case pluginTag:
+ if plugin, ok := dep.(*Plugin); ok {
+ deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
+ if plugin.pluginProperties.Processor_class != nil {
+ deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
+ }
+ deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
+ } else {
+ ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
+ }
case frameworkResTag:
if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
// framework.jar has a one-off dependency on the R.java and Manifest.java files
@@ -723,14 +741,15 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
}
case kotlinStdlibTag:
deps.kotlinStdlib = dep.HeaderJars()
+ case kotlinAnnotationsTag:
+ deps.kotlinAnnotations = dep.HeaderJars()
}
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
case SdkLibraryDependency:
switch tag {
case libTag:
- linkType, _ := getLinkType(j, ctx.ModuleName())
- deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
+ deps.classpath = append(deps.classpath, dep.HeaderJars(ctx, j.sdkVersion())...)
// names of sdk libs that are directly depended are exported
j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
default:
@@ -748,6 +767,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
case android.DefaultsDepTag, android.SourceDepTag:
// Nothing to do
+ case publicApiFileTag, systemApiFileTag, testApiFileTag:
+ // Nothing to do
default:
ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
}
@@ -847,6 +868,8 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
flags.classpath = append(flags.classpath, deps.classpath...)
flags.processorPath = append(flags.processorPath, deps.processorPath...)
+ flags.processor = strings.Join(deps.processorClasses, ",")
+
if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
!Bool(j.properties.No_standard_libs) &&
inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
@@ -932,6 +955,10 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
// that IDEInfo struct will use
j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
+ if j.properties.Jarjar_rules != nil {
+ j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules")
+ }
+
jarName := ctx.ModuleName() + ".jar"
javaSrcFiles := srcFiles.FilterByExt(".java")
@@ -968,18 +995,29 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
- flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...)
- flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
- flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
+ flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
+ flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
+
+ flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
+ flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
+
+ if len(flags.processorPath) > 0 {
+ // Use kapt for annotation processing
+ kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
+ kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
+ srcJars = append(srcJars, kaptSrcJar)
+ // Disable annotation processing in javac, it's already been handled by kapt
+ flags.processorPath = nil
+ flags.processor = ""
+ }
kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
- TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
+ kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
if ctx.Failed() {
return
}
// Make javac rule depend on the kotlinc rule
- flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
flags.classpath = append(flags.classpath, kotlinJar)
// Jar kotlin classes into the final jar after javac
@@ -994,15 +1032,14 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
j.compiledSrcJars = srcJars
enable_sharding := false
- if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
+ if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
enable_sharding = true
- if len(j.properties.Annotation_processors) != 0 ||
- len(j.properties.Annotation_processor_classes) != 0 {
- ctx.PropertyErrorf("javac_shard_size",
- "%q cannot be set when annotation processors are enabled.",
- j.properties.Javac_shard_size)
- }
+ // Formerly, there was a check here that prevented annotation processors
+ // from being used when sharding was enabled, as some annotation processors
+ // do not function correctly in sharded environments. It was removed to
+ // allow for the use of annotation processors that do function correctly
+ // with sharding enabled. See: b/77284273.
}
j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
if ctx.Failed() {
@@ -1126,17 +1163,16 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
// jarjar implementation jar if necessary
- if j.properties.Jarjar_rules != nil {
- jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
+ if j.expandJarjarRules != nil {
// Transform classes.jar into classes-jarjar.jar
jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
- TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
+ TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
outputFile = jarjarFile
// jarjar resource jar if necessary
if j.resourceJar != nil {
resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
- TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, jarjar_rules)
+ TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
j.resourceJar = resourceJarJarFile
}
@@ -1172,23 +1208,45 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
j.implementationAndResourcesJar = implementationAndResourcesJar
if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
+ // Dex compilation
var dexOutputFile android.ModuleOutPath
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Failed() {
return
}
+ // Hidden API CSV generation and dex encoding
+ if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
+ isBootJar := inList(ctx.ModuleName(), ctx.Config().BootJars())
+ if isBootJar || inList(ctx.ModuleName(), ctx.Config().HiddenAPIExtraAppUsageJars()) {
+ // Derive the greylist from classes jar.
+ hiddenAPIGenerateCSV(ctx, j.implementationJarFile)
+ }
+ if isBootJar {
+ hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName)
+ hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile, j.deviceProperties.UncompressDex)
+ dexOutputFile = hiddenAPIJar
+ }
+ }
+
// merge dex jar with resources if necessary
if j.resourceJar != nil {
jars := android.Paths{dexOutputFile, j.resourceJar}
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
false, nil, nil)
- dexOutputFile = combinedJar
+ if j.deviceProperties.UncompressDex {
+ combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
+ TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
+ dexOutputFile = combinedAlignedJar
+ } else {
+ dexOutputFile = combinedJar
+ }
}
j.dexJarFile = dexOutputFile
+ // Dexpreopting
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
j.dexpreopter.uncompressedDex = j.deviceProperties.UncompressDex
dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
@@ -1263,11 +1321,10 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
false, nil, []string{"META-INF"})
headerJar = combinedJar
- if j.properties.Jarjar_rules != nil {
- jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
+ if j.expandJarjarRules != nil {
// Transform classes.jar into classes-jarjar.jar
jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
- TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules)
+ TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
headerJar = jarjarFile
if ctx.Failed() {
return nil
@@ -1343,8 +1400,8 @@ func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
- if j.properties.Jarjar_rules != nil {
- dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, *j.properties.Jarjar_rules)
+ if j.expandJarjarRules != nil {
+ dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
}
}
@@ -1364,10 +1421,10 @@ type Library struct {
}
func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
- // Store uncompressed (and do not strip) dex files from boot class path jars that are not
- // part of the boot image.
+ // Store uncompressed (and do not strip) dex files from boot class path jars that are
+ // in an apex.
if inList(ctx.ModuleName(), ctx.Config().BootJars()) &&
- !inList(ctx.ModuleName(), ctx.Config().PreoptBootJars()) {
+ android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
return true
}
return false
@@ -1379,13 +1436,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.deviceProperties.UncompressDex = j.shouldUncompressDex(ctx)
j.compile(ctx)
- if Bool(j.properties.Installable) || ctx.Host() {
- if j.deviceProperties.UncompressDex {
- alignedOutputFile := android.PathForModuleOut(ctx, "aligned", ctx.ModuleName()+".jar")
- TransformZipAlign(ctx, alignedOutputFile, j.outputFile)
- j.outputFile = alignedOutputFile
- }
-
+ if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
ctx.ModuleName()+".jar", j.outputFile)
}