diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/java/java.go b/java/java.go index 44830839d..fee262d83 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 { @@ -440,11 +448,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()) @@ -812,8 +820,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 +829,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) } } }) @@ -965,8 +969,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 +983,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 +1179,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 +1290,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 +1299,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 +1481,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 +1495,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) // |