aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2022-03-31 15:42:30 +0100
committerCherrypicker Worker <android-build-cherrypicker-worker@google.com>2022-07-12 12:00:58 +0000
commitab9fbab7ef165c1312f540899ab00301fab0de81 (patch)
tree2d7cc6b461b35b5ac1fc22eb2dcdcb450429b5b1
parent2bf4389d33aa63fc0b73571f962037ad101d5db6 (diff)
downloadsoong-ab9fbab7ef165c1312f540899ab00301fab0de81.tar.gz
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 (cherry picked from commit c15b9e99e5e208410a1f1c3766c97125e63c22b3) Merged-In: Iee5c09d5b580d088ba081d95a788dbde883078ed
-rw-r--r--java/bootclasspath_fragment.go15
-rw-r--r--java/bootclasspath_fragment_test.go39
2 files changed, 54 insertions, 0 deletions
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 1c77fdb43..3dce64095 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -37,6 +37,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)
}
@@ -231,6 +232,9 @@ type BootclasspathFragmentModule struct {
android.SdkBase
ClasspathFragmentBase
+ // True if this fragment is for testing purposes.
+ testFragment bool
+
properties bootclasspathFragmentProperties
sourceOnlyProperties SourceOnlyBootclasspathProperties
@@ -302,6 +306,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) {
@@ -823,6 +833,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())
+}