diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 130 |
1 files changed, 79 insertions, 51 deletions
diff --git a/java/java.go b/java/java.go index b4ce35ede..2ded80bc1 100644 --- a/java/java.go +++ b/java/java.go @@ -137,6 +137,12 @@ type Module struct { // output file suitable for inserting into the classpath of another compile classpathFile android.Path + // output file containing classes.dex + dexJarFile android.Path + + // output files containing resources + resourceJarFiles android.Paths + // output file suitable for installing or running outputFile android.Path @@ -154,6 +160,7 @@ type Module struct { type Dependency interface { ClasspathFiles() android.Paths + ResourceJarFiles() android.Paths AidlIncludeDirs() android.Paths } @@ -168,12 +175,11 @@ type dependencyTag struct { } var ( - staticLibTag = dependencyTag{name: "staticlib"} - libTag = dependencyTag{name: "javalib"} - bootClasspathTag = dependencyTag{name: "bootclasspath"} - frameworkResTag = dependencyTag{name: "framework-res"} - sdkDependencyTag = dependencyTag{name: "sdk"} - annotationProcessorTag = dependencyTag{name: "annotation processor"} + staticLibTag = dependencyTag{name: "staticlib"} + libTag = dependencyTag{name: "javalib"} + bootClasspathTag = dependencyTag{name: "bootclasspath"} + frameworkResTag = dependencyTag{name: "framework-res"} + sdkDependencyTag = dependencyTag{name: "sdk"} ) func (j *Module) deps(ctx android.BottomUpMutatorContext) { @@ -202,7 +208,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...) - ctx.AddDependency(ctx.Module(), annotationProcessorTag, j.properties.Annotation_processors...) + ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...) android.ExtractSourcesDeps(ctx, j.properties.Srcs) } @@ -230,13 +236,13 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt } type deps struct { - classpath android.Paths - bootClasspath android.Paths - staticJars android.Paths - aidlIncludeDirs android.Paths - srcFileLists android.Paths - annotationProcessors android.Paths - aidlPreprocess android.OptionalPath + classpath android.Paths + bootClasspath android.Paths + staticJars android.Paths + staticJarResources android.Paths + aidlIncludeDirs android.Paths + srcFileLists android.Paths + aidlPreprocess android.OptionalPath } func (j *Module) collectDeps(ctx android.ModuleContext) deps { @@ -264,8 +270,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case staticLibTag: deps.classpath = append(deps.classpath, dep.ClasspathFiles()...) deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...) - case annotationProcessorTag: - deps.annotationProcessors = append(deps.annotationProcessors, dep.ClasspathFiles()...) + deps.staticJarResources = append(deps.staticJarResources, dep.ResourceJarFiles()...) case frameworkResTag: if ctx.ModuleName() == "framework" { // framework.jar has a one-off dependency on the R.java and Manifest.java files @@ -306,21 +311,17 @@ func (j *Module) compile(ctx android.ModuleContext) { javacFlags = config.StripJavac9Flags(javacFlags) } - if len(deps.annotationProcessors) > 0 { - javacFlags = append(javacFlags, - "-processorpath "+strings.Join(deps.annotationProcessors.Strings(), ":")) - } - - for _, c := range j.properties.Annotation_processor_classes { - javacFlags = append(javacFlags, "-processor "+c) - } - if j.properties.Java_version != nil { flags.javaVersion = *j.properties.Java_version } else { flags.javaVersion = "${config.DefaultJavaVersion}" } + var extraDeps android.Paths + + flags.bootClasspath.AddPaths(deps.bootClasspath) + flags.classpath.AddPaths(deps.classpath) + if len(javacFlags) > 0 { ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) flags.javacFlags = "$javacFlags" @@ -332,21 +333,6 @@ func (j *Module) compile(ctx android.ModuleContext) { flags.aidlFlags = "$aidlFlags" } - var extraDeps android.Paths - - if len(deps.bootClasspath) > 0 { - flags.bootClasspath = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":") - extraDeps = append(extraDeps, deps.bootClasspath...) - } else if ctx.Device() { - // Explicitly clear the bootclasspath for device builds - flags.bootClasspath = `-bootclasspath ""` - } - - if len(deps.classpath) > 0 { - flags.classpath = "-classpath " + strings.Join(deps.classpath.Strings(), ":") - extraDeps = append(extraDeps, deps.classpath...) - } - srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) srcFiles = j.genSources(ctx, srcFiles, flags) @@ -385,23 +371,29 @@ func (j *Module) compile(ctx android.ModuleContext) { } resourceJarSpecs := ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs) - manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest) - - if len(resourceJarSpecs) > 0 || manifest.Valid() { + if len(resourceJarSpecs) > 0 { // Combine classes + resources into classes-full-debug.jar - resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, manifest, extraJarDeps) + resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, extraJarDeps) if ctx.Failed() { return } + j.resourceJarFiles = append(j.resourceJarFiles, resourceJar) jars = append(jars, resourceJar) } + // Propagate the resources from the transitive closure of static dependencies for copying + // into dex jars + j.resourceJarFiles = append(j.resourceJarFiles, deps.staticJarResources...) + + // static classpath jars have the resources in them, so the resource jars aren't necessary here jars = append(jars, deps.staticJars...) + manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest) + // Combine the classes built from sources, any manifests, and any static libraries into // classes-combined.jar. If there is only one input jar this step will be skipped. - outputFile := TransformJarsToJar(ctx, "classes-combined.jar", jars) + outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false) if j.properties.Jarjar_rules != nil { jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) @@ -450,14 +442,39 @@ func (j *Module) compile(ctx android.ModuleContext) { flags.dxFlags = strings.Join(dxFlags, " ") + desugarFlags := []string{ + "--min_sdk_version " + minSdkVersion, + "--desugar_try_with_resources_if_needed=false", + "--allow_empty_bootclasspath", + } + + if inList("--core-library", dxFlags) { + desugarFlags = append(desugarFlags, "--core_library") + } + + flags.desugarFlags = strings.Join(desugarFlags, " ") + + desugarJar := TransformDesugar(ctx, outputFile, flags) + if ctx.Failed() { + return + } + + // TODO(ccross): For now, use the desugared jar as the classpath file. Eventually this + // might cause problems because desugar wants non-desugared jars in its class path. + j.classpathFile = desugarJar + // Compile classes.jar into classes.dex - dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags) + dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags) if ctx.Failed() { return } - // Combine classes.dex + resources into javalib.jar - outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec) + jars := android.Paths{dexJarFile} + jars = append(jars, j.resourceJarFiles...) + + outputFile = TransformJarsToJar(ctx, "javalib.jar", jars, android.OptionalPath{}, true) + + j.dexJarFile = outputFile } ctx.CheckbuildFile(outputFile) j.outputFile = outputFile @@ -469,6 +486,10 @@ func (j *Module) ClasspathFiles() android.Paths { return android.Paths{j.classpathFile} } +func (j *Module) ResourceJarFiles() android.Paths { + return j.resourceJarFiles +} + func (j *Module) AidlIncludeDirs() android.Paths { return j.exportAidlIncludeDirs } @@ -616,7 +637,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars) - j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles) + j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false) } var _ Dependency = (*Import)(nil) @@ -625,6 +646,11 @@ func (j *Import) ClasspathFiles() android.Paths { return j.classpathFiles } +func (j *Import) ResourceJarFiles() android.Paths { + // resources are in the ClasspathFiles + return nil +} + func (j *Import) AidlIncludeDirs() android.Paths { return nil } @@ -687,9 +713,11 @@ func (j *sdkPrebuilt) AidlPreprocessed() android.OptionalPath { func SdkPrebuiltFactory() android.Module { module := &sdkPrebuilt{} - module.AddProperties(&module.sdkProperties) + module.AddProperties( + &module.sdkProperties, + &module.Import.properties) - android.InitPrebuiltModule(module, &module.properties.Jars) + android.InitPrebuiltModule(module, &module.Import.properties.Jars) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) return module } |