summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go83
1 files changed, 52 insertions, 31 deletions
diff --git a/java/java.go b/java/java.go
index 44830839d..c42ca28e8 100644
--- a/java/java.go
+++ b/java/java.go
@@ -351,15 +351,22 @@ type Module struct {
dexpreopter
}
-func (j *Module) Srcs() android.Paths {
- return append(android.Paths{j.outputFile}, j.extraOutputFiles...)
+func (j *Module) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case "":
+ return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
+ case ".jar":
+ return android.Paths{j.implementationAndResourcesJar}, nil
+ default:
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+ }
}
func (j *Module) DexJarFile() android.Path {
return j.dexJarFile
}
-var _ android.SourceFileProducer = (*Module)(nil)
+var _ android.OutputFileProducer = (*Module)(nil)
type Dependency interface {
HeaderJars() android.Paths
@@ -373,8 +380,8 @@ type Dependency interface {
}
type SdkLibraryDependency interface {
- SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
- SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
+ SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
+ SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
}
type SrcDependency interface {
@@ -420,6 +427,7 @@ var (
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
certificateTag = dependencyTag{name: "certificate"}
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
+ usesLibTag = dependencyTag{name: "uses-library"}
)
type sdkDep struct {
@@ -432,6 +440,16 @@ type sdkDep struct {
jars android.Paths
aidl android.OptionalPath
+
+ noStandardLibs, noFrameworksLibs bool
+}
+
+func (s sdkDep) hasStandardLibs() bool {
+ return !s.noStandardLibs
+}
+
+func (s sdkDep) hasFrameworkLibs() bool {
+ return !s.noStandardLibs && !s.noFrameworksLibs
}
type jniLib struct {
@@ -440,11 +458,11 @@ type jniLib struct {
target android.Target
}
-func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
+func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
}
-func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
+func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
return j.shouldInstrument(ctx) &&
(ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
ctx.Config().UnbundledBuild())
@@ -468,14 +486,22 @@ func (j *Module) targetSdkVersion() string {
return j.sdkVersion()
}
+func (j *Module) noFrameworkLibs() bool {
+ return Bool(j.properties.No_framework_libs)
+}
+
+func (j *Module) noStandardLibs() bool {
+ return Bool(j.properties.No_standard_libs)
+}
+
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
if ctx.Device() {
- if !Bool(j.properties.No_standard_libs) {
- sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ sdkDep := decodeSdkDep(ctx, sdkContext(j))
+ if sdkDep.hasStandardLibs() {
if sdkDep.useDefaultLibs {
ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
- if !Bool(j.properties.No_framework_libs) {
+ if sdkDep.hasFrameworkLibs() {
ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
}
} else if sdkDep.useModule {
@@ -656,7 +682,7 @@ func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
return javaSdk, true
case ver == "current":
return javaSdk, false
- case ver == "":
+ case ver == "" || ver == "none":
return javaPlatform, false
default:
if _, err := strconv.Atoi(ver); err != nil {
@@ -812,8 +838,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
}
default:
switch tag {
- case android.DefaultsDepTag, android.SourceDepTag:
- // Nothing to do
case systemModulesTag:
if deps.systemModules != nil {
panic("Found two system module dependencies")
@@ -823,8 +847,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
panic("Missing directory for system module dependency")
}
deps.systemModules = sm.outputFile
- default:
- ctx.ModuleErrorf("depends on non-java module %q", otherName)
}
}
})
@@ -838,7 +860,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
var ret string
v := sdkContext.sdkVersion()
// For PDK builds, use the latest SDK version instead of "current"
- if ctx.Config().IsPdkBuild() && (v == "" || v == "current") {
+ if ctx.Config().IsPdkBuild() && (v == "" || v == "none" || v == "current") {
sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int)
latestSdkVersion := 0
if len(sdkVersions) > 0 {
@@ -857,7 +879,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
ret = "1.7"
} else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() {
ret = "1.8"
- } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
+ } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdkContext.sdkVersion() != "none" && sdk == android.FutureApiLevel {
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
ret = "1.8"
} else {
@@ -909,7 +931,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
flags.processor = strings.Join(deps.processorClasses, ",")
if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
- !Bool(j.properties.No_standard_libs) &&
+ decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() &&
inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
// Give host-side tools a version of OpenJDK's standard libraries
// close to what they're targeting. As of Dec 2017, AOSP is only
@@ -965,8 +987,6 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
- hasSrcs := false
-
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
deps := j.collectDeps(ctx)
@@ -981,9 +1001,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
}
srcFiles = j.genSources(ctx, srcFiles, flags)
- if len(srcFiles) > 0 {
- hasSrcs = true
- }
srcJars := srcFiles.FilterByExt(".srcjar")
srcJars = append(srcJars, deps.srcJars...)
@@ -1180,7 +1197,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
if len(deps.staticJars) > 0 {
jars = append(jars, deps.staticJars...)
- hasSrcs = true
}
manifest := j.overrideManifest
@@ -1292,7 +1308,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.implementationAndResourcesJar = implementationAndResourcesJar
- if ctx.Device() && hasSrcs &&
+ if ctx.Device() && j.hasCode(ctx) &&
(Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
// Dex compilation
var dexOutputFile android.ModuleOutPath
@@ -1301,9 +1317,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
return
}
- // Hidden API CSV generation and dex encoding
- dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
- j.deviceProperties.UncompressDex)
+ if !ctx.Config().UnbundledBuild() {
+ // Hidden API CSV generation and dex encoding
+ dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
+ j.deviceProperties.UncompressDex)
+ }
// merge dex jar with resources if necessary
if j.resourceJar != nil {
@@ -1481,6 +1499,7 @@ func (j *Module) logtags() android.Paths {
func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
+ dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
if j.expandJarjarRules != nil {
dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
@@ -1494,6 +1513,11 @@ func (j *Module) CompilerDeps() []string {
return jdeps
}
+func (j *Module) hasCode(ctx android.ModuleContext) bool {
+ srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
+ return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
+}
+
//
// Java libraries (.jar file)
//
@@ -2125,9 +2149,6 @@ type Defaults struct {
android.DefaultsModuleBase
}
-func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
-}
-
// java_defaults provides a set of properties that can be inherited by other java or android modules.
//
// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each