Skip to content

Commit

Permalink
Merge changes I093fbec4,Iee5c09d5
Browse files Browse the repository at this point in the history
* changes:
  bootclasspath_fragment: Treat some specific modules as test
  bootclasspath_fragment: Add test specific module type
  • Loading branch information
paulduffin authored and Gerrit Code Review committed May 30, 2022
2 parents 97fd87e + ff9b6fa commit 1db9d96
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
30 changes: 30 additions & 0 deletions java/bootclasspath_fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -227,6 +228,9 @@ type BootclasspathFragmentModule struct {
android.SdkBase
ClasspathFragmentBase

// True if this fragment is for testing purposes.
testFragment bool

properties bootclasspathFragmentProperties

sourceOnlyProperties SourceOnlyBootclasspathProperties
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -815,6 +825,26 @@ 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 {
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)
// 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 {
Expand Down
61 changes: 61 additions & 0 deletions java/bootclasspath_fragment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,64 @@ 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 {
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"],
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("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())
}

0 comments on commit 1db9d96

Please sign in to comment.