Merge "bootclasspath_fragment: Add contents to snapshot" am: 6e0a62b773
am: 889010d73a
am: 855362a5da
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1682090 Change-Id: Ie107e8986b9b0dc4251f8e28427399854b44ec43
This commit is contained in:
commit
3b34058072
5 changed files with 186 additions and 6 deletions
|
@ -25,5 +25,7 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers(
|
|||
// Needed by apex.
|
||||
"system/core/rootdir/etc/public.libraries.android.txt": nil,
|
||||
"build/soong/scripts/gen_ndk_backedby_apex.sh": nil,
|
||||
// Needed by prebuilt_apex.
|
||||
"build/soong/scripts/unpack-prebuilt-apex.sh": nil,
|
||||
}.AddToFixture(),
|
||||
)
|
||||
|
|
|
@ -321,19 +321,33 @@ func (b *bootImageMemberType) CreateVariantPropertiesStruct() android.SdkMemberP
|
|||
type bootImageSdkMemberProperties struct {
|
||||
android.SdkMemberPropertiesBase
|
||||
|
||||
// The image name
|
||||
Image_name *string
|
||||
|
||||
// Contents of the bootclasspath fragment
|
||||
Contents []string
|
||||
}
|
||||
|
||||
func (b *bootImageSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
||||
module := variant.(*BootImageModule)
|
||||
|
||||
b.Image_name = module.properties.Image_name
|
||||
if b.Image_name == nil {
|
||||
// Only one of image_name or contents can be specified. However, if image_name is set then the
|
||||
// contents property is updated to match the configuration used to create the corresponding
|
||||
// boot image. Therefore, contents property is only copied if the image name is not specified.
|
||||
b.Contents = module.properties.Contents
|
||||
}
|
||||
}
|
||||
|
||||
func (b *bootImageSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
||||
if b.Image_name != nil {
|
||||
propertySet.AddProperty("image_name", *b.Image_name)
|
||||
}
|
||||
|
||||
if len(b.Contents) > 0 {
|
||||
propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
|
||||
}
|
||||
}
|
||||
|
||||
var _ android.SdkMemberType = (*bootImageMemberType)(nil)
|
||||
|
|
|
@ -200,6 +200,9 @@ func FixtureConfigureBootJars(bootJars ...string) android.FixturePreparer {
|
|||
}),
|
||||
dexpreopt.FixtureSetBootJars(bootJars...),
|
||||
dexpreopt.FixtureSetArtBootJars(artBootJars...),
|
||||
|
||||
// Add a fake dex2oatd module.
|
||||
dexpreopt.PrepareForTestWithFakeDex2oatd,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -212,6 +215,9 @@ func FixtureConfigureUpdatableBootJars(bootJars ...string) android.FixturePrepar
|
|||
variables.UpdatableBootJars = android.CreateTestConfiguredJarList(bootJars)
|
||||
}),
|
||||
dexpreopt.FixtureSetUpdatableBootJars(bootJars...),
|
||||
|
||||
// Add a fake dex2oatd module.
|
||||
dexpreopt.PrepareForTestWithFakeDex2oatd,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,20 +18,146 @@ import (
|
|||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func TestSnapshotWithBootclasspathFragment(t *testing.T) {
|
||||
func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForSdkTestWithJava,
|
||||
prepareForSdkTestWithApex,
|
||||
|
||||
// Some additional files needed for the art apex.
|
||||
android.FixtureMergeMockFs(android.MockFS{
|
||||
"com.android.art.avbpubkey": nil,
|
||||
"com.android.art.pem": nil,
|
||||
"system/sepolicy/apex/com.android.art-file_contexts": nil,
|
||||
}),
|
||||
java.FixtureConfigureBootJars("com.android.art:mybootlib"),
|
||||
android.FixtureWithRootAndroidBp(`
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
bootclasspath_fragments: ["mybootclasspathfragment"],
|
||||
java_boot_libs: ["mybootlib"],
|
||||
}
|
||||
|
||||
apex {
|
||||
name: "com.android.art",
|
||||
key: "com.android.art.key",
|
||||
bootclasspath_fragments: [
|
||||
"mybootclasspathfragment",
|
||||
],
|
||||
updatable: false,
|
||||
}
|
||||
|
||||
bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
image_name: "art",
|
||||
apex_available: ["com.android.art"],
|
||||
}
|
||||
|
||||
apex_key {
|
||||
name: "com.android.art.key",
|
||||
public_key: "com.android.art.avbpubkey",
|
||||
private_key: "com.android.art.pem",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "mybootlib",
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
compile_dex: true,
|
||||
apex_available: ["com.android.art"],
|
||||
}
|
||||
`),
|
||||
).RunTest(t)
|
||||
|
||||
CheckSnapshot(t, result, "mysdk", "",
|
||||
checkUnversionedAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
prebuilt_bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["com.android.art"],
|
||||
image_name: "art",
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mybootlib",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["com.android.art"],
|
||||
jars: ["java/mybootlib.jar"],
|
||||
}
|
||||
`),
|
||||
checkVersionedAndroidBpContents(`
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
prebuilt_bootclasspath_fragment {
|
||||
name: "mysdk_mybootclasspathfragment@current",
|
||||
sdk_member_name: "mybootclasspathfragment",
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["com.android.art"],
|
||||
image_name: "art",
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mysdk_mybootlib@current",
|
||||
sdk_member_name: "mybootlib",
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["com.android.art"],
|
||||
jars: ["java/mybootlib.jar"],
|
||||
}
|
||||
|
||||
sdk_snapshot {
|
||||
name: "mysdk@current",
|
||||
visibility: ["//visibility:public"],
|
||||
bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
|
||||
java_boot_libs: ["mysdk_mybootlib@current"],
|
||||
}
|
||||
`),
|
||||
checkAllCopyRules(`
|
||||
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
|
||||
`),
|
||||
snapshotTestPreparer(checkSnapshotPreferredWithSource, android.GroupFixturePreparers(
|
||||
android.FixtureAddTextFile("prebuilts/apex/Android.bp", `
|
||||
prebuilt_apex {
|
||||
name: "com.android.art",
|
||||
src: "art.apex",
|
||||
exported_java_libs: [
|
||||
"mybootlib",
|
||||
],
|
||||
}
|
||||
`),
|
||||
android.FixtureAddFile("prebuilts/apex/art.apex", nil),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForSdkTestWithJava,
|
||||
android.FixtureWithRootAndroidBp(`
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
bootclasspath_fragments: ["mybootclasspathfragment"],
|
||||
java_boot_libs: ["mybootlib"],
|
||||
}
|
||||
|
||||
bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
image_name: "art",
|
||||
contents: ["mybootlib"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "mybootlib",
|
||||
srcs: ["Test.java"],
|
||||
system_modules: "none",
|
||||
sdk_version: "none",
|
||||
compile_dex: true,
|
||||
}
|
||||
`),
|
||||
).RunTest(t)
|
||||
|
@ -45,7 +171,15 @@ prebuilt_bootclasspath_fragment {
|
|||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["//apex_available:platform"],
|
||||
image_name: "art",
|
||||
contents: ["mybootlib"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mybootlib",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["//apex_available:platform"],
|
||||
jars: ["java/mybootlib.jar"],
|
||||
}
|
||||
`),
|
||||
checkVersionedAndroidBpContents(`
|
||||
|
@ -56,16 +190,27 @@ prebuilt_bootclasspath_fragment {
|
|||
sdk_member_name: "mybootclasspathfragment",
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["//apex_available:platform"],
|
||||
image_name: "art",
|
||||
contents: ["mysdk_mybootlib@current"],
|
||||
}
|
||||
|
||||
java_import {
|
||||
name: "mysdk_mybootlib@current",
|
||||
sdk_member_name: "mybootlib",
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["//apex_available:platform"],
|
||||
jars: ["java/mybootlib.jar"],
|
||||
}
|
||||
|
||||
sdk_snapshot {
|
||||
name: "mysdk@current",
|
||||
visibility: ["//visibility:public"],
|
||||
bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
|
||||
java_boot_libs: ["mysdk_mybootlib@current"],
|
||||
}
|
||||
`),
|
||||
checkAllCopyRules(""))
|
||||
checkAllCopyRules(`
|
||||
.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
|
||||
`))
|
||||
}
|
||||
|
||||
// Test that bootclasspath_fragment works with sdk.
|
||||
|
|
|
@ -255,13 +255,14 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st
|
|||
|
||||
var runSnapshotTestWithCheckers = func(t *testing.T, testConfig snapshotTest, extraPreparer android.FixturePreparer) {
|
||||
customization := snapshotBuildInfo.snapshotTestCustomization(testConfig)
|
||||
customizedPreparers := android.GroupFixturePreparers(customization.preparers...)
|
||||
|
||||
// TODO(b/183184375): Set Config.TestAllowNonExistentPaths = false to verify that all the
|
||||
// files the snapshot needs are actually copied into the snapshot.
|
||||
|
||||
// Run the snapshot with the snapshot preparer and the extra preparer, which must come after as
|
||||
// it may need to modify parts of the MockFS populated by the snapshot preparer.
|
||||
result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer).
|
||||
result := android.GroupFixturePreparers(snapshotPreparer, extraPreparer, customizedPreparers).
|
||||
ExtendWithErrorHandler(customization.errorHandler).
|
||||
RunTest(t)
|
||||
|
||||
|
@ -369,6 +370,15 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
|
|||
|
||||
type resultChecker func(t *testing.T, result *android.TestResult)
|
||||
|
||||
// snapshotTestPreparer registers a preparer that will be used to customize the specified
|
||||
// snapshotTest.
|
||||
func snapshotTestPreparer(snapshotTest snapshotTest, preparer android.FixturePreparer) snapshotBuildInfoChecker {
|
||||
return func(info *snapshotBuildInfo) {
|
||||
customization := info.snapshotTestCustomization(snapshotTest)
|
||||
customization.preparers = append(customization.preparers, preparer)
|
||||
}
|
||||
}
|
||||
|
||||
// snapshotTestChecker registers a checker that will be run against the result of processing the
|
||||
// generated snapshot for the specified snapshotTest.
|
||||
func snapshotTestChecker(snapshotTest snapshotTest, checker resultChecker) snapshotBuildInfoChecker {
|
||||
|
@ -395,6 +405,9 @@ func snapshotTestErrorHandler(snapshotTest snapshotTest, handler android.Fixture
|
|||
|
||||
// Encapsulates information provided by each test to customize a specific snapshotTest.
|
||||
type snapshotTestCustomization struct {
|
||||
// Preparers that are used to customize the test fixture before running the test.
|
||||
preparers []android.FixturePreparer
|
||||
|
||||
// Checkers that are run on the result of processing the preferred snapshot in a specific test
|
||||
// case.
|
||||
checkers []resultChecker
|
||||
|
|
Loading…
Reference in a new issue