diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/androidmk.go | 6 | ||||
| -rwxr-xr-x | java/app.go | 11 | ||||
| -rw-r--r-- | java/app_import.go | 2 | ||||
| -rw-r--r-- | java/base.go | 6 | ||||
| -rw-r--r-- | java/dexpreopt.go | 33 | ||||
| -rw-r--r-- | java/droiddoc.go | 4 | ||||
| -rw-r--r-- | java/droidstubs.go | 51 | ||||
| -rw-r--r-- | java/java.go | 48 | ||||
| -rw-r--r-- | java/java_test.go | 30 | ||||
| -rw-r--r-- | java/jdeps.go | 9 | ||||
| -rw-r--r-- | java/sdk.go | 16 | ||||
| -rw-r--r-- | java/sdk_library.go | 13 |
12 files changed, 158 insertions, 71 deletions
diff --git a/java/androidmk.go b/java/androidmk.go index eca5caacb..4c115d58c 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -47,6 +47,7 @@ func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries { if library.dexJarFile.IsSet() { entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path()) } + entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", library.hostdexInstallFile) entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex") @@ -285,11 +286,6 @@ func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries { }} } else { outputFile := binary.wrapperFile - // Have Make installation trigger Soong installation by using Soong's install path as - // the output file. - if binary.Host() { - outputFile = binary.binaryFile - } return []android.AndroidMkEntries{android.AndroidMkEntries{ Class: "EXECUTABLES", diff --git a/java/app.go b/java/app.go index 6554d6693..c08ec0697 100755 --- a/java/app.go +++ b/java/app.go @@ -471,6 +471,7 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries() a.dexpreopter.classLoaderContexts = a.classLoaderContexts a.dexpreopter.manifestFile = a.mergedManifestFile + a.dexpreopter.preventInstall = a.appProperties.PreventInstall if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) @@ -720,11 +721,15 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) // Install the app package. - if (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() { - ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile) + if (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() && + !a.appProperties.PreventInstall { + + var extraInstalledPaths android.Paths for _, extra := range a.extraOutputFiles { - ctx.InstallFile(a.installDir, extra.Base(), extra) + installed := ctx.InstallFile(a.installDir, extra.Base(), extra) + extraInstalledPaths = append(extraInstalledPaths, installed) } + ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile, extraInstalledPaths...) } a.buildAppDependencyInfo(ctx) diff --git a/java/app_import.go b/java/app_import.go index 3e5f972a4..4d1969ebb 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -108,6 +108,8 @@ func (a *AndroidAppImport) IsInstallable() bool { return true } +func (a *AndroidAppImport) InstallBypassMake() bool { return true } + // Updates properties with variant-specific values. func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) { config := ctx.Config() diff --git a/java/base.go b/java/base.go index ca34f2eef..6930bcd17 100644 --- a/java/base.go +++ b/java/base.go @@ -407,6 +407,9 @@ type Module struct { // installed file for binary dependency installFile android.Path + // installed file for hostdex copy + hostdexInstallFile android.InstallPath + // list of .java files and srcjars that was passed to javac compiledJavaSrcs android.Paths compiledSrcJars android.Paths @@ -784,6 +787,9 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt flags = append(flags, "--transaction_names") } + aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String() + flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion) + return strings.Join(flags, " "), deps } diff --git a/java/dexpreopt.go b/java/dexpreopt.go index e9dc982c7..7c081b6e5 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -66,6 +66,7 @@ type dexpreopter struct { isApp bool isTest bool isPresignedPrebuilt bool + preventInstall bool manifestFile android.Path statusFile android.WritablePath @@ -335,17 +336,19 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr dexpreoptRule.Build("dexpreopt", "dexpreopt") - if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { - // APEX variants of java libraries are hidden from Make, so their dexpreopt outputs need special - // handling. Currently, for APEX variants of java libraries, only those in the system server - // classpath are handled here. Preopting of boot classpath jars in the ART APEX are handled in - // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. - for _, install := range dexpreoptRule.Installs() { - // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. - installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") - installBase := filepath.Base(install.To) - arch := filepath.Base(installDir) - installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) + for _, install := range dexpreoptRule.Installs() { + // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. + installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") + installBase := filepath.Base(install.To) + arch := filepath.Base(installDir) + installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) + + if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { + // APEX variants of java libraries are hidden from Make, so their dexpreopt + // outputs need special handling. Currently, for APEX variants of java + // libraries, only those in the system server classpath are handled here. + // Preopting of boot classpath jars in the ART APEX are handled in + // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. // The installs will be handled by Make as sub-modules of the java library. d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ name: arch + "-" + installBase, @@ -354,10 +357,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr installDirOnDevice: installPath, installFileOnDevice: installBase, }) + } else if !d.preventInstall { + ctx.InstallFile(installPath, installBase, install.From) } - } else { - // The installs will be handled by Make as LOCAL_SOONG_BUILT_INSTALLED of the java library - // module. + } + + if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { d.builtInstalled = dexpreoptRule.Installs().String() } } diff --git a/java/droiddoc.go b/java/droiddoc.go index 869a5982d..c84a15c1f 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -769,8 +769,8 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") - jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") - doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") + jsilver := ctx.Config().HostJavaToolPath(ctx, "jsilver.jar") + doclava := ctx.Config().HostJavaToolPath(ctx, "doclava.jar") outDir := android.PathForModuleOut(ctx, "out") srcJarDir := android.PathForModuleOut(ctx, "srcjars") diff --git a/java/droidstubs.go b/java/droidstubs.go index 0c66ccf40..7ad316fcf 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -16,6 +16,7 @@ package java import ( "fmt" + "path/filepath" "strings" "github.com/google/blueprint/proptools" @@ -805,7 +806,7 @@ type PrebuiltStubsSources struct { properties PrebuiltStubsSourcesProperties - stubsSrcJar android.ModuleOutPath + stubsSrcJar android.Path } func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) { @@ -822,35 +823,39 @@ func (d *PrebuiltStubsSources) StubsSrcJar() android.Path { } func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { - p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") - if len(p.properties.Srcs) != 1 { - ctx.PropertyErrorf("srcs", "must only specify one directory path, contains %d paths", len(p.properties.Srcs)) + ctx.PropertyErrorf("srcs", "must only specify one directory path or srcjar, contains %d paths", len(p.properties.Srcs)) return } - localSrcDir := p.properties.Srcs[0] - // Although PathForModuleSrc can return nil if either the path doesn't exist or - // the path components are invalid it won't in this case because no components - // are specified and the module directory must exist in order to get this far. - srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, localSrcDir) - - // Glob the contents of the directory just in case the directory does not exist. - srcGlob := localSrcDir + "/**/*" - srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) + src := p.properties.Srcs[0] + if filepath.Ext(src) == ".srcjar" { + // This is a srcjar. We can use it directly. + p.stubsSrcJar = android.PathForModuleSrc(ctx, src) + } else { + outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") - rule := android.NewRuleBuilder(pctx, ctx) - rule.Command(). - BuiltTool("soong_zip"). - Flag("-write_if_changed"). - Flag("-jar"). - FlagWithOutput("-o ", p.stubsSrcJar). - FlagWithArg("-C ", srcDir.String()). - FlagWithRspFileInputList("-r ", p.stubsSrcJar.ReplaceExtension(ctx, "rsp"), srcPaths) + // This is a directory. Glob the contents just in case the directory does not exist. + srcGlob := src + "/**/*" + srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) - rule.Restat() + // Although PathForModuleSrc can return nil if either the path doesn't exist or + // the path components are invalid it won't in this case because no components + // are specified and the module directory must exist in order to get this far. + srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, src) - rule.Build("zip src", "Create srcjar from prebuilt source") + rule := android.NewRuleBuilder(pctx, ctx) + rule.Command(). + BuiltTool("soong_zip"). + Flag("-write_if_changed"). + Flag("-jar"). + FlagWithOutput("-o ", outPath). + FlagWithArg("-C ", srcDir.String()). + FlagWithRspFileInputList("-r ", outPath.ReplaceExtension(ctx, "rsp"), srcPaths) + rule.Restat() + rule.Build("zip src", "Create srcjar from prebuilt source") + p.stubsSrcJar = outPath + } } func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt { diff --git a/java/java.go b/java/java.go index 854097b0a..2f9e03a80 100644 --- a/java/java.go +++ b/java/java.go @@ -265,6 +265,8 @@ func (j *Module) XrefJavaFiles() android.Paths { return j.kytheFiles } +func (j *Module) InstallBypassMake() bool { return true } + type dependencyTag struct { blueprint.BaseDependencyTag name string @@ -567,8 +569,23 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { if j.InstallMixin != nil { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) } - j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - j.Stem()+".jar", j.outputFile, extraInstallDeps...) + hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host() + if hostDexNeeded { + j.hostdexInstallFile = ctx.InstallFile( + android.PathForHostDexInstall(ctx, "framework"), + j.Stem()+"-hostdex.jar", j.outputFile) + } + var installDir android.InstallPath + if ctx.InstallInTestcases() { + var archDir string + if !ctx.Host() { + archDir = ctx.DeviceConfig().DeviceArch() + } + installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + } else { + installDir = android.PathForModuleInstall(ctx, "framework") + } + j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) } } @@ -842,6 +859,20 @@ type JavaTestImport struct { dexJarFile android.Path } +func (j *Test) InstallInTestcases() bool { + // Host java tests install into $(HOST_OUT_JAVA_LIBRARIES), and then are copied into + // testcases by base_rules.mk. + return !j.Host() +} + +func (j *TestHelperLibrary) InstallInTestcases() bool { + return true +} + +func (j *JavaTestImport) InstallInTestcases() bool { + return true +} + func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { if len(j.testHostProperties.Data_native_bins) > 0 { for _, target := range ctx.MultiTargets() { @@ -1376,8 +1407,17 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { }) if Bool(j.properties.Installable) { - ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - jarName, outputFile) + var installDir android.InstallPath + if ctx.InstallInTestcases() { + var archDir string + if !ctx.Host() { + archDir = ctx.DeviceConfig().DeviceArch() + } + installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + } else { + installDir = android.PathForModuleInstall(ctx, "framework") + } + ctx.InstallFile(installDir, jarName, outputFile) } j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) diff --git a/java/java_test.go b/java/java_test.go index bc9b40964..c039f7246 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1357,6 +1357,36 @@ func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { } } +func TestAidlFlagsWithMinSdkVersion(t *testing.T) { + fixture := android.GroupFixturePreparers( + prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{"14": {"foo"}})) + + for _, tc := range []struct { + name string + sdkVersion string + expected string + }{ + {"default is current", "", "current"}, + {"use sdk_version", `sdk_version: "14"`, "14"}, + {"system_current", `sdk_version: "system_current"`, "current"}, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := fixture.RunTestWithBp(t, ` + java_library { + name: "foo", + srcs: ["aidl/foo/IFoo.aidl"], + `+tc.sdkVersion+` + } + `) + aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + expectedAidlFlag := "--min_sdk_version=" + tc.expected + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } + }) + } +} + func TestDataNativeBinaries(t *testing.T) { ctx, _ := testJava(t, ` java_test_host { diff --git a/java/jdeps.go b/java/jdeps.go index 0ab2e422b..eff9a3174 100644 --- a/java/jdeps.go +++ b/java/jdeps.go @@ -40,16 +40,11 @@ type jdepsGeneratorSingleton struct { var _ android.SingletonMakeVarsProvider = (*jdepsGeneratorSingleton)(nil) const ( - // Environment variables used to modify behavior of this singleton. - envVariableCollectJavaDeps = "SOONG_COLLECT_JAVA_DEPS" - jdepsJsonFileName = "module_bp_java_deps.json" + jdepsJsonFileName = "module_bp_java_deps.json" ) func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonContext) { - if !ctx.Config().IsEnvTrue(envVariableCollectJavaDeps) { - return - } - + // (b/204397180) Generate module_bp_java_deps.json by default. moduleInfos := make(map[string]android.IdeInfo) ctx.VisitAllModules(func(module android.Module) { diff --git a/java/sdk.go b/java/sdk.go index 697deb1ec..e6bf220b4 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -141,11 +141,13 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) } } - toModule := func(systemModules string, module string, aidl android.Path) sdkDep { + toModule := func(module string, aidl android.Path) sdkDep { + // Select the kind of system modules needed for the sdk version. + systemModulesKind := systemModuleKind(sdkVersion.Kind, android.FutureApiLevel) return sdkDep{ useModule: true, bootclasspath: []string{module, config.DefaultLambdaStubsLibrary}, - systemModules: systemModules, + systemModules: fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind), java9Classpath: []string{module}, frameworkResModule: "framework-res", aidl: android.OptionalPathForPath(aidl), @@ -186,11 +188,11 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) noFrameworksLibs: true, } case android.SdkPublic: - return toModule("core-public-stubs-system-modules", "android_stubs_current", sdkFrameworkAidlPath(ctx)) + return toModule("android_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkSystem: - return toModule("core-public-stubs-system-modules", "android_system_stubs_current", sdkFrameworkAidlPath(ctx)) + return toModule("android_system_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkTest: - return toModule("core-public-stubs-system-modules", "android_test_stubs_current", sdkFrameworkAidlPath(ctx)) + return toModule("android_test_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkCore: return sdkDep{ useModule: true, @@ -200,10 +202,10 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) } case android.SdkModule: // TODO(146757305): provide .apk and .aidl that have more APIs for modules - return toModule("core-module-lib-stubs-system-modules", "android_module_lib_stubs_current", nonUpdatableFrameworkAidlPath(ctx)) + return toModule("android_module_lib_stubs_current", nonUpdatableFrameworkAidlPath(ctx)) case android.SdkSystemServer: // TODO(146757305): provide .apk and .aidl that have more APIs for modules - return toModule("core-module-lib-stubs-system-modules", "android_system_server_stubs_current", sdkFrameworkAidlPath(ctx)) + return toModule("android_system_server_stubs_current", sdkFrameworkAidlPath(ctx)) default: panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw)) } diff --git a/java/sdk_library.go b/java/sdk_library.go index 273efec13..d7f14d659 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -361,13 +361,14 @@ type ApiScopeProperties struct { // The sdk_version to use for building the stubs. // // If not specified then it will use an sdk_version determined as follows: + // // 1) If the sdk_version specified on the java_sdk_library is none then this - // will be none. This is used for java_sdk_library instances that are used - // to create stubs that contribute to the core_current sdk version. - // 2) Otherwise, it is assumed that this library extends but does not contribute - // directly to a specific sdk_version and so this uses the sdk_version appropriate - // for the api scope. e.g. public will use sdk_version: current, system will use - // sdk_version: system_current, etc. + // will be none. This is used for java_sdk_library instances that are used + // to create stubs that contribute to the core_current sdk version. + // 2) Otherwise, it is assumed that this library extends but does not + // contribute directly to a specific sdk_version and so this uses the + // sdk_version appropriate for the api scope. e.g. public will use + // sdk_version: current, system will use sdk_version: system_current, etc. // // This does not affect the sdk_version used for either generating the stubs source // or the API file. They both have to use the same sdk_version as is used for |