diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/Android.bp | 2 | ||||
| -rw-r--r-- | java/bootclasspath_fragment.go | 2 | ||||
| -rw-r--r-- | java/core-libraries/Android.bp | 59 | ||||
| -rw-r--r-- | java/dexpreopt_check.go | 96 | ||||
| -rw-r--r-- | java/java.go | 3 | ||||
| -rw-r--r-- | java/prebuilt_apis.go | 21 | ||||
| -rw-r--r-- | java/prebuilt_apis_test.go | 56 | ||||
| -rw-r--r-- | java/proto.go | 3 | ||||
| -rw-r--r-- | java/robolectric.go | 12 | ||||
| -rw-r--r-- | java/sdk.go | 65 | ||||
| -rw-r--r-- | java/sdk_test.go | 233 | ||||
| -rw-r--r-- | java/systemserver_classpath_fragment.go | 16 | ||||
| -rw-r--r-- | java/testing.go | 30 |
13 files changed, 494 insertions, 104 deletions
diff --git a/java/Android.bp b/java/Android.bp index 9ffa12384..8835b4456 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -40,6 +40,7 @@ bootstrap_go_package { "dex.go", "dexpreopt.go", "dexpreopt_bootjars.go", + "dexpreopt_check.go", "dexpreopt_config.go", "droiddoc.go", "droidstubs.go", @@ -92,6 +93,7 @@ bootstrap_go_package { "platform_bootclasspath_test.go", "platform_compat_config_test.go", "plugin_test.go", + "prebuilt_apis_test.go", "rro_test.go", "sdk_test.go", "sdk_library_test.go", diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 8f18790ea..bfa683824 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -616,6 +616,8 @@ func (b *BootclasspathFragmentModule) configuredJars(ctx android.ModuleContext) // This is an exception to support end-to-end test for SdkExtensions, until such support exists. if android.InList("test_framework-sdkextensions", possibleUpdatableModules) { jars = jars.Append("com.android.sdkext", "test_framework-sdkextensions") + } else if android.InList("test_framework-apexd", possibleUpdatableModules) { + jars = jars.Append("com.android.apex.test_package", "test_framework-apexd") } else if global.ApexBootJars.Len() != 0 && !android.IsModuleInVersionedSdk(ctx.Module()) { unknown = android.RemoveListFromList(unknown, b.properties.Coverage.Contents) _, unknown = android.RemoveFromList("core-icu4j", unknown) diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp index b198c2456..cf3974601 100644 --- a/java/core-libraries/Android.bp +++ b/java/core-libraries/Android.bp @@ -28,6 +28,11 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +dist_targets = [ + "sdk", + "win_sdk", +] + java_library { name: "core.current.stubs", visibility: ["//visibility:public"], @@ -40,15 +45,16 @@ java_library { system_modules: "none", dist: { - targets: [ - "sdk", - "win_sdk", - ], + targets: dist_targets, }, } // Distributed with the SDK for turning into system modules to compile apps // against. +// +// Also, produces dist files that are used by the +// prebuilts/sdk/update_prebuilts.py script to update the prebuilts/sdk +// directory. java_library { name: "core-current-stubs-for-system-modules", visibility: ["//development/sdk"], @@ -65,18 +71,22 @@ java_library { ], sdk_version: "none", system_modules: "none", - dist: { - dest: "core-for-system-modules.jar", - targets: [ - "sdk", - "win_sdk", - ], - }, + dists: [ + { + // Legacy dist location for the public file. + dest: "core-for-system-modules.jar", + targets: dist_targets, + }, + { + dest: "system-modules/public/core-for-system-modules.jar", + targets: dist_targets, + }, + ], } // Used when compiling higher-level code against core.current.stubs. java_system_modules { - name: "core-current-stubs-system-modules", + name: "core-public-stubs-system-modules", visibility: ["//visibility:public"], libs: [ "core-current-stubs-for-system-modules", @@ -103,10 +113,13 @@ java_library { visibility: ["//visibility:private"], } -// Used when compiling higher-level code with sdk_version "module_current" -java_system_modules { - name: "core-module-lib-stubs-system-modules", - libs: [ +// Produces a dist file that is used by the +// prebuilts/sdk/update_prebuilts.py script to update the prebuilts/sdk +// directory. +java_library { + name: "core-module-lib-stubs-for-system-modules", + visibility: ["//visibility:private"], + static_libs: [ "core.module_lib.stubs", // This one is not on device but it's needed when javac compiles code // containing lambdas. @@ -117,6 +130,20 @@ java_system_modules { // See http://b/123891440. "core-generated-annotation-stubs", ], + sdk_version: "none", + system_modules: "none", + dist: { + dest: "system-modules/module-lib/core-for-system-modules.jar", + targets: dist_targets, + }, +} + +// Used when compiling higher-level code with sdk_version "module_current" +java_system_modules { + name: "core-module-lib-stubs-system-modules", + libs: [ + "core-module-lib-stubs-for-system-modules", + ], visibility: ["//visibility:public"], } diff --git a/java/dexpreopt_check.go b/java/dexpreopt_check.go new file mode 100644 index 000000000..565901d35 --- /dev/null +++ b/java/dexpreopt_check.go @@ -0,0 +1,96 @@ +// Copyright 2021 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "strings" + + "android/soong/android" + "android/soong/dexpreopt" + + "github.com/google/blueprint/pathtools" +) + +func init() { + RegisterDexpreoptCheckBuildComponents(android.InitRegistrationContext) +} + +func RegisterDexpreoptCheckBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterSingletonModuleType("dexpreopt_systemserver_check", dexpreoptSystemserverCheckFactory) +} + +// A build-time check to verify if all compilation artifacts of system server jars are installed +// into the system image. When the check fails, it means that dexpreopting is not working for some +// system server jars and needs to be fixed. +// This singleton module generates a list of the paths to the artifacts based on +// PRODUCT_SYSTEM_SERVER_JARS and PRODUCT_APEX_SYSTEM_SERVER_JARS, and passes it to Make via a +// variable. Make will then do the actual check. +// Currently, it only checks artifacts of modules defined in Soong. Artifacts of modules defined in +// Makefile are generated by a script generated by dexpreopt_gen, and their existence is unknown to +// Make and Ninja. +type dexpreoptSystemserverCheck struct { + android.SingletonModuleBase + + // Mapping from the module name to the install paths to the compilation artifacts. + artifactsByModuleName map[string][]string + + // The install paths to the compilation artifacts. + artifacts []string +} + +func dexpreoptSystemserverCheckFactory() android.SingletonModule { + m := &dexpreoptSystemserverCheck{} + m.artifactsByModuleName = make(map[string][]string) + android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) + return m +} + +func getInstallPath(ctx android.ModuleContext, location string) android.InstallPath { + return android.PathForModuleInPartitionInstall( + ctx, "", strings.TrimPrefix(location, "/")).ToMakePath() +} + +func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.ModuleContext) { + global := dexpreopt.GetGlobalConfig(ctx) + targets := ctx.Config().Targets[android.Android] + + // The check should be skipped on unbundled builds because system server jars are not preopted on + // unbundled builds since the artifacts are installed into the system image, not the APEXes. + if global.DisablePreopt || len(targets) == 0 || ctx.Config().UnbundledBuild() { + return + } + + systemServerJars := dexpreopt.AllSystemServerJars(ctx, global) + for _, jar := range systemServerJars.CopyOfJars() { + dexLocation := dexpreopt.GetSystemServerDexLocation(global, jar) + odexLocation := dexpreopt.ToOdexPath(dexLocation, targets[0].Arch.ArchType) + odexPath := getInstallPath(ctx, odexLocation) + vdexPath := getInstallPath(ctx, pathtools.ReplaceExtension(odexLocation, "vdex")) + m.artifactsByModuleName[jar] = []string{odexPath.String(), vdexPath.String()} + } +} + +func (m *dexpreoptSystemserverCheck) GenerateSingletonBuildActions(ctx android.SingletonContext) { + // Only keep modules defined in Soong. + ctx.VisitAllModules(func(module android.Module) { + if artifacts, ok := m.artifactsByModuleName[module.Name()]; ok { + m.artifacts = append(m.artifacts, artifacts...) + } + }) +} + +func (m *dexpreoptSystemserverCheck) MakeVars(ctx android.MakeVarsContext) { + ctx.Strict("DEXPREOPT_SYSTEMSERVER_ARTIFACTS", strings.Join(m.artifacts, " ")) +} diff --git a/java/java.go b/java/java.go index 29f31e5b6..854097b0a 100644 --- a/java/java.go +++ b/java/java.go @@ -1540,9 +1540,6 @@ var _ android.IDEInfo = (*Import)(nil) var _ android.IDECustomizedModuleName = (*Import)(nil) // Collect information for opening IDE project files in java/jdeps.go. -const ( - removedPrefix = "prebuilt_" -) func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index c33e6c229..c67e2bd59 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -167,30 +167,24 @@ func prebuiltSdkStubs(mctx android.LoadHookContext, p *prebuiltApis) { localPath := strings.TrimPrefix(f, mydir) module, apiver, scope := parseJarPath(localPath) createImport(mctx, module, scope, apiver, localPath, sdkVersion, compileDex) + + if module == "core-for-system-modules" { + createSystemModules(mctx, apiver, scope) + } } } -func createSystemModules(mctx android.LoadHookContext, apiver string) { +func createSystemModules(mctx android.LoadHookContext, apiver string, scope string) { props := struct { Name *string Libs []string }{} - props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, "system_modules", "public", apiver)) - props.Libs = append(props.Libs, prebuiltApiModuleName(mctx, "core-for-system-modules", "public", apiver)) + props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, "system_modules", scope, apiver)) + props.Libs = append(props.Libs, prebuiltApiModuleName(mctx, "core-for-system-modules", scope, apiver)) mctx.CreateModule(systemModulesImportFactory, &props) } -func prebuiltSdkSystemModules(mctx android.LoadHookContext, p *prebuiltApis) { - for _, apiver := range p.properties.Api_dirs { - jar := android.ExistentPathForSource(mctx, - mctx.ModuleDir(), apiver, "public", "core-for-system-modules.jar") - if jar.Valid() { - createSystemModules(mctx, apiver) - } - } -} - func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { mydir := mctx.ModuleDir() + "/" // <apiver>/<scope>/api/<module>.txt @@ -273,7 +267,6 @@ func createPrebuiltApiModules(mctx android.LoadHookContext) { if p, ok := mctx.Module().(*prebuiltApis); ok { prebuiltApiFiles(mctx, p) prebuiltSdkStubs(mctx, p) - prebuiltSdkSystemModules(mctx, p) } } diff --git a/java/prebuilt_apis_test.go b/java/prebuilt_apis_test.go new file mode 100644 index 000000000..79f42250b --- /dev/null +++ b/java/prebuilt_apis_test.go @@ -0,0 +1,56 @@ +// Copyright 2021 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "sort" + "strings" + "testing" + + "android/soong/android" + "github.com/google/blueprint" +) + +func TestPrebuiltApis_SystemModulesCreation(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + FixtureWithPrebuiltApis(map[string][]string{ + "31": {}, + "32": {}, + "current": {}, + }), + ).RunTest(t) + + sdkSystemModules := []string{} + result.VisitAllModules(func(module blueprint.Module) { + name := android.RemoveOptionalPrebuiltPrefix(module.Name()) + if strings.HasPrefix(name, "sdk_") && strings.HasSuffix(name, "_system_modules") { + sdkSystemModules = append(sdkSystemModules, name) + } + }) + sort.Strings(sdkSystemModules) + expected := []string{ + // 31 only has public system modules. + "sdk_public_31_system_modules", + + // 32 and current both have public and module-lib system modules. + "sdk_public_32_system_modules", + "sdk_module-lib_32_system_modules", + "sdk_public_current_system_modules", + "sdk_module-lib_current_system_modules", + } + sort.Strings(expected) + android.AssertArrayString(t, "sdk system modules", expected, sdkSystemModules) +} diff --git a/java/proto.go b/java/proto.go index 2fa22b626..ab913d868 100644 --- a/java/proto.go +++ b/java/proto.go @@ -102,6 +102,9 @@ func protoFlags(ctx android.ModuleContext, j *CommonProperties, p *android.Proto if String(p.Proto.Plugin) == "" { var typeToPlugin string switch String(p.Proto.Type) { + case "stream": + flags.proto.OutTypeFlag = "--javastream_out" + typeToPlugin = "javastream" case "micro": flags.proto.OutTypeFlag = "--javamicro_out" typeToPlugin = "javamicro" diff --git a/java/robolectric.go b/java/robolectric.go index a3603adf8..16af546ba 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -212,13 +212,7 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) installDeps = append(installDeps, installedData) } - installed := ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.combinedJar, installDeps...) - - if r.ExportedToMake() { - // Soong handles installation here, but Make is usually what creates the phony rule that atest - // uses to build the module. Create it here for now. - ctx.Phony(ctx.ModuleName(), installed) - } + r.installFile = ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.combinedJar, installDeps...) } func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, @@ -282,6 +276,10 @@ func (r *robolectricTest) generateRoboSrcJar(ctx android.ModuleContext, outputFi func (r *robolectricTest) AndroidMkEntries() []android.AndroidMkEntries { entriesList := r.Library.AndroidMkEntries() entries := &entriesList[0] + entries.ExtraEntries = append(entries.ExtraEntries, + func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { + entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) + }) entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{ func(w io.Writer, name, prefix, moduleDir string) { diff --git a/java/sdk.go b/java/sdk.go index 80f2d6a69..e6bf220b4 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -60,6 +60,30 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe } } +// systemModuleKind returns the kind of system modules to use for the supplied combination of sdk +// kind and API level. +func systemModuleKind(sdkKind android.SdkKind, apiLevel android.ApiLevel) android.SdkKind { + systemModuleKind := sdkKind + if apiLevel.LessThanOrEqualTo(android.LastWithoutModuleLibCoreSystemModules) { + // API levels less than or equal to 31 did not provide a core-for-system-modules.jar + // specifically for the module-lib API. So, always use the public system modules for them. + systemModuleKind = android.SdkPublic + } else if systemModuleKind == android.SdkCore { + // Core is by definition what is included in the system module for the public API so should + // just use its system modules. + systemModuleKind = android.SdkPublic + } else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest { + // The core system and test APIs are currently the same as the public API so they should use + // its system modules. + systemModuleKind = android.SdkPublic + } else if systemModuleKind == android.SdkSystemServer { + // The core system server API is the same as the core module-lib API. + systemModuleKind = android.SdkModule + } + + return systemModuleKind +} + func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep { sdkVersion := sdkContext.SdkVersion(ctx) if !sdkVersion.Valid() { @@ -105,7 +129,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) var systemModules string if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() { - systemModules = "sdk_public_" + sdkVersion.ApiLevel.String() + "_system_modules" + systemModuleKind := systemModuleKind(sdkVersion.Kind, sdkVersion.ApiLevel) + systemModules = fmt.Sprintf("sdk_%s_%s_system_modules", systemModuleKind, sdkVersion.ApiLevel) } return sdkDep{ @@ -116,13 +141,15 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) } } - toModule := func(modules []string, res 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: append(modules, config.DefaultLambdaStubsLibrary), - systemModules: "core-current-stubs-system-modules", - java9Classpath: modules, - frameworkResModule: res, + bootclasspath: []string{module, config.DefaultLambdaStubsLibrary}, + systemModules: fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind), + java9Classpath: []string{module}, + frameworkResModule: "framework-res", aidl: android.OptionalPathForPath(aidl), } } @@ -161,38 +188,24 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) noFrameworksLibs: true, } case android.SdkPublic: - return toModule([]string{"android_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) + return toModule("android_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkSystem: - return toModule([]string{"android_system_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) + return toModule("android_system_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkTest: - return toModule([]string{"android_test_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) + return toModule("android_test_stubs_current", sdkFrameworkAidlPath(ctx)) case android.SdkCore: return sdkDep{ useModule: true, bootclasspath: []string{"core.current.stubs", config.DefaultLambdaStubsLibrary}, - systemModules: "core-current-stubs-system-modules", + systemModules: "core-public-stubs-system-modules", noFrameworksLibs: true, } case android.SdkModule: // TODO(146757305): provide .apk and .aidl that have more APIs for modules - return sdkDep{ - useModule: true, - bootclasspath: []string{"android_module_lib_stubs_current", config.DefaultLambdaStubsLibrary}, - systemModules: "core-module-lib-stubs-system-modules", - java9Classpath: []string{"android_module_lib_stubs_current"}, - frameworkResModule: "framework-res", - aidl: android.OptionalPathForPath(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 sdkDep{ - useModule: true, - bootclasspath: []string{"android_system_server_stubs_current", config.DefaultLambdaStubsLibrary}, - systemModules: "core-module-lib-stubs-system-modules", - java9Classpath: []string{"android_system_server_stubs_current"}, - frameworkResModule: "framework-res", - aidl: android.OptionalPathForPath(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_test.go b/java/sdk_test.go index 6d6213011..9e8ba6ed0 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -25,27 +25,36 @@ import ( "android/soong/java/config" ) +type classpathTestCase struct { + name string + unbundled bool + moduleType string + host android.OsClass + properties string + + // for java 8 + bootclasspath []string + java8classpath []string + + // for java 9 + system string + java9classpath []string + + forces8 bool // if set, javac will always be called with java 8 arguments + + aidl string + + // Indicates how this test case is affected by the setting of Always_use_prebuilt_sdks. + // + // If this is nil then the test case is unaffected by the setting of Always_use_prebuilt_sdks. + // Otherwise, the test case can only be used when + // Always_use_prebuilt_sdks=*forAlwaysUsePrebuiltSdks. + forAlwaysUsePrebuiltSdks *bool +} + func TestClasspath(t *testing.T) { const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl" - var classpathTestcases = []struct { - name string - unbundled bool - moduleType string - host android.OsClass - properties string - - // for java 8 - bootclasspath []string - java8classpath []string - - // for java 9 - system string - java9classpath []string - - forces8 bool // if set, javac will always be called with java 8 arguments - - aidl string - }{ + var classpathTestcases = []classpathTestCase{ { name: "default", bootclasspath: config.StableCorePlatformBootclasspathLibraries, @@ -91,25 +100,52 @@ func TestClasspath(t *testing.T) { aidl: "-pprebuilts/sdk/30/public/framework.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), name: "current", properties: `sdk_version: "current",`, bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"}, - system: "core-current-stubs-system-modules", + system: "core-public-stubs-system-modules", java9classpath: []string{"android_stubs_current"}, aidl: "-pout/soong/framework.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + + name: "current", + properties: `sdk_version: "current",`, + bootclasspath: []string{`""`}, + system: "sdk_public_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", + }, + { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), name: "system_current", properties: `sdk_version: "system_current",`, bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"}, - system: "core-current-stubs-system-modules", + system: "core-public-stubs-system-modules", java9classpath: []string{"android_system_stubs_current"}, aidl: "-pout/soong/framework.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + name: "system_current", + properties: `sdk_version: "system_current",`, + bootclasspath: []string{`""`}, + system: "sdk_public_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", + }, + { name: "system_29", properties: `sdk_version: "system_29",`, bootclasspath: []string{`""`}, @@ -118,7 +154,6 @@ func TestClasspath(t *testing.T) { aidl: "-pprebuilts/sdk/29/public/framework.aidl", }, { - name: "system_30", properties: `sdk_version: "system_30",`, bootclasspath: []string{`""`}, @@ -128,20 +163,57 @@ func TestClasspath(t *testing.T) { aidl: "-pprebuilts/sdk/30/public/framework.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), name: "test_current", properties: `sdk_version: "test_current",`, bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"}, - system: "core-current-stubs-system-modules", + system: "core-public-stubs-system-modules", java9classpath: []string{"android_test_stubs_current"}, aidl: "-pout/soong/framework.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + + name: "test_current", + properties: `sdk_version: "test_current",`, + bootclasspath: []string{`""`}, + system: "sdk_public_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", + }, + { + name: "test_30", + properties: `sdk_version: "test_30",`, + bootclasspath: []string{`""`}, + system: "sdk_public_30_system_modules", + java8classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/30/public/framework.aidl", + }, + { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), name: "core_current", properties: `sdk_version: "core_current",`, bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, - system: "core-current-stubs-system-modules", + system: "core-public-stubs-system-modules", + }, + { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + + name: "core_current", + properties: `sdk_version: "core_current",`, + bootclasspath: []string{`""`}, + system: "sdk_public_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", }, { @@ -214,8 +286,10 @@ func TestClasspath(t *testing.T) { java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, aidl: "-pprebuilts/sdk/current/public/framework.aidl", }, - { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), + name: "module_current", properties: `sdk_version: "module_current",`, bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"}, @@ -224,6 +298,48 @@ func TestClasspath(t *testing.T) { aidl: "-pout/soong/framework_non_updatable.aidl", }, { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + + name: "module_current", + properties: `sdk_version: "module_current",`, + bootclasspath: []string{`""`}, + system: "sdk_module-lib_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", + }, + { + name: "module_30", + properties: `sdk_version: "module_30",`, + bootclasspath: []string{`""`}, + system: "sdk_public_30_system_modules", + java8classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/30/public/framework.aidl", + }, + { + name: "module_31", + properties: `sdk_version: "module_31",`, + bootclasspath: []string{`""`}, + system: "sdk_public_31_system_modules", + java8classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/31/public/framework.aidl", + }, + { + name: "module_32", + properties: `sdk_version: "module_32",`, + bootclasspath: []string{`""`}, + system: "sdk_module-lib_32_system_modules", + java8classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/32/public/framework.aidl", + }, + { + // Test case only applies when Always_use_prebuilt_sdks=false (the default). + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false), + name: "system_server_current", properties: `sdk_version: "system_server_current",`, bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"}, @@ -231,9 +347,62 @@ func TestClasspath(t *testing.T) { java9classpath: []string{"android_system_server_stubs_current"}, aidl: "-pout/soong/framework.aidl", }, + { + // Test case only applies when Always_use_prebuilt_sdks=true. + forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true), + + name: "system_server_current", + properties: `sdk_version: "system_server_current",`, + bootclasspath: []string{`""`}, + system: "sdk_module-lib_current_system_modules", + java8classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/current/public/framework.aidl", + }, + { + name: "system_server_30", + properties: `sdk_version: "system_server_30",`, + bootclasspath: []string{`""`}, + system: "sdk_public_30_system_modules", + java8classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/30/public/framework.aidl", + }, + { + name: "system_server_31", + properties: `sdk_version: "system_server_31",`, + bootclasspath: []string{`""`}, + system: "sdk_public_31_system_modules", + java8classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/31/public/framework.aidl", + }, + { + name: "system_server_32", + properties: `sdk_version: "system_server_32",`, + bootclasspath: []string{`""`}, + system: "sdk_module-lib_32_system_modules", + java8classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + java9classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, + aidl: "-pprebuilts/sdk/32/public/framework.aidl", + }, } + t.Run("basic", func(t *testing.T) { + testClasspathTestCases(t, classpathTestcases, false) + }) + + t.Run("Always_use_prebuilt_sdks=true", func(t *testing.T) { + testClasspathTestCases(t, classpathTestcases, true) + }) +} + +func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks bool) { for _, testcase := range classpathTestcases { + if testcase.forAlwaysUsePrebuiltSdks != nil && *testcase.forAlwaysUsePrebuiltSdks != alwaysUsePrebuiltSdks { + continue + } + t.Run(testcase.name, func(t *testing.T) { moduleType := "java_library" if testcase.moduleType != "" { @@ -299,7 +468,9 @@ func TestClasspath(t *testing.T) { system = "--system=none" } else if testcase.system != "" { dir := "" - if strings.HasPrefix(testcase.system, "sdk_public_") { + // If the system modules name starts with sdk_ then it is a prebuilt module and so comes + // from the prebuilt directory. + if strings.HasPrefix(testcase.system, "sdk_") { dir = "prebuilts/sdk" } else { dir = defaultJavaDir @@ -351,11 +522,20 @@ func TestClasspath(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits) } + preparer := android.NullFixturePreparer + if alwaysUsePrebuiltSdks { + preparer = android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) + }) + } + fixtureFactory := android.GroupFixturePreparers( prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{ "29": {}, "30": {}, + "31": {}, + "32": {}, "current": {}, }), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { @@ -369,6 +549,7 @@ func TestClasspath(t *testing.T) { env["ANDROID_JAVA8_HOME"] = "jdk8" } }), + preparer, ) // Test with legacy javac -source 1.8 -target 1.8 diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index f209f4a68..d75635c43 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -120,9 +120,19 @@ func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules) // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore. _, unknown = android.RemoveFromList("geotz", unknown) - - // For non test apexes, make sure that all contents are actually declared in make. - if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) { + // This module only exists in car products. + // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS. + // TODO(b/203233647): Add better mechanism to make it optional. + _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown) + + // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths + // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead, + // we should check if we are creating a config for apex_test via ApexInfo and amend the values. + // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists. + if android.InList("test_service-apexd", possibleUpdatableModules) { + jars = jars.Append("com.android.apex.test_package", "test_service-apexd") + } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) { + // For non test apexes, make sure that all contents are actually declared in make. ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown) } diff --git a/java/testing.go b/java/testing.go index 99d55a054..7441e4497 100644 --- a/java/testing.go +++ b/java/testing.go @@ -159,8 +159,7 @@ func FixtureWithPrebuiltApis(release2Modules map[string][]string) android.Fixtur `, strings.Join(android.SortedStringKeys(release2Modules), `", "`)) for release, modules := range release2Modules { - libs := append([]string{"android", "core-for-system-modules"}, modules...) - mockFS.Merge(prebuiltApisFilesForLibs([]string{release}, libs)) + mockFS.Merge(prebuiltApisFilesForModules([]string{release}, modules)) } return android.GroupFixturePreparers( android.FixtureAddTextFile(path, bp), @@ -168,19 +167,32 @@ func FixtureWithPrebuiltApis(release2Modules map[string][]string) android.Fixtur ) } -func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][]byte { +func prebuiltApisFilesForModules(apiLevels []string, modules []string) map[string][]byte { + libs := append([]string{"android"}, modules...) + fs := make(map[string][]byte) for _, level := range apiLevels { - for _, lib := range sdkLibs { - for _, scope := range []string{"public", "system", "module-lib", "system-server", "test"} { - fs[fmt.Sprintf("prebuilts/sdk/%s/%s/%s.jar", level, scope, lib)] = nil + apiLevel := android.ApiLevelForTest(level) + for _, sdkKind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkModule, android.SdkSystemServer, android.SdkTest} { + // A core-for-system-modules file must only be created for the sdk kind that supports it. + if sdkKind == systemModuleKind(sdkKind, apiLevel) { + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/core-for-system-modules.jar", level, sdkKind)] = nil + } + + for _, lib := range libs { + // Create a jar file for every library. + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/%s.jar", level, sdkKind, lib)] = nil + // No finalized API files for "current" if level != "current" { - fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s.txt", level, scope, lib)] = nil - fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s-removed.txt", level, scope, lib)] = nil + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s.txt", level, sdkKind, lib)] = nil + fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s-removed.txt", level, sdkKind, lib)] = nil } } } + if level == "current" { + fs["prebuilts/sdk/current/core/android.jar"] = nil + } fs[fmt.Sprintf("prebuilts/sdk/%s/public/framework.aidl", level)] = nil } return fs @@ -332,7 +344,7 @@ func gatherRequiredDepsForTest() string { }` systemModules := []string{ - "core-current-stubs-system-modules", + "core-public-stubs-system-modules", "core-module-lib-stubs-system-modules", "legacy-core-platform-api-stubs-system-modules", "stable-core-platform-api-stubs-system-modules", |