diff options
Diffstat (limited to 'java')
60 files changed, 1493 insertions, 733 deletions
diff --git a/java/Android.bp b/java/Android.bp index 885e6825a..911af8336 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -51,6 +51,7 @@ bootstrap_go_package { "gen.go", "generated_java_library.go", "genrule.go", + "genrule_combiner.go", "hiddenapi.go", "hiddenapi_modular.go", "hiddenapi_monolithic.go", @@ -95,6 +96,7 @@ bootstrap_go_package { "droiddoc_test.go", "droidstubs_test.go", "fuzz_test.go", + "genrule_combiner_test.go", "genrule_test.go", "generated_java_library_test.go", "hiddenapi_singleton_test.go", diff --git a/java/aar.go b/java/aar.go index 0a5a4c4d7..f7c5c13de 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1625,14 +1625,21 @@ var _ UsesLibraryDependency = (*AARImport)(nil) var _ android.ApexModule = (*AARImport)(nil) // Implements android.ApexModule -func (a *AARImport) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { - return a.depIsInSameApex(tag) +func (m *AARImport) GetDepInSameApexChecker() android.DepInSameApexChecker { + return AARImportDepInSameApexChecker{} +} + +type AARImportDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m AARImportDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { + return depIsInSameApex(tag) } // Implements android.ApexModule -func (a *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - return nil +func (a *AARImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } var _ android.PrebuiltInterface = (*AARImport)(nil) diff --git a/java/aar_test.go b/java/aar_test.go index 3ac228d35..088ad6c92 100644 --- a/java/aar_test.go +++ b/java/aar_test.go @@ -53,7 +53,7 @@ func TestAarImportProducesJniPackages(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() appMod := ctx.Module(tc.name, "android_common") - appTestMod := ctx.ModuleForTests(tc.name, "android_common") + appTestMod := ctx.ModuleForTests(t, tc.name, "android_common") info, ok := android.OtherModuleProvider(ctx, appMod, JniPackageProvider) if !ok { @@ -117,7 +117,7 @@ func TestLibraryFlagsPackages(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") // android_library module depends on aconfig_declarations listed in flags_packages android.AssertBoolEquals(t, "foo expected to depend on bar", true, @@ -159,9 +159,9 @@ func TestAndroidLibraryOutputFilesRel(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") - bar := result.ModuleForTests("bar", "android_common") - baz := result.ModuleForTests("baz", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") + baz := result.ModuleForTests(t, "baz", "android_common") fooOutputPaths := foo.OutputFiles(result.TestContext, t, "") barOutputPaths := bar.OutputFiles(result.TestContext, t, "") diff --git a/java/android_manifest_test.go b/java/android_manifest_test.go index edb22fcb7..ce227b9c8 100644 --- a/java/android_manifest_test.go +++ b/java/android_manifest_test.go @@ -81,7 +81,7 @@ func TestManifestMerger(t *testing.T) { result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) - manifestMergerRule := result.ModuleForTests("app", "android_common").Rule("manifestMerger") + manifestMergerRule := result.ModuleForTests(t, "app", "android_common").Rule("manifestMerger") android.AssertPathRelativeToTopEquals(t, "main manifest", "out/soong/.intermediates/app/android_common/manifest_fixer/AndroidManifest.xml", manifestMergerRule.Input) @@ -129,7 +129,7 @@ func TestManifestValuesApplicationIdSetsPackageName(t *testing.T) { result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) - manifestMergerRule := result.ModuleForTests("test", "android_common").Rule("manifestMerger") + manifestMergerRule := result.ModuleForTests(t, "test", "android_common").Rule("manifestMerger") android.AssertStringMatches(t, "manifest merger args", manifestMergerRule.Args["args"], diff --git a/java/androidmk.go b/java/androidmk.go index f069e7590..c9de7e6d2 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -120,6 +120,14 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { } }, }, + ExtraFooters: []android.AndroidMkExtraFootersFunc{ + func(w io.Writer, name, prefix, moduleDir string) { + if library.apiXmlFile != nil { + fmt.Fprintf(w, "$(call declare-1p-target,%s,)\n", library.apiXmlFile.String()) + fmt.Fprintf(w, "$(eval $(call copy-one-file,%s,$(TARGET_OUT_COMMON_INTERMEDIATES)/%s))\n", library.apiXmlFile.String(), library.apiXmlFile.Base()) + } + }, + }, }) } @@ -552,8 +560,6 @@ func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries { func(w io.Writer, name, prefix, moduleDir string) { if dstubs.apiLintTimestamp != nil { if dstubs.apiLintReport != nil { - fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint", - dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt") fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String()) } } diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 9306e72a3..b4b13b11a 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -32,7 +32,7 @@ func TestRequired(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_common").Module() + mod := ctx.ModuleForTests(t, "foo", "android_common").Module() entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] expected := []string{"libfoo"} @@ -52,7 +52,7 @@ func TestHostdex(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_common").Module() + mod := ctx.ModuleForTests(t, "foo", "android_common").Module() entriesList := android.AndroidMkEntriesForTest(t, ctx, mod) if len(entriesList) != 2 { t.Errorf("two entries are expected, but got %d", len(entriesList)) @@ -84,7 +84,7 @@ func TestHostdexRequired(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_common").Module() + mod := ctx.ModuleForTests(t, "foo", "android_common").Module() entriesList := android.AndroidMkEntriesForTest(t, ctx, mod) if len(entriesList) != 2 { t.Errorf("two entries are expected, but got %d", len(entriesList)) @@ -120,7 +120,7 @@ func TestHostdexSpecificRequired(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_common").Module() + mod := ctx.ModuleForTests(t, "foo", "android_common").Module() entriesList := android.AndroidMkEntriesForTest(t, ctx, mod) if len(entriesList) != 2 { t.Errorf("two entries are expected, but got %d", len(entriesList)) @@ -158,7 +158,7 @@ func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) { `) // Verify the existence of internal modules - result.ModuleForTests("foo-shared_library.xml", "android_common") + result.ModuleForTests(t, "foo-shared_library.xml", "android_common") testCases := []struct { moduleName string @@ -168,7 +168,7 @@ func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) { {"foo-no_shared_library", []string{"foo-no_shared_library.impl"}}, } for _, tc := range testCases { - mod := result.ModuleForTests(tc.moduleName, "android_common").Module() + mod := result.ModuleForTests(t, tc.moduleName, "android_common").Module() entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] if !reflect.DeepEqual(tc.expected, actual) { @@ -205,7 +205,7 @@ func TestAndroidTestHelperApp_LocalDisableTestConfig(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_common").Module() + mod := ctx.ModuleForTests(t, "foo", "android_common").Module() entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] expected := []string{"true"} @@ -254,7 +254,7 @@ func TestGetOverriddenPackages(t *testing.T) { } for _, expected := range expectedVariants { - mod := ctx.ModuleForTests(expected.name, expected.variantName).Module() + mod := ctx.ModuleForTests(t, expected.name, expected.variantName).Module() entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] actual := entries.EntryMap["LOCAL_OVERRIDES_PACKAGES"] @@ -304,7 +304,7 @@ func TestJniAsRequiredDeps(t *testing.T) { } for _, tc := range testcases { - mod := ctx.ModuleForTests(tc.name, "android_common").Module() + mod := ctx.ModuleForTests(t, tc.name, "android_common").Module() entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)[0] required := entries.EntryMap["LOCAL_REQUIRED_MODULES"] android.AssertDeepEquals(t, "unexpected required deps", tc.expected, required) diff --git a/java/app.go b/java/app.go index abbf034fa..89d688d62 100644 --- a/java/app.go +++ b/java/app.go @@ -512,10 +512,14 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer // The domain of cc.sdk_version is "current" and <number> // We can rely on android.SdkSpec to convert it to <number> so that "current" is // handled properly regardless of sdk finalization. - jniSdkVersion, err := android.SdkSpecFrom(ctx, commonInfo.MinSdkVersion).EffectiveVersion(ctx) + ver := "" + if !commonInfo.MinSdkVersion.IsPlatform { + ver = commonInfo.MinSdkVersion.ApiLevel.String() + } + jniSdkVersion, err := android.SdkSpecFrom(ctx, ver).EffectiveVersion(ctx) if err != nil || minSdkVersion.LessThan(jniSdkVersion) { ctx.OtherModuleErrorf(m, "min_sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)", - commonInfo.MinSdkVersion, minSdkVersion, ctx.ModuleName()) + ver, minSdkVersion, ctx.ModuleName()) return } @@ -1256,7 +1260,7 @@ func (a *AndroidApp) WalkPayloadDeps(ctx android.BaseModuleContext, do android.P // TODO(ccross): Should this use android.DepIsInSameApex? Right now it is applying the android app // heuristics to every transitive dependency, when it should probably be using the heuristics of the // immediate parent. - isExternal := !a.OutgoingDepIsInSameApex(ctx.OtherModuleDependencyTag(child)) + isExternal := !a.GetDepInSameApexChecker().OutgoingDepIsInSameApex(ctx.OtherModuleDependencyTag(child)) if am, ok := child.(android.ApexModule); ok { if !do(ctx, parent, am, isExternal) { return false @@ -1277,7 +1281,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { // Skip dependencies that are only available to APEXes; they are developed with updatability // in mind and don't need manual approval. - if to.(android.ApexModule).NotAvailableForPlatform() { + if android.OtherModuleProviderOrDefault(ctx, to, android.CommonModuleInfoKey).NotAvailableForPlatform { return true } @@ -1287,18 +1291,9 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { depsInfo[depName] = info } else { toMinSdkVersion := "(no version)" - if m, ok := to.(interface { - MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel - }); ok { - if v := m.MinSdkVersion(ctx); !v.IsNone() { - toMinSdkVersion = v.String() - } - } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { - // TODO(b/175678607) eliminate the use of MinSdkVersion returning - // string - if v := m.MinSdkVersion(); v != "" { - toMinSdkVersion = v - } + if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoKey); ok && + !info.MinSdkVersion.IsPlatform && info.MinSdkVersion.ApiLevel != nil { + toMinSdkVersion = info.MinSdkVersion.ApiLevel.String() } depsInfo[depName] = android.ApexModuleDepInfo{ To: depName, @@ -1333,11 +1328,19 @@ func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string { return a.overridableAppProperties.Certificate.GetOrDefault(ctx, "") } -func (a *AndroidApp) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { +func (m *AndroidApp) GetDepInSameApexChecker() android.DepInSameApexChecker { + return AppDepInSameApexChecker{} +} + +type AppDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m AppDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { if IsJniDepTag(tag) { return true } - return a.Library.OutgoingDepIsInSameApex(tag) + return depIsInSameApex(tag) } func (a *AndroidApp) Privileged() bool { diff --git a/java/app_import.go b/java/app_import.go index 352e995e2..919266f28 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -628,7 +628,15 @@ func (a *AndroidAppImport) Privileged() bool { return Bool(a.properties.Privileged) } -func (a *AndroidAppImport) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { +func (m *AndroidAppImport) GetDepInSameApexChecker() android.DepInSameApexChecker { + return AppImportDepInSameApexChecker{} +} + +type AppImportDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m AppImportDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { // android_app_import might have extra dependencies via uses_libs property. // Don't track the dependency as we don't automatically add those libraries // to the classpath. It should be explicitly added to java_libs property of APEX @@ -646,10 +654,8 @@ func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android var _ android.ApexModule = (*AndroidAppImport)(nil) // Implements android.ApexModule -func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // Do not check for prebuilts against the min_sdk_version of enclosing APEX - return nil +func (m *AndroidAppImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } func createVariantGroupType(variants []string, variantGroupName string) reflect.Type { @@ -772,9 +778,27 @@ type AndroidTestImport struct { func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.generateAndroidBuildActions(ctx) + a.updateModuleInfoJSON(ctx) + a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) } +func (a *AndroidTestImport) updateModuleInfoJSON(ctx android.ModuleContext) { + moduleInfoJSON := ctx.ModuleInfoJSON() + moduleInfoJSON.Class = []string{"APPS"} + moduleInfoJSON.CompatibilitySuites = []string{"null-suite"} + if len(a.testProperties.Test_suites) > 0 { + moduleInfoJSON.CompatibilitySuites = a.testProperties.Test_suites + } + moduleInfoJSON.SystemSharedLibs = []string{"none"} + moduleInfoJSON.Tags = []string{"tests"} + moduleInfoJSON.RegisterNameOverride = a.BaseModuleName() + testConfig := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "AndroidTest.xml") + if testConfig.Valid() { + moduleInfoJSON.TestConfig = []string{testConfig.String()} + } +} + func (a *AndroidTestImport) InstallInTestcases() bool { return true } diff --git a/java/app_import_test.go b/java/app_import_test.go index 52ae71979..2600767c1 100644 --- a/java/app_import_test.go +++ b/java/app_import_test.go @@ -38,7 +38,7 @@ func TestAndroidAppImport(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") // Check dexpreopt outputs. if variant.MaybeOutput("dexpreopt/foo/oat/arm64/package.vdex").Rule == nil || @@ -78,7 +78,7 @@ func TestAndroidAppImportWithDefaults(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") // Check dexpreopt outputs. if variant.MaybeOutput("dexpreopt/foo/oat/arm64/package.vdex").Rule == nil || @@ -113,7 +113,7 @@ func TestAndroidAppImport_NoDexPreopt(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") // Check dexpreopt outputs. They shouldn't exist. if variant.MaybeOutput("dexpreopt/foo/oat/arm64/package.vdex").Rule != nil || @@ -141,7 +141,7 @@ func TestAndroidAppImport_Presigned(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") // Check dexpreopt outputs. if variant.MaybeOutput("dexpreopt/foo/oat/arm64/package.vdex").Rule == nil || @@ -181,7 +181,7 @@ func TestAndroidAppImport_SigningLineage(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") signedApk := variant.Output("signed/foo.apk") // Check certificates @@ -223,7 +223,7 @@ func TestAndroidAppImport_SigningLineageFilegroup(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") signedApk := variant.Output("signed/foo.apk") // Check cert signing lineage flag. @@ -253,7 +253,7 @@ func TestAndroidAppImport_DefaultDevCert(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") // Check dexpreopt outputs. if variant.MaybeOutput("dexpreopt/foo/oat/arm64/package.vdex").Rule == nil || @@ -349,7 +349,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { }), ).RunTestWithBp(t, bp) - variant := result.ModuleForTests("foo", "android_common") + variant := result.ModuleForTests(t, "foo", "android_common") input := variant.Output("jnis-uncompressed/foo.apk").Input.String() if strings.HasSuffix(input, test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, input) @@ -433,7 +433,7 @@ func TestAndroidAppImport_Filename(t *testing.T) { } for _, test := range testCases { - variant := ctx.ModuleForTests(test.name, "android_common") + variant := ctx.ModuleForTests(t, test.name, "android_common") if variant.MaybeOutput(test.expected).Rule == nil { t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs()) } @@ -586,7 +586,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { t.Parallel() ctx, _ := testJava(t, test.bp) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") if test.expected == "" { if variant.Module().Enabled(android.PanickingConfigAndErrorContext(ctx)) { t.Error("module should have been disabled, but wasn't") @@ -665,7 +665,7 @@ func TestAndroidAppImport_SoongConfigVariables(t *testing.T) { }), ).RunTestWithBp(t, test.bp).TestContext - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") if test.expected == "" { if variant.Module().Enabled(android.PanickingConfigAndErrorContext(ctx)) { t.Error("module should have been disabled, but wasn't") @@ -704,7 +704,7 @@ func TestAndroidAppImport_overridesDisabledAndroidApp(t *testing.T) { } `) - variant := ctx.ModuleForTests("prebuilt_foo", "android_common") + variant := ctx.ModuleForTests(t, "prebuilt_foo", "android_common") a := variant.Module().(*AndroidAppImport) // The prebuilt module should still be enabled and active even if the source-based counterpart // is disabled. @@ -765,7 +765,7 @@ func TestAndroidAppImport_relativeInstallPath(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { t.Parallel() ctx, _ := testJava(t, bp) - mod := ctx.ModuleForTests(testCase.name, "android_common").Module().(*AndroidAppImport) + mod := ctx.ModuleForTests(t, testCase.name, "android_common").Module().(*AndroidAppImport) android.AssertPathRelativeToTopEquals(t, testCase.errorMessage, testCase.expectedInstallPath, mod.installPath) }) } @@ -782,7 +782,7 @@ func TestAndroidAppImport_ExtractApk(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") extractRuleArgs := variant.Output("extract-apk/foo.apk").BuildParams.Args if extractRuleArgs["extract_apk"] != "extract_path/sub_app.apk" { t.Errorf("Unexpected extract apk args: %s", extractRuleArgs["extract_apk"]) @@ -801,7 +801,7 @@ func TestAndroidTestImport(t *testing.T) { } `) - test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport) + test := ctx.ModuleForTests(t, "foo", "android_common").Module().(*AndroidTestImport) // Check android mks. entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] @@ -839,13 +839,13 @@ func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) { } `) - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") jniRule := variant.Output("jnis-uncompressed/foo.apk").BuildParams.Rule.String() if jniRule == android.Cp.String() { t.Errorf("Unexpected JNI uncompress rule command: %s", jniRule) } - variant = ctx.ModuleForTests("foo_presigned", "android_common") + variant = ctx.ModuleForTests(t, "foo_presigned", "android_common") jniRule = variant.Output("jnis-uncompressed/foo_presigned.apk").BuildParams.Rule.String() if jniRule != android.Cp.String() { t.Errorf("Unexpected JNI uncompress rule: %s", jniRule) @@ -867,7 +867,7 @@ func TestAndroidTestImport_Preprocessed(t *testing.T) { `) apkName := "foo.apk" - variant := ctx.ModuleForTests("foo", "android_common") + variant := ctx.ModuleForTests(t, "foo", "android_common") jniRule := variant.Output("jnis-uncompressed/" + apkName).BuildParams.Rule.String() if jniRule != android.Cp.String() { t.Errorf("Unexpected JNI uncompress rule: %s", jniRule) @@ -912,7 +912,7 @@ func TestAndroidAppImport_Preprocessed(t *testing.T) { // non-privileged app apkName := "foo.apk" - variant := result.ModuleForTests("foo", "android_common") + variant := result.ModuleForTests(t, "foo", "android_common") outputBuildParams := variant.Output(apkName).BuildParams if outputBuildParams.Rule.String() != android.Cp.String() { t.Errorf("Unexpected prebuilt android_app_import rule: %s", outputBuildParams.Rule.String()) @@ -934,7 +934,7 @@ func TestAndroidAppImport_Preprocessed(t *testing.T) { // privileged app apkName = "bar.apk" - variant = result.ModuleForTests("bar", "android_common") + variant = result.ModuleForTests(t, "bar", "android_common") outputBuildParams = variant.Output(apkName).BuildParams if outputBuildParams.Rule.String() != android.Cp.String() { t.Errorf("Unexpected prebuilt android_app_import rule: %s", outputBuildParams.Rule.String()) @@ -1003,7 +1003,7 @@ func TestAndroidTestImport_UncompressDex(t *testing.T) { }), ).RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") actual := foo.MaybeRule("uncompress-dex").Rule != nil expect := !unbundled @@ -1047,7 +1047,7 @@ func TestAppImportMissingCertificateAllowMissingDependencies(t *testing.T) { certificate: ":missing_certificate", }`) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") fooApk := foo.Output("signed/foo.apk") if fooApk.Rule != android.ErrorRule { t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String()) diff --git a/java/app_set_test.go b/java/app_set_test.go index cc7af042b..9b4c44bc9 100644 --- a/java/app_set_test.go +++ b/java/app_set_test.go @@ -31,7 +31,7 @@ func TestAndroidAppSet(t *testing.T) { set: "prebuilts/apks/app.apks", prerelease: true, }`) - module := result.ModuleForTests("foo", "android_common") + module := result.ModuleForTests(t, "foo", "android_common") const packedSplitApks = "foo.zip" params := module.Output(packedSplitApks) if params.Rule == nil { @@ -127,7 +127,7 @@ func TestAndroidAppSet_Variants(t *testing.T) { }), ).RunTestWithBp(t, bp) - module := ctx.ModuleForTests("foo", "android_common") + module := ctx.ModuleForTests(t, "foo", "android_common") const packedSplitApks = "foo.zip" params := module.Output(packedSplitApks) for k, v := range test.expected { diff --git a/java/app_test.go b/java/app_test.go index 701fc3594..4f23f61a4 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -72,14 +72,14 @@ func TestApp(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") var expectedLinkImplicits []string manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml") expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String()) - frameworkRes := result.ModuleForTests("framework-res", "android_common") + frameworkRes := result.ModuleForTests(t, "framework-res", "android_common") expectedLinkImplicits = append(expectedLinkImplicits, frameworkRes.Output("package-res.apk").Output.String()) @@ -96,7 +96,7 @@ func TestApp(t *testing.T) { expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) // Check that the link rule uses - res := result.ModuleForTests("foo", "android_common").Output("package-res.apk") + res := result.ModuleForTests(t, "foo", "android_common").Output("package-res.apk") android.AssertDeepEquals(t, "aapt2 link implicits", expectedLinkImplicits, res.Implicits.Strings()) }) } @@ -112,7 +112,7 @@ func TestAppSplits(t *testing.T) { sdk_version: "current" }`) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") expectedOutputs := []string{ "out/soong/.intermediates/foo/android_common/foo.apk", @@ -448,11 +448,11 @@ func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) { ctx, _ := testJavaWithFS(t, bp, fs) - inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits + inputs := ctx.ModuleForTests(t, "libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits var crtbeginFound, crtendFound bool - expectedCrtBegin := ctx.ModuleForTests("crtbegin_so", + expectedCrtBegin := ctx.ModuleForTests(t, "crtbegin_so", "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output - expectedCrtEnd := ctx.ModuleForTests("crtend_so", + expectedCrtEnd := ctx.ModuleForTests(t, "crtend_so", "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output implicits := []string{} for _, input := range inputs { @@ -542,7 +542,7 @@ func TestUpdatableApps_ApplyDefaultUpdatableModuleVersion(t *testing.T) { updatable: true, } `) - foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") + foo := result.ModuleForTests(t, "com.android.foo", "android_common").Rule("manifestFixer") android.AssertStringDoesContain(t, "com.android.foo: expected manifest fixer to set override-placeholder-version to RELEASE_DEFAULT_UPDATABLE_MODULE_VERSION", foo.BuildParams.Args["args"], @@ -566,7 +566,7 @@ func TestUpdatableApps_ApplyOverrideApexManifestDefaultVersion(t *testing.T) { updatable: true, } `) - foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") + foo := result.ModuleForTests(t, "com.android.foo", "android_common").Rule("manifestFixer") android.AssertStringDoesContain(t, "com.android.foo: expected manifest fixer to set override-placeholder-version to 1234", foo.BuildParams.Args["args"], @@ -618,7 +618,7 @@ func TestResourceDirs(t *testing.T) { fs.AddToFixture(), ).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop)) - module := result.ModuleForTests("foo", "android_common") + module := result.ModuleForTests(t, "foo", "android_common") resourceList := module.MaybeOutput("aapt2/res.list") var resources []string @@ -730,7 +730,7 @@ func TestLibraryAssets(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { t.Parallel() - m := ctx.ModuleForTests(test.name, "android_common") + m := ctx.ModuleForTests(t, test.name, "android_common") // Check asset flag in aapt2 link flags var aapt2link android.TestingBuildParams @@ -783,7 +783,7 @@ func TestAppJavaResources(t *testing.T) { ctx := testApp(t, bp) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") fooResources := foo.Output("res/foo.jar") fooDexJar := foo.Output("dex-withres/foo.jar") fooDexJarAligned := foo.Output("dex-withres-aligned/foo.jar") @@ -801,7 +801,7 @@ func TestAppJavaResources(t *testing.T) { t.Errorf("expected aligned dex jar %q in foo apk inputs %q", w, g) } - bar := ctx.ModuleForTests("bar", "android_common") + bar := ctx.ModuleForTests(t, "bar", "android_common") barResources := bar.Output("res/bar.jar") barApk := bar.Rule("combineApk") @@ -1352,7 +1352,7 @@ func TestAndroidResourceProcessor(t *testing.T) { } getAaptInfo := func(moduleName string) (aaptInfo aaptInfo) { - mod := result.ModuleForTests(moduleName, "android_common") + mod := result.ModuleForTests(t, moduleName, "android_common") resourceListRule := mod.MaybeOutput("aapt2/res.list") overlayListRule := mod.MaybeOutput("aapt2/overlay.list") aaptRule := mod.Rule("aapt2Link") @@ -1670,7 +1670,7 @@ func TestAndroidResourceOverlays(t *testing.T) { } getResources := func(moduleName, variantName string) (resourceFiles, overlayFiles, rroDirs []string) { - module := result.ModuleForTests(moduleName, variantName) + module := result.ModuleForTests(t, moduleName, variantName) resourceList := module.MaybeOutput("aapt2/res.list") if resourceList.Rule != nil { resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs)) @@ -1729,7 +1729,7 @@ func TestAndroidResourceOverlays(t *testing.T) { } func checkSdkVersion(t *testing.T, result *android.TestResult, expectedSdkVersion string) { - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") link := foo.Output("package-res.apk") linkFlags := strings.Split(link.Args["flags"], " ") min := android.IndexList("--min-sdk-version", linkFlags) @@ -1986,7 +1986,7 @@ func TestJNIABI(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { t.Parallel() - app := ctx.ModuleForTests(test.name, "android_common") + app := ctx.ModuleForTests(t, test.name, "android_common") jniLibZip := app.Output("jnilibs.zip") var abis []string args := strings.Fields(jniLibZip.Args["jarArgs"]) @@ -2122,7 +2122,7 @@ func TestJNIPackaging(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { t.Parallel() - app := ctx.ModuleForTests(test.name, "android_common") + app := ctx.ModuleForTests(t, test.name, "android_common") jniLibZip := app.MaybeOutput("jnilibs.zip") if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { t.Errorf("expected jni packaged %v, got %v", w, g) @@ -2204,17 +2204,17 @@ func TestJNISDK(t *testing.T) { {name: "app_vendor", vendorJNI: true}, } - platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared"). + platformJNI := ctx.ModuleForTests(t, "libjni", "android_arm64_armv8-a_shared"). Output("libjni.so").Output.String() - sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared"). + sdkJNI := ctx.ModuleForTests(t, "libjni", "android_arm64_armv8-a_sdk_shared"). Output("libjni.so").Output.String() - vendorJNI := ctx.ModuleForTests("libvendorjni", "android_vendor_arm64_armv8-a_shared"). + vendorJNI := ctx.ModuleForTests(t, "libvendorjni", "android_vendor_arm64_armv8-a_shared"). Output("libvendorjni.so").Output.String() for _, test := range testCases { t.Run(test.name, func(t *testing.T) { t.Parallel() - app := ctx.ModuleForTests(test.name, "android_common") + app := ctx.ModuleForTests(t, test.name, "android_common") jniLibZip := app.MaybeOutput("jnilibs.zip") if len(jniLibZip.Implicits) != 1 { @@ -2417,7 +2417,7 @@ func TestCertificates(t *testing.T) { }), ).RunTestWithBp(t, test.bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") certificate := foo.Module().(*AndroidApp).certificate android.AssertPathRelativeToTopEquals(t, "certificates key", test.expectedCertificate+".pk8", certificate.Key) @@ -2489,7 +2489,7 @@ func TestRequestV4SigningFlag(t *testing.T) { PrepareForTestWithJavaDefaultModules, ).RunTestWithBp(t, test.bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") signapk := foo.Output("foo.apk") signFlags := signapk.Args["flags"] @@ -2567,7 +2567,7 @@ func TestPackageNameOverride(t *testing.T) { }), ).RunTestWithBp(t, test.bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") outSoongDir := result.Config.SoongOutDir() @@ -2608,7 +2608,7 @@ func TestInstrumentationTargetOverridden(t *testing.T) { }), ).RunTestWithBp(t, bp) - bar := result.ModuleForTests("bar", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") res := bar.Output("package-res.apk") aapt2Flags := res.Args["flags"] e := "--rename-instrumentation-target-package org.dandroid.bp" @@ -2766,7 +2766,7 @@ func TestOverrideAndroidApp(t *testing.T) { }, } for _, expected := range expectedVariants { - variant := result.ModuleForTests(expected.name, expected.variantName) + variant := result.ModuleForTests(t, expected.name, expected.variantName) // Check the final apk name variant.Output(expected.apkPath) @@ -2851,7 +2851,7 @@ func TestOverrideAndroidAppOverrides(t *testing.T) { }, } for _, expected := range expectedVariants { - variant := ctx.ModuleForTests(expected.name, expected.variantName) + variant := ctx.ModuleForTests(t, expected.name, expected.variantName) // Check if the overrides field values are correctly aggregated. mod := variant.Module().(*AndroidApp) @@ -2883,13 +2883,13 @@ func TestOverrideAndroidAppWithPrebuilt(t *testing.T) { `) // An app that has an override that also has a prebuilt should not be hidden. - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") if foo.Module().IsHideFromMake() { t.Errorf("expected foo to have HideFromMake false") } // An override that also has a prebuilt should be hidden. - barOverride := result.ModuleForTests("foo", "android_common_bar") + barOverride := result.ModuleForTests(t, "foo", "android_common_bar") if !barOverride.Module().IsHideFromMake() { t.Errorf("expected bar override variant of foo to have HideFromMake true") } @@ -2965,7 +2965,7 @@ func TestOverrideAndroidAppStem(t *testing.T) { apkPath: "out/target/product/test_device/system/app/baz2_stem/baz2_stem.apk", }, } { - variant := ctx.ModuleForTests(expected.moduleName, expected.variantName) + variant := ctx.ModuleForTests(t, expected.moduleName, expected.variantName) variant.Output(expected.apkPath) } } @@ -2999,14 +2999,14 @@ func TestOverrideAndroidAppDependency(t *testing.T) { `) // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. - javac := ctx.ModuleForTests("baz", "android_common").Rule("javac") + javac := ctx.ModuleForTests(t, "baz", "android_common").Rule("javac") fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar" if !strings.Contains(javac.Args["classpath"], fooTurbine) { t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) } // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. - javac = ctx.ModuleForTests("qux", "android_common").Rule("javac") + javac = ctx.ModuleForTests(t, "qux", "android_common").Rule("javac") barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar" if !strings.Contains(javac.Args["classpath"], barTurbine) { t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) @@ -3070,7 +3070,7 @@ func TestOverrideAndroidTest(t *testing.T) { }, } for _, expected := range expectedVariants { - variant := ctx.ModuleForTests("foo_test", expected.variantName) + variant := ctx.ModuleForTests(t, "foo_test", expected.variantName) // Check the final apk name variant.Output("out" + expected.apkPath) @@ -3161,7 +3161,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) { } for _, test := range testCases { - variant := ctx.ModuleForTests(test.moduleName, test.variantName) + variant := ctx.ModuleForTests(t, test.moduleName, test.variantName) params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml") if len(test.expectedFlags) > 0 { @@ -3251,7 +3251,7 @@ func TestStl(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { t.Parallel() - app := ctx.ModuleForTests(test.name, "android_common") + app := ctx.ModuleForTests(t, test.name, "android_common") jniLibZip := app.Output("jnilibs.zip") var jnis []string args := strings.Fields(jniLibZip.Args["jarArgs"]) @@ -3428,8 +3428,8 @@ func TestUsesLibraries(t *testing.T) { }), ).RunTestWithBp(t, bp) - app := result.ModuleForTests("app", "android_common") - prebuilt := result.ModuleForTests("prebuilt", "android_common") + app := result.ModuleForTests(t, "app", "android_common") + prebuilt := result.ModuleForTests(t, "prebuilt", "android_common") // Test that implicit dependencies on java_sdk_library instances are passed to the manifest. // These also include explicit `uses_libs`/`optional_uses_libs` entries, as they may be @@ -3534,7 +3534,7 @@ func TestDexpreoptBcp(t *testing.T) { dexpreopt.FixtureSetPreoptWithUpdatableBcp(test.with), ).RunTestWithBp(t, bp) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") cmd := app.Rule("dexpreopt").RuleParams.Command bcp := " -Xbootclasspath-locations:" + test.expect + " " // space at the end matters android.AssertStringDoesContain(t, "dexpreopt app bcp", cmd, bcp) @@ -3611,7 +3611,7 @@ func TestCodelessApp(t *testing.T) { t.Parallel() ctx := testApp(t, test.bp) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode { t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs) @@ -3709,7 +3709,7 @@ func TestUncompressDex(t *testing.T) { }), ).RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") dex := foo.Rule("r8") uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0") aligned := foo.MaybeRule("zipalign").Rule != nil @@ -3795,7 +3795,7 @@ func TestExportedProguardFlagFiles(t *testing.T) { `) - m := ctx.ModuleForTests("foo", "android_common") + m := ctx.ModuleForTests(t, "foo", "android_common") r8 := m.Rule("java.r8") implicits := r8.Implicits.RelativeToTop().Strings() android.AssertStringListContains(t, "r8 implicits", implicits, "lib1proguard.cfg") @@ -3895,7 +3895,7 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) { ) result := fixture.RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) @@ -3993,7 +3993,7 @@ func TestDefaultAppTargetSdkVersionForUpdatableModules(t *testing.T) { ) result := fixture.RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+*testCase.targetSdkVersionExpected) @@ -4082,7 +4082,7 @@ func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) { result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) if !errExpected { - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) } @@ -4157,7 +4157,7 @@ func TestEnforceDefaultAppTargetSdkVersionFlagForTests(t *testing.T) { result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) if !errExpected { - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) } @@ -4187,7 +4187,7 @@ func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { sdk_version: "current", }`) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") fooApk := foo.Output("foo.apk") if fooApk.Rule != android.ErrorRule { t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String()) @@ -4260,7 +4260,7 @@ func TestAppIncludesJniPackages(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { t.Parallel() - app := ctx.ModuleForTests(tc.name, "android_common") + app := ctx.ModuleForTests(t, tc.name, "android_common") outputFile := "jnilibs.zip" jniOutputLibZip := app.MaybeOutput(outputFile) @@ -4343,7 +4343,7 @@ func TestTargetSdkVersionMtsTests(t *testing.T) { t.Run(testCase.desc, func(t *testing.T) { t.Parallel() result := fixture.RunTestWithBp(t, fmt.Sprintf(bpTemplate, testCase.moduleType, testCase.targetSdkVersionInBp, testCase.testSuites)) - mytest := result.ModuleForTests("mytest", "android_common") + mytest := result.ModuleForTests(t, "mytest", "android_common") manifestFixerArgs := mytest.Output("manifest_fixer/AndroidManifest.xml").Args["args"] android.AssertStringDoesContain(t, testCase.desc, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) }) @@ -4377,8 +4377,8 @@ func TestPrivappAllowlist(t *testing.T) { } `, ) - app := result.ModuleForTests("foo", "android_common") - overrideApp := result.ModuleForTests("foo", "android_common_bar") + app := result.ModuleForTests(t, "foo", "android_common") + overrideApp := result.ModuleForTests(t, "foo", "android_common_bar") // verify that privapp allowlist is created for override apps overrideApp.Output("out/soong/.intermediates/foo/android_common_bar/privapp_allowlist_com.google.android.foo.xml") @@ -4415,8 +4415,8 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) { } `, ) - baseApp := result.ModuleForTests("foo", "android_common") - overrideApp := result.ModuleForTests("foo", "android_common_bar") + baseApp := result.ModuleForTests(t, "foo", "android_common") + overrideApp := result.ModuleForTests(t, "foo", "android_common_bar") baseAndroidApp := baseApp.Module().(*AndroidApp) baseEntries := android.AndroidMkEntriesForTest(t, result.TestContext, baseAndroidApp)[0] @@ -4512,7 +4512,7 @@ func TestAppFlagsPackages(t *testing.T) { } `) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") // android_app module depends on aconfig_declarations listed in flags_packages android.AssertBoolEquals(t, "foo expected to depend on bar", true, @@ -4597,7 +4597,7 @@ func TestAppFlagsPackagesPropagation(t *testing.T) { } `) - bazApp := ctx.ModuleForTests("baz_app", "android_common") + bazApp := ctx.ModuleForTests(t, "baz_app", "android_common") // android_app module depends on aconfig_declarations listed in flags_packages // and that of static libs, but not libs @@ -4635,7 +4635,7 @@ func TestNoDexpreoptOptionalUsesLibDoesNotHaveImpl(t *testing.T) { } ` result := prepareForJavaTest.RunTestWithBp(t, bp) - dexpreopt := result.ModuleForTests("app", "android_common").MaybeRule("dexpreopt").Rule + dexpreopt := result.ModuleForTests(t, "app", "android_common").MaybeRule("dexpreopt").Rule android.AssertBoolEquals(t, "dexpreopt should be disabled if optional_uses_libs does not have an implementation", true, dexpreopt == nil) } @@ -4731,7 +4731,7 @@ func TestTestConfigTemplate(t *testing.T) { } return ret } - rule := ctx.ModuleForTests("android-test", "android_common").Rule("autogenInstrumentationTest") + rule := ctx.ModuleForTests(t, "android-test", "android_common").Rule("autogenInstrumentationTest") android.AssertSameArray(t, "extraConfigs mismatch", []option{ {"name1", "key1", "value1"}, @@ -4756,7 +4756,7 @@ func TestAppStem(t *testing.T) { sdk_version: "current", }`) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") outputs := fmt.Sprint(foo.AllOutputs()) if !strings.Contains(outputs, "foo-new.apk") { @@ -4782,8 +4782,8 @@ func TestAppMinSdkVersionOverride(t *testing.T) { min_sdk_version: "33", } `) - foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") - fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer") + foo := result.ModuleForTests(t, "com.android.foo", "android_common").Rule("manifestFixer") + fooOverride := result.ModuleForTests(t, "com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer") android.AssertStringDoesContain(t, "com.android.foo: expected manifest fixer to set minSdkVersion to T", @@ -4810,7 +4810,7 @@ func TestNotApplyDefaultUpdatableModuleVersion(t *testing.T) { min_sdk_version: "31", } `) - foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") + foo := result.ModuleForTests(t, "com.android.foo", "android_common").Rule("manifestFixer") android.AssertStringDoesNotContain(t, "com.android.foo: expected manifest fixer to not set override-placeholder-version", foo.BuildParams.Args["args"], @@ -4833,7 +4833,7 @@ func TestNotApplyOverrideApexManifestDefaultVersion(t *testing.T) { min_sdk_version: "31", } `) - foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") + foo := result.ModuleForTests(t, "com.android.foo", "android_common").Rule("manifestFixer") android.AssertStringDoesNotContain(t, "com.android.foo: expected manifest fixer to not set override-placeholder-version", foo.BuildParams.Args["args"], @@ -4861,7 +4861,7 @@ func TestResourcesWithFlagDirectories(t *testing.T) { ], } `) - fooModule := result.ModuleForTests("foo", "android_common") + fooModule := result.ModuleForTests(t, "foo", "android_common") compileOutputPaths := fooModule.Rule("aapt2Compile").Outputs.Strings() android.AssertStringListContains( @@ -4956,9 +4956,9 @@ override_android_app { }), android.OptionalFixturePreparer(tc.preparer), ).RunTestWithBp(t, bp) - vendorOverlayApk := result.ModuleForTests("foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("foo__test_product__auto_generated_rro_vendor.apk") + vendorOverlayApk := result.ModuleForTests(t, "foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("foo__test_product__auto_generated_rro_vendor.apk") android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, vendorOverlayApk.Rule != nil) - overrideVendorOverlayApk := result.ModuleForTests("override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("override_foo__test_product__auto_generated_rro_vendor.apk") + overrideVendorOverlayApk := result.ModuleForTests(t, "override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("override_foo__test_product__auto_generated_rro_vendor.apk") android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, overrideVendorOverlayApk.Rule != nil) }) } @@ -5034,7 +5034,7 @@ my_custom_override_android_app { }.AddToFixture(), android.OptionalFixturePreparer(tc.preparer), ).RunTestWithBp(t, bp) - overrideVendorOverlayApk := result.ModuleForTests("override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").Module().(*AutogenRuntimeResourceOverlay) + overrideVendorOverlayApk := result.ModuleForTests(t, "override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").Module().(*AutogenRuntimeResourceOverlay) android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, overrideVendorOverlayApk.exportPackage != nil) }) } diff --git a/java/base.go b/java/base.go index d89c324a5..21ad73f84 100644 --- a/java/base.go +++ b/java/base.go @@ -377,7 +377,7 @@ func (e *embeddableInModuleAndImport) initModuleAndImport(module android.Module) // // This cannot implement OutgoingDepIsInSameApex(...) directly as that leads to ambiguity with // the one provided by ApexModuleBase. -func (e *embeddableInModuleAndImport) depIsInSameApex(tag blueprint.DependencyTag) bool { +func depIsInSameApex(tag blueprint.DependencyTag) bool { // dependencies other than the static linkage are all considered crossing APEX boundary if tag == staticLibTag { return true @@ -2254,25 +2254,29 @@ func (j *Module) hasCode(ctx android.ModuleContext) bool { } // Implements android.ApexModule -func (j *Module) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { - return j.depIsInSameApex(tag) +func (m *Module) GetDepInSameApexChecker() android.DepInSameApexChecker { + return JavaDepInSameApexChecker{} +} + +type JavaDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m JavaDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { + return depIsInSameApex(tag) } // Implements android.ApexModule -func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { +func (j *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { sdkVersionSpec := j.SdkVersion(ctx) minSdkVersion := j.MinSdkVersion(ctx) - if !minSdkVersion.Specified() { - return fmt.Errorf("min_sdk_version is not specified") - } + // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { - return nil - } - if minSdkVersion.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", minSdkVersion) + return android.MinApiLevel } - return nil + + return minSdkVersion } func (j *Module) Stem() string { @@ -2948,14 +2952,18 @@ func (module *Module) collectJarJarRules(ctx android.ModuleContext) *JarJarProvi // Get the jarjar rule text for a given provider for the fully resolved rules. Classes that map // to "" won't be in this list because they shouldn't be renamed yet. func getJarJarRuleText(provider *JarJarProviderData) string { - result := "" + result := strings.Builder{} for _, orig := range android.SortedKeys(provider.Rename) { renamed := provider.Rename[orig] if renamed != "" { - result += "rule " + orig + " " + renamed + "\n" + result.WriteString("rule ") + result.WriteString(orig) + result.WriteString(" ") + result.WriteString(renamed) + result.WriteString("\n") } } - return result + return result.String() } // Repackage the flags if the jarjar rule txt for the flags is generated diff --git a/java/bootclasspath.go b/java/bootclasspath.go index 3413cf350..98fb417d0 100644 --- a/java/bootclasspath.go +++ b/java/bootclasspath.go @@ -15,6 +15,8 @@ package java import ( + "fmt" + "android/soong/android" "github.com/google/blueprint" @@ -23,36 +25,9 @@ import ( // Contains code that is common to both platform_bootclasspath and bootclasspath_fragment. -func init() { - registerBootclasspathBuildComponents(android.InitRegistrationContext) -} - -func registerBootclasspathBuildComponents(ctx android.RegistrationContext) { - ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("bootclasspath_deps", bootclasspathDepsMutator) - }) -} - -// BootclasspathDepsMutator is the interface that a module must implement if it wants to add -// dependencies onto APEX specific variants of bootclasspath fragments or bootclasspath contents. -type BootclasspathDepsMutator interface { - // BootclasspathDepsMutator implementations should add dependencies using - // addDependencyOntoApexModulePair and addDependencyOntoApexVariants. - BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) -} - -// bootclasspathDepsMutator is called during the final deps phase after all APEX variants have -// been created so can add dependencies onto specific APEX variants of modules. -func bootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { - m := ctx.Module() - if p, ok := m.(BootclasspathDepsMutator); ok { - p.BootclasspathDepsMutator(ctx) - } -} - // addDependencyOntoApexVariants adds dependencies onto the appropriate apex specific variants of // the module as specified in the ApexVariantReference list. -func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tag blueprint.DependencyTag) { +func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tagType bootclasspathDependencyTagType) { for i, ref := range refs { apex := proptools.StringDefault(ref.Apex, "platform") @@ -62,7 +37,7 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN } name := proptools.String(ref.Module) - addDependencyOntoApexModulePair(ctx, apex, name, tag) + addDependencyOntoApexModulePair(ctx, apex, name, tagType) } } @@ -75,68 +50,154 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN // module when both source and prebuilt modules are available. // // Use gatherApexModulePairDepsWithTag to retrieve the dependencies. -func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) { - var variations []blueprint.Variation - if !android.IsConfiguredJarForPlatform(apex) { - // Pick the correct apex variant. - variations = []blueprint.Variation{ - {Mutator: "apex", Variation: apex}, - } +func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tagType bootclasspathDependencyTagType) { + tag := bootclasspathDependencyTag{ + typ: tagType, } - target := ctx.Module().Target() - variations = append(variations, target.Variations()...) - - addedDep := false - if ctx.OtherModuleDependencyVariantExists(variations, name) { - ctx.AddFarVariationDependencies(variations, tag, name) - addedDep = true + if android.IsConfiguredJarForPlatform(apex) { + // Platform variant, add a direct dependency. + ctx.AddFarVariationDependencies(target.Variations(), tag, name) + } else { + // A module in an apex. Dependencies can't be added directly onto an apex variation, as that would + // require constructing a full ApexInfo configuration, which can't be predicted here. Add a dependency + // on the apex instead, and annotate the dependency tag with the desired module in the apex. + tag.moduleInApex = name + ctx.AddFarVariationDependencies(target.Variations(), tag, apex) } - // Add a dependency on the prebuilt module if it exists. - prebuiltName := android.PrebuiltNameFromSource(name) - if ctx.OtherModuleDependencyVariantExists(variations, prebuiltName) { - ctx.AddVariationDependencies(variations, tag, prebuiltName) - addedDep = true +} + +// gatherFragments collects fragments that are direct dependencies of this module, as well as +// any fragments in apexes via the dependency on the apex. It returns a list of the fragment +// modules and map from apex name to the fragment in that apex. +func gatherFragments(ctx android.BaseModuleContext) ([]android.Module, map[string]android.Module) { + var fragments []android.Module + + type fragmentInApex struct { + module string + apex string } - // If no appropriate variant existing for this, so no dependency could be added, then it is an - // error, unless missing dependencies are allowed. The simplest way to handle that is to add a - // dependency that will not be satisfied and the default behavior will handle it. - if !addedDep { - // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does - // not exist. The resulting error message will contain useful information about the available - // variants. - reportMissingVariationDependency(ctx, variations, name) - - // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists - // so that information about its available variants will be reported too. - if ctx.OtherModuleExists(prebuiltName) { - reportMissingVariationDependency(ctx, variations, prebuiltName) + var fragmentsInApexes []fragmentInApex + + // Find any direct dependencies, as well as a list of the modules in apexes. + ctx.VisitDirectDeps(func(module android.Module) { + t := ctx.OtherModuleDependencyTag(module) + if bcpTag, ok := t.(bootclasspathDependencyTag); ok && bcpTag.typ == fragment { + if bcpTag.moduleInApex != "" { + fragmentsInApexes = append(fragmentsInApexes, fragmentInApex{bcpTag.moduleInApex, ctx.OtherModuleName(module)}) + } else { + fragments = append(fragments, module) + } } - } -} + }) -// reportMissingVariationDependency intentionally adds a dependency on a missing variation in order -// to generate an appropriate error message with information about the available variations. -func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) { - ctx.AddFarVariationDependencies(variations, nil, name) + fragmentsMap := make(map[string]android.Module) + for _, fragmentInApex := range fragmentsInApexes { + var found android.Module + // Find a desired module in an apex. + ctx.WalkDeps(func(child, parent android.Module) bool { + t := ctx.OtherModuleDependencyTag(child) + if parent == ctx.Module() { + if bcpTag, ok := t.(bootclasspathDependencyTag); ok && bcpTag.typ == fragment && ctx.OtherModuleName(child) == fragmentInApex.apex { + // This is the dependency from this module to the apex, recurse into it. + return true + } + } else if android.IsDontReplaceSourceWithPrebuiltTag(t) { + return false + } else if t == android.PrebuiltDepTag { + return false + } else if IsBootclasspathFragmentContentDepTag(t) { + return false + } else if android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child)) == fragmentInApex.module { + // This is the desired module inside the apex. + if found != nil && child != found { + panic(fmt.Errorf("found two conflicting modules %q in apex %q: %s and %s", + fragmentInApex.module, fragmentInApex.apex, found, child)) + } + found = child + } + return false + }) + if found != nil { + if existing, exists := fragmentsMap[fragmentInApex.apex]; exists { + ctx.ModuleErrorf("apex %s has multiple fragments, %s and %s", fragmentInApex.apex, fragmentInApex.module, existing) + } else { + fragmentsMap[fragmentInApex.apex] = found + fragments = append(fragments, found) + } + } else if !ctx.Config().AllowMissingDependencies() { + ctx.ModuleErrorf("failed to find fragment %q in apex %q\n", + fragmentInApex.module, fragmentInApex.apex) + } + } + return fragments, fragmentsMap } // gatherApexModulePairDepsWithTag returns the list of dependencies with the supplied tag that was // added by addDependencyOntoApexModulePair. -func gatherApexModulePairDepsWithTag(ctx android.BaseModuleContext, tag blueprint.DependencyTag) []android.Module { +func gatherApexModulePairDepsWithTag(ctx android.BaseModuleContext, tagType bootclasspathDependencyTagType) ([]android.Module, map[android.Module]string) { var modules []android.Module - isActiveModulePred := func(module android.Module) bool { - return isActiveModule(ctx, module) + modulesToApex := make(map[android.Module]string) + + type moduleInApex struct { + module string + apex string } - ctx.VisitDirectDepsIf(isActiveModulePred, func(module android.Module) { + + var modulesInApexes []moduleInApex + + ctx.VisitDirectDeps(func(module android.Module) { t := ctx.OtherModuleDependencyTag(module) - if t == tag { - modules = append(modules, module) + if bcpTag, ok := t.(bootclasspathDependencyTag); ok && bcpTag.typ == tagType { + if bcpTag.moduleInApex != "" { + modulesInApexes = append(modulesInApexes, moduleInApex{bcpTag.moduleInApex, ctx.OtherModuleName(module)}) + } else { + modules = append(modules, module) + } } }) - return modules + + for _, moduleInApex := range modulesInApexes { + var found android.Module + ctx.WalkDeps(func(child, parent android.Module) bool { + t := ctx.OtherModuleDependencyTag(child) + if parent == ctx.Module() { + if bcpTag, ok := t.(bootclasspathDependencyTag); ok && bcpTag.typ == tagType && ctx.OtherModuleName(child) == moduleInApex.apex { + // recurse into the apex + return true + } + } else if tagType != fragment && android.IsFragmentInApexTag(t) { + return true + } else if android.IsDontReplaceSourceWithPrebuiltTag(t) { + return false + } else if t == android.PrebuiltDepTag { + return false + } else if IsBootclasspathFragmentContentDepTag(t) { + return false + } else if android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child)) == moduleInApex.module { + if found != nil && child != found { + panic(fmt.Errorf("found two conflicting modules %q in apex %q: %s and %s", + moduleInApex.module, moduleInApex.apex, found, child)) + } + found = child + } + return false + }) + if found != nil { + modules = append(modules, found) + if existing, exists := modulesToApex[found]; exists && existing != moduleInApex.apex { + ctx.ModuleErrorf("module %s is in two apexes, %s and %s", moduleInApex.module, existing, moduleInApex.apex) + } else { + modulesToApex[found] = moduleInApex.apex + } + } else if !ctx.Config().AllowMissingDependencies() { + ctx.ModuleErrorf("failed to find module %q in apex %q\n", + moduleInApex.module, moduleInApex.apex) + } + } + return modules, modulesToApex } // ApexVariantReference specifies a particular apex variant of a module. @@ -165,7 +226,7 @@ type BootclasspathFragmentsDepsProperties struct { // addDependenciesOntoFragments adds dependencies to the fragments specified in this properties // structure. func (p *BootclasspathFragmentsDepsProperties) addDependenciesOntoFragments(ctx android.BottomUpMutatorContext) { - addDependencyOntoApexVariants(ctx, "fragments", p.Fragments, bootclasspathFragmentDepTag) + addDependencyOntoApexVariants(ctx, "fragments", p.Fragments, fragment) } // bootclasspathDependencyTag defines dependencies from/to bootclasspath_fragment, @@ -174,23 +235,38 @@ func (p *BootclasspathFragmentsDepsProperties) addDependenciesOntoFragments(ctx type bootclasspathDependencyTag struct { blueprint.BaseDependencyTag - name string + typ bootclasspathDependencyTagType + + // moduleInApex is set to the name of the desired module when this dependency points + // to the apex that the modules is contained in. + moduleInApex string } +type bootclasspathDependencyTagType int + +const ( + // The tag used for dependencies onto bootclasspath_fragments. + fragment bootclasspathDependencyTagType = iota + // The tag used for dependencies onto platform_bootclasspath. + platform + dexpreoptBootJar + artBootJar + platformBootJar + apexBootJar +) + func (t bootclasspathDependencyTag) ExcludeFromVisibilityEnforcement() { } +func (t bootclasspathDependencyTag) LicenseAnnotations() []android.LicenseAnnotation { + return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} +} + // Dependencies that use the bootclasspathDependencyTag instances are only added after all the // visibility checking has been done so this has no functional effect. However, it does make it // clear that visibility is not being enforced on these tags. var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathDependencyTag{} -// The tag used for dependencies onto bootclasspath_fragments. -var bootclasspathFragmentDepTag = bootclasspathDependencyTag{name: "fragment"} - -// The tag used for dependencies onto platform_bootclasspath. -var platformBootclasspathDepTag = bootclasspathDependencyTag{name: "platform"} - // BootclasspathNestedAPIProperties defines properties related to the API provided by parts of the // bootclasspath that are nested within the main BootclasspathAPIProperties. type BootclasspathNestedAPIProperties struct { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index f6d6cad4a..7a3c21e44 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -89,6 +89,19 @@ func (b bootclasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex // The tag used for the dependency between the bootclasspath_fragment module and its contents. var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{} +type moduleInFragmentDependencyTag struct { + blueprint.DependencyTag +} + +func (m moduleInFragmentDependencyTag) ExcludeFromVisibilityEnforcement() { +} + +// moduleInFragmentDepTag is added alongside bootclasspathFragmentContentDependencyTag, +// but doesn't set ReplaceSourceWithPrebuilt. It is used to find modules in the fragment +// by traversing from the apex to the fragment to the module, which prevents having to +// construct a dependency on the apex variant of the fragment directly. +var moduleInFragmentDepTag = moduleInFragmentDependencyTag{} + var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag var _ android.SdkMemberDependencyTag = bootclasspathFragmentContentDepTag @@ -239,6 +252,8 @@ type BootclasspathFragmentModule struct { profilePathErr error } +var _ android.ApexModule = (*BootclasspathFragmentModule)(nil) + // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt // bootclasspath fragment modules. type commonBootclasspathFragment interface { @@ -397,7 +412,15 @@ func (i BootclasspathFragmentApexContentInfo) ProfileInstallPathInApex() string return i.profileInstallPathInApex } -func (b *BootclasspathFragmentModule) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { +func (m *BootclasspathFragmentModule) GetDepInSameApexChecker() android.DepInSameApexChecker { + return BootclasspathFragmentDepInSameApexChecker{} +} + +type BootclasspathFragmentDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (b BootclasspathFragmentDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { // If the module is a default module, do not check the tag if tag == android.DefaultsDepTag { return true @@ -410,17 +433,31 @@ func (b *BootclasspathFragmentModule) OutgoingDepIsInSameApex(tag blueprint.Depe // Cross-cutting metadata dependencies are metadata. return false } + if tag == moduleInFragmentDepTag { + return true + } // Dependency to the bootclasspath fragment of another apex // e.g. concsrypt-bootclasspath-fragment --> art-bootclasspath-fragment - if tag == bootclasspathFragmentDepTag { + if bcpTag, ok := tag.(bootclasspathDependencyTag); ok && bcpTag.typ == fragment { + return false + } + if tag == moduleInFragmentDepTag { + return false + } + if tag == dexpreopt.Dex2oatDepTag { + return false + } + if tag == android.PrebuiltDepTag { + return false + } + if _, ok := tag.(hiddenAPIStubsDependencyTag); ok { return false - } - panic(fmt.Errorf("boot_image module %q should not have a dependency tag %s", b, android.PrettyPrintTag(tag))) + panic(fmt.Errorf("boot_image module should not have a dependency tag %s", android.PrettyPrintTag(tag))) } -func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { - return nil +func (m *BootclasspathFragmentModule) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a @@ -458,24 +495,24 @@ func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorCon } } - if !dexpreopt.IsDex2oatNeeded(ctx) { - return + if dexpreopt.IsDex2oatNeeded(ctx) { + // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The + // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). + dexpreopt.RegisterToolDeps(ctx) } - // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The - // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). - dexpreopt.RegisterToolDeps(ctx) - // Add a dependency to `all_apex_contributions` to determine if prebuilts are active. // If prebuilts are active, `contents` validation on the source bootclasspath fragment should be disabled. if _, isPrebuiltModule := ctx.Module().(*PrebuiltBootclasspathFragmentModule); !isPrebuiltModule { ctx.AddDependency(b, android.AcDepTag, "all_apex_contributions") } -} -func (b *BootclasspathFragmentModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { // Add dependencies on all the fragments. b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx) + + for _, name := range b.properties.Contents.GetOrDefault(ctx, nil) { + ctx.AddDependency(ctx.Module(), moduleInFragmentDepTag, name) + } } func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -498,7 +535,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo } }) - fragments := gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag) + fragments, _ := gatherFragments(ctx) // Perform hidden API processing. hiddenAPIOutput := b.generateHiddenAPIBuildActions(ctx, contents, fragments) @@ -606,7 +643,7 @@ func (b *BootclasspathFragmentModule) configuredJars(ctx android.ModuleContext) if android.IsModulePrebuilt(ctx.Module()) { // prebuilt bcpf. the validation of this will be done at the top-level apex providerClasspathFragmentValidationInfoProvider(ctx, unknown) - } else if !disableSourceApexVariant(ctx) { + } else if !disableSourceApexVariant(ctx) && android.IsModulePreferred(ctx.Module()) { // source bcpf, and prebuilt apex are not selected. ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_BOOT_JARS", unknown) } @@ -1142,6 +1179,13 @@ func prebuiltBootclasspathFragmentFactory() android.Module { android.InitPrebuiltModule(m, &[]string{"placeholder"}) android.InitApexModule(m) android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) + android.InitDefaultableModule(m) + + m.SetDefaultableHook(func(mctx android.DefaultableHookContext) { + if mctx.Config().AlwaysUsePrebuiltSdks() { + m.prebuilt.ForcePrefer() + } + }) return m } diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index d181ce060..87b853c56 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -371,7 +371,7 @@ func TestFromTextWidestApiScope(t *testing.T) { } `) - fragment := result.ModuleForTests("myfragment", "android_common") + fragment := result.ModuleForTests(t, "myfragment", "android_common") dependencyStubDexFlag := "--dependency-stub-dex=out/soong/.intermediates/default/java/android-non-updatable.stubs.test_module_lib/android_common/dex/android-non-updatable.stubs.test_module_lib.jar" stubFlagsCommand := fragment.Output("modular-hiddenapi/stub-flags.csv").RuleParams.Command android.AssertStringDoesContain(t, @@ -479,7 +479,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { // Make sure that the signature-patterns.csv is passed all the appropriate package properties // from the bootclasspath_fragment and its contents. - fragment := result.ModuleForTests("mybootclasspathfragment", "android_common") + fragment := result.ModuleForTests(t, "mybootclasspathfragment", "android_common") rule := fragment.Output("modular-hiddenapi/signature-patterns.csv") expectedCommand := strings.Join([]string{ "--split-package newlibrary", diff --git a/java/builder.go b/java/builder.go index 22dad103b..ade978450 100644 --- a/java/builder.go +++ b/java/builder.go @@ -323,6 +323,13 @@ var ( Command: `${keep-flagged-apis} ${in} > ${out}`, CommandDeps: []string{"${keep-flagged-apis}"}, }) + + generateApiXMLRule = pctx.AndroidStaticRule("generateApiXMLRule", + blueprint.RuleParams{ + Command: `${config.JavaCmd} ${config.JavaVmFlags} -Xmx4g -jar ${config.MetalavaJar} jar-to-jdiff ${in} ${out}`, + CommandDeps: []string{"${config.JavaCmd}", "${config.MetalavaJar}"}, + Description: "Converting API file to XML", + }) ) func init() { diff --git a/java/classpath_element.go b/java/classpath_element.go index abbcae7a3..4af277012 100644 --- a/java/classpath_element.go +++ b/java/classpath_element.go @@ -108,33 +108,18 @@ type ClasspathElementContext interface { // // e.g. Given the following input: // -// libraries: com.android.art:core-oj, com.android.art:core-libart, framework, ext -// fragments: com.android.art:art-bootclasspath-fragment +// libraries: core-oj, core-libart, framework, ext +// fragments: art-bootclasspath-fragment +// libraryToApex: core-oj: com.android.art, core-libart: com.android.art +// apexNameToFragment: com.android.art: art-bootclasspath-fragment // // Then this will return: // // ClasspathFragmentElement(art-bootclasspath-fragment, [core-oj, core-libart]), // ClasspathLibraryElement(framework), // ClasspathLibraryElement(ext), -func CreateClasspathElements(ctx ClasspathElementContext, libraries []android.Module, fragments []android.Module) ClasspathElements { - // Create a map from apex name to the fragment module. This makes it easy to find the fragment - // associated with a particular apex. - apexToFragment := map[string]android.Module{} - for _, fragment := range fragments { - apexInfo, ok := android.OtherModuleProvider(ctx, fragment, android.ApexInfoProvider) - if !ok { - ctx.ModuleErrorf("fragment %s is not part of an apex", fragment) - continue - } - - for _, apex := range apexInfo.InApexVariants { - if existing, ok := apexToFragment[apex]; ok { - ctx.ModuleErrorf("apex %s has multiple fragments, %s and %s", apex, fragment, existing) - continue - } - apexToFragment[apex] = fragment - } - } +func CreateClasspathElements(ctx ClasspathElementContext, libraries []android.Module, fragments []android.Module, + libraryToApex map[android.Module]string, apexNameToFragment map[string]android.Module) ClasspathElements { fragmentToElement := map[android.Module]*ClasspathFragmentElement{} elements := []ClasspathElement{} @@ -144,31 +129,28 @@ skipLibrary: // Iterate over the libraries to construct the ClasspathElements list. for _, library := range libraries { var element ClasspathElement - if apexInfo, ok := android.OtherModuleProvider(ctx, library, android.ApexInfoProvider); ok { - + if libraryApex, ok := libraryToApex[library]; ok { var fragment android.Module // Make sure that the library is in only one fragment of the classpath. - for _, apex := range apexInfo.InApexVariants { - if f, ok := apexToFragment[apex]; ok { - if fragment == nil { - // This is the first fragment so just save it away. - fragment = f - } else if f != fragment { - // This apex variant of the library is in a different fragment. - ctx.ModuleErrorf("library %s is in two separate fragments, %s and %s", library, fragment, f) - // Skip over this library entirely as otherwise the resulting classpath elements would - // be invalid. - continue skipLibrary - } - } else { - // There is no fragment associated with the library's apex. + if f, ok := apexNameToFragment[libraryApex]; ok { + if fragment == nil { + // This is the first fragment so just save it away. + fragment = f + } else if f != fragment { + // This apex variant of the library is in a different fragment. + ctx.ModuleErrorf("library %s is in two separate fragments, %s and %s", library, fragment, f) + // Skip over this library entirely as otherwise the resulting classpath elements would + // be invalid. + continue skipLibrary } + } else { + // There is no fragment associated with the library's apex. } if fragment == nil { ctx.ModuleErrorf("library %s is from apexes %s which have no corresponding fragment in %s", - library, apexInfo.InApexVariants, fragments) + library, []string{libraryApex}, fragments) // Skip over this library entirely as otherwise the resulting classpath elements would // be invalid. continue skipLibrary diff --git a/java/container_test.go b/java/container_test.go index 515236d7d..35a3020ec 100644 --- a/java/container_test.go +++ b/java/container_test.go @@ -155,7 +155,7 @@ func TestJavaContainersModuleProperties(t *testing.T) { } for _, c := range testcases { - m := result.ModuleForTests(c.moduleName, "android_common") + m := result.ModuleForTests(t, c.moduleName, "android_common") containers, _ := android.OtherModuleProvider(result.TestContext.OtherModuleProviderAdaptor(), m.Module(), android.ContainersInfoProvider) belongingContainers := containers.BelongingContainers() checkContainerMatch(t, c.moduleName, "system", c.isSystemContainer, android.InList(android.SystemContainer, belongingContainers)) diff --git a/java/device_host_converter_test.go b/java/device_host_converter_test.go index 45369e2d6..197bb9f95 100644 --- a/java/device_host_converter_test.go +++ b/java/device_host_converter_test.go @@ -53,15 +53,15 @@ func TestDeviceForHost(t *testing.T) { ctx, config := testJava(t, bp) - deviceModule := ctx.ModuleForTests("device_module", "android_common") + deviceModule := ctx.ModuleForTests(t, "device_module", "android_common") deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar") deviceJavac := deviceModule.Output("javac/device_module.jar") deviceRes := deviceModule.Output("res/device_module.jar") - deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common") + deviceImportModule := ctx.ModuleForTests(t, "device_import_module", "android_common") deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar") - hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String()) + hostModule := ctx.ModuleForTests(t, "host_module", config.BuildOSCommonTarget.String()) hostJavac := hostModule.Output("javac/host_module.jar") hostRes := hostModule.Output("res/host_module.jar") combined := hostModule.Output("combined/host_module.jar") @@ -135,15 +135,15 @@ func TestHostForDevice(t *testing.T) { ctx, config := testJava(t, bp) - hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String()) + hostModule := ctx.ModuleForTests(t, "host_module", config.BuildOSCommonTarget.String()) hostJavac := hostModule.Output("javac/host_module.jar") hostJavacHeader := hostModule.Output("javac-header/host_module.jar") hostRes := hostModule.Output("res/host_module.jar") - hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String()) + hostImportModule := ctx.ModuleForTests(t, "host_import_module", config.BuildOSCommonTarget.String()) hostImportCombined := hostImportModule.Output("combined/host_import_module.jar") - deviceModule := ctx.ModuleForTests("device_module", "android_common") + deviceModule := ctx.ModuleForTests(t, "device_module", "android_common") deviceJavac := deviceModule.Output("javac/device_module.jar") deviceRes := deviceModule.Output("res/device_module.jar") combined := deviceModule.Output("combined/device_module.jar") diff --git a/java/dex_test.go b/java/dex_test.go index 4e515b403..2126e42e8 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -60,11 +60,11 @@ func TestR8(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") - stableApp := result.ModuleForTests("stable_app", "android_common") - corePlatformApp := result.ModuleForTests("core_platform_app", "android_common") - lib := result.ModuleForTests("lib", "android_common") - staticLib := result.ModuleForTests("static_lib", "android_common") + app := result.ModuleForTests(t, "app", "android_common") + stableApp := result.ModuleForTests(t, "stable_app", "android_common") + corePlatformApp := result.ModuleForTests(t, "core_platform_app", "android_common") + lib := result.ModuleForTests(t, "lib", "android_common") + staticLib := result.ModuleForTests(t, "static_lib", "android_common") appJavac := app.Rule("javac") appR8 := app.Rule("r8") @@ -210,14 +210,14 @@ func TestR8TransitiveDeps(t *testing.T) { result := fixturePreparer.RunTestWithBp(t, bp) getHeaderJar := func(name string) android.Path { - mod := result.ModuleForTests(name, "android_common") + mod := result.ModuleForTests(t, name, "android_common") return mod.Output("turbine-combined/" + name + ".jar").Output } - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") - overrideAppR8 := result.ModuleForTests("app", "android_common_override_app").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") + overrideAppR8 := result.ModuleForTests(t, "app", "android_common_override_app").Rule("r8") appHeader := getHeaderJar("app") - overrideAppHeader := result.ModuleForTests("app", "android_common_override_app").Output("turbine-combined/app.jar").Output + overrideAppHeader := result.ModuleForTests(t, "app", "android_common_override_app").Output("turbine-combined/app.jar").Output libHeader := getHeaderJar("lib") transitiveLibHeader := getHeaderJar("transitive_lib") transitiveLib2Header := getHeaderJar("transitive_lib_2") @@ -226,7 +226,7 @@ func TestR8TransitiveDeps(t *testing.T) { repeatedDepHeader := getHeaderJar("repeated_dep") usesLibHeader := getHeaderJar("uses_lib") optionalUsesLibHeader := getHeaderJar("optional_uses_lib") - prebuiltLibHeader := result.ModuleForTests("prebuilt_lib", "android_common").Output("combined/lib.jar").Output + prebuiltLibHeader := result.ModuleForTests(t, "prebuilt_lib", "android_common").Output("combined/lib.jar").Output for _, rule := range []android.TestingBuildParams{appR8, overrideAppR8} { android.AssertStringDoesNotContain(t, "expected no app header jar in app r8 classpath", @@ -278,7 +278,7 @@ func TestR8Flags(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags", appR8.Args["r8Flags"], "-dontshrink") @@ -323,10 +323,10 @@ func TestD8(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") - lib := result.ModuleForTests("lib", "android_common") - app := result.ModuleForTests("app", "android_common") - staticLib := result.ModuleForTests("static_lib", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") + lib := result.ModuleForTests(t, "lib", "android_common") + app := result.ModuleForTests(t, "app", "android_common") + staticLib := result.ModuleForTests(t, "static_lib", "android_common") fooJavac := foo.Rule("javac") fooD8 := foo.Rule("d8") @@ -398,7 +398,7 @@ func TestProguardFlagsInheritanceStatic(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected primary_lib's proguard flags from direct dep", appR8.Args["r8Flags"], "primary.flags") @@ -647,7 +647,7 @@ func TestProguardFlagsInheritance(t *testing.T) { tc.transitiveDepExportsFlagsFiles, ), ) - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") shouldHaveDepFlags := android.InList(directDepFlagsFileName, tc.expectedFlagsFiles) if shouldHaveDepFlags { @@ -689,7 +689,7 @@ func TestProguardFlagsInheritanceAppImport(t *testing.T) { PrepareForTestWithJavaDefaultModules, ).RunTestWithBp(t, bp) - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") android.AssertStringDoesContain(t, "expected aarimports's proguard flags", appR8.Args["r8Flags"], "proguard.txt") } @@ -709,7 +709,7 @@ func TestR8FlagsArtProfile(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected --art-profile in app r8 flags", appR8.Args["r8Flags"], "--art-profile") @@ -847,7 +847,7 @@ func TestDebugReleaseFlags(t *testing.T) { dexRuleKey = "d8" } dexFlagsKey := dexRuleKey + "Flags" - appDex := result.ModuleForTests("app", "android_common").Rule(dexRuleKey) + appDex := result.ModuleForTests(t, "app", "android_common").Rule(dexRuleKey) android.AssertStringDoesContain(t, "expected flag in dex flags", appDex.Args[dexFlagsKey], tc.expectedFlags) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 15e40ba0d..5755dec23 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -177,10 +177,7 @@ func disableSourceApexVariant(ctx android.BaseModuleContext) bool { // Find the apex variant for this module apexVariants := []string{} if apexInfo.BaseApexName != "" { - // This is a transitive dependency of an override_apex apexVariants = append(apexVariants, apexInfo.BaseApexName) - } else { - apexVariants = append(apexVariants, apexInfo.InApexVariants...) } if apexInfo.ApexAvailableName != "" { apexVariants = append(apexVariants, apexInfo.ApexAvailableName) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 093cc876b..27027f07d 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -15,6 +15,7 @@ package java import ( + "fmt" "path/filepath" "strings" @@ -225,7 +226,6 @@ var artApexNames = []string{ } var ( - dexpreoptBootJarDepTag = bootclasspathDependencyTag{name: "dexpreopt-boot-jar"} dexBootJarsFragmentsKey = android.NewOnceKey("dexBootJarsFragments") apexContributionsMetadataDepTag = dependencyTag{name: "all_apex_contributions"} ) @@ -467,9 +467,6 @@ func dexpreoptBootJarsFactory() android.SingletonModule { func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) { ctx.RegisterParallelSingletonModuleType("dex_bootjars", dexpreoptBootJarsFactory) ctx.RegisterModuleType("art_boot_images", artBootImagesFactory) - ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("dex_bootjars_deps", DexpreoptBootJarsMutator) - }) } func SkipDexpreoptBootJars(ctx android.PathContext) bool { @@ -505,12 +502,6 @@ type dexpreoptBootJars struct { func (dbj *dexpreoptBootJars) DepsMutator(ctx android.BottomUpMutatorContext) { // Create a dependency on all_apex_contributions to determine the selected mainline module ctx.AddDependency(ctx.Module(), apexContributionsMetadataDepTag, "all_apex_contributions") -} - -func DexpreoptBootJarsMutator(ctx android.BottomUpMutatorContext) { - if _, ok := ctx.Module().(*dexpreoptBootJars); !ok { - return - } if dexpreopt.IsDex2oatNeeded(ctx) { // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The @@ -524,7 +515,7 @@ func DexpreoptBootJarsMutator(ctx android.BottomUpMutatorContext) { continue } // For accessing the boot jars. - addDependenciesOntoBootImageModules(ctx, config.modules, dexpreoptBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, config.modules, dexpreoptBootJar) // Create a dependency on the apex selected using RELEASE_APEX_CONTRIBUTIONS_* // TODO: b/308174306 - Remove the direct depedendency edge to the java_library (source/prebuilt) once all mainline modules // have been flagged using RELEASE_APEX_CONTRIBUTIONS_* @@ -537,11 +528,11 @@ func DexpreoptBootJarsMutator(ctx android.BottomUpMutatorContext) { if ctx.OtherModuleExists("platform-bootclasspath") { // For accessing all bootclasspath fragments. - addDependencyOntoApexModulePair(ctx, "platform", "platform-bootclasspath", platformBootclasspathDepTag) + addDependencyOntoApexModulePair(ctx, "platform", "platform-bootclasspath", platform) } else if ctx.OtherModuleExists("art-bootclasspath-fragment") { // For accessing the ART bootclasspath fragment on a thin manifest (e.g., master-art) where // platform-bootclasspath doesn't exist. - addDependencyOntoApexModulePair(ctx, "com.android.art", "art-bootclasspath-fragment", bootclasspathFragmentDepTag) + addDependencyOntoApexModulePair(ctx, "com.android.art", "art-bootclasspath-fragment", fragment) } } @@ -559,17 +550,11 @@ func addDependenciesOntoSelectedBootImageApexes(ctx android.BottomUpMutatorConte // We need to add a dep on only the apex listed in `contents` of the selected apex_contributions module // This is not available in a structured format in `apex_contributions`, so this hack adds a dep on all `contents` // (some modules like art.module.public.api do not have an apex variation since it is a pure stub module that does not get installed) - apexVariationOfSelected := append(ctx.Target().Variations(), blueprint.Variation{Mutator: "apex", Variation: apex}) - if ctx.OtherModuleDependencyVariantExists(apexVariationOfSelected, selected) { - ctx.AddFarVariationDependencies(apexVariationOfSelected, dexpreoptBootJarDepTag, selected) - } else if ctx.OtherModuleDependencyVariantExists(apexVariationOfSelected, android.RemoveOptionalPrebuiltPrefix(selected)) { - // The prebuilt might have been renamed by prebuilt_rename mutator if the source module does not exist. - // Remove the prebuilt_ prefix. - ctx.AddFarVariationDependencies(apexVariationOfSelected, dexpreoptBootJarDepTag, android.RemoveOptionalPrebuiltPrefix(selected)) - } else { - // Couldn't find a dependency, do it again to report an error. - ctx.AddFarVariationDependencies(apexVariationOfSelected, dexpreoptBootJarDepTag, selected) + tag := bootclasspathDependencyTag{ + typ: dexpreoptBootJar, } + + ctx.AddFarVariationDependencies(ctx.Target().Variations(), tag, android.RemoveOptionalPrebuiltPrefix(selected)) } } } @@ -577,23 +562,55 @@ func addDependenciesOntoSelectedBootImageApexes(ctx android.BottomUpMutatorConte func gatherBootclasspathFragments(ctx android.ModuleContext) map[string]android.Module { return ctx.Config().Once(dexBootJarsFragmentsKey, func() interface{} { fragments := make(map[string]android.Module) + + type moduleInApexPair struct { + module string + apex string + } + + var modulesInApexes []moduleInApexPair + + // Find the list of modules in apexes. ctx.WalkDeps(func(child, parent android.Module) bool { if !isActiveModule(ctx, child) { return false } tag := ctx.OtherModuleDependencyTag(child) - if tag == platformBootclasspathDepTag { - return true - } - if tag == bootclasspathFragmentDepTag { - apexInfo, _ := android.OtherModuleProvider(ctx, child, android.ApexInfoProvider) - for _, apex := range apexInfo.InApexVariants { - fragments[apex] = child + if bcpTag, ok := tag.(bootclasspathDependencyTag); ok { + if bcpTag.typ == platform { + return true + } + if bcpTag.typ == fragment { + if bcpTag.moduleInApex == "" { + panic(fmt.Errorf("expected fragment to be in apex")) + } + modulesInApexes = append(modulesInApexes, moduleInApexPair{bcpTag.moduleInApex, ctx.OtherModuleName(child)}) + return true } - return false } return false }) + + for _, moduleInApex := range modulesInApexes { + // Find a desired module in an apex. + ctx.WalkDeps(func(child, parent android.Module) bool { + t := ctx.OtherModuleDependencyTag(child) + if bcpTag, ok := t.(bootclasspathDependencyTag); ok { + if bcpTag.typ == platform { + return true + } + if bcpTag.typ == fragment && ctx.OtherModuleName(child) == moduleInApex.apex { + // This is the dependency from this module to the apex, recurse into it. + return true + } + } else if android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child)) == moduleInApex.module { + // This is the desired module inside the apex. + fragments[android.RemoveOptionalPrebuiltPrefix(moduleInApex.apex)] = child + } + return false + }) + } + return fragments }).(map[string]android.Module) } @@ -717,7 +734,8 @@ func getModulesForImage(ctx android.ModuleContext, imageConfig *bootImageConfig) modules := make([]apexJarModulePair, 0, imageConfig.modules.Len()) for i := 0; i < imageConfig.modules.Len(); i++ { found := false - for _, module := range gatherApexModulePairDepsWithTag(ctx, dexpreoptBootJarDepTag) { + dexpreoptBootJarModules, _ := gatherApexModulePairDepsWithTag(ctx, dexpreoptBootJar) + for _, module := range dexpreoptBootJarModules { name := android.RemoveOptionalPrebuiltPrefix(module.Name()) if name == imageConfig.modules.Jar(i) { modules = append(modules, apexJarModulePair{ @@ -800,11 +818,16 @@ func getDexJarForApex(ctx android.ModuleContext, pair apexJarModulePair, apexNam "APEX '%[2]s' doesn't exist or is not added as a dependency of dex_bootjars", pair.jarModule.Name(), pair.apex) + return nil } bootclasspathFragmentInfo, _ := android.OtherModuleProvider(ctx, fragment, BootclasspathFragmentApexContentInfoProvider) jar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(pair.jarModule) if err != nil { - ctx.ModuleErrorf("%s", err) + if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies([]string{pair.jarModule.String()}) + } else { + ctx.ModuleErrorf("%s", err) + } } return jar } @@ -963,9 +986,16 @@ func getProfilePathForApex(ctx android.ModuleContext, apexName string, apexNameT func getApexNameToApexExportsInfoMap(ctx android.ModuleContext) apexNameToApexExportsInfoMap { apexNameToApexExportsInfoMap := apexNameToApexExportsInfoMap{} - ctx.VisitDirectDepsWithTag(dexpreoptBootJarDepTag, func(am android.Module) { - if info, exists := android.OtherModuleProvider(ctx, am, android.ApexExportsInfoProvider); exists { - apexNameToApexExportsInfoMap[info.ApexName] = info + + ctx.VisitDirectDeps(func(am android.Module) { + tag := ctx.OtherModuleDependencyTag(am) + if bcpTag, ok := tag.(bootclasspathDependencyTag); ok && bcpTag.typ == dexpreoptBootJar { + if bcpTag.moduleInApex == "" { + info, exists := android.OtherModuleProvider(ctx, am, android.ApexExportsInfoProvider) + if exists { + apexNameToApexExportsInfoMap[info.ApexName] = info + } + } } }) return apexNameToApexExportsInfoMap @@ -1448,24 +1478,33 @@ func artBootImagesFactory() android.Module { func (dbj *artBootImages) DepsMutator(ctx android.BottomUpMutatorContext) { // Create a dependency on `dex_bootjars` to access the intermediate locations of host art boot image. - ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), dexpreoptBootJarDepTag, "dex_bootjars") + tag := bootclasspathDependencyTag{ + typ: dexpreoptBootJar, + } + ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), tag, "dex_bootjars") } func (d *artBootImages) GenerateAndroidBuildActions(ctx android.ModuleContext) { - ctx.VisitDirectDepsWithTag(dexpreoptBootJarDepTag, func(m android.Module) { - hostInstallsInfo, ok := android.OtherModuleProvider(ctx, m, artBootImageHostInfoProvider) - if !ok { - ctx.ModuleErrorf("Could not find information about the host variant of ART boot image") - } - installs := d.installFile(ctx, hostInstallsInfo.installs) - if len(installs) > 0 { - d.outputFile = android.OptionalPathForPath(installs[0]) - // Create a phony target that can ART run-tests can depend on. - ctx.Phony(d.Name(), installs...) - } else { - // this might be true e.g. when building with `WITH_DEXPREOPT=false` - // create an empty file so that the `art_boot_images` is known to the packaging system. - d.outputFile = android.OptionalPathForPath(android.PathForModuleOut(ctx, "undefined_art_boot_images")) + ctx.VisitDirectDeps(func(m android.Module) { + tag := ctx.OtherModuleDependencyTag(m) + if bcpTag, ok := tag.(bootclasspathDependencyTag); ok && bcpTag.typ == dexpreoptBootJar { + if bcpTag.moduleInApex != "" { + panic("unhandled moduleInApex") + } + hostInstallsInfo, ok := android.OtherModuleProvider(ctx, m, artBootImageHostInfoProvider) + if !ok { + ctx.ModuleErrorf("Could not find information about the host variant of ART boot image") + } + installs := d.installFile(ctx, hostInstallsInfo.installs) + if len(installs) > 0 { + d.outputFile = android.OptionalPathForPath(installs[0]) + // Create a phony target that can ART run-tests can depend on. + ctx.Phony(d.Name(), installs...) + } else { + // this might be true e.g. when building with `WITH_DEXPREOPT=false` + // create an empty file so that the `art_boot_images` is known to the packaging system. + d.outputFile = android.OptionalPathForPath(android.PathForModuleOut(ctx, "undefined_art_boot_images")) + } } }) } diff --git a/java/dexpreopt_config_testing.go b/java/dexpreopt_config_testing.go index fbdb7b028..241941eb8 100644 --- a/java/dexpreopt_config_testing.go +++ b/java/dexpreopt_config_testing.go @@ -1237,7 +1237,7 @@ func nestedCheckBootImageConfig(t *testing.T, result *android.TestResult, imageC android.AssertPathRelativeToTopEquals(t, "zip", expected.zip, imageConfig.zip) if !mutated { - dexBootJarModule := result.ModuleForTests("dex_bootjars", "android_common") + dexBootJarModule := result.ModuleForTests(t, "dex_bootjars", "android_common") profileInstallInfo, _ := android.OtherModuleProvider(result, dexBootJarModule.Module(), profileInstallInfoProvider) assertInstallsEqual(t, "profileInstalls", expected.profileInstalls, profileInstallInfo.profileInstalls) android.AssertStringEquals(t, "profileLicenseMetadataFile", expected.profileLicenseMetadataFile, profileInstallInfo.profileLicenseMetadataFile.RelativeToTop().String()) @@ -1281,7 +1281,7 @@ func CheckMutatedFrameworkBootImageConfig(t *testing.T, result *android.TestResu // checkDexpreoptMakeVars checks the DEXPREOPT_ prefixed make vars produced by dexpreoptBootJars // singleton. func checkDexpreoptMakeVars(t *testing.T, result *android.TestResult, expectedLicenseMetadataFile string) { - vars := result.MakeVarsForTesting(func(variable android.MakeVarVariable) bool { + vars := result.MakeVarsForTesting(t, func(variable android.MakeVarVariable) bool { return strings.HasPrefix(variable.Name(), "DEXPREOPT_") }) diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index bf660475f..f437da02c 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -239,7 +239,7 @@ func TestDexpreoptEnabled(t *testing.T) { variant += "_apex1000" } - dexpreopt := ctx.ModuleForTests(moduleName, variant).MaybeRule("dexpreopt") + dexpreopt := ctx.ModuleForTests(t, moduleName, variant).MaybeRule("dexpreopt") enabled := dexpreopt.Rule != nil if enabled != test.enabled { @@ -325,7 +325,7 @@ func TestApexSystemServerDexpreoptInstalls(t *testing.T) { sdk_version: "current", }`) ctx := result.TestContext - module := ctx.ModuleForTests("service-foo", "android_common_apex1000") + module := ctx.ModuleForTests(t, "service-foo", "android_common_apex1000") library := module.Module().(*Library) installs := library.dexpreopter.ApexSystemServerDexpreoptInstalls() @@ -367,7 +367,7 @@ func TestApexSystemServerDexpreoptInstalls(t *testing.T) { sdk_version: "current", }`) ctx = result.TestContext - module = ctx.ModuleForTests("foo", "android_common") + module = ctx.ModuleForTests(t, "foo", "android_common") library = module.Module().(*Library) installs = library.dexpreopter.ApexSystemServerDexpreoptInstalls() @@ -396,7 +396,7 @@ func TestGenerateProfileEvenIfDexpreoptIsDisabled(t *testing.T) { }`) ctx := result.TestContext - dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeRule("dexpreopt") + dexpreopt := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("dexpreopt") expected := []string{"out/soong/.intermediates/foo/android_common/dexpreopt/foo/profile.prof"} diff --git a/java/droiddoc_test.go b/java/droiddoc_test.go index 2256f1e23..0c977bceb 100644 --- a/java/droiddoc_test.go +++ b/java/droiddoc_test.go @@ -70,13 +70,13 @@ func TestDroiddoc(t *testing.T) { "bar-doc/a.java": nil, "bar-doc/b.java": nil, }) - barStubsOutputs := ctx.ModuleForTests("bar-stubs", "android_common").OutputFiles(ctx, t, "") + barStubsOutputs := ctx.ModuleForTests(t, "bar-stubs", "android_common").OutputFiles(ctx, t, "") if len(barStubsOutputs) != 1 { t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs) } barStubsOutput := barStubsOutputs[0] - barDoc := ctx.ModuleForTests("bar-doc", "android_common") + barDoc := ctx.ModuleForTests(t, "bar-doc", "android_common") javaDoc := barDoc.Rule("javadoc") if g, w := android.PathsRelativeToTop(javaDoc.Implicits), android.PathRelativeToTop(barStubsOutput); !inList(w, g) { t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) diff --git a/java/droidstubs.go b/java/droidstubs.go index 22f4d981d..caad6883e 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -1429,6 +1429,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { d.setOutputFiles(ctx) d.setPhonyRules(ctx) + + if d.apiLintTimestamp != nil { + if d.apiLintReport != nil { + ctx.DistForGoalsWithFilename( + []string{fmt.Sprintf("%s-api-lint", d.Name()), "droidcore"}, + d.apiLintReport, + fmt.Sprintf("apilint/%s-lint-report.txt", d.Name()), + ) + } + } } func setDroidInfo(ctx android.ModuleContext, d *Droidstubs, info *StubsInfo, typ StubsType) { diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index faa9a1539..dfdf87703 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -83,7 +83,7 @@ func TestDroidstubs(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") manifest := m.Output("metalava.sbox.textproto") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, manifest) cmdline := String(sboxProto.Commands[0].Command) @@ -132,7 +132,7 @@ func getAndroidJarPatternsForDroidstubs(t *testing.T, sdkType string) []string { "foo-doc/a.java": nil, }) - m := ctx.ModuleForTests("foo-stubs", "android_common") + m := ctx.ModuleForTests(t, "foo-stubs", "android_common") manifest := m.Output("metalava.sbox.textproto") cmd := String(android.RuleBuilderSboxProtoForTests(t, ctx, manifest).Commands[0].Command) r := regexp.MustCompile(`--android-jar-pattern [^ ]+/android.jar`) @@ -210,7 +210,7 @@ func TestDroidstubsSandbox(t *testing.T) { "bar-doc/a.java": nil, }) - m := ctx.ModuleForTests("bar-stubs", "android_common") + m := ctx.ModuleForTests(t, "bar-stubs", "android_common") metalava := m.Rule("metalava") if g, w := metalava.Inputs.Strings(), []string{"bar-doc/a.java"}; !reflect.DeepEqual(w, g) { t.Errorf("Expected inputs %q, got %q", w, g) @@ -271,7 +271,7 @@ func TestDroidstubsWithSystemModules(t *testing.T) { } func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) { - metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava") + metalavaRule := ctx.ModuleForTests(t, moduleName, "android_common").Rule("metalava") var systemJars []string for _, i := range metalavaRule.Implicits { systemJars = append(systemJars, i.Base()) @@ -304,7 +304,7 @@ func TestDroidstubsWithSdkExtensions(t *testing.T) { "sdk/extensions/1/public/some-mainline-module-stubs.jar": nil, "sdk/extensions/info.txt": nil, }) - m := ctx.ModuleForTests("baz-stubs", "android_common") + m := ctx.ModuleForTests(t, "baz-stubs", "android_common") manifest := m.Output("metalava.sbox.textproto") cmdline := String(android.RuleBuilderSboxProtoForTests(t, ctx, manifest).Commands[0].Command) android.AssertStringDoesContain(t, "android-jar-pattern present", cmdline, "--android-jar-pattern sdk/extensions/{version:extension}/public/{module}.jar") @@ -332,7 +332,7 @@ func TestDroidStubsApiContributionGeneration(t *testing.T) { }, ) - ctx.ModuleForTests("foo.api.contribution", "") + ctx.ModuleForTests(t, "foo.api.contribution", "") } func TestGeneratedApiContributionVisibilityTest(t *testing.T) { @@ -366,7 +366,7 @@ func TestGeneratedApiContributionVisibilityTest(t *testing.T) { }, ) - ctx.ModuleForTests("bar", "android_common") + ctx.ModuleForTests(t, "bar", "android_common") } func TestAconfigDeclarations(t *testing.T) { @@ -408,7 +408,7 @@ func TestAconfigDeclarations(t *testing.T) { android.AssertBoolEquals(t, "foo expected to depend on bar", CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "bar"), true) - m := result.ModuleForTests("foo", "android_common") + m := result.ModuleForTests(t, "foo", "android_common") android.AssertStringDoesContain(t, "foo generates revert annotations file", strings.Join(m.AllOutputs(), ""), "revert-annotations-exportable.txt") @@ -458,7 +458,7 @@ func TestReleaseExportRuntimeApis(t *testing.T) { } `) - m := result.ModuleForTests("foo", "android_common") + m := result.ModuleForTests(t, "foo", "android_common") rule := m.Output("released-flagged-apis-exportable.txt") exposeWritableApisFilter := "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'" diff --git a/java/fuzz_test.go b/java/fuzz_test.go index 40adae0cb..8cbe873ad 100644 --- a/java/fuzz_test.go +++ b/java/fuzz_test.go @@ -64,14 +64,14 @@ func TestJavaFuzz(t *testing.T) { osCommonTarget := result.Config.BuildOSCommonTarget.String() - javac := result.ModuleForTests("foo", osCommonTarget).Rule("javac") - combineJar := result.ModuleForTests("foo", osCommonTarget).Description("for javac") + javac := result.ModuleForTests(t, "foo", osCommonTarget).Rule("javac") + combineJar := result.ModuleForTests(t, "foo", osCommonTarget).Description("for javac") if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) } - baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String() + baz := result.ModuleForTests(t, "baz", osCommonTarget).Rule("javac").Output.String() barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac-header", "bar.jar") bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac-header", "baz.jar") @@ -83,7 +83,7 @@ func TestJavaFuzz(t *testing.T) { } ctx := result.TestContext - foo := ctx.ModuleForTests("foo", osCommonTarget).Module().(*JavaFuzzTest) + foo := ctx.ModuleForTests(t, "foo", osCommonTarget).Module().(*JavaFuzzTest) expected := "lib64/libjni.so" if runtime.GOOS == "darwin" { diff --git a/java/generated_java_library_test.go b/java/generated_java_library_test.go index 7efd54b39..e5ee5861e 100644 --- a/java/generated_java_library_test.go +++ b/java/generated_java_library_test.go @@ -61,6 +61,6 @@ func TestGenLib(t *testing.T) { ` result := testGenLib(t, android.FixtureExpectsNoErrors, bp) - javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule) + javagenlibtest := result.ModuleForTests(t, "javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule) android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars) } diff --git a/java/genrule_combiner.go b/java/genrule_combiner.go new file mode 100644 index 000000000..357dc2c76 --- /dev/null +++ b/java/genrule_combiner.go @@ -0,0 +1,252 @@ +// Copyright 2019 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 ( + "fmt" + "io" + + "android/soong/android" + "android/soong/dexpreopt" + + "github.com/google/blueprint/depset" + "github.com/google/blueprint/proptools" +) + +type GenruleCombiner struct { + android.ModuleBase + android.DefaultableModuleBase + + genruleCombinerProperties GenruleCombinerProperties + + headerJars android.Paths + implementationJars android.Paths + implementationAndResourceJars android.Paths + resourceJars android.Paths + aconfigProtoFiles android.Paths + + srcJarArgs []string + srcJarDeps android.Paths + + headerDirs android.Paths + + combinedHeaderJar android.Path + combinedImplementationJar android.Path +} + +type GenruleCombinerProperties struct { + // List of modules whose implementation (and resources) jars will be visible to modules + // that depend on this module. + Static_libs proptools.Configurable[[]string] `android:"arch_variant"` + + // List of modules whose header jars will be visible to modules that depend on this module. + Headers proptools.Configurable[[]string] `android:"arch_variant"` +} + +// java_genrule_combiner provides the implementation and resource jars from `static_libs`, with +// the header jars from `headers`. +// +// This is useful when a java_genrule is used to change the implementation of a java library +// without requiring a change in the header jars. +func GenruleCombinerFactory() android.Module { + module := &GenruleCombiner{} + + module.AddProperties(&module.genruleCombinerProperties) + InitJavaModule(module, android.HostAndDeviceSupported) + return module +} + +var genruleCombinerHeaderDepTag = dependencyTag{name: "genrule_combiner_header"} + +func (j *GenruleCombiner) DepsMutator(ctx android.BottomUpMutatorContext) { + ctx.AddVariationDependencies(nil, staticLibTag, + j.genruleCombinerProperties.Static_libs.GetOrDefault(ctx, nil)...) + ctx.AddVariationDependencies(nil, genruleCombinerHeaderDepTag, + j.genruleCombinerProperties.Headers.GetOrDefault(ctx, nil)...) +} + +func (j *GenruleCombiner) GenerateAndroidBuildActions(ctx android.ModuleContext) { + if len(j.genruleCombinerProperties.Static_libs.GetOrDefault(ctx, nil)) < 1 { + ctx.PropertyErrorf("static_libs", "at least one dependency is required") + } + + if len(j.genruleCombinerProperties.Headers.GetOrDefault(ctx, nil)) < 1 { + ctx.PropertyErrorf("headers", "at least one dependency is required") + } + + var transitiveHeaderJars []depset.DepSet[android.Path] + var transitiveImplementationJars []depset.DepSet[android.Path] + var transitiveResourceJars []depset.DepSet[android.Path] + var sdkVersion android.SdkSpec + var stubsLinkType StubsLinkType + moduleWithSdkDepInfo := &ModuleWithSdkDepInfo{} + + // Collect the headers first, so that aconfig flag values for the libraries will override + // values from the headers (if they are different). + ctx.VisitDirectDepsWithTag(genruleCombinerHeaderDepTag, func(m android.Module) { + if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok { + j.headerJars = append(j.headerJars, dep.HeaderJars...) + + j.srcJarArgs = append(j.srcJarArgs, dep.SrcJarArgs...) + j.srcJarDeps = append(j.srcJarDeps, dep.SrcJarDeps...) + j.aconfigProtoFiles = append(j.aconfigProtoFiles, dep.AconfigIntermediateCacheOutputPaths...) + sdkVersion = dep.SdkVersion + stubsLinkType = dep.StubsLinkType + *moduleWithSdkDepInfo = *dep.ModuleWithSdkDepInfo + + transitiveHeaderJars = append(transitiveHeaderJars, dep.TransitiveStaticLibsHeaderJars) + } else if dep, ok := android.OtherModuleProvider(ctx, m, android.CodegenInfoProvider); ok { + j.aconfigProtoFiles = append(j.aconfigProtoFiles, dep.IntermediateCacheOutputPaths...) + } else { + ctx.PropertyErrorf("headers", "module %q cannot be used as a dependency", ctx.OtherModuleName(m)) + } + }) + ctx.VisitDirectDepsWithTag(staticLibTag, func(m android.Module) { + if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok { + j.implementationJars = append(j.implementationJars, dep.ImplementationJars...) + j.implementationAndResourceJars = append(j.implementationAndResourceJars, dep.ImplementationAndResourcesJars...) + j.resourceJars = append(j.resourceJars, dep.ResourceJars...) + + transitiveImplementationJars = append(transitiveImplementationJars, dep.TransitiveStaticLibsImplementationJars) + transitiveResourceJars = append(transitiveResourceJars, dep.TransitiveStaticLibsResourceJars) + j.aconfigProtoFiles = append(j.aconfigProtoFiles, dep.AconfigIntermediateCacheOutputPaths...) + } else if dep, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider); ok { + // This is provided by `java_genrule` modules. + j.implementationJars = append(j.implementationJars, dep.DefaultOutputFiles...) + j.implementationAndResourceJars = append(j.implementationAndResourceJars, dep.DefaultOutputFiles...) + stubsLinkType = Implementation + } else { + ctx.PropertyErrorf("static_libs", "module %q cannot be used as a dependency", ctx.OtherModuleName(m)) + } + }) + + jarName := ctx.ModuleName() + ".jar" + + if len(j.implementationAndResourceJars) > 1 { + outputFile := android.PathForModuleOut(ctx, "combined", jarName) + TransformJarsToJar(ctx, outputFile, "combine", j.implementationAndResourceJars, + android.OptionalPath{}, false, nil, nil) + j.combinedImplementationJar = outputFile + } else if len(j.implementationAndResourceJars) == 1 { + j.combinedImplementationJar = j.implementationAndResourceJars[0] + } + + if len(j.headerJars) > 1 { + outputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) + TransformJarsToJar(ctx, outputFile, "turbine combine", j.headerJars, + android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"}) + j.combinedHeaderJar = outputFile + j.headerDirs = append(j.headerDirs, android.PathForModuleOut(ctx, "turbine-combined")) + } else if len(j.headerJars) == 1 { + j.combinedHeaderJar = j.headerJars[0] + } + + javaInfo := &JavaInfo{ + HeaderJars: android.Paths{j.combinedHeaderJar}, + LocalHeaderJars: android.Paths{j.combinedHeaderJar}, + TransitiveStaticLibsHeaderJars: depset.New(depset.PREORDER, android.Paths{j.combinedHeaderJar}, transitiveHeaderJars), + TransitiveStaticLibsImplementationJars: depset.New(depset.PREORDER, android.Paths{j.combinedImplementationJar}, transitiveImplementationJars), + TransitiveStaticLibsResourceJars: depset.New(depset.PREORDER, nil, transitiveResourceJars), + GeneratedSrcjars: android.Paths{j.combinedImplementationJar}, + ImplementationAndResourcesJars: android.Paths{j.combinedImplementationJar}, + ImplementationJars: android.Paths{j.combinedImplementationJar}, + ModuleWithSdkDepInfo: moduleWithSdkDepInfo, + ResourceJars: j.resourceJars, + OutputFile: j.combinedImplementationJar, + SdkVersion: sdkVersion, + SrcJarArgs: j.srcJarArgs, + SrcJarDeps: j.srcJarDeps, + StubsLinkType: stubsLinkType, + AconfigIntermediateCacheOutputPaths: j.aconfigProtoFiles, + } + setExtraJavaInfo(ctx, j, javaInfo) + ctx.SetOutputFiles(android.Paths{javaInfo.OutputFile}, "") + ctx.SetOutputFiles(android.Paths{javaInfo.OutputFile}, android.DefaultDistTag) + ctx.SetOutputFiles(javaInfo.ImplementationAndResourcesJars, ".jar") + ctx.SetOutputFiles(javaInfo.HeaderJars, ".hjar") + android.SetProvider(ctx, JavaInfoProvider, javaInfo) + +} + +func (j *GenruleCombiner) GeneratedSourceFiles() android.Paths { + return append(android.Paths{}, j.combinedImplementationJar) +} + +func (j *GenruleCombiner) GeneratedHeaderDirs() android.Paths { + return append(android.Paths{}, j.headerDirs...) +} + +func (j *GenruleCombiner) GeneratedDeps() android.Paths { + return append(android.Paths{}, j.combinedImplementationJar) +} + +func (j *GenruleCombiner) Srcs() android.Paths { + return append(android.Paths{}, j.implementationAndResourceJars...) +} + +func (j *GenruleCombiner) HeaderJars() android.Paths { + return j.headerJars +} + +func (j *GenruleCombiner) ImplementationAndResourcesJars() android.Paths { + return j.implementationAndResourceJars +} + +func (j *GenruleCombiner) DexJarBuildPath(ctx android.ModuleErrorfContext) android.Path { + return nil +} + +func (j *GenruleCombiner) DexJarInstallPath() android.Path { + return nil +} + +func (j *GenruleCombiner) AidlIncludeDirs() android.Paths { + return nil +} + +func (j *GenruleCombiner) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { + return nil +} + +func (j *GenruleCombiner) JacocoReportClassesFile() android.Path { + return nil +} + +func (j *GenruleCombiner) AndroidMk() android.AndroidMkData { + return android.AndroidMkData{ + Class: "JAVA_LIBRARIES", + OutputFile: android.OptionalPathForPath(j.combinedImplementationJar), + // Make does not support Windows Java modules + Disabled: j.Os() == android.Windows, + Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", + Extra: []android.AndroidMkExtraFunc{ + func(w io.Writer, outputFile android.Path) { + fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") + fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", j.combinedHeaderJar.String()) + fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", j.combinedImplementationJar.String()) + }, + }, + } +} + +// implement the following interface for IDE completion. +var _ android.IDEInfo = (*GenruleCombiner)(nil) + +func (j *GenruleCombiner) IDEInfo(ctx android.BaseModuleContext, ideInfo *android.IdeInfo) { + ideInfo.Deps = append(ideInfo.Deps, j.genruleCombinerProperties.Static_libs.GetOrDefault(ctx, nil)...) + ideInfo.Libs = append(ideInfo.Libs, j.genruleCombinerProperties.Static_libs.GetOrDefault(ctx, nil)...) + ideInfo.Deps = append(ideInfo.Deps, j.genruleCombinerProperties.Headers.GetOrDefault(ctx, nil)...) + ideInfo.Libs = append(ideInfo.Libs, j.genruleCombinerProperties.Headers.GetOrDefault(ctx, nil)...) +} diff --git a/java/genrule_combiner_test.go b/java/genrule_combiner_test.go new file mode 100644 index 000000000..7d024cfec --- /dev/null +++ b/java/genrule_combiner_test.go @@ -0,0 +1,237 @@ +// Copyright 2018 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 ( + "reflect" + "testing" + + "android/soong/android" +) + +func TestJarGenruleCombinerSingle(t *testing.T) { + t.Parallel() + t.Helper() + ctx := prepareForJavaTest.RunTestWithBp(t, ` + java_library { + name: "foo", + srcs: ["a.java"], + } + + java_genrule { + name: "gen", + tool_files: ["b.java"], + cmd: "$(location b.java) $(in) $(out)", + out: ["gen.jar"], + srcs: [":foo"], + } + + java_genrule_combiner { + name: "jarcomb", + static_libs: ["gen"], + headers: ["foo"], + } + + java_library { + name: "bar", + static_libs: ["jarcomb"], + srcs: ["c.java"], + } + + java_library { + name: "baz", + libs: ["jarcomb"], + srcs: ["c.java"], + } + `).TestContext + + fooMod := ctx.ModuleForTests(t, "foo", "android_common") + fooCombined := fooMod.Output("turbine-combined/foo.jar") + fooOutputFiles, _ := android.OtherModuleProvider(ctx.OtherModuleProviderAdaptor(), fooMod.Module(), android.OutputFilesProvider) + fooHeaderJars := fooOutputFiles.TaggedOutputFiles[".hjar"] + + genMod := ctx.ModuleForTests(t, "gen", "android_common") + gen := genMod.Output("gen.jar") + + jarcombMod := ctx.ModuleForTests(t, "jarcomb", "android_common") + jarcombInfo, _ := android.OtherModuleProvider(ctx.OtherModuleProviderAdaptor(), jarcombMod.Module(), JavaInfoProvider) + jarcombOutputFiles, _ := android.OtherModuleProvider(ctx.OtherModuleProviderAdaptor(), jarcombMod.Module(), android.OutputFilesProvider) + + // Confirm that jarcomb simply forwards the jarcomb implementation and the foo headers. + if len(jarcombOutputFiles.DefaultOutputFiles) != 1 || + android.PathRelativeToTop(jarcombOutputFiles.DefaultOutputFiles[0]) != android.PathRelativeToTop(gen.Output) { + t.Errorf("jarcomb Implementation %v is not [%q]", + android.PathsRelativeToTop(jarcombOutputFiles.DefaultOutputFiles), android.PathRelativeToTop(gen.Output)) + } + jarcombHeaderJars := jarcombOutputFiles.TaggedOutputFiles[".hjar"] + if !reflect.DeepEqual(jarcombHeaderJars, fooHeaderJars) { + t.Errorf("jarcomb Header jar %v is not %q", + jarcombHeaderJars, fooHeaderJars) + } + + // Confirm that JavaInfoProvider agrees. + if len(jarcombInfo.ImplementationJars) != 1 || + android.PathRelativeToTop(jarcombInfo.ImplementationJars[0]) != android.PathRelativeToTop(gen.Output) { + t.Errorf("jarcomb ImplementationJars %v is not [%q]", + android.PathsRelativeToTop(jarcombInfo.ImplementationJars), android.PathRelativeToTop(gen.Output)) + } + if len(jarcombInfo.HeaderJars) != 1 || + android.PathRelativeToTop(jarcombInfo.HeaderJars[0]) != android.PathRelativeToTop(fooCombined.Output) { + t.Errorf("jarcomb HeaderJars %v is not [%q]", + android.PathsRelativeToTop(jarcombInfo.HeaderJars), android.PathRelativeToTop(fooCombined.Output)) + } + + barMod := ctx.ModuleForTests(t, "bar", "android_common") + bar := barMod.Output("javac/bar.jar") + barCombined := barMod.Output("combined/bar.jar") + + // Confirm that bar uses the Implementation from gen and headerJars from foo. + if len(barCombined.Inputs) != 2 || + barCombined.Inputs[0].String() != bar.Output.String() || + barCombined.Inputs[1].String() != gen.Output.String() { + t.Errorf("bar combined jar inputs %v is not [%q, %q]", + barCombined.Inputs.Strings(), bar.Output.String(), gen.Output.String()) + } + + bazMod := ctx.ModuleForTests(t, "baz", "android_common") + baz := bazMod.Output("javac/baz.jar") + + string_in_list := func(s string, l []string) bool { + for _, v := range l { + if s == v { + return true + } + } + return false + } + + // Confirm that baz uses the headerJars from foo. + bazImplicitsRel := android.PathsRelativeToTop(baz.Implicits) + for _, v := range android.PathsRelativeToTop(fooHeaderJars) { + if !string_in_list(v, bazImplicitsRel) { + t.Errorf("baz Implicits %v does not contain %q", bazImplicitsRel, v) + } + } +} + +func TestJarGenruleCombinerMulti(t *testing.T) { + t.Parallel() + t.Helper() + ctx := prepareForJavaTest.RunTestWithBp(t, ` + java_library { + name: "foo1", + srcs: ["foo1_a.java"], + } + + java_library { + name: "foo2", + srcs: ["foo2_a.java"], + } + + java_genrule { + name: "gen1", + tool_files: ["b.java"], + cmd: "$(location b.java) $(in) $(out)", + out: ["gen1.jar"], + srcs: [":foo1"], + } + + java_genrule { + name: "gen2", + tool_files: ["b.java"], + cmd: "$(location b.java) $(in) $(out)", + out: ["gen2.jar"], + srcs: [":foo2"], + } + + // Combine multiple java_genrule modules. + java_genrule_combiner { + name: "jarcomb", + static_libs: ["gen1", "gen2"], + headers: ["foo1", "foo2"], + } + + java_library { + name: "bar", + static_libs: ["jarcomb"], + srcs: ["c.java"], + } + + java_library { + name: "baz", + libs: ["jarcomb"], + srcs: ["c.java"], + } + `).TestContext + + gen1Mod := ctx.ModuleForTests(t, "gen1", "android_common") + gen1 := gen1Mod.Output("gen1.jar") + gen2Mod := ctx.ModuleForTests(t, "gen2", "android_common") + gen2 := gen2Mod.Output("gen2.jar") + + jarcombMod := ctx.ModuleForTests(t, "jarcomb", "android_common") + jarcomb := jarcombMod.Output("combined/jarcomb.jar") + jarcombTurbine := jarcombMod.Output("turbine-combined/jarcomb.jar") + _ = jarcombTurbine + jarcombInfo, _ := android.OtherModuleProvider(ctx.OtherModuleProviderAdaptor(), jarcombMod.Module(), JavaInfoProvider) + _ = jarcombInfo + jarcombOutputFiles, _ := android.OtherModuleProvider(ctx.OtherModuleProviderAdaptor(), jarcombMod.Module(), android.OutputFilesProvider) + jarcombHeaderJars := jarcombOutputFiles.TaggedOutputFiles[".hjar"] + + if len(jarcomb.Inputs) != 2 || + jarcomb.Inputs[0].String() != gen1.Output.String() || + jarcomb.Inputs[1].String() != gen2.Output.String() { + t.Errorf("jarcomb inputs %v are not [%q, %q]", + jarcomb.Inputs.Strings(), gen1.Output.String(), gen2.Output.String()) + } + + if len(jarcombHeaderJars) != 1 || + android.PathRelativeToTop(jarcombHeaderJars[0]) != android.PathRelativeToTop(jarcombTurbine.Output) { + t.Errorf("jarcomb Header jars %v is not [%q]", + android.PathsRelativeToTop(jarcombHeaderJars), android.PathRelativeToTop(jarcombTurbine.Output)) + } + + barMod := ctx.ModuleForTests(t, "bar", "android_common") + bar := barMod.Output("javac/bar.jar") + barCombined := barMod.Output("combined/bar.jar") + + // Confirm that bar uses the Implementation and Headers from jarcomb. + if len(barCombined.Inputs) != 2 || + barCombined.Inputs[0].String() != bar.Output.String() || + barCombined.Inputs[1].String() != jarcomb.Output.String() { + t.Errorf("bar combined jar inputs %v is not [%q, %q]", + barCombined.Inputs.Strings(), bar.Output.String(), jarcomb.Output.String()) + } + + bazMod := ctx.ModuleForTests(t, "baz", "android_common") + baz := bazMod.Output("javac/baz.jar") + + string_in_list := func(s string, l []string) bool { + for _, v := range l { + if s == v { + return true + } + } + return false + } + + // Confirm that baz uses the headerJars from foo. + bazImplicitsRel := android.PathsRelativeToTop(baz.Implicits) + for _, v := range android.PathsRelativeToTop(jarcombHeaderJars) { + if !string_in_list(v, bazImplicitsRel) { + t.Errorf("baz Implicits %v does not contain %q", bazImplicitsRel, v) + } + } +} diff --git a/java/genrule_test.go b/java/genrule_test.go index b4e9d218d..c112e4503 100644 --- a/java/genrule_test.go +++ b/java/genrule_test.go @@ -57,7 +57,7 @@ func TestGenruleCmd(t *testing.T) { t.Fatal(errs) } - gen := ctx.ModuleForTests("gen", "android_common").Output("out") + gen := ctx.ModuleForTests(t, "gen", "android_common").Output("out") expected := []string{"foo"} if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) { t.Errorf(`want arm inputs %v, got %v`, expected, gen.Implicits.Strings()) @@ -93,11 +93,11 @@ func TestJarGenrules(t *testing.T) { } `) - foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar") - jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar") - bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar") - baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar") - barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar") + foo := ctx.ModuleForTests(t, "foo", "android_common").Output("javac/foo.jar") + jargen := ctx.ModuleForTests(t, "jargen", "android_common").Output("jargen.jar") + bar := ctx.ModuleForTests(t, "bar", "android_common").Output("javac/bar.jar") + baz := ctx.ModuleForTests(t, "baz", "android_common").Output("javac/baz.jar") + barCombined := ctx.ModuleForTests(t, "bar", "android_common").Output("combined/bar.jar") if g, w := jargen.Implicits.Strings(), foo.Output.String(); !android.InList(w, g) { t.Errorf("expected jargen inputs [%q], got %q", w, g) diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index 7d21b7a61..2c8694237 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -171,11 +171,11 @@ func isModuleInConfiguredList(ctx android.BaseModuleContext, module android.Modu // Now match the apex part of the boot image configuration. requiredApex := configuredBootJars.Apex(index) if android.IsConfiguredJarForPlatform(requiredApex) { - if len(apexInfo.InApexVariants) != 0 { + if apexInfo.ApexVariationName != "" { // A platform variant is required but this is for an apex so ignore it. return false } - } else if !apexInfo.InApexVariant(requiredApex) { + } else if apexInfo.BaseApexName != requiredApex { // An apex variant for a specific apex is required but this is the wrong apex. return false } diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index c14fdb7bb..147f326c7 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -57,7 +57,7 @@ func TestHiddenAPISingleton(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) @@ -101,7 +101,7 @@ func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) @@ -128,7 +128,7 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") fromSourceJarArg := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, fromSourceJarArg) @@ -158,7 +158,7 @@ func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") prebuiltJarArg := "--boot-dex=out/soong/.intermediates/prebuilt_foo/android_common/dex/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, prebuiltJarArg) @@ -219,7 +219,7 @@ func TestHiddenAPISingletonSdks(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") wantPublicStubs := "--public-stub-classpath=" + generateSdkDexPath(tc.publicStub, tc.unbundledBuild) android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantPublicStubs) @@ -279,9 +279,9 @@ func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) { expectedCpOutput := "out/soong/hiddenapi/hiddenapi-flags.csv" expectedFlagsCsv := "out/soong/hiddenapi/hiddenapi-flags.csv" - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") - hiddenAPI := result.SingletonForTests("hiddenapi") + hiddenAPI := result.SingletonForTests(t, "hiddenapi") cpRule := hiddenAPI.Rule("Cp") actualCpInput := cpRule.BuildParams.Input actualCpOutput := cpRule.BuildParams.Output @@ -318,7 +318,7 @@ func TestHiddenAPIEncoding_JavaSdkLibrary(t *testing.T) { `) checkDexEncoded := func(t *testing.T, name, unencodedDexJar, encodedDexJar string) { - moduleForTests := result.ModuleForTests(name+".impl", "android_common") + moduleForTests := result.ModuleForTests(t, name+".impl", "android_common") encodeDexRule := moduleForTests.Rule("hiddenAPIEncodeDex") actualUnencodedDexJar := encodeDexRule.Input diff --git a/java/jarjar_test.go b/java/jarjar_test.go index 82bfa2b86..b68976155 100644 --- a/java/jarjar_test.go +++ b/java/jarjar_test.go @@ -22,7 +22,7 @@ import ( ) func AssertJarJarRename(t *testing.T, result *android.TestResult, libName, original, expectedRename string) { - module := result.ModuleForTests(libName, "android_common") + module := result.ModuleForTests(t, libName, "android_common") provider, found := android.OtherModuleProvider(result.OtherModuleProviderAdaptor(), module.Module(), JarJarProvider) android.AssertBoolEquals(t, fmt.Sprintf("found provider (%s)", libName), true, found) diff --git a/java/java.go b/java/java.go index 900f0e32f..c5dee0c97 100644 --- a/java/java.go +++ b/java/java.go @@ -64,6 +64,7 @@ func registerJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_api_library", ApiLibraryFactory) ctx.RegisterModuleType("java_api_contribution", ApiContributionFactory) ctx.RegisterModuleType("java_api_contribution_import", ApiContributionImportFactory) + ctx.RegisterModuleType("java_genrule_combiner", GenruleCombinerFactory) // This mutator registers dependencies on dex2oat for modules that should be // dexpreopted. This is done late when the final variants have been @@ -373,7 +374,7 @@ type JavaInfo struct { ProvidesUsesLibInfo *ProvidesUsesLibInfo - ModuleWithUsesLibraryInfo *ModuleWithUsesLibraryInfo + MissingOptionalUsesLibs []string ModuleWithSdkDepInfo *ModuleWithSdkDepInfo @@ -828,6 +829,8 @@ type Library struct { combinedExportedProguardFlagsFile android.Path InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths) + + apiXmlFile android.WritablePath } var _ android.ApexModule = (*Library)(nil) @@ -1155,6 +1158,8 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.javaLibraryModuleInfoJSON(ctx) buildComplianceMetadata(ctx) + + j.createApiXmlFile(ctx) } func (j *Library) javaLibraryModuleInfoJSON(ctx android.ModuleContext) *android.ModuleInfoJSON { @@ -1189,7 +1194,7 @@ func buildComplianceMetadata(ctx android.ModuleContext) { for _, paths := range ctx.GetOutputFiles().TaggedOutputFiles { builtFiles = append(builtFiles, paths.Strings()...) } - complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.BUILT_FILES, android.FirstUniqueStrings(builtFiles)) + complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.BUILT_FILES, android.SortedUniqueStrings(builtFiles)) // Static deps staticDepNames := make([]string, 0) @@ -1202,8 +1207,8 @@ func buildComplianceMetadata(ctx android.ModuleContext) { staticDepFiles = append(staticDepFiles, dep.ResourceJars...) } }) - complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames)) - complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.FirstUniqueStrings(staticDepFiles.Strings())) + complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.SortedUniqueStrings(staticDepNames)) + complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.SortedUniqueStrings(staticDepFiles.Strings())) } func (j *Library) getJarInstallDir(ctx android.ModuleContext) android.InstallPath { @@ -1259,6 +1264,28 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { } } +var apiXMLGeneratingApiSurfaces = []android.SdkKind{ + android.SdkPublic, + android.SdkSystem, + android.SdkModule, + android.SdkSystemServer, + android.SdkTest, +} + +func (j *Library) createApiXmlFile(ctx android.ModuleContext) { + if kind, ok := android.JavaLibraryNameToSdkKind(ctx.ModuleName()); ok && android.InList(kind, apiXMLGeneratingApiSurfaces) { + scopePrefix := AllApiScopes.matchingScopeFromSdkKind(kind).apiFilePrefix + j.apiXmlFile = android.PathForModuleOut(ctx, fmt.Sprintf("%sapi.xml", scopePrefix)) + ctx.Build(pctx, android.BuildParams{ + Rule: generateApiXMLRule, + // LOCAL_SOONG_CLASSES_JAR + Input: j.implementationAndResourcesJar, + Output: j.apiXmlFile, + }) + ctx.DistForGoal("dist_files", j.apiXmlFile) + } +} + const ( aidlIncludeDir = "aidl" javaDir = "java" @@ -3252,26 +3279,29 @@ func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { var _ android.ApexModule = (*Import)(nil) // Implements android.ApexModule -func (j *Import) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { - return j.depIsInSameApex(tag) +func (m *Import) GetDepInSameApexChecker() android.DepInSameApexChecker { + return JavaImportDepInSameApexChecker{} +} + +type JavaImportDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m JavaImportDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { + return depIsInSameApex(tag) } // Implements android.ApexModule -func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { +func (j *Import) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { sdkVersionSpec := j.SdkVersion(ctx) minSdkVersion := j.MinSdkVersion(ctx) - if !minSdkVersion.Specified() { - return fmt.Errorf("min_sdk_version is not specified") - } + // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { - return nil - } - if minSdkVersion.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", minSdkVersion) + return android.MinApiLevel } - return nil + + return minSdkVersion } // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or @@ -3487,10 +3517,8 @@ func (j *DexImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDex var _ android.ApexModule = (*DexImport)(nil) // Implements android.ApexModule -func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // we don't check prebuilt modules for sdk_version - return nil +func (m *DexImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // dex_import imports a `.jar` file containing classes.dex files. @@ -3512,7 +3540,6 @@ func DexImportFactory() android.Module { type Defaults struct { android.ModuleBase android.DefaultsModuleBase - android.ApexModuleBase } // java_defaults provides a set of properties that can be inherited by other java or android modules. @@ -3679,11 +3706,11 @@ func addMissingOptionalUsesLibsFromDep(ctx android.ModuleContext, depModule andr usesLibrary *usesLibrary) { dep, ok := android.OtherModuleProvider(ctx, depModule, JavaInfoProvider) - if !ok || dep.ModuleWithUsesLibraryInfo == nil { + if !ok { return } - for _, lib := range dep.ModuleWithUsesLibraryInfo.UsesLibrary.usesLibraryProperties.Missing_optional_uses_libs { + for _, lib := range dep.MissingOptionalUsesLibs { if !android.InList(lib, usesLibrary.usesLibraryProperties.Missing_optional_uses_libs) { usesLibrary.usesLibraryProperties.Missing_optional_uses_libs = append(usesLibrary.usesLibraryProperties.Missing_optional_uses_libs, lib) @@ -3771,9 +3798,7 @@ func setExtraJavaInfo(ctx android.ModuleContext, module android.Module, javaInfo } if mwul, ok := module.(ModuleWithUsesLibrary); ok { - javaInfo.ModuleWithUsesLibraryInfo = &ModuleWithUsesLibraryInfo{ - UsesLibrary: mwul.UsesLibrary(), - } + javaInfo.MissingOptionalUsesLibs = mwul.UsesLibrary().usesLibraryProperties.Missing_optional_uses_libs } if mwsd, ok := module.(moduleWithSdkDep); ok { diff --git a/java/java_test.go b/java/java_test.go index de58237bc..f097762eb 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -349,7 +349,7 @@ func TestSimple(t *testing.T) { PrepareForTestWithJavaDefaultModules, tt.preparer, ).RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") fooJavac := foo.Rule("javac") android.AssertPathsRelativeToTopEquals(t, "foo javac inputs", tt.fooJavacInputs, fooJavac.Inputs) @@ -364,7 +364,7 @@ func TestSimple(t *testing.T) { fooCombinedHeaderJar := foo.Output("turbine-combined/foo.jar") android.AssertPathsRelativeToTopEquals(t, "foo header combined inputs", tt.fooHeaderCombinedInputs, fooCombinedHeaderJar.Inputs) - bar := result.ModuleForTests("bar", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") barJavac := bar.Rule("javac") android.AssertPathsRelativeToTopEquals(t, "bar javac inputs", tt.barJavacInputs, barJavac.Inputs) @@ -475,11 +475,11 @@ func TestExportedPlugins(t *testing.T) { `+test.extra) for _, want := range test.results { - javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac") + javac := ctx.ModuleForTests(t, want.library, "android_common").Rule("javac") if javac.Args["processor"] != want.processors { t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"]) } - turbine := ctx.ModuleForTests(want.library, "android_common").MaybeRule("turbine") + turbine := ctx.ModuleForTests(t, want.library, "android_common").MaybeRule("turbine") disableTurbine := turbine.BuildParams.Rule == nil if disableTurbine != want.disableTurbine { t.Errorf("For library %v, expected disableTurbine %v, found %v", want.library, want.disableTurbine, disableTurbine) @@ -545,7 +545,7 @@ func TestArchSpecific(t *testing.T) { } `) - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" { t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs) } @@ -576,11 +576,11 @@ func TestBinary(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - bar := ctx.ModuleForTests("bar", buildOS+"_common") + bar := ctx.ModuleForTests(t, "bar", buildOS+"_common") barJar := bar.Output("bar.jar").Output.String() barWrapperDeps := bar.Output("bar").Implicits.Strings() - libjni := ctx.ModuleForTests("libjni", buildOS+"_x86_64_shared") + libjni := ctx.ModuleForTests(t, "libjni", buildOS+"_x86_64_shared") libjniSO := libjni.Rule("Cp").Output.String() // Test that the install binary wrapper depends on the installed jar file @@ -613,7 +613,7 @@ func TestTest(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) + foo := ctx.ModuleForTests(t, "foo", buildOS+"_common").Module().(*TestHost) expected := "lib64/libjni.so" if runtime.GOOS == "darwin" { @@ -649,7 +649,7 @@ func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { ).RunTestWithBp(t, bp) // first, check that the -g flag is added to target modules - targetLibrary := result.ModuleForTests("target_library", "android_common") + targetLibrary := result.ModuleForTests(t, "target_library", "android_common") targetJavaFlags := targetLibrary.Module().VariablesForTests()["javacFlags"] if !strings.Contains(targetJavaFlags, "-g:source,lines") { t.Errorf("target library javac flags %v should contain "+ @@ -658,7 +658,7 @@ func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { // check that -g is not overridden for host modules buildOS := result.Config.BuildOS.String() - hostBinary := result.ModuleForTests("host_binary", buildOS+"_common") + hostBinary := result.ModuleForTests(t, "host_binary", buildOS+"_common") hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"] if strings.Contains(hostJavaFlags, "-g:source,lines") { t.Errorf("java_binary_host javac flags %v should not have "+ @@ -722,14 +722,14 @@ func TestPrebuilts(t *testing.T) { } `) - fooModule := ctx.ModuleForTests("foo", "android_common") + fooModule := ctx.ModuleForTests(t, "foo", "android_common") javac := fooModule.Rule("javac") - combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") - barModule := ctx.ModuleForTests("bar", "android_common") + combineJar := ctx.ModuleForTests(t, "foo", "android_common").Description("for javac") + barModule := ctx.ModuleForTests(t, "bar", "android_common") barJar := barModule.Output("combined/bar.jar").Output - bazModule := ctx.ModuleForTests("baz", "android_common") + bazModule := ctx.ModuleForTests(t, "baz", "android_common") bazJar := bazModule.Output("combined/baz.jar").Output - sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common"). + sdklibStubsJar := ctx.ModuleForTests(t, "sdklib.stubs", "android_common"). Output("combined/sdklib.stubs.jar").Output fooLibrary := fooModule.Module().(*Library) @@ -762,7 +762,7 @@ func TestPrebuilts(t *testing.T) { expectedDexJar := "out/soong/.intermediates/baz/android_common/dex/baz.jar" android.AssertPathRelativeToTopEquals(t, "baz dex jar build path", expectedDexJar, bazDexJar) - ctx.ModuleForTests("qux", "android_common").Rule("Cp") + ctx.ModuleForTests(t, "qux", "android_common").Rule("Cp") entries := android.AndroidMkEntriesForTest(t, ctx, fooModule.Module())[0] android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "java_library", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0]) @@ -788,7 +788,7 @@ prebuilt_stubs_sources { "stubs/sources/pkg/B.java": nil, }) - zipSrc := ctx.ModuleForTests("stubs-source", "android_common").Rule("zip_src") + zipSrc := ctx.ModuleForTests(t, "stubs-source", "android_common").Rule("zip_src") if expected, actual := expectedInputs, zipSrc.Inputs.Strings(); !reflect.DeepEqual(expected, actual) { t.Errorf("mismatch of inputs to soong_zip: expected %q, actual %q", expected, actual) } @@ -851,8 +851,8 @@ func TestDefaults(t *testing.T) { } `) - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") - combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") + combineJar := ctx.ModuleForTests(t, "foo", "android_common").Description("for javac") if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) @@ -863,22 +863,22 @@ func TestDefaults(t *testing.T) { t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine) } - baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() + baz := ctx.ModuleForTests(t, "baz", "android_common").Rule("javac").Output.String() if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz) } - atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8") + atestOptimize := ctx.ModuleForTests(t, "atestOptimize", "android_common").MaybeRule("r8") if atestOptimize.Output == nil { t.Errorf("atestOptimize should optimize APK") } - atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8") + atestNoOptimize := ctx.ModuleForTests(t, "atestNoOptimize", "android_common").MaybeRule("d8") if atestNoOptimize.Output == nil { t.Errorf("atestNoOptimize should not optimize APK") } - atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("d8") + atestDefault := ctx.ModuleForTests(t, "atestDefault", "android_common").MaybeRule("d8") if atestDefault.Output == nil { t.Errorf("atestDefault should not optimize APK") } @@ -976,8 +976,8 @@ func TestResources(t *testing.T) { }, ) - foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") - fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") + foo := ctx.ModuleForTests(t, "foo", "android_common").Output("withres/foo.jar") + fooRes := ctx.ModuleForTests(t, "foo", "android_common").Output("res/foo.jar") if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { t.Errorf("foo combined jars %v does not contain %q", @@ -1022,8 +1022,8 @@ func TestIncludeSrcs(t *testing.T) { }) // Test a library with include_srcs: true - foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") - fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar") + foo := ctx.ModuleForTests(t, "foo", "android_common").Output("withres/foo.jar") + fooSrcJar := ctx.ModuleForTests(t, "foo", "android_common").Output("foo.srcjar") if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) { t.Errorf("foo combined jars %v does not contain %q", w, g) @@ -1034,10 +1034,10 @@ func TestIncludeSrcs(t *testing.T) { } // Test a library with include_srcs: true and resources - bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar") - barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar") - barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar") - barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar") + bar := ctx.ModuleForTests(t, "bar", "android_common").Output("withres/bar.jar") + barResCombined := ctx.ModuleForTests(t, "bar", "android_common").Output("res-combined/bar.jar") + barRes := ctx.ModuleForTests(t, "bar", "android_common").Output("res/bar.jar") + barSrcJar := ctx.ModuleForTests(t, "bar", "android_common").Output("bar.srcjar") if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { t.Errorf("bar combined resource jars %v does not contain %q", w, g) @@ -1082,8 +1082,8 @@ func TestGeneratedSources(t *testing.T) { "b.java": nil, }) - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") - genrule := ctx.ModuleForTests("gen", "").Rule("generator") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") + genrule := ctx.ModuleForTests(t, "gen", "").Rule("generator") if filepath.Base(genrule.Output.String()) != "gen.java" { t.Fatalf(`gen output file %v is not ".../gen.java"`, genrule.Output.String()) @@ -1123,11 +1123,11 @@ func TestTurbine(t *testing.T) { } `) - fooTurbine := result.ModuleForTests("foo", "android_common").Rule("turbine") - barTurbine := result.ModuleForTests("bar", "android_common").Rule("turbine") - barJavac := result.ModuleForTests("bar", "android_common").Rule("javac") - barTurbineCombined := result.ModuleForTests("bar", "android_common").Description("for turbine") - bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac") + fooTurbine := result.ModuleForTests(t, "foo", "android_common").Rule("turbine") + barTurbine := result.ModuleForTests(t, "bar", "android_common").Rule("turbine") + barJavac := result.ModuleForTests(t, "bar", "android_common").Rule("javac") + barTurbineCombined := result.ModuleForTests(t, "bar", "android_common").Description("for turbine") + bazJavac := result.ModuleForTests(t, "baz", "android_common").Rule("javac") android.AssertPathsRelativeToTopEquals(t, "foo inputs", []string{"a.java"}, fooTurbine.Inputs) @@ -1151,7 +1151,7 @@ func TestSharding(t *testing.T) { barHeaderJar := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine", "bar.jar") for i := 0; i < 3; i++ { - barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i)) + barJavac := ctx.ModuleForTests(t, "bar", "android_common").Description("javac" + strconv.Itoa(i)) if !strings.HasPrefix(barJavac.Args["classpath"], "-classpath "+barHeaderJar+":") { t.Errorf("bar javac classpath %v does start with %q", barJavac.Args["classpath"], barHeaderJar) } @@ -1178,7 +1178,7 @@ func TestExcludeFileGroupInSrcs(t *testing.T) { } `) - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" { t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) @@ -1249,7 +1249,7 @@ func TestJavaImport(t *testing.T) { PrepareForTestWithJavaDefaultModules, ).RunTestWithBp(t, bp) - source := ctx.ModuleForTests("source_library", "android_common") + source := ctx.ModuleForTests(t, "source_library", "android_common") sourceJar := source.Output("javac/source_library.jar") sourceHeaderJar := source.Output("turbine-combined/source_library.jar") sourceJavaInfo, _ := android.OtherModuleProvider(ctx, source.Module(), JavaInfoProvider) @@ -1260,7 +1260,7 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "source library header jar", []string{sourceHeaderJar.Output.String()}, sourceJavaInfo.HeaderJars) - importWithNoDeps := ctx.ModuleForTests("import_with_no_deps", "android_common") + importWithNoDeps := ctx.ModuleForTests(t, "import_with_no_deps", "android_common") importWithNoDepsJar := importWithNoDeps.Output("combined/import_with_no_deps.jar") importWithNoDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithNoDeps.Module(), JavaInfoProvider) @@ -1272,7 +1272,7 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "import with no deps combined inputs", []string{"no_deps.jar"}, importWithNoDepsJar.Inputs) - importWithSourceDeps := ctx.ModuleForTests("import_with_source_deps", "android_common") + importWithSourceDeps := ctx.ModuleForTests(t, "import_with_source_deps", "android_common") importWithSourceDepsJar := importWithSourceDeps.Output("combined/import_with_source_deps.jar") importWithSourceDepsHeaderJar := importWithSourceDeps.Output("turbine-combined/import_with_source_deps.jar") importWithSourceDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithSourceDeps.Module(), JavaInfoProvider) @@ -1287,7 +1287,7 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "import with source deps combined header jar inputs", []string{"source_deps.jar", sourceHeaderJar.Output.String()}, importWithSourceDepsHeaderJar.Inputs) - importWithImportDeps := ctx.ModuleForTests("import_with_import_deps", "android_common") + importWithImportDeps := ctx.ModuleForTests(t, "import_with_import_deps", "android_common") importWithImportDepsJar := importWithImportDeps.Output("combined/import_with_import_deps.jar") importWithImportDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithImportDeps.Module(), JavaInfoProvider) @@ -1364,7 +1364,7 @@ func TestCompilerFlags(t *testing.T) { // TODO(jungjw): Consider making this more robust by ignoring path order. func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) { - variables := ctx.ModuleForTests(moduleName, "android_common").VariablesForTestsRelativeToTop() + variables := ctx.ModuleForTests(t, moduleName, "android_common").VariablesForTestsRelativeToTop() flags := strings.Split(variables["javacFlags"], " ") got := "" for _, flag := range flags { @@ -1505,7 +1505,7 @@ func TestJavaLibraryWithSystemModules(t *testing.T) { } func checkBootClasspathForLibWithSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { - javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac") + javacRule := ctx.ModuleForTests(t, moduleName, "android_common").Rule("javac") bootClasspath := javacRule.Args["bootClasspath"] if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) { t.Errorf("bootclasspath of %q must start with --system and end with %q, but was %#v.", moduleName, expectedSuffix, bootClasspath) @@ -1530,7 +1530,7 @@ func TestAidlExportIncludeDirsFromImports(t *testing.T) { } `) - aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + aidlCommand := ctx.ModuleForTests(t, "foo", "android_common").Rule("aidl").RuleParams.Command expectedAidlFlag := "-Iaidl/bar" if !strings.Contains(aidlCommand, expectedAidlFlag) { t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) @@ -1547,7 +1547,7 @@ func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { } `) - aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + aidlCommand := ctx.ModuleForTests(t, "foo", "android_common").Rule("aidl").RuleParams.Command expectedAidlFlag := "-Werror" if !strings.Contains(aidlCommand, expectedAidlFlag) { t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) @@ -1577,7 +1577,7 @@ func TestAidlFlagsWithMinSdkVersion(t *testing.T) { `+tc.sdkVersion+` } `) - aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + aidlCommand := ctx.ModuleForTests(t, "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) @@ -1614,7 +1614,7 @@ func TestAidlFlagsMinSdkVersionDroidstubs(t *testing.T) { } for _, tc := range testCases { ctx := prepareForJavaTest.RunTestWithBp(t, fmt.Sprintf(bpTemplate, tc.sdkVersionBp)) - aidlCmd := ctx.ModuleForTests("foo-stubs", "android_common").Rule("aidl").RuleParams.Command + aidlCmd := ctx.ModuleForTests(t, "foo-stubs", "android_common").Rule("aidl").RuleParams.Command expected := "--min_sdk_version=" + tc.minSdkVersionExpected android.AssertStringDoesContain(t, "aidl command conatins incorrect min_sdk_version for testCse: "+tc.desc, aidlCmd, expected) } @@ -1630,7 +1630,7 @@ func TestAidlEnforcePermissions(t *testing.T) { } `) - aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + aidlCommand := ctx.ModuleForTests(t, "foo", "android_common").Rule("aidl").RuleParams.Command expectedAidlFlag := "-Wmissing-permission-annotation -Werror" if !strings.Contains(aidlCommand, expectedAidlFlag) { t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) @@ -1647,7 +1647,7 @@ func TestAidlEnforcePermissionsException(t *testing.T) { } `) - aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + aidlCommand := ctx.ModuleForTests(t, "foo", "android_common").Rule("aidl").RuleParams.Command expectedAidlFlag := "$$FLAGS -Wmissing-permission-annotation -Werror aidl/foo/IFoo.aidl" if !strings.Contains(aidlCommand, expectedAidlFlag) { t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) @@ -1677,7 +1677,7 @@ func TestDataNativeBinaries(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) + test := ctx.ModuleForTests(t, "foo", buildOS+"_common").Module().(*TestHost) entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] expected := []string{"out/soong/.intermediates/bin/" + buildOS + "_x86_64/bin:bin"} actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] @@ -1693,7 +1693,7 @@ func TestDefaultInstallable(t *testing.T) { `) buildOS := ctx.Config().BuildOS.String() - module := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) + module := ctx.ModuleForTests(t, "foo", buildOS+"_common").Module().(*TestHost) assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true), module.properties.Installable) } @@ -1710,7 +1710,7 @@ func TestErrorproneEnabled(t *testing.T) { } `) - javac := ctx.ModuleForTests("foo", "android_common").Description("javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").Description("javac") // Test that the errorprone plugins are passed to javac expectedSubstring := "-Xplugin:ErrorProne" @@ -1721,7 +1721,7 @@ func TestErrorproneEnabled(t *testing.T) { // Modules with errorprone { enabled: true } will include errorprone checks // in the main javac build rule. Only when RUN_ERROR_PRONE is true will // the explicit errorprone build rule be created. - errorprone := ctx.ModuleForTests("foo", "android_common").MaybeDescription("errorprone") + errorprone := ctx.ModuleForTests(t, "foo", "android_common").MaybeDescription("errorprone") if errorprone.RuleParams.Description != "" { t.Errorf("expected errorprone build rule to not exist, but it did") } @@ -1745,7 +1745,7 @@ func TestErrorproneDisabled(t *testing.T) { }), ).RunTestWithBp(t, bp) - javac := ctx.ModuleForTests("foo", "android_common").Description("javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").Description("javac") // Test that the errorprone plugins are not passed to javac, like they would // be if enabled was true. @@ -1756,7 +1756,7 @@ func TestErrorproneDisabled(t *testing.T) { // Check that no errorprone build rule is created, like there would be // if enabled was unset and RUN_ERROR_PRONE was true. - errorprone := ctx.ModuleForTests("foo", "android_common").MaybeDescription("errorprone") + errorprone := ctx.ModuleForTests(t, "foo", "android_common").MaybeDescription("errorprone") if errorprone.RuleParams.Description != "" { t.Errorf("expected errorprone build rule to not exist, but it did") } @@ -1777,8 +1777,8 @@ func TestErrorproneEnabledOnlyByEnvironmentVariable(t *testing.T) { }), ).RunTestWithBp(t, bp) - javac := ctx.ModuleForTests("foo", "android_common").Description("javac") - errorprone := ctx.ModuleForTests("foo", "android_common").Description("errorprone") + javac := ctx.ModuleForTests(t, "foo", "android_common").Description("javac") + errorprone := ctx.ModuleForTests(t, "foo", "android_common").Description("errorprone") // Check that the errorprone plugins are not passed to javac, because they // will instead be passed to the separate errorprone compilation @@ -1940,7 +1940,7 @@ func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) { } buildOS := ctx.Config.BuildOS.String() - fooVariant := ctx.ModuleForTests("foo", buildOS+"_common") + fooVariant := ctx.ModuleForTests(t, "foo", buildOS+"_common") fooMod := fooVariant.Module().(*TestHost) entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0] @@ -1952,7 +1952,7 @@ func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) { expectedData := []string{} for _, variant := range tc.variants { - barVariant := ctx.ModuleForTests("bar", variant) + barVariant := ctx.ModuleForTests(t, "bar", variant) relocated := barVariant.Output("bar") expectedInput := fmt.Sprintf("out/soong/.intermediates/bar/%s/unstripped/bar", variant) android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input) @@ -1976,7 +1976,7 @@ func TestDeviceBinaryWrapperGeneration(t *testing.T) { main_class: "foo.bar.jb", } `) - wrapperPath := fmt.Sprint(ctx.ModuleForTests("foo", "android_common").AllOutputs()) + wrapperPath := fmt.Sprint(ctx.ModuleForTests(t, "foo", "android_common").AllOutputs()) if !strings.Contains(wrapperPath, "foo.sh") { t.Errorf("wrapper file foo.sh is not generated") } @@ -2072,7 +2072,7 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") manifest := m.Output("metalava.sbox.textproto") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, manifest) manifestCommand := sboxProto.Commands[0].GetCommand() @@ -2181,7 +2181,7 @@ func TestJavaApiLibraryAndDefaultsLink(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") manifest := m.Output("metalava.sbox.textproto") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, manifest) manifestCommand := sboxProto.Commands[0].GetCommand() @@ -2249,7 +2249,7 @@ func TestJavaApiLibraryJarGeneration(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") outputs := fmt.Sprint(m.AllOutputs()) if !strings.Contains(outputs, c.outputJarName) { t.Errorf("Module output does not contain expected jar %s", c.outputJarName) @@ -2335,7 +2335,7 @@ func TestJavaApiLibraryLibsLink(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") javacRules := m.Rule("javac") classPathArgs := javacRules.Args["classpath"] for _, jarName := range c.classPathJarNames { @@ -2424,7 +2424,7 @@ func TestJavaApiLibraryStaticLibsLink(t *testing.T) { }, } for _, c := range testcases { - m := ctx.ModuleForTests(c.moduleName, "android_common") + m := ctx.ModuleForTests(t, c.moduleName, "android_common") mergeZipsCommand := m.Rule("merge_zips").RuleParams.Command for _, jarName := range c.staticLibJarNames { if !strings.Contains(mergeZipsCommand, jarName) { @@ -2452,7 +2452,7 @@ func TestTransitiveSrcFiles(t *testing.T) { static_libs: ["b"], } `) - c := ctx.ModuleForTests("c", "android_common").Module() + c := ctx.ModuleForTests(t, "c", "android_common").Module() javaInfo, _ := android.OtherModuleProvider(ctx, c, JavaInfoProvider) transitiveSrcFiles := android.Paths(javaInfo.TransitiveSrcFiles.ToList()) android.AssertArrayString(t, "unexpected jar deps", []string{"b.java", "c.java"}, transitiveSrcFiles.Strings()) @@ -2475,7 +2475,7 @@ java_test_host { `) buildOS := result.Config.BuildOS.String() - args := result.ModuleForTests("foo", buildOS+"_common"). + args := result.ModuleForTests(t, "foo", buildOS+"_common"). Output("out/soong/.intermediates/foo/" + buildOS + "_common/foo.config").Args expected := proptools.NinjaAndShellEscape("<option name=\"exclude-path\" value=\"org/apache\" />") if args["extraConfigs"] != expected { @@ -2500,7 +2500,7 @@ java_test_host { `) buildOS := result.Config.BuildOS.String() - args := result.ModuleForTests("foo", buildOS+"_common"). + args := result.ModuleForTests(t, "foo", buildOS+"_common"). Output("out/soong/.intermediates/foo/" + buildOS + "_common/foo.config").Args expected := proptools.NinjaAndShellEscape("<option name=\"test-timeout\" value=\"10m\" />\\n ") if args["extraTestRunnerConfigs"] != expected { @@ -2521,7 +2521,7 @@ func TestJavaLibraryWithResourcesStem(t *testing.T) { "test-jar/test/resource.txt": nil, }) - m := ctx.ModuleForTests("foo", "android_common") + m := ctx.ModuleForTests(t, "foo", "android_common") outputs := fmt.Sprint(m.AllOutputs()) if !strings.Contains(outputs, "test.jar") { t.Errorf("Module output does not contain expected jar %s", "test.jar") @@ -2538,12 +2538,12 @@ func TestHeadersOnly(t *testing.T) { } `) - turbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine") + turbine := ctx.ModuleForTests(t, "foo", "android_common").Rule("turbine") if len(turbine.Inputs) != 1 || turbine.Inputs[0].String() != "a.java" { t.Errorf(`foo inputs %v != ["a.java"]`, turbine.Inputs) } - javac := ctx.ModuleForTests("foo", "android_common").MaybeRule("javac") + javac := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("javac") android.AssertDeepEquals(t, "javac rule", nil, javac.Rule) } @@ -2568,7 +2568,7 @@ func TestJavaApiContributionImport(t *testing.T) { api_surface: "public", } `) - m := ctx.ModuleForTests("foo", "android_common") + m := ctx.ModuleForTests(t, "foo", "android_common") manifest := m.Output("metalava.sbox.textproto") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, manifest) manifestCommand := sboxProto.Commands[0].GetCommand() @@ -2591,7 +2591,7 @@ func TestJavaApiLibraryApiFilesSorting(t *testing.T) { stubs_type: "everything", } `) - m := ctx.ModuleForTests("foo", "android_common") + m := ctx.ModuleForTests(t, "foo", "android_common") manifest := m.Output("metalava.sbox.textproto") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, manifest) manifestCommand := sboxProto.Commands[0].GetCommand() @@ -2666,9 +2666,9 @@ func TestApiLibraryDroidstubsDependency(t *testing.T) { `) currentApiTimestampPath := "api-stubs-docs-non-updatable/android_common/everything/check_current_api.timestamp" - foo := result.ModuleForTests("foo", "android_common").Module().(*ApiLibrary) + foo := result.ModuleForTests(t, "foo", "android_common").Module().(*ApiLibrary) fooValidationPathsString := strings.Join(foo.validationPaths.Strings(), " ") - bar := result.ModuleForTests("bar", "android_common").Module().(*ApiLibrary) + bar := result.ModuleForTests(t, "bar", "android_common").Module().(*ApiLibrary) barValidationPathsString := strings.Join(bar.validationPaths.Strings(), " ") android.AssertStringDoesContain(t, "Module expected to have validation", @@ -2796,8 +2796,8 @@ func TestMultiplePrebuilts(t *testing.T) { ).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) // check that rdep gets the correct variation of dep - foo := ctx.ModuleForTests("foo", "android_common") - expectedDependency := ctx.ModuleForTests(tc.expectedDependencyName, "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") + expectedDependency := ctx.ModuleForTests(t, tc.expectedDependencyName, "android_common") android.AssertBoolEquals(t, fmt.Sprintf("expected dependency from %s to %s\n", foo.Module().Name(), tc.expectedDependencyName), true, hasDep(ctx, foo.Module(), expectedDependency.Module())) // check that output file of dep is always bar.jar @@ -2866,7 +2866,7 @@ func TestMultiplePlatformCompatConfigPrebuilts(t *testing.T) { android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), ).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) - mergedGlobalConfig := ctx.SingletonForTests("platform_compat_config_singleton").Output("compat_config/merged_compat_config.xml") + mergedGlobalConfig := ctx.SingletonForTests(t, "platform_compat_config_singleton").Output("compat_config/merged_compat_config.xml") android.AssertIntEquals(t, "The merged compat config file should only have a single dependency", 1, len(mergedGlobalConfig.Implicits)) android.AssertStringEquals(t, "The merged compat config file is missing the appropriate platform compat config", mergedGlobalConfig.Implicits[0].String(), tc.expectedPlatformCompatConfigXml) } @@ -2915,7 +2915,7 @@ func TestApiLibraryAconfigDeclarations(t *testing.T) { android.AssertBoolEquals(t, "foo expected to depend on bar", CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "bar"), true) - m := result.ModuleForTests("foo", "android_common") + m := result.ModuleForTests(t, "foo", "android_common") android.AssertStringDoesContain(t, "foo generates revert annotations file", strings.Join(m.AllOutputs(), ""), "revert-annotations-exportable.txt") @@ -3030,7 +3030,7 @@ func TestJavaLibHostWithStem(t *testing.T) { `) buildOS := ctx.Config().BuildOS.String() - foo := ctx.ModuleForTests("foo", buildOS+"_common") + foo := ctx.ModuleForTests(t, "foo", buildOS+"_common") outputs := fmt.Sprint(foo.AllOutputs()) if !strings.Contains(outputs, "foo-new.jar") { @@ -3048,7 +3048,7 @@ func TestJavaLibWithStem(t *testing.T) { } `) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") outputs := fmt.Sprint(foo.AllOutputs()) if !strings.Contains(outputs, "foo-new.jar") { @@ -3079,9 +3079,9 @@ func TestJavaLibraryOutputFilesRel(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") - bar := result.ModuleForTests("bar", "android_common") - baz := result.ModuleForTests("baz", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") + baz := result.ModuleForTests(t, "baz", "android_common") fooOutputPaths := foo.OutputFiles(result.TestContext, t, "") barOutputPaths := bar.OutputFiles(result.TestContext, t, "") @@ -3124,8 +3124,8 @@ func TestCoverage(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") - androidCar := result.ModuleForTests("android.car", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") + androidCar := result.ModuleForTests(t, "android.car", "android_common") fooJacoco := foo.Rule("jacoco") fooCombine := foo.Description("for javac") @@ -3196,6 +3196,6 @@ cc_library_shared { } ` res, _ := testJava(t, bp) - deps := findDepsOfModule(res, res.ModuleForTests("myjavabin", "android_common").Module(), "mynativelib") + deps := findDepsOfModule(res, res.ModuleForTests(t, "myjavabin", "android_common").Module(), "mynativelib") android.AssertIntEquals(t, "Create a dep on the first variant", 1, len(deps)) } diff --git a/java/jdeps.go b/java/jdeps.go index c2ce50383..927c1694d 100644 --- a/java/jdeps.go +++ b/java/jdeps.go @@ -37,8 +37,6 @@ type jdepsGeneratorSingleton struct { outputPath android.Path } -var _ android.SingletonMakeVarsProvider = (*jdepsGeneratorSingleton)(nil) - const ( jdepsJsonFileName = "module_bp_java_deps.json" ) @@ -101,13 +99,6 @@ func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCont Rule: android.Touch, Output: jfpath, }) -} - -func (j *jdepsGeneratorSingleton) MakeVars(ctx android.MakeVarsContext) { - if j.outputPath == nil { - return - } - ctx.DistForGoal("general-tests", j.outputPath) } diff --git a/java/jdeps_test.go b/java/jdeps_test.go index 2cbf75bc7..00f383997 100644 --- a/java/jdeps_test.go +++ b/java/jdeps_test.go @@ -32,7 +32,7 @@ func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) { libs: ["Foo", "Bar"], } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) for _, expected := range []string{"Foo", "Bar"} { @@ -53,7 +53,7 @@ func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) { static_libs: ["Foo", "Bar"], } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) for _, expected := range []string{"Foo", "Bar"} { @@ -72,7 +72,7 @@ func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) { srcs: ["Foo.java", "Bar.java"], } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) expected := []string{"Foo.java", "Bar.java"} @@ -92,7 +92,7 @@ func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) { }, } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) expected := []string{"Foo", "Bar"} @@ -111,7 +111,7 @@ func TestCollectJavaLibraryWithJarJarRules(t *testing.T) { jarjar_rules: "jarjar_rules.txt", } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) android.AssertStringEquals(t, "IdeInfo.Srcs of repackaged library should not be empty", "foo.java", dpInfo.Srcs[0]) @@ -135,7 +135,7 @@ func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) { sdk_version: "29", } `) - module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + module := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android") @@ -171,11 +171,11 @@ func TestDoNotAddNoneSystemModulesToDeps(t *testing.T) { api_surface: "public", } `) - javalib := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) + javalib := ctx.ModuleForTests(t, "javalib", "android_common").Module().(*Library) dpInfo, _ := android.OtherModuleProvider(ctx, javalib, android.IdeInfoProviderKey) android.AssertStringListDoesNotContain(t, "IdeInfo.Deps should contain not contain `none`", dpInfo.Deps, "none") - javalib_stubs := ctx.ModuleForTests("javalib.stubs", "android_common").Module().(*ApiLibrary) + javalib_stubs := ctx.ModuleForTests(t, "javalib.stubs", "android_common").Module().(*ApiLibrary) dpInfo, _ = android.OtherModuleProvider(ctx, javalib_stubs, android.IdeInfoProviderKey) android.AssertStringListDoesNotContain(t, "IdeInfo.Deps should contain not contain `none`", dpInfo.Deps, "none") } diff --git a/java/kotlin_test.go b/java/kotlin_test.go index 3a203358a..c7b1ece98 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -240,7 +240,7 @@ func TestKotlin(t *testing.T) { PrepareForTestWithJavaDefaultModules, tt.preparer, ).RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") fooKotlinc := foo.Rule("kotlinc") android.AssertPathsRelativeToTopEquals(t, "foo kotlinc inputs", tt.fooKotlincInputs, fooKotlinc.Inputs) @@ -260,7 +260,7 @@ func TestKotlin(t *testing.T) { fooCombinedHeaderJar := foo.Output("turbine-combined/foo.jar") android.AssertPathsRelativeToTopEquals(t, "foo header combined inputs", tt.fooHeaderCombinedInputs, fooCombinedHeaderJar.Inputs) - bar := result.ModuleForTests("bar", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") barKotlinc := bar.Rule("kotlinc") android.AssertPathsRelativeToTopEquals(t, "bar kotlinc inputs", tt.barKotlincInputs, barKotlinc.Inputs) @@ -311,14 +311,14 @@ func TestKapt(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") kaptStubs := foo.Rule("kapt") turbineApt := foo.Description("turbine apt") kotlinc := foo.Rule("kotlinc") javac := foo.Rule("javac") - bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String() - baz := ctx.ModuleForTests("baz", buildOS+"_common").Rule("javac").Output.String() + bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String() + baz := ctx.ModuleForTests(t, "baz", buildOS+"_common").Rule("javac").Output.String() // Test that the kotlin and java sources are passed to kapt and kotlinc if len(kaptStubs.Inputs) != 2 || kaptStubs.Inputs[0].String() != "a.java" || kaptStubs.Inputs[1].String() != "b.kt" { @@ -400,13 +400,13 @@ func TestKapt(t *testing.T) { buildOS := result.Config.BuildOS.String() - kapt := result.ModuleForTests("foo", "android_common").Rule("kapt") - javac := result.ModuleForTests("foo", "android_common").Description("javac") - errorprone := result.ModuleForTests("foo", "android_common").Description("errorprone") + kapt := result.ModuleForTests(t, "foo", "android_common").Rule("kapt") + javac := result.ModuleForTests(t, "foo", "android_common").Description("javac") + errorprone := result.ModuleForTests(t, "foo", "android_common").Description("errorprone") - bar := result.ModuleForTests("bar", buildOS+"_common").Description("javac").Output.String() - baz := result.ModuleForTests("baz", buildOS+"_common").Description("javac").Output.String() - myCheck := result.ModuleForTests("my_check", buildOS+"_common").Description("javac").Output.String() + bar := result.ModuleForTests(t, "bar", buildOS+"_common").Description("javac").Output.String() + baz := result.ModuleForTests(t, "baz", buildOS+"_common").Description("javac").Output.String() + myCheck := result.ModuleForTests(t, "my_check", buildOS+"_common").Description("javac").Output.String() // Test that the errorprone plugins are not passed to kapt expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + @@ -531,9 +531,9 @@ func TestKotlinCompose(t *testing.T) { buildOS := result.Config.BuildOS.String() - composeCompiler := result.ModuleForTests("kotlin-compose-compiler-plugin", buildOS+"_common").Rule("combineJar").Output - withCompose := result.ModuleForTests("withcompose", "android_common") - noCompose := result.ModuleForTests("nocompose", "android_common") + composeCompiler := result.ModuleForTests(t, "kotlin-compose-compiler-plugin", buildOS+"_common").Rule("combineJar").Output + withCompose := result.ModuleForTests(t, "withcompose", "android_common") + noCompose := result.ModuleForTests(t, "nocompose", "android_common") android.AssertStringListContains(t, "missing compose compiler dependency", withCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) @@ -579,9 +579,9 @@ func TestKotlinPlugin(t *testing.T) { buildOS := result.Config.BuildOS.String() - kotlinPlugin := result.ModuleForTests("kotlin_plugin", buildOS+"_common").Rule("combineJar").Output - withKotlinPlugin := result.ModuleForTests("with_kotlin_plugin", "android_common") - noKotlinPlugin := result.ModuleForTests("no_kotlin_plugin", "android_common") + kotlinPlugin := result.ModuleForTests(t, "kotlin_plugin", buildOS+"_common").Rule("combineJar").Output + withKotlinPlugin := result.ModuleForTests(t, "with_kotlin_plugin", "android_common") + noKotlinPlugin := result.ModuleForTests(t, "no_kotlin_plugin", "android_common") android.AssertStringListContains(t, "missing plugin compiler dependency", withKotlinPlugin.Rule("kotlinc").Implicits.Strings(), kotlinPlugin.String()) diff --git a/java/lint.go b/java/lint.go index 3838745e4..66f7f8549 100644 --- a/java/lint.go +++ b/java/lint.go @@ -704,16 +704,12 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) { zip(l.referenceBaselineZip, func(l *LintInfo) android.Path { return l.ReferenceBaseline }) ctx.Phony("lint-check", l.htmlZip, l.textZip, l.xmlZip, l.referenceBaselineZip) -} -func (l *lintSingleton) MakeVars(ctx android.MakeVarsContext) { if !ctx.Config().UnbundledBuild() { ctx.DistForGoal("lint-check", l.htmlZip, l.textZip, l.xmlZip, l.referenceBaselineZip) } } -var _ android.SingletonMakeVarsProvider = (*lintSingleton)(nil) - func init() { android.RegisterParallelSingletonType("lint", func() android.Singleton { return &lintSingleton{} }) diff --git a/java/lint_test.go b/java/lint_test.go index f7d3229b9..236fa63ba 100644 --- a/java/lint_test.go +++ b/java/lint_test.go @@ -38,7 +38,7 @@ func TestJavaLintDoesntUseBaselineImplicitly(t *testing.T) { "lint-baseline.xml": nil, }) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto")) if strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") { @@ -87,7 +87,7 @@ func TestJavaLintUsesCorrectBpConfig(t *testing.T) { "mybaseline.xml": nil, }) - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto")) if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") { @@ -193,7 +193,7 @@ func TestJavaLintStrictUpdatabilityLinting(t *testing.T) { result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()). RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") strictUpdatabilityCheck := foo.Output("lint_strict_updatability_check.stamp") if !strings.Contains(strictUpdatabilityCheck.RuleParams.Command, "--disallowed_issues NewApi") { @@ -256,7 +256,7 @@ func TestJavaLintDatabaseSelectionFull(t *testing.T) { })). RunTestWithBp(t, thisBp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") sboxProto := android.RuleBuilderSboxProtoForTests(t, result.TestContext, foo.Output("lint.sbox.textproto")) if !strings.Contains(*sboxProto.Commands[0].Command, "/"+testCase.expected_file) { t.Error("did not use full api database for case", testCase) @@ -313,7 +313,7 @@ func TestNotTestViaDefault(t *testing.T) { result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) ctx := result.TestContext - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto")) command := *sboxProto.Commands[0].Command @@ -321,7 +321,7 @@ func TestNotTestViaDefault(t *testing.T) { t.Fatalf("Expected command to not contain --test") } - foo2 := ctx.ModuleForTests("foo2", "android_common") + foo2 := ctx.ModuleForTests(t, "foo2", "android_common") sboxProto2 := android.RuleBuilderSboxProtoForTests(t, ctx, foo2.Output("lint.sbox.textproto")) command2 := *sboxProto2.Commands[0].Command diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index 86062d489..155afc6c2 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -15,6 +15,9 @@ package java import ( + "maps" + "slices" + "github.com/google/blueprint" "android/soong/android" @@ -31,12 +34,6 @@ func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContex // The tags used for the dependencies between the platform bootclasspath and any configured boot // jars. -var ( - platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"} - platformBootclasspathBootJarDepTag = bootclasspathDependencyTag{name: "platform-boot-jar"} - platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag{name: "apex-boot-jar"} -) - type platformBootclasspathImplLibDepTagType struct { blueprint.BaseDependencyTag } @@ -59,6 +56,12 @@ type platformBootclasspathModule struct { // The apex:module pairs obtained from the fragments. fragments []android.Module + // The map of apex to the fragments they contain. + apexNameToFragment map[string]android.Module + + // The map of library modules in the bootclasspath to the fragments that contain them. + libraryToApex map[android.Module]string + // Path to the monolithic hiddenapi-flags.csv file. hiddenAPIFlagsCSV android.OutputPath @@ -100,26 +103,12 @@ func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorCon b.hiddenAPIDepsMutator(ctx) - if !dexpreopt.IsDex2oatNeeded(ctx) { - return - } - - // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The - // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). - dexpreopt.RegisterToolDeps(ctx) -} - -func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) { - if ctx.Config().DisableHiddenApiChecks() { - return + if dexpreopt.IsDex2oatNeeded(ctx) { + // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The + // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). + dexpreopt.RegisterToolDeps(ctx) } - // Add dependencies onto the stub lib modules. - apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) - hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules) -} - -func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { // Add dependencies on all the ART jars. global := dexpreopt.GetGlobalConfig(ctx) addDependenciesOntoSelectedBootImageApexes(ctx, "com.android.art") @@ -127,13 +116,13 @@ func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.Botto var bootImageModuleNames []string // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly - addDependenciesOntoBootImageModules(ctx, global.ArtApexJars, platformBootclasspathArtBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, global.ArtApexJars, artBootJar) bootImageModuleNames = append(bootImageModuleNames, global.ArtApexJars.CopyOfJars()...) // Add dependencies on all the non-updatable jars, which are on the platform or in non-updatable // APEXes. platformJars := b.platformJars(ctx) - addDependenciesOntoBootImageModules(ctx, platformJars, platformBootclasspathBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, platformJars, platformBootJar) bootImageModuleNames = append(bootImageModuleNames, platformJars.CopyOfJars()...) // Add dependencies on all the updatable jars, except the ART jars. @@ -144,7 +133,7 @@ func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.Botto } addDependenciesOntoSelectedBootImageApexes(ctx, android.FirstUniqueStrings(apexes)...) // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly - addDependenciesOntoBootImageModules(ctx, apexJars, platformBootclasspathApexBootJarDepTag) + addDependenciesOntoBootImageModules(ctx, apexJars, apexBootJar) bootImageModuleNames = append(bootImageModuleNames, apexJars.CopyOfJars()...) // Add dependencies on all the fragments. @@ -158,27 +147,37 @@ func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.Botto } } -func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) { +func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) { + if ctx.Config().DisableHiddenApiChecks() { + return + } + + // Add dependencies onto the stub lib modules. + apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) + hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules) +} + +func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tagType bootclasspathDependencyTagType) { for i := 0; i < modules.Len(); i++ { apex := modules.Apex(i) name := modules.Jar(i) - addDependencyOntoApexModulePair(ctx, apex, name, tag) + addDependencyOntoApexModulePair(ctx, apex, name, tagType) } } func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Gather all the dependencies from the art, platform, and apex boot jars. - artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag) - platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathBootJarDepTag) - apexModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathApexBootJarDepTag) + artModules, artModulesToApex := gatherApexModulePairDepsWithTag(ctx, artBootJar) + platformModules, platformModulesToApex := gatherApexModulePairDepsWithTag(ctx, platformBootJar) + apexModules, apexModulesToApex := gatherApexModulePairDepsWithTag(ctx, apexBootJar) // Concatenate them all, in order as they would appear on the bootclasspath. - var allModules []android.Module - allModules = append(allModules, artModules...) - allModules = append(allModules, platformModules...) - allModules = append(allModules, apexModules...) + allModules := slices.Concat(artModules, platformModules, apexModules) b.configuredModules = allModules + b.libraryToApex = maps.Clone(artModulesToApex) + maps.Copy(b.libraryToApex, platformModulesToApex) + maps.Copy(b.libraryToApex, apexModulesToApex) // Do not add implLibModule to allModules as the impl lib is only used to collect the // transitive source files @@ -199,7 +198,7 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo TransformResourcesToJar(ctx, srcjar, jarArgs, transitiveSrcFiles) // Gather all the fragments dependencies. - b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag) + b.fragments, b.apexNameToFragment = gatherFragments(ctx) // Check the configuration of the boot modules. // ART modules are checked by the art-bootclasspath-fragment. @@ -208,7 +207,7 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo b.generateClasspathProtoBuildActions(ctx) - bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) + bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments, b.libraryToApex, b.apexNameToFragment) buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) ctx.SetOutputFiles(android.Paths{b.hiddenAPIFlagsCSV}, "hiddenapi-flags.csv") @@ -259,7 +258,7 @@ func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleCon fromUpdatableApex := apexInfo.Updatable if fromUpdatableApex { // error: this jar is part of an updatable apex - ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants) + ctx.ModuleErrorf("module %q from updatable apex %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.BaseApexName) } else { // ok: this jar is part of the platform or a non-updatable apex } @@ -283,7 +282,11 @@ func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext // modules is complete. if !ctx.Config().AlwaysUsePrebuiltSdks() { // error: this jar is part of the platform - ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name) + if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies([]string{"module_" + name + "_from_platform_is_not_allowed_in_the_apex_boot_jars_list"}) + } else { + ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name) + } } } else { // TODO(b/177892522): Treat this as an error. @@ -295,7 +298,8 @@ func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext } // generateHiddenAPIBuildActions generates all the hidden API related build rules. -func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule { +func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, + fragments []android.Module, libraryToApex map[android.Module]string, apexNameToFragment map[string]android.Module) bootDexJarByModule { createEmptyHiddenApiFiles := func() { paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} for _, path := range paths { @@ -322,7 +326,7 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android. } // Construct a list of ClasspathElement objects from the modules and fragments. - classpathElements := CreateClasspathElements(ctx, modules, fragments) + classpathElements := CreateClasspathElements(ctx, modules, fragments, libraryToApex, apexNameToFragment) monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements) diff --git a/java/platform_bootclasspath_test.go b/java/platform_bootclasspath_test.go index db8557914..727e30670 100644 --- a/java/platform_bootclasspath_test.go +++ b/java/platform_bootclasspath_test.go @@ -93,7 +93,7 @@ func TestPlatformBootclasspath(t *testing.T) { checkSrcJarInputs := func(t *testing.T, result *android.TestResult, name string, expected []string) { t.Helper() - srcjar := result.ModuleForTests(name, "android_common").Output(name + "-transitive.srcjar") + srcjar := result.ModuleForTests(t, name, "android_common").Output(name + "-transitive.srcjar") android.AssertStringDoesContain(t, "srcjar arg", srcjar.Args["jarArgs"], "-srcjar") android.AssertArrayString(t, "srcjar inputs", expected, srcjar.Implicits.Strings()) } @@ -367,7 +367,7 @@ func TestPlatformBootclasspath_HiddenAPIMonolithicFiles(t *testing.T) { // Make sure that the foo-hiddenapi-annotations.jar is included in the inputs to the rules that // creates the index.csv file. - platformBootclasspath := result.ModuleForTests("myplatform-bootclasspath", "android_common") + platformBootclasspath := result.ModuleForTests(t, "myplatform-bootclasspath", "android_common") var rule android.TestingBuildParams diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index bb9894400..d4d2fb5bb 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -278,12 +278,7 @@ func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.Singlet rule.Build("merged-compat-config", "Merge compat config") p.metadata = outputPath -} - -func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) { - if p.metadata != nil { - ctx.DistForGoal("droidcore", p.metadata) - } + ctx.DistForGoal("droidcore", p.metadata) } func platformCompatConfigSingletonFactory() android.Singleton { diff --git a/java/plugin_test.go b/java/plugin_test.go index 95f4aca4c..007b74a9e 100644 --- a/java/plugin_test.go +++ b/java/plugin_test.go @@ -27,8 +27,8 @@ func TestNoPlugin(t *testing.T) { } `) - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") - turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") + turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine") if turbine.Rule == nil { t.Errorf("expected turbine to be enabled") @@ -61,14 +61,14 @@ func TestPlugin(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") - turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") + turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine") if turbine.Rule == nil { t.Errorf("expected turbine to be enabled") } - bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String() + bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String() if !inList(bar, javac.Implicits.Strings()) { t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar) @@ -102,14 +102,14 @@ func TestPluginGeneratesApi(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") - turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") + javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac") + turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine") if turbine.Rule != nil { t.Errorf("expected turbine to be disabled") } - bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String() + bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String() if !inList(bar, javac.Implicits.Strings()) { t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar) diff --git a/java/prebuilt_apis_test.go b/java/prebuilt_apis_test.go index c6a5913b0..1f095e49b 100644 --- a/java/prebuilt_apis_test.go +++ b/java/prebuilt_apis_test.go @@ -78,9 +78,9 @@ func TestPrebuiltApis_WithExtensions(t *testing.T) { "2": {"foo", "bar"}, }), ).RunTest(t) - foo_input = result.ModuleForTests("foo.api.public.latest", "").Rule("generator").Implicits[0].String() - bar_input = result.ModuleForTests("bar.api.public.latest", "").Rule("generator").Implicits[0].String() - baz_input = result.ModuleForTests("baz.api.public.latest", "").Rule("generator").Implicits[0].String() + foo_input = result.ModuleForTests(t, "foo.api.public.latest", "").Rule("generator").Implicits[0].String() + bar_input = result.ModuleForTests(t, "bar.api.public.latest", "").Rule("generator").Implicits[0].String() + baz_input = result.ModuleForTests(t, "baz.api.public.latest", "").Rule("generator").Implicits[0].String() return } // Extension 2 is the latest for both foo and bar, finalized after the base extension version. @@ -114,9 +114,9 @@ func TestPrebuiltApis_WithIncrementalApi(t *testing.T) { "current": {"foo", "bar"}, }), ).RunTest(t) - foo_input = result.ModuleForTests("foo.api.public.latest", "").Rule("generator").Implicits[0].String() - bar_input = result.ModuleForTests("bar.api.public.latest", "").Rule("generator").Implicits[0].String() - baz_input = result.ModuleForTests("baz.api.public.latest", "").Rule("generator").Implicits[0].String() + foo_input = result.ModuleForTests(t, "foo.api.public.latest", "").Rule("generator").Implicits[0].String() + bar_input = result.ModuleForTests(t, "bar.api.public.latest", "").Rule("generator").Implicits[0].String() + baz_input = result.ModuleForTests(t, "baz.api.public.latest", "").Rule("generator").Implicits[0].String() return } // 33.1 is the latest for baz, 33.2 is the latest for both foo & bar diff --git a/java/proto_test.go b/java/proto_test.go index 5b184b673..3fbe3e602 100644 --- a/java/proto_test.go +++ b/java/proto_test.go @@ -46,7 +46,7 @@ func TestProtoStream(t *testing.T) { PrepareForIntegrationTestWithJava, ).RunTestWithBp(t, protoModules+bp) - proto0 := ctx.ModuleForTests("java-stream-protos", "android_common").Output("proto/proto0.srcjar") + proto0 := ctx.ModuleForTests(t, "java-stream-protos", "android_common").Output("proto/proto0.srcjar") if cmd := proto0.RuleParams.Command; !strings.Contains(cmd, "--javastream_out=") { t.Errorf("expected '--javastream_out' in %q", cmd) diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go index ac4f14782..24a02bbdc 100644 --- a/java/ravenwood_test.go +++ b/java/ravenwood_test.go @@ -121,7 +121,7 @@ func TestRavenwoodRuntime(t *testing.T) { CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood") // Verify that we've emitted artifacts in expected location - runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common") + runtime := ctx.ModuleForTests(t, "ravenwood-runtime", "android_common") runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar") runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar") runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni1.so") @@ -129,7 +129,7 @@ func TestRavenwoodRuntime(t *testing.T) { runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so") runtime.Output(installPathPrefix + "/ravenwood-runtime/ravenwood-data/app1.apk") runtime.Output(installPathPrefix + "/ravenwood-runtime/fonts/Font.ttf") - utils := ctx.ModuleForTests("ravenwood-utils", "android_common") + utils := ctx.ModuleForTests(t, "ravenwood-utils", "android_common") utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar") } @@ -193,7 +193,7 @@ func TestRavenwoodTest(t *testing.T) { CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils") CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "jni-lib") - module := ctx.ModuleForTests("ravenwood-test", "android_common") + module := ctx.ModuleForTests(t, "ravenwood-test", "android_common") classpath := module.Rule("javac").Args["classpath"] // Verify that we're linking against test_current @@ -214,7 +214,7 @@ func TestRavenwoodTest(t *testing.T) { module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-res.apk") module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-inst-res.apk") - module = ctx.ModuleForTests("ravenwood-test-empty", "android_common") + module = ctx.ModuleForTests(t, "ravenwood-test-empty", "android_common") module.Output(installPathPrefix + "/ravenwood-test-empty/ravenwood.properties") // ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted. diff --git a/java/robolectric_test.go b/java/robolectric_test.go index ad0613ebd..4bf224b4f 100644 --- a/java/robolectric_test.go +++ b/java/robolectric_test.go @@ -105,6 +105,6 @@ func TestRobolectricJniTest(t *testing.T) { CheckModuleHasDependency(t, ctx.TestContext, "robo-test", "android_common", "jni-lib1") // Check that the .so files make it into the output. - module := ctx.ModuleForTests("robo-test", "android_common") + module := ctx.ModuleForTests(t, "robo-test", "android_common") module.Output(installPathPrefix + "/robo-test/lib64/jni-lib1.so") } diff --git a/java/rro_test.go b/java/rro_test.go index 1978ad67d..0ccc8e707 100644 --- a/java/rro_test.go +++ b/java/rro_test.go @@ -67,7 +67,7 @@ func TestRuntimeResourceOverlay(t *testing.T) { fs.AddToFixture(), ).RunTestWithBp(t, bp) - m := result.ModuleForTests("foo", "android_common") + m := result.ModuleForTests(t, "foo", "android_common") // Check AAPT2 link flags. aapt2Flags := m.Output("package-res.apk").Args["flags"] @@ -116,7 +116,7 @@ func TestRuntimeResourceOverlay(t *testing.T) { android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) // A themed module has a different device location - m = result.ModuleForTests("foo_themed", "android_common") + m = result.ModuleForTests(t, "foo_themed", "android_common") androidMkEntries = android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0] path = androidMkEntries.EntryMap["LOCAL_MODULE_PATH"] expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay/faza")} @@ -155,7 +155,7 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { // // RRO module with defaults // - m := result.ModuleForTests("foo_with_defaults", "android_common") + m := result.ModuleForTests(t, "foo_with_defaults", "android_common") // Check AAPT2 link flags. aapt2Flags := strings.Split(m.Output("package-res.apk").Args["flags"], " ") @@ -173,7 +173,7 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { // // RRO module without defaults // - m = result.ModuleForTests("foo_barebones", "android_common") + m = result.ModuleForTests(t, "foo_barebones", "android_common") // Check AAPT2 link flags. aapt2Flags = strings.Split(m.Output("package-res.apk").Args["flags"], " ") @@ -235,7 +235,7 @@ func TestOverrideRuntimeResourceOverlay(t *testing.T) { }, } for _, expected := range expectedVariants { - variant := ctx.ModuleForTests("foo_overlay", expected.variantName) + variant := ctx.ModuleForTests(t, "foo_overlay", expected.variantName) // Check the final apk name variant.Output(expected.apkPath) @@ -306,7 +306,7 @@ func TestRuntimeResourceOverlayPartition(t *testing.T) { } for _, testCase := range testCases { ctx, _ := testJava(t, bp) - mod := ctx.ModuleForTests(testCase.name, "android_common").Module().(*RuntimeResourceOverlay) + mod := ctx.ModuleForTests(t, testCase.name, "android_common").Module().(*RuntimeResourceOverlay) android.AssertPathRelativeToTopEquals(t, "Install dir is not correct for "+testCase.name, testCase.expectedPath, mod.installDir) } } @@ -341,7 +341,7 @@ func TestRuntimeResourceOverlayFlagsPackages(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") // runtime_resource_overlay module depends on aconfig_declarations listed in flags_packages android.AssertBoolEquals(t, "foo expected to depend on bar", true, diff --git a/java/sdk.go b/java/sdk.go index bb2aa8d7e..27b2434c5 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -381,6 +381,10 @@ func createAPIFingerprint(ctx android.SingletonContext) { } rule.Build("api_fingerprint", "generate api_fingerprint.txt") + + if ctx.Config().BuildOS == android.Linux { + ctx.DistForGoals([]string{"sdk", "droidcore"}, out) + } } func sdkMakeVars(ctx android.MakeVarsContext) { diff --git a/java/sdk_library.go b/java/sdk_library.go index 07f059928..cf31b5095 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -316,6 +316,15 @@ func (scopes apiScopes) ConvertStubsLibraryExportableToEverything(name string) s return name } +func (scopes apiScopes) matchingScopeFromSdkKind(kind android.SdkKind) *apiScope { + for _, scope := range scopes { + if scope.kind == kind { + return scope + } + } + return nil +} + var ( scopeByName = make(map[string]*apiScope) allScopeNames []string @@ -922,6 +931,8 @@ type commonSdkLibraryAndImportModule interface { RootLibraryName() string } +var _ android.ApexModule = (*SdkLibrary)(nil) + func (m *SdkLibrary) RootLibraryName() string { return m.BaseModuleName() } @@ -1699,14 +1710,22 @@ func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { } // Implements android.ApexModule -func (module *SdkLibrary) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool { - if depTag == xmlPermissionsFileTag { +func (m *SdkLibrary) GetDepInSameApexChecker() android.DepInSameApexChecker { + return SdkLibraryDepInSameApexChecker{} +} + +type SdkLibraryDepInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m SdkLibraryDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { + if tag == xmlPermissionsFileTag { return true } - if depTag == implLibraryTag { + if tag == implLibraryTag { return true } - return module.Library.OutgoingDepIsInSameApex(depTag) + return depIsInSameApex(tag) } // Implements android.ApexModule @@ -2117,8 +2136,16 @@ func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) var _ android.ApexModule = (*SdkLibraryImport)(nil) // Implements android.ApexModule -func (module *SdkLibraryImport) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool { - if depTag == xmlPermissionsFileTag { +func (m *SdkLibraryImport) GetDepInSameApexChecker() android.DepInSameApexChecker { + return SdkLibraryImportDepIsInSameApexChecker{} +} + +type SdkLibraryImportDepIsInSameApexChecker struct { + android.BaseDepInSameApexChecker +} + +func (m SdkLibraryImportDepIsInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { + if tag == xmlPermissionsFileTag { return true } @@ -2128,13 +2155,10 @@ func (module *SdkLibraryImport) OutgoingDepIsInSameApex(depTag blueprint.Depende } // Implements android.ApexModule -func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // we don't check prebuilt modules for sdk_version - return nil +func (m *SdkLibraryImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } -// Implements android.ApexModule func (module *SdkLibraryImport) UniqueApexVariations() bool { return module.uniqueApexVariations() } diff --git a/java/sdk_library_internal.go b/java/sdk_library_internal.go index db9cd24ce..578969223 100644 --- a/java/sdk_library_internal.go +++ b/java/sdk_library_internal.go @@ -807,10 +807,8 @@ func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { var _ android.ApexModule = (*sdkLibraryXml)(nil) // Implements android.ApexModule -func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked - return nil +func (m *sdkLibraryXml) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // File path to the runtime implementation library diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 0aed4b81a..2cb827dc2 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -115,19 +115,19 @@ func TestJavaSdkLibrary(t *testing.T) { `) // check the existence of the internal modules - foo := result.ModuleForTests("foo", "android_common") - result.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common") - result.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") - result.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common") - result.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common") - result.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common") - result.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common") - result.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo")+".api.contribution", "") - result.ModuleForTests(apiScopePublic.apiLibraryModuleName("foo"), "android_common") - result.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") - result.ModuleForTests("foo.api.public.28", "") - result.ModuleForTests("foo.api.system.28", "") - result.ModuleForTests("foo.api.test.28", "") + foo := result.ModuleForTests(t, "foo", "android_common") + result.ModuleForTests(t, apiScopePublic.stubsLibraryModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopeTest.stubsLibraryModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopePublic.stubsSourceModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopeSystem.stubsSourceModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopeTest.stubsSourceModuleName("foo"), "android_common") + result.ModuleForTests(t, apiScopePublic.stubsSourceModuleName("foo")+".api.contribution", "") + result.ModuleForTests(t, apiScopePublic.apiLibraryModuleName("foo"), "android_common") + result.ModuleForTests(t, "foo"+sdkXmlFileSuffix, "android_common") + result.ModuleForTests(t, "foo.api.public.28", "") + result.ModuleForTests(t, "foo.api.system.28", "") + result.ModuleForTests(t, "foo.api.test.28", "") exportedComponentsInfo, _ := android.OtherModuleProvider(result, foo.Module(), android.ExportedComponentsInfoProvider) expectedFooExportedComponents := []string{ @@ -147,7 +147,7 @@ func TestJavaSdkLibrary(t *testing.T) { } android.AssertArrayString(t, "foo exported components", expectedFooExportedComponents, exportedComponentsInfo.Components) - bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac") + bazJavac := result.ModuleForTests(t, "baz", "android_common").Rule("javac") // tests if baz is actually linked to the stubs lib android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.jar") // ... and not to the impl lib @@ -155,20 +155,20 @@ func TestJavaSdkLibrary(t *testing.T) { // test if baz is not linked to the system variant of foo android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.jar") - bazTestJavac := result.ModuleForTests("baz-test", "android_common").Rule("javac") + bazTestJavac := result.ModuleForTests(t, "baz-test", "android_common").Rule("javac") // tests if baz-test is actually linked to the test stubs lib android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.jar") - baz29Javac := result.ModuleForTests("baz-29", "android_common").Rule("javac") + baz29Javac := result.ModuleForTests(t, "baz-29", "android_common").Rule("javac") // tests if baz-29 is actually linked to the system 29 stubs lib android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/sdk_system_29_foo/android_common/combined/sdk_system_29_foo.jar") - bazModule30Javac := result.ModuleForTests("baz-module-30", "android_common").Rule("javac") + bazModule30Javac := result.ModuleForTests(t, "baz-module-30", "android_common").Rule("javac") // tests if "baz-module-30" is actually linked to the module 30 stubs lib android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/sdk_module-lib_30_foo/android_common/combined/sdk_module-lib_30_foo.jar") // test if baz has exported SDK lib names foo and bar to qux - qux := result.ModuleForTests("qux", "android_common") + qux := result.ModuleForTests(t, "qux", "android_common") if quxLib, ok := qux.Module().(*Library); ok { requiredSdkLibs, optionalSdkLibs := quxLib.ClassLoaderContexts().UsesLibs() android.AssertDeepEquals(t, "qux exports (required)", []string{"fred", "quuz", "foo", "bar"}, requiredSdkLibs) @@ -176,13 +176,13 @@ func TestJavaSdkLibrary(t *testing.T) { } // test if quuz have created the api_contribution module - result.ModuleForTests(apiScopePublic.stubsSourceModuleName("quuz")+".api.contribution", "") + result.ModuleForTests(t, apiScopePublic.stubsSourceModuleName("quuz")+".api.contribution", "") - fooImplDexJar := result.ModuleForTests("foo.impl", "android_common").Rule("d8") + fooImplDexJar := result.ModuleForTests(t, "foo.impl", "android_common").Rule("d8") // tests if kotlinc generated files are NOT excluded from output of foo.impl. android.AssertStringDoesNotContain(t, "foo.impl dex", fooImplDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module") - barImplDexJar := result.ModuleForTests("bar.impl", "android_common").Rule("d8") + barImplDexJar := result.ModuleForTests(t, "bar.impl", "android_common").Rule("d8") // tests if kotlinc generated files are excluded from output of bar.impl. android.AssertStringDoesContain(t, "bar.impl dex", barImplDexJar.BuildParams.Args["mergeZipsFlags"], "-stripFile META-INF/*.kotlin_module") } @@ -220,7 +220,7 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) { `) // test that updatability attributes are passed on correctly - fooUpdatable := result.ModuleForTests("fooUpdatable.xml", "android_common").Output("fooUpdatable.xml") + fooUpdatable := result.ModuleForTests(t, "fooUpdatable.xml", "android_common").Output("fooUpdatable.xml") fooUpdatableContents := android.ContentFromFileRuleForTests(t, result.TestContext, fooUpdatable) android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `on-bootclasspath-since="U"`) android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `on-bootclasspath-before="V"`) @@ -229,7 +229,7 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) { // double check that updatability attributes are not written if they don't exist in the bp file // the permissions file for the foo library defined above - fooPermissions := result.ModuleForTests("foo.xml", "android_common").Output("foo.xml") + fooPermissions := result.ModuleForTests(t, "foo.xml", "android_common").Output("foo.xml") fooPermissionsContents := android.ContentFromFileRuleForTests(t, result.TestContext, fooPermissions) android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `on-bootclasspath-since`) android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `on-bootclasspath-before`) @@ -370,7 +370,7 @@ func TestJavaSdkLibrary_UpdatableLibrary_usesNewTag(t *testing.T) { } `) // test that updatability attributes are passed on correctly - fooUpdatable := result.ModuleForTests("foo.xml", "android_common").Output("foo.xml") + fooUpdatable := result.ModuleForTests(t, "foo.xml", "android_common").Output("foo.xml") fooUpdatableContents := android.ContentFromFileRuleForTests(t, result.TestContext, fooUpdatable) android.AssertStringDoesContain(t, "foo.xml contents", fooUpdatableContents, `<apex-library`) android.AssertStringDoesNotContain(t, "foo.xml contents", fooUpdatableContents, `<library`) @@ -417,11 +417,11 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { {lib: "stub-only-static-lib", in_stub_combined: true}, } verify := func(sdklib, dep string, cp, combined bool) { - sdklibCp := result.ModuleForTests(sdklib, "android_common").Rule("javac").Args["classpath"] + sdklibCp := result.ModuleForTests(t, sdklib, "android_common").Rule("javac").Args["classpath"] expected := cp || combined // Every combined jar is also on the classpath. android.AssertStringContainsEquals(t, "bad classpath for "+sdklib, sdklibCp, "/"+dep+".jar", expected) - combineJarInputs := result.ModuleForTests(sdklib, "android_common").Rule("combineJar").Inputs.Strings() + combineJarInputs := result.ModuleForTests(t, sdklib, "android_common").Rule("combineJar").Inputs.Strings() depPath := filepath.Join("out", "soong", ".intermediates", dep, "android_common", "turbine-combined", dep+".jar") android.AssertStringListContainsEquals(t, "bad combined inputs for "+sdklib, combineJarInputs, depPath, combined) } @@ -457,7 +457,7 @@ func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { `) // The bar library should depend on the stubs jar. - barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac") + barLibrary := result.ModuleForTests(t, "bar", "android_common").Rule("javac") if expected, actual := `^-classpath .*:out/soong/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { t.Errorf("expected %q, found %#q", expected, actual) } @@ -797,7 +797,7 @@ func TestJavaSdkLibrary_SystemServer_AccessToStubScopeLibs(t *testing.T) { // The bar library should depend on the highest (where system server is highest and public is // lowest) API scopes provided by each of the foo-* modules. The highest API scope provided by the // foo-<x> module is <x>. - barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac") + barLibrary := result.ModuleForTests(t, "bar", "android_common").Rule("javac") stubLibraries := []string{ stubsPath("foo-public", apiScopePublic), stubsPath("foo-system", apiScopeSystem), @@ -850,10 +850,10 @@ func TestJavaSdkLibraryImport(t *testing.T) { `) for _, scope := range []string{"", ".system", ".test"} { - fooModule := result.ModuleForTests("foo"+scope, "android_common") + fooModule := result.ModuleForTests(t, "foo"+scope, "android_common") javac := fooModule.Rule("javac") - sdklibStubsJar := result.ModuleForTests("sdklib.stubs"+scope, "android_common").Output("combined/sdklib.stubs" + scope + ".jar").Output + sdklibStubsJar := result.ModuleForTests(t, "sdklib.stubs"+scope, "android_common").Output("combined/sdklib.stubs" + scope + ".jar").Output android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], sdklibStubsJar.String()) } @@ -993,15 +993,13 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an CheckModuleDependencies(t, result.TestContext, "combined", "android_common", []string{ // Each use of :sdklib{...} adds a dependency onto prebuilt_sdklib. `prebuilt_sdklib`, - `prebuilt_sdklib`, - `prebuilt_sdklib`, `prebuilt_sdklib.stubs`, `prebuilt_sdklib.stubs.source`, }) // Make sure that dependencies on sdklib that resolve to one of the child libraries use the // prebuilt library. - public := result.ModuleForTests("public", "android_common") + public := result.ModuleForTests(t, "public", "android_common") rule := public.Output("javac/public.jar") inputs := rule.Implicits.Strings() expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/combined/sdklib.stubs.jar" @@ -1121,7 +1119,7 @@ func TestSdkLibraryImport_MetadataModuleSupersedesPreferred(t *testing.T) { ).RunTestWithBp(t, bp) // Make sure that rdeps get the correct source vs prebuilt based on mainline_module_contributions - public := result.ModuleForTests("public", "android_common") + public := result.ModuleForTests(t, "public", "android_common") rule := public.Output("javac/public.jar") inputs := rule.Implicits.Strings() expectedInputs := []string{ @@ -1209,7 +1207,7 @@ func TestJavaSdkLibraryDist(t *testing.T) { for _, tt := range testCases { t.Run(tt.module, func(t *testing.T) { t.Parallel() - m := result.ModuleForTests(apiScopePublic.exportableStubsLibraryModuleName(tt.module), "android_common").Module().(*Library) + m := result.ModuleForTests(t, apiScopePublic.exportableStubsLibraryModuleName(tt.module), "android_common").Module().(*Library) dists := m.Dists() if len(dists) != 1 { t.Fatalf("expected exactly 1 dist entry, got %d", len(dists)) @@ -1332,7 +1330,7 @@ func TestJavaSdkLibrary_StubOnlyLibs_PassedToDroidstubs(t *testing.T) { `) // The foo.stubs.source should depend on bar-lib - fooStubsSources := result.ModuleForTests("foo.stubs.source", "android_common").Module().(*Droidstubs) + fooStubsSources := result.ModuleForTests(t, "foo.stubs.source", "android_common").Module().(*Droidstubs) eval := fooStubsSources.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext)) android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs.GetOrDefault(eval, nil), "bar-lib") } @@ -1360,7 +1358,7 @@ func TestJavaSdkLibrary_Scope_Libs_PassedToDroidstubs(t *testing.T) { `) // The foo.stubs.source should depend on bar-lib - fooStubsSources := result.ModuleForTests("foo.stubs.source", "android_common").Module().(*Droidstubs) + fooStubsSources := result.ModuleForTests(t, "foo.stubs.source", "android_common").Module().(*Droidstubs) eval := fooStubsSources.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext)) android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs.GetOrDefault(eval, nil), "bar-lib") } @@ -1411,7 +1409,7 @@ func TestJavaSdkLibrary_ApiLibrary(t *testing.T) { } for _, c := range testCases { - m := result.ModuleForTests(c.scope.apiLibraryModuleName("foo"), "android_common").Module().(*ApiLibrary) + m := result.ModuleForTests(t, c.scope.apiLibraryModuleName("foo"), "android_common").Module().(*ApiLibrary) android.AssertArrayString(t, "Module expected to contain api contributions", c.apiContributions, m.properties.Api_contributions) } } @@ -1474,7 +1472,7 @@ func TestSdkLibraryDependency(t *testing.T) { } `) - barPermissions := result.ModuleForTests("bar.xml", "android_common").Output("bar.xml") + barPermissions := result.ModuleForTests(t, "bar.xml", "android_common").Output("bar.xml") barContents := android.ContentFromFileRuleForTests(t, result.TestContext, barPermissions) android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barContents, `dependency="foo"`) } @@ -1517,8 +1515,8 @@ func TestSdkLibraryExportableStubsLibrary(t *testing.T) { exportableSourceStubsLibraryModuleName := apiScopePublic.exportableSourceStubsLibraryModuleName("foo") // Check modules generation - result.ModuleForTests(exportableStubsLibraryModuleName, "android_common") - result.ModuleForTests(exportableSourceStubsLibraryModuleName, "android_common") + result.ModuleForTests(t, exportableStubsLibraryModuleName, "android_common") + result.ModuleForTests(t, exportableSourceStubsLibraryModuleName, "android_common") // Check static lib dependency android.AssertBoolEquals(t, "exportable top level stubs library module depends on the"+ @@ -1577,7 +1575,7 @@ func TestStubResolutionOfJavaSdkLibraryInLibs(t *testing.T) { result := fixture.RunTestWithBp(t, bp) // Make sure that rdeps get the correct source vs prebuilt based on mainline_module_contributions - public := result.ModuleForTests("mymodule", "android_common") + public := result.ModuleForTests(t, "mymodule", "android_common") rule := public.Output("javac/mymodule.jar") inputs := rule.Implicits.Strings() android.AssertStringListContains(t, "Could not find the expected stub on classpath", inputs, "out/soong/.intermediates/sdklib.stubs/android_common/turbine-combined/sdklib.stubs.jar") @@ -1663,7 +1661,7 @@ func TestMultipleSdkLibraryPrebuilts(t *testing.T) { result := fixture.RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) // Make sure that rdeps get the correct source vs prebuilt based on mainline_module_contributions - public := result.ModuleForTests("mymodule", "android_common") + public := result.ModuleForTests(t, "mymodule", "android_common") rule := public.Output("javac/mymodule.jar") inputs := rule.Implicits.Strings() android.AssertStringListContains(t, "Could not find the expected stub on classpath", inputs, tc.expectedStubPath) diff --git a/java/sdk_test.go b/java/sdk_test.go index e926307fb..49983ada2 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -501,7 +501,7 @@ func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase } checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) { - foo := result.ModuleForTests("foo", variant(result)) + foo := result.ModuleForTests(t, "foo", variant(result)) javac := foo.Rule("javac") var deps []string @@ -579,7 +579,7 @@ func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase checkClasspath(t, result, true /* isJava8 */) if testcase.host != android.Host { - aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") + aidl := result.ModuleForTests(t, "foo", variant(result)).Rule("aidl") android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") } @@ -593,7 +593,7 @@ func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase checkClasspath(t, result, false /* isJava8 */) if testcase.host != android.Host { - aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") + aidl := result.ModuleForTests(t, "foo", variant(result)).Rule("aidl") android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") } diff --git a/java/sdk_version_test.go b/java/sdk_version_test.go index 6f0370a52..03d55f70a 100644 --- a/java/sdk_version_test.go +++ b/java/sdk_version_test.go @@ -58,7 +58,7 @@ func TestSystemSdkFromVendor(t *testing.T) { vendor: true, sdk_version: "system_current", }`) - fooModule := result.ModuleForTests("foo", "android_common") + fooModule := result.ModuleForTests(t, "foo", "android_common") fooClasspath := fooModule.Rule("javac").Args["classpath"] android.AssertStringDoesContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/34/system/android.jar") diff --git a/java/system_modules_test.go b/java/system_modules_test.go index b7a99b51a..99301bc52 100644 --- a/java/system_modules_test.go +++ b/java/system_modules_test.go @@ -55,7 +55,7 @@ func TestJavaSystemModules(t *testing.T) { result := android.GroupFixturePreparers(prepareForJavaTest, addSourceSystemModules).RunTest(t) // check the existence of the source module - sourceSystemModules := result.ModuleForTests("system-modules", "android_common") + sourceSystemModules := result.ModuleForTests(t, "system-modules", "android_common") sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs // The expected paths are the header jars from the source input modules. @@ -83,7 +83,7 @@ func TestJavaSystemModulesImport(t *testing.T) { result := android.GroupFixturePreparers(prepareForJavaTest, addPrebuiltSystemModules).RunTest(t) // check the existence of the renamed prebuilt module - prebuiltSystemModules := result.ModuleForTests("system-modules", "android_common") + prebuiltSystemModules := result.ModuleForTests(t, "system-modules", "android_common") prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs // The expected paths are the header jars from the renamed prebuilt input modules. @@ -100,7 +100,7 @@ func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) { ).RunTest(t) // check the existence of the source module - sourceSystemModules := result.ModuleForTests("system-modules", "android_common") + sourceSystemModules := result.ModuleForTests(t, "system-modules", "android_common") sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs // The expected paths are the header jars from the source input modules. @@ -108,7 +108,7 @@ func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) { android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, sourceInputs.RelativeToTop().Strings()) // check the existence of the renamed prebuilt module - prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common") + prebuiltSystemModules := result.ModuleForTests(t, "prebuilt_system-modules", "android_common") prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs // The expected paths are the header jars from the renamed prebuilt input modules. diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index f3074ed0a..a60f6b82c 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -95,8 +95,10 @@ type SystemServerClasspathModule struct { properties systemServerClasspathFragmentProperties } -func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { - return nil +var _ android.ApexModule = (*SystemServerClasspathModule)(nil) + +func (m *SystemServerClasspathModule) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } type systemServerClasspathFragmentProperties struct { @@ -119,6 +121,7 @@ func systemServerClasspathFactory() android.Module { android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) return m } + func (m *SystemServerClasspathModule) UniqueApexVariations() bool { return true } diff --git a/java/testing.go b/java/testing.go index 0ea4e6408..35319ae58 100644 --- a/java/testing.go +++ b/java/testing.go @@ -18,7 +18,6 @@ import ( "fmt" "reflect" "regexp" - "sort" "strings" "testing" @@ -378,7 +377,6 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) { RegisterAppBuildComponents(ctx) RegisterAppImportBuildComponents(ctx) RegisterAppSetBuildComponents(ctx) - registerBootclasspathBuildComponents(ctx) registerBootclasspathFragmentBuildComponents(ctx) RegisterDexpreoptBootJarsComponents(ctx) RegisterDocsBuildComponents(ctx) @@ -607,19 +605,18 @@ func gatherRequiredDepsForTest() string { func getModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string) []string { t.Helper() - module := ctx.ModuleForTests(name, variant).Module() + module := ctx.ModuleForTests(t, name, variant).Module() deps := []string{} ctx.VisitDirectDeps(module, func(m blueprint.Module) { deps = append(deps, m.Name()) }) - sort.Strings(deps) - - return deps + return android.SortedUniqueStrings(deps) } // CheckModuleDependencies checks if the expected dependencies of the module are // identical to the actual dependencies. func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { + t.Helper() deps := getModuleDependencies(t, ctx, name, variant) if actual := deps; !reflect.DeepEqual(expected, actual) { @@ -639,7 +636,7 @@ func CheckModuleHasDependency(t *testing.T, ctx *android.TestContext, name, vari // CheckModuleHasDependency returns true if the module depends on the expected dependency. func CheckModuleHasDependencyWithTag(t *testing.T, ctx *android.TestContext, name, variant string, desiredTag blueprint.DependencyTag, expected string) bool { - module := ctx.ModuleForTests(name, variant).Module() + module := ctx.ModuleForTests(t, name, variant).Module() found := false ctx.VisitDirectDepsWithTags(module, func(m blueprint.Module, tag blueprint.DependencyTag) { if tag == desiredTag && m.Name() == expected { @@ -654,7 +651,7 @@ func CheckModuleHasDependencyWithTag(t *testing.T, ctx *android.TestContext, nam func CheckPlatformBootclasspathModules(t *testing.T, result *android.TestResult, name string, expected []string) { t.Helper() platformBootclasspath := result.Module(name, "android_common").(*platformBootclasspathModule) - pairs := ApexNamePairsFromModules(result.TestContext, platformBootclasspath.configuredModules) + pairs := apexNamePairsFromModules(result.TestContext, platformBootclasspath.configuredModules, platformBootclasspath.libraryToApex) android.AssertDeepEquals(t, fmt.Sprintf("%s modules", "platform-bootclasspath"), expected, pairs) } @@ -669,23 +666,54 @@ func CheckClasspathFragmentProtoContentInfoProvider(t *testing.T, result *androi android.AssertPathRelativeToTopEquals(t, "install filepath", installDir, info.ClasspathFragmentProtoInstallDir) } -// ApexNamePairsFromModules returns the apex:module pair for the supplied modules. -func ApexNamePairsFromModules(ctx *android.TestContext, modules []android.Module) []string { +// CheckPlatformBootclasspathDependencies checks the dependencies of the selected module against the expected list. +// +// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the +// name of the apex, or platform is it is not part of an apex and <module> is the module name. +func CheckPlatformBootclasspathDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { + t.Helper() + platformBootclasspath := ctx.ModuleForTests(t, name, variant).Module().(*platformBootclasspathModule) + modules := []android.Module{} + ctx.VisitDirectDeps(platformBootclasspath, func(m blueprint.Module) { + modules = append(modules, m.(android.Module)) + }) + + pairs := apexNamePairsFromModules(ctx, modules, platformBootclasspath.libraryToApex) + android.AssertDeepEquals(t, "module dependencies", expected, pairs) +} + +// apexNamePairsFromModules returns the apex:module pair for the supplied modules. +func apexNamePairsFromModules(ctx *android.TestContext, modules []android.Module, modulesToApex map[android.Module]string) []string { pairs := []string{} for _, module := range modules { - pairs = append(pairs, apexNamePairFromModule(ctx, module)) + pairs = append(pairs, apexNamePairFromModule(ctx, module, modulesToApex)) + } + return pairs +} + +// ApexFragmentPairsFromModules returns the apex:fragment pair for the supplied fragments. +func ApexFragmentPairsFromModules(ctx *android.TestContext, fragments []android.Module, apexNameToFragment map[string]android.Module) []string { + pairs := []string{} + for _, fragment := range fragments { + found := false + for apex, apexFragment := range apexNameToFragment { + if apexFragment == fragment { + pairs = append(pairs, apex+":"+ctx.ModuleName(fragment)) + found = true + } + } + if !found { + pairs = append(pairs, "platform:"+ctx.ModuleName(fragment)) + } } return pairs } -func apexNamePairFromModule(ctx *android.TestContext, module android.Module) string { +func apexNamePairFromModule(ctx *android.TestContext, module android.Module, modulesToApex map[android.Module]string) string { name := module.Name() - var apex string - apexInfo, _ := android.OtherModuleProvider(ctx, module, android.ApexInfoProvider) - if apexInfo.IsForPlatform() { + apex := modulesToApex[module] + if apex == "" { apex = "platform" - } else { - apex = apexInfo.InApexVariants[0] } return fmt.Sprintf("%s:%s", apex, name) @@ -696,7 +724,7 @@ func apexNamePairFromModule(ctx *android.TestContext, module android.Module) str func CheckPlatformBootclasspathFragments(t *testing.T, result *android.TestResult, name string, expected []string) { t.Helper() platformBootclasspath := result.Module(name, "android_common").(*platformBootclasspathModule) - pairs := ApexNamePairsFromModules(result.TestContext, platformBootclasspath.fragments) + pairs := ApexFragmentPairsFromModules(result.TestContext, platformBootclasspath.fragments, platformBootclasspath.apexNameToFragment) android.AssertDeepEquals(t, fmt.Sprintf("%s fragments", "platform-bootclasspath"), expected, pairs) } @@ -719,7 +747,7 @@ func CheckHiddenAPIRuleInputs(t *testing.T, message string, expected string, hid // Check that the merged file create by platform_compat_config_singleton has the correct inputs. func CheckMergedCompatConfigInputs(t *testing.T, result *android.TestResult, message string, expectedPaths ...string) { - sourceGlobalCompatConfig := result.SingletonForTests("platform_compat_config_singleton") + sourceGlobalCompatConfig := result.SingletonForTests(t, "platform_compat_config_singleton") allOutputs := sourceGlobalCompatConfig.AllOutputs() android.AssertIntEquals(t, message+": output len", 1, len(allOutputs)) output := sourceGlobalCompatConfig.Output(allOutputs[0]) |