From c15b9e99e5e208410a1f1c3766c97125e63c22b3 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 31 Mar 2022 15:42:30 +0100 Subject: [PATCH 1/2] bootclasspath_fragment: Add test specific module type This is needed to allow the behavior of the bootclasspath_fragment to be tweaked for test fragments. Bug: 194063708 Test: m nothing Change-Id: Iee5c09d5b580d088ba081d95a788dbde883078ed --- java/bootclasspath_fragment.go | 15 +++++++++++ java/bootclasspath_fragment_test.go | 39 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 0345aadfd..11634fabf 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -42,6 +42,7 @@ func init() { func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory) + ctx.RegisterModuleType("bootclasspath_fragment_test", testBootclasspathFragmentFactory) ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory) } @@ -227,6 +228,9 @@ type BootclasspathFragmentModule struct { android.SdkBase ClasspathFragmentBase + // True if this fragment is for testing purposes. + testFragment bool + properties bootclasspathFragmentProperties sourceOnlyProperties SourceOnlyBootclasspathProperties @@ -298,6 +302,12 @@ func bootclasspathFragmentFactory() android.Module { return m } +func testBootclasspathFragmentFactory() android.Module { + m := bootclasspathFragmentFactory().(*BootclasspathFragmentModule) + m.testFragment = true + return m +} + // bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if // necessary. func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) { @@ -815,6 +825,11 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul return input } +// isTestFragment returns true if the current module is a test bootclasspath_fragment. +func (b *BootclasspathFragmentModule) isTestFragment() bool { + return b.testFragment +} + // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) // for the fragment as well as encoding the flags in the boot dex jars. func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput { diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index d3de675d8..2307ce02b 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -278,3 +278,42 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope()) } + +func TestBootclasspathFragment_Test(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForTestWithBootclasspathFragment, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("mysdklibrary"), + ).RunTestWithBp(t, ` + bootclasspath_fragment { + name: "myfragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + bootclasspath_fragment_test { + name: "a_test_fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + + java_sdk_library { + name: "mysdklibrary", + srcs: ["a.java"], + shared_library: false, + public: {enabled: true}, + system: {enabled: true}, + } + `) + + fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) + + fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) +} From ff9b6faba2b9a949289c70657db87c0b1790cc07 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 12 Apr 2022 18:20:14 +0100 Subject: [PATCH 2/2] bootclasspath_fragment: Treat some specific modules as test Treats bootclasspath_fragment modules that have not yet been converted to test modules as if they were test modules. This is a temporary work around to ease the migration to bootclasspath_fragment_test modules and is expected to be reverted. Bug: 194063708 Test: m nothing Change-Id: I093fbec4e926719b644c64ebfc63f9e3070e28db --- java/bootclasspath_fragment.go | 17 ++++++++++++++++- java/bootclasspath_fragment_test.go | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 11634fabf..b28d70cab 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -827,7 +827,22 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul // isTestFragment returns true if the current module is a test bootclasspath_fragment. func (b *BootclasspathFragmentModule) isTestFragment() bool { - return b.testFragment + if b.testFragment { + return true + } + + // TODO(b/194063708): Once test fragments all use bootclasspath_fragment_test + // Some temporary exceptions until all test fragments use the + // bootclasspath_fragment_test module type. + name := b.BaseModuleName() + if strings.HasPrefix(name, "test_") { + return true + } + if name == "apex.apexd_test_bootclasspath-fragment" { + return true + } + + return false } // produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files) diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 2307ce02b..8ffe99a77 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -293,6 +293,22 @@ func TestBootclasspathFragment_Test(t *testing.T) { }, } + bootclasspath_fragment { + name: "test_fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + + bootclasspath_fragment { + name: "apex.apexd_test_bootclasspath-fragment", + contents: ["mysdklibrary"], + hidden_api: { + split_packages: [], + }, + } + bootclasspath_fragment_test { name: "a_test_fragment", contents: ["mysdklibrary"], @@ -314,6 +330,12 @@ func TestBootclasspathFragment_Test(t *testing.T) { fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) + fragment = result.Module("test_fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by prefix", true, fragment.isTestFragment()) + fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) + + fragment = result.Module("apex.apexd_test_bootclasspath-fragment", "android_common").(*BootclasspathFragmentModule) + android.AssertBoolEquals(t, "is a test fragment by name", true, fragment.isTestFragment()) }