diff options
Diffstat (limited to 'java')
| -rwxr-xr-x | java/app.go | 42 | ||||
| -rw-r--r-- | java/app_builder.go | 6 | ||||
| -rw-r--r-- | java/app_test.go | 92 | ||||
| -rw-r--r-- | java/dexpreopt_bootjars_test.go | 6 | ||||
| -rw-r--r-- | java/hiddenapi_singleton.go | 23 | ||||
| -rw-r--r-- | java/java.go | 33 | ||||
| -rw-r--r-- | java/java_test.go | 143 | ||||
| -rw-r--r-- | java/sdk_test.go | 16 | ||||
| -rw-r--r-- | java/sysprop.go | 60 | ||||
| -rw-r--r-- | java/testing.go | 104 |
10 files changed, 322 insertions, 203 deletions
diff --git a/java/app.go b/java/app.go index 9fa7179fd..ae637fd7f 100755 --- a/java/app.go +++ b/java/app.go @@ -167,18 +167,11 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { a.aapt.deps(ctx, sdkDep) } + tag := &jniDependencyTag{} for _, jniTarget := range ctx.MultiTargets() { variation := append(jniTarget.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) - tag := &jniDependencyTag{ - target: jniTarget, - } ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) - if String(a.appProperties.Stl) == "c++_shared" { - if a.shouldEmbedJnis(ctx) { - ctx.AddFarVariationDependencies(variation, tag, "ndk_libc++_shared") - } - } } a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs()) @@ -471,7 +464,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { dexJarFile := a.dexBuildActions(ctx) - jniLibs, certificateDeps := collectAppDeps(ctx) + jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx)) jniJarFile := a.jniBuildActions(jniLibs, ctx) if ctx.Failed() { @@ -507,22 +500,33 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { } } -func collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) { +func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool) ([]jniLib, []Certificate) { var jniLibs []jniLib var certificates []Certificate + seenModulePaths := make(map[string]bool) - ctx.VisitDirectDeps(func(module android.Module) { + ctx.WalkDeps(func(module android.Module, parent android.Module) bool { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) - if jniTag, ok := tag.(*jniDependencyTag); ok { + if IsJniDepTag(tag) || tag == cc.SharedDepTag { if dep, ok := module.(*cc.Module); ok { + if dep.IsNdk() || dep.IsStubs() { + return false + } + lib := dep.OutputFile() + path := lib.Path() + if seenModulePaths[path.String()] { + return false + } + seenModulePaths[path.String()] = true + if lib.Valid() { jniLibs = append(jniLibs, jniLib{ name: ctx.OtherModuleName(module), - path: lib.Path(), - target: jniTag.target, + path: path, + target: module.Target(), }) } else { ctx.ModuleErrorf("dependency %q missing output file", otherName) @@ -530,13 +534,19 @@ func collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) { } else { ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) } - } else if tag == certificateTag { + + return shouldCollectRecursiveNativeDeps + } + + if tag == certificateTag { if dep, ok := module.(*AndroidAppCertificate); ok { certificates = append(certificates, dep.Certificate) } else { ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) } } + + return false }) return jniLibs, certificates @@ -968,7 +978,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set") } - _, certificates := collectAppDeps(ctx) + _, certificates := collectAppDeps(ctx, false) // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK // TODO: LOCAL_PACKAGE_SPLITS diff --git a/java/app_builder.go b/java/app_builder.go index ec2f6dafe..5e7fbe6de 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -200,14 +200,14 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl } if uncompressJNI { - jarArgs = append(jarArgs, "-L 0") + jarArgs = append(jarArgs, "-L", "0") } for _, j := range jniLibs { deps = append(deps, j.path) jarArgs = append(jarArgs, - "-P "+targetToJniDir(j.target), - "-f "+j.path.String()) + "-P", targetToJniDir(j.target), + "-f", j.path.String()) } ctx.Build(pctx, android.BuildParams{ diff --git a/java/app_test.go b/java/app_test.go index 1800bb73b..9bdef4e92 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -43,7 +43,7 @@ var ( } ) -func testAppContext(bp string, fs map[string][]byte) *android.TestContext { +func testAppConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { appFS := map[string][]byte{} for k, v := range fs { appFS[k] = v @@ -53,13 +53,13 @@ func testAppContext(bp string, fs map[string][]byte) *android.TestContext { appFS[file] = nil } - return testContext(bp, appFS) + return testConfig(env, bp, appFS) } func testApp(t *testing.T, bp string) *android.TestContext { - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) @@ -301,8 +301,8 @@ func TestResourceDirs(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - config := testConfig(nil) - ctx := testContext(fmt.Sprintf(bp, testCase.prop), fs) + config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs) + ctx := testContext() run(t, ctx, config) module := ctx.ModuleForTests("foo", "android_common") @@ -509,7 +509,7 @@ func TestAndroidResources(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - config := testConfig(nil) + config := testAppConfig(nil, bp, fs) config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays config.TestProductVariables.ProductResourceOverlays = productResourceOverlays if testCase.enforceRROTargets != nil { @@ -519,7 +519,7 @@ func TestAndroidResources(t *testing.T) { config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays } - ctx := testAppContext(bp, fs) + ctx := testContext() run(t, ctx, config) resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { @@ -649,12 +649,12 @@ func TestAppSdkVersion(t *testing.T) { %s }`, moduleType, test.sdkVersion, platformApiProp) - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) @@ -777,9 +777,6 @@ func TestAppSdkVersionByPartition(t *testing.T) { `) for _, enforce := range []bool{true, false} { - - config := testConfig(nil) - config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) bp := ` android_app { name: "foo", @@ -788,10 +785,13 @@ func TestAppSdkVersionByPartition(t *testing.T) { platform_apis: true, } ` + + config := testAppConfig(nil, bp, nil) + config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) if enforce { - testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config) + testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config) } else { - testJavaWithConfig(t, bp, config) + testJavaWithConfig(t, config) } } } @@ -954,11 +954,11 @@ func TestCertificates(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - config := testConfig(nil) + config := testAppConfig(nil, test.bp, nil) if test.certificateOverride != "" { config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride} } - ctx := testAppContext(test.bp, nil) + ctx := testContext() run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -1014,11 +1014,11 @@ func TestPackageNameOverride(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - config := testConfig(nil) + config := testAppConfig(nil, test.bp, nil) if test.packageNameOverride != "" { config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride} } - ctx := testAppContext(test.bp, nil) + ctx := testContext() run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -1051,9 +1051,9 @@ func TestInstrumentationTargetOverridden(t *testing.T) { sdk_version: "current", } ` - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) @@ -1471,10 +1471,10 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") for _, test := range testCases { - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) @@ -1631,7 +1631,45 @@ func TestAndroidTestImport(t *testing.T) { func TestStl(t *testing.T) { ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { + name: "ndk_libunwind", + sdk_version: "current", + stl: "none", + system_shared_libs: [], + } + + cc_library { + name: "libc.ndk.current", + sdk_version: "current", + stl: "none", + system_shared_libs: [], + } + + cc_library { + name: "libm.ndk.current", + sdk_version: "current", + stl: "none", + system_shared_libs: [], + } + + cc_library { + name: "libdl.ndk.current", + sdk_version: "current", + stl: "none", + system_shared_libs: [], + } + + cc_object { + name: "ndk_crtbegin_so.27", + } + + cc_object { + name: "ndk_crtend_so.27", + } + + cc_library { name: "libjni", + sdk_version: "current", + stl: "c++_shared", } android_test { @@ -1732,10 +1770,10 @@ func TestUsesLibraries(t *testing.T) { } ` - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) config.TestProductVariables.MissingUsesLibraries = []string{"baz"} - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) @@ -2006,12 +2044,12 @@ func TestUncompressDex(t *testing.T) { test := func(t *testing.T, bp string, want bool, unbundled bool) { t.Helper() - config := testConfig(nil) + config := testAppConfig(nil, bp, nil) if unbundled { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } - ctx := testAppContext(bp, nil) + ctx := testContext() run(t, ctx, config) diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index 29a5abe7f..8f29e9eee 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -44,14 +44,14 @@ func TestDexpreoptBootJars(t *testing.T) { } ` - config := testConfig(nil) + config := testConfig(nil, bp, nil) - pathCtx := android.PathContextForTesting(config, nil) + pathCtx := android.PathContextForTesting(config) dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) dexpreoptConfig.ArtApexJars = []string{"foo", "bar", "baz"} setDexpreoptTestGlobalConfig(config, dexpreoptConfig) - ctx := testContext(bp, nil) + ctx := testContext() ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory) diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index e9e4a45b0..ad84cdea2 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -16,7 +16,6 @@ package java import ( "fmt" - "strings" "android/soong/android" ) @@ -153,23 +152,11 @@ func stubFlagsRule(ctx android.SingletonContext) { // Collect dex jar paths for modules that had hiddenapi encode called on them. if h, ok := module.(hiddenAPIIntf); ok { if jar := h.bootDexJar(); jar != nil { - // Don't add multiple variants of the same library to bootDexJars, otherwise - // hiddenapi tool will complain about duplicated classes. Such multiple variants - // of the same library can happen when the library is included in one or more APEXes. - // TODO(b/146308764): remove this heuristic - if a, ok := module.(android.ApexModule); ok && android.InAnyApex(module.Name()) { - if a.AvailableFor("//apex_available:platform") && !a.IsForPlatform() { - // skip the apex variants if the jar is available for the platform - return - } - apexName := a.ApexName() - if strings.Contains(apexName, "test") { - // skip the if the jar is in test APEX - return - } - - if strings.Contains(apexName, "com.android.art") && apexName != "com.android.art.release" { - // skip the ART APEX variants other than com.android.art.release + // For a java lib included in an APEX, only take the one built for + // the platform variant, and skip the variants for APEXes. + // Otherwise, the hiddenapi tool will complain about duplicated classes + if a, ok := module.(android.ApexModule); ok { + if android.InAnyApex(module.Name()) && !a.IsForPlatform() { return } } diff --git a/java/java.go b/java/java.go index 59bfaf758..052e06f6f 100644 --- a/java/java.go +++ b/java/java.go @@ -466,7 +466,6 @@ type dependencyTag struct { type jniDependencyTag struct { blueprint.BaseDependencyTag - target android.Target } func IsJniDepTag(depTag blueprint.DependencyTag) bool { @@ -595,8 +594,36 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } } - ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) - ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) + syspropPublicStubs := syspropPublicStubs(ctx.Config()) + + // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library, + // and redirects dependency to public stub depending on the link type. + rewriteSyspropLibs := func(libs []string, prop string) []string { + // make a copy + ret := android.CopyOf(libs) + + for idx, lib := range libs { + stub, ok := syspropPublicStubs[lib] + + if !ok { + continue + } + + linkType, _ := j.getLinkType(ctx.ModuleName()) + if linkType == javaSystem { + ret[idx] = stub + } else if linkType != javaPlatform { + ctx.PropertyErrorf("sdk_version", + "can't link against sysprop_library %q from a module using public or core API", + lib) + } + } + + return ret + } + + ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...) + ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) diff --git a/java/java_test.go b/java/java_test.go index 4a549e6c8..49838c7c7 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -56,11 +56,11 @@ func TestMain(m *testing.M) { os.Exit(run()) } -func testConfig(env map[string]string) android.Config { - return TestConfig(buildDir, env) +func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { + return TestConfig(buildDir, env, bp, fs) } -func testContext(bp string, fs map[string][]byte) *android.TestContext { +func testContext() *android.TestContext { ctx := android.NewTestArchContext() ctx.RegisterModuleType("android_app", AndroidAppFactory) @@ -116,119 +116,16 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext { ctx.BottomUp("begin", cc.BeginMutator).Parallel() }) - bp += GatherRequiredDepsForTest() - - mockFS := map[string][]byte{ - "Android.bp": []byte(bp), - "a.java": nil, - "b.java": nil, - "c.java": nil, - "b.kt": nil, - "a.jar": nil, - "b.jar": nil, - "APP_NOTICE": nil, - "GENRULE_NOTICE": nil, - "LIB_NOTICE": nil, - "TOOL_NOTICE": nil, - "java-res/a/a": nil, - "java-res/b/b": nil, - "java-res2/a": nil, - "java-fg/a.java": nil, - "java-fg/b.java": nil, - "java-fg/c.java": nil, - "api/current.txt": nil, - "api/removed.txt": nil, - "api/system-current.txt": nil, - "api/system-removed.txt": nil, - "api/test-current.txt": nil, - "api/test-removed.txt": nil, - "framework/aidl/a.aidl": nil, - - "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so": nil, - - "prebuilts/sdk/14/public/android.jar": nil, - "prebuilts/sdk/14/public/framework.aidl": nil, - "prebuilts/sdk/14/system/android.jar": nil, - "prebuilts/sdk/17/public/android.jar": nil, - "prebuilts/sdk/17/public/framework.aidl": nil, - "prebuilts/sdk/17/system/android.jar": nil, - "prebuilts/sdk/29/public/android.jar": nil, - "prebuilts/sdk/29/public/framework.aidl": nil, - "prebuilts/sdk/29/system/android.jar": nil, - "prebuilts/sdk/current/core/android.jar": nil, - "prebuilts/sdk/current/public/android.jar": nil, - "prebuilts/sdk/current/public/framework.aidl": nil, - "prebuilts/sdk/current/public/core.jar": nil, - "prebuilts/sdk/current/system/android.jar": nil, - "prebuilts/sdk/current/test/android.jar": nil, - "prebuilts/sdk/28/public/api/foo.txt": nil, - "prebuilts/sdk/28/system/api/foo.txt": nil, - "prebuilts/sdk/28/test/api/foo.txt": nil, - "prebuilts/sdk/28/public/api/foo-removed.txt": nil, - "prebuilts/sdk/28/system/api/foo-removed.txt": nil, - "prebuilts/sdk/28/test/api/foo-removed.txt": nil, - "prebuilts/sdk/28/public/api/bar.txt": nil, - "prebuilts/sdk/28/system/api/bar.txt": nil, - "prebuilts/sdk/28/test/api/bar.txt": nil, - "prebuilts/sdk/28/public/api/bar-removed.txt": nil, - "prebuilts/sdk/28/system/api/bar-removed.txt": nil, - "prebuilts/sdk/28/test/api/bar-removed.txt": nil, - "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, - "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`), - - "prebuilts/apk/app.apk": nil, - "prebuilts/apk/app_arm.apk": nil, - "prebuilts/apk/app_arm64.apk": nil, - "prebuilts/apk/app_xhdpi.apk": nil, - "prebuilts/apk/app_xxhdpi.apk": nil, - - // For framework-res, which is an implicit dependency for framework - "AndroidManifest.xml": nil, - "build/make/target/product/security/testkey": nil, - - "build/soong/scripts/jar-wrapper.sh": nil, - - "build/make/core/verify_uses_libraries.sh": nil, - - "build/make/core/proguard.flags": nil, - "build/make/core/proguard_basic_keeps.flags": nil, - - "jdk8/jre/lib/jce.jar": nil, - "jdk8/jre/lib/rt.jar": nil, - "jdk8/lib/tools.jar": nil, - - "bar-doc/a.java": nil, - "bar-doc/b.java": nil, - "bar-doc/IFoo.aidl": nil, - "bar-doc/IBar.aidl": nil, - "bar-doc/known_oj_tags.txt": nil, - "external/doclava/templates-sdk": nil, - - "cert/new_cert.x509.pem": nil, - "cert/new_cert.pk8": nil, - - "testdata/data": nil, - - "stubs-sources/foo/Foo.java": nil, - "stubs/sources/foo/Foo.java": nil, - } - - for k, v := range fs { - mockFS[k] = v - } - - ctx.MockFileSystem(mockFS) - return ctx } func run(t *testing.T, ctx *android.TestContext, config android.Config) { t.Helper() - pathCtx := android.PathContextForTesting(config, nil) + pathCtx := android.PathContextForTesting(config) setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) - ctx.Register() + ctx.Register(config) _, errs := ctx.ParseBlueprintsFiles("Android.bp") android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) @@ -237,17 +134,17 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) { func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) { t.Helper() - return testJavaErrorWithConfig(t, pattern, bp, testConfig(nil)) + return testJavaErrorWithConfig(t, pattern, testConfig(nil, bp, nil)) } -func testJavaErrorWithConfig(t *testing.T, pattern string, bp string, config android.Config) (*android.TestContext, android.Config) { +func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) { t.Helper() - ctx := testContext(bp, nil) + ctx := testContext() - pathCtx := android.PathContextForTesting(config, nil) + pathCtx := android.PathContextForTesting(config) setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) - ctx.Register() + ctx.Register(config) _, errs := ctx.ParseBlueprintsFiles("Android.bp") if len(errs) > 0 { android.FailIfNoMatchingErrors(t, pattern, errs) @@ -266,12 +163,12 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, bp string, config and func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { t.Helper() - return testJavaWithConfig(t, bp, testConfig(nil)) + return testJavaWithConfig(t, testConfig(nil, bp, nil)) } -func testJavaWithConfig(t *testing.T, bp string, config android.Config) (*android.TestContext, android.Config) { +func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) { t.Helper() - ctx := testContext(bp, nil) + ctx := testContext() run(t, ctx, config) return ctx, config @@ -520,9 +417,6 @@ func TestSdkVersionByPartition(t *testing.T) { `) for _, enforce := range []bool{true, false} { - - config := testConfig(nil) - config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) bp := ` java_library { name: "foo", @@ -530,10 +424,13 @@ func TestSdkVersionByPartition(t *testing.T) { product_specific: true, } ` + + config := testConfig(nil, bp, nil) + config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) if enforce { - testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config) + testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config) } else { - testJavaWithConfig(t, bp, config) + testJavaWithConfig(t, config) } } } @@ -1127,8 +1024,7 @@ func TestExcludeFileGroupInSrcs(t *testing.T) { } func TestJavaLibrary(t *testing.T) { - config := testConfig(nil) - ctx := testContext("", map[string][]byte{ + config := testConfig(nil, "", map[string][]byte{ "libcore/Android.bp": []byte(` java_library { name: "core", @@ -1136,6 +1032,7 @@ func TestJavaLibrary(t *testing.T) { system_modules: "none", }`), }) + ctx := testContext() run(t, ctx, config) } diff --git a/java/sdk_test.go b/java/sdk_test.go index 525c89887..9cabd7772 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -327,14 +327,14 @@ func TestClasspath(t *testing.T) { // Test with legacy javac -source 1.8 -target 1.8 t.Run("Java language level 8", func(t *testing.T) { - config := testConfig(nil) + config := testConfig(nil, bpJava8, nil) if testcase.unbundled { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(bpJava8, nil) + ctx := testContext() run(t, ctx, config) checkClasspath(t, ctx, true /* isJava8 */) @@ -350,14 +350,14 @@ func TestClasspath(t *testing.T) { // Test with default javac -source 9 -target 9 t.Run("Java language level 9", func(t *testing.T) { - config := testConfig(nil) + config := testConfig(nil, bp, nil) if testcase.unbundled { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(bp, nil) + ctx := testContext() run(t, ctx, config) checkClasspath(t, ctx, false /* isJava8 */) @@ -373,7 +373,7 @@ func TestClasspath(t *testing.T) { // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8 t.Run("REL + Java language level 8", func(t *testing.T) { - config := testConfig(nil) + config := testConfig(nil, bpJava8, nil) config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) @@ -383,7 +383,7 @@ func TestClasspath(t *testing.T) { if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(bpJava8, nil) + ctx := testContext() run(t, ctx, config) checkClasspath(t, ctx, true /* isJava8 */) @@ -391,7 +391,7 @@ func TestClasspath(t *testing.T) { // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9 t.Run("REL + Java language level 9", func(t *testing.T) { - config := testConfig(nil) + config := testConfig(nil, bp, nil) config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) @@ -401,7 +401,7 @@ func TestClasspath(t *testing.T) { if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(bp, nil) + ctx := testContext() run(t, ctx, config) checkClasspath(t, ctx, false /* isJava8 */) diff --git a/java/sysprop.go b/java/sysprop.go new file mode 100644 index 000000000..1a70499b8 --- /dev/null +++ b/java/sysprop.go @@ -0,0 +1,60 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// 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 ( + "sync" + + "android/soong/android" +) + +type syspropLibraryInterface interface { + BaseModuleName() string + Owner() string + HasPublicStub() bool + JavaPublicStubName() string +} + +var ( + syspropPublicStubsKey = android.NewOnceKey("syspropPublicStubsJava") + syspropPublicStubsLock sync.Mutex +) + +func init() { + android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("sysprop_java", SyspropMutator).Parallel() + }) +} + +func syspropPublicStubs(config android.Config) map[string]string { + return config.Once(syspropPublicStubsKey, func() interface{} { + return make(map[string]string) + }).(map[string]string) +} + +// gather list of sysprop libraries owned by platform. +func SyspropMutator(mctx android.BottomUpMutatorContext) { + if m, ok := mctx.Module().(syspropLibraryInterface); ok { + if m.Owner() != "Platform" || !m.HasPublicStub() { + return + } + + syspropPublicStubs := syspropPublicStubs(mctx.Config()) + syspropPublicStubsLock.Lock() + defer syspropPublicStubsLock.Unlock() + + syspropPublicStubs[m.BaseModuleName()] = m.JavaPublicStubName() + } +} diff --git a/java/testing.go b/java/testing.go index acbefb92c..c9f59054e 100644 --- a/java/testing.go +++ b/java/testing.go @@ -20,14 +20,114 @@ import ( "android/soong/android" ) -func TestConfig(buildDir string, env map[string]string) android.Config { +func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) android.Config { + bp += GatherRequiredDepsForTest() + + mockFS := map[string][]byte{ + "a.java": nil, + "b.java": nil, + "c.java": nil, + "b.kt": nil, + "a.jar": nil, + "b.jar": nil, + "APP_NOTICE": nil, + "GENRULE_NOTICE": nil, + "LIB_NOTICE": nil, + "TOOL_NOTICE": nil, + "java-res/a/a": nil, + "java-res/b/b": nil, + "java-res2/a": nil, + "java-fg/a.java": nil, + "java-fg/b.java": nil, + "java-fg/c.java": nil, + "api/current.txt": nil, + "api/removed.txt": nil, + "api/system-current.txt": nil, + "api/system-removed.txt": nil, + "api/test-current.txt": nil, + "api/test-removed.txt": nil, + "framework/aidl/a.aidl": nil, + + "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so": nil, + + "prebuilts/sdk/14/public/android.jar": nil, + "prebuilts/sdk/14/public/framework.aidl": nil, + "prebuilts/sdk/14/system/android.jar": nil, + "prebuilts/sdk/17/public/android.jar": nil, + "prebuilts/sdk/17/public/framework.aidl": nil, + "prebuilts/sdk/17/system/android.jar": nil, + "prebuilts/sdk/29/public/android.jar": nil, + "prebuilts/sdk/29/public/framework.aidl": nil, + "prebuilts/sdk/29/system/android.jar": nil, + "prebuilts/sdk/current/core/android.jar": nil, + "prebuilts/sdk/current/public/android.jar": nil, + "prebuilts/sdk/current/public/framework.aidl": nil, + "prebuilts/sdk/current/public/core.jar": nil, + "prebuilts/sdk/current/system/android.jar": nil, + "prebuilts/sdk/current/test/android.jar": nil, + "prebuilts/sdk/28/public/api/foo.txt": nil, + "prebuilts/sdk/28/system/api/foo.txt": nil, + "prebuilts/sdk/28/test/api/foo.txt": nil, + "prebuilts/sdk/28/public/api/foo-removed.txt": nil, + "prebuilts/sdk/28/system/api/foo-removed.txt": nil, + "prebuilts/sdk/28/test/api/foo-removed.txt": nil, + "prebuilts/sdk/28/public/api/bar.txt": nil, + "prebuilts/sdk/28/system/api/bar.txt": nil, + "prebuilts/sdk/28/test/api/bar.txt": nil, + "prebuilts/sdk/28/public/api/bar-removed.txt": nil, + "prebuilts/sdk/28/system/api/bar-removed.txt": nil, + "prebuilts/sdk/28/test/api/bar-removed.txt": nil, + "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, + "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`), + + "prebuilts/apk/app.apk": nil, + "prebuilts/apk/app_arm.apk": nil, + "prebuilts/apk/app_arm64.apk": nil, + "prebuilts/apk/app_xhdpi.apk": nil, + "prebuilts/apk/app_xxhdpi.apk": nil, + + // For framework-res, which is an implicit dependency for framework + "AndroidManifest.xml": nil, + "build/make/target/product/security/testkey": nil, + + "build/soong/scripts/jar-wrapper.sh": nil, + + "build/make/core/verify_uses_libraries.sh": nil, + + "build/make/core/proguard.flags": nil, + "build/make/core/proguard_basic_keeps.flags": nil, + + "jdk8/jre/lib/jce.jar": nil, + "jdk8/jre/lib/rt.jar": nil, + "jdk8/lib/tools.jar": nil, + + "bar-doc/a.java": nil, + "bar-doc/b.java": nil, + "bar-doc/IFoo.aidl": nil, + "bar-doc/IBar.aidl": nil, + "bar-doc/known_oj_tags.txt": nil, + "external/doclava/templates-sdk": nil, + + "cert/new_cert.x509.pem": nil, + "cert/new_cert.pk8": nil, + + "testdata/data": nil, + + "stubs-sources/foo/Foo.java": nil, + "stubs/sources/foo/Foo.java": nil, + } + + for k, v := range fs { + mockFS[k] = v + } + if env == nil { env = make(map[string]string) } if env["ANDROID_JAVA8_HOME"] == "" { env["ANDROID_JAVA8_HOME"] = "jdk8" } - config := android.TestArchConfig(buildDir, env) + config := android.TestArchConfig(buildDir, env, bp, mockFS) return config } |