Merge "Improve realism of boot jar tests" am: 21fb92d7f6 am: 590a50fe8f

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1674028

Change-Id: I7fc246996b751bb748b33877f8e758bf5a9a3516
This commit is contained in:
Paul Duffin
2021-04-13 19:46:44 +00:00
committed by Automerger Merge Worker
6 changed files with 121 additions and 105 deletions

View File

@@ -4375,9 +4375,7 @@ func TestPrebuiltOverrides(t *testing.T) {
// These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the
// propagation of paths to dex implementation jars from the former to the latter. // propagation of paths to dex implementation jars from the former to the latter.
func TestPrebuiltExportDexImplementationJars(t *testing.T) { func TestPrebuiltExportDexImplementationJars(t *testing.T) {
transform := func(config *dexpreopt.GlobalConfig) { transform := android.NullFixturePreparer
// Empty transformation.
}
checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) {
// Make sure the import has been given the correct path to the dex jar. // Make sure the import has been given the correct path to the dex jar.
@@ -4547,9 +4545,7 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
} }
func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
transform := func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("myapex:libfoo", "myapex:libbar")
config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo", "myapex:libbar"})
}
checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) {
t.Helper() t.Helper()
@@ -4605,7 +4601,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
} }
` `
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", preparer)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
@@ -4639,7 +4635,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
} }
` `
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", preparer)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
@@ -4698,7 +4694,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
// prebuilt_apex module always depends on the prebuilt, and so it doesn't // prebuilt_apex module always depends on the prebuilt, and so it doesn't
// find the dex boot jar in it. We either need to disable the source libfoo // find the dex boot jar in it. We either need to disable the source libfoo
// or make the prebuilt libfoo preferred. // or make the prebuilt libfoo preferred.
testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", transform) testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", preparer)
}) })
t.Run("prebuilt library preferred with source", func(t *testing.T) { t.Run("prebuilt library preferred with source", func(t *testing.T) {
@@ -4746,7 +4742,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
} }
` `
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", preparer)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
@@ -4813,7 +4809,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
} }
` `
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", preparer)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar")
@@ -4882,7 +4878,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
} }
` `
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", preparer)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
@@ -6440,7 +6436,7 @@ func TestAppSetBundlePrebuilt(t *testing.T) {
android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String()) android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String())
} }
func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer android.FixturePreparer) {
t.Helper() t.Helper()
bp := ` bp := `
@@ -6528,10 +6524,10 @@ func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpre
} }
` `
testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) testDexpreoptWithApexes(t, bp, errmsg, preparer)
} }
func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) *android.TestContext { func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.FixturePreparer) *android.TestContext {
t.Helper() t.Helper()
fs := android.MockFS{ fs := android.MockFS{
@@ -6557,17 +6553,7 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreopt
java.PrepareForTestWithJavaDefaultModules, java.PrepareForTestWithJavaDefaultModules,
java.PrepareForTestWithJavaSdkLibraryFiles, java.PrepareForTestWithJavaSdkLibraryFiles,
PrepareForTestWithApexBuildComponents, PrepareForTestWithApexBuildComponents,
android.FixtureModifyConfig(func(config android.Config) { preparer,
pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
transformDexpreoptConfig(dexpreoptConfig)
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
// Make sure that any changes to these dexpreopt properties are mirrored in the corresponding
// product variables.
config.TestProductVariables.BootJars = dexpreoptConfig.BootJars
config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars
}),
fs.AddToFixture(), fs.AddToFixture(),
). ).
ExtendWithErrorHandler(errorHandler). ExtendWithErrorHandler(errorHandler).
@@ -6608,92 +6594,95 @@ func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) {
} }
func TestNoUpdatableJarsInBootImage(t *testing.T) { func TestNoUpdatableJarsInBootImage(t *testing.T) {
var err string // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can
var transform func(*dexpreopt.GlobalConfig) // result in an invalid configuration as it does not set the ArtApexJars and allows art apex
// modules to be included in the BootJars.
prepareSetBootJars := func(bootJars ...string) android.FixturePreparer {
return android.GroupFixturePreparers(
dexpreopt.FixtureSetBootJars(bootJars...),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.BootJars = android.CreateTestConfiguredJarList(bootJars)
}),
)
}
// Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the
// same value. This can result in an invalid configuration as it allows non art apex jars to be
// specified in the ArtApexJars configuration.
prepareSetArtJars := func(bootJars ...string) android.FixturePreparer {
return android.GroupFixturePreparers(
dexpreopt.FixtureSetArtBootJars(bootJars...),
dexpreopt.FixtureSetBootJars(bootJars...),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.BootJars = android.CreateTestConfiguredJarList(bootJars)
}),
)
}
t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib")
config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) testNoUpdatableJarsInBootImage(t, "", preparer)
}
testNoUpdatableJarsInBootImage(t, "", transform)
}) })
t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) {
err = `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image`
transform = func(config *dexpreopt.GlobalConfig) { // Update the dexpreopt BootJars directly.
config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) preparer := prepareSetBootJars("com.android.art.debug:some-art-lib")
} testNoUpdatableJarsInBootImage(t, err, preparer)
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image`
transform = func(config *dexpreopt.GlobalConfig) { // Update the dexpreopt ArtApexJars directly.
config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib")
} testNoUpdatableJarsInBootImage(t, err, preparer)
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) {
err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` err := `module "some-non-updatable-apex-lib" is not allowed in the ART boot image`
transform = func(config *dexpreopt.GlobalConfig) { // Update the dexpreopt ArtApexJars directly.
config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib")
} testNoUpdatableJarsInBootImage(t, err, preparer)
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) {
err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image`
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib")
config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) testNoUpdatableJarsInBootImage(t, err, preparer)
}
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("some-non-updatable-apex:some-non-updatable-apex-lib")
config.BootJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) testNoUpdatableJarsInBootImage(t, "", preparer)
}
testNoUpdatableJarsInBootImage(t, "", transform)
}) })
t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) {
err = "failed to find a dex jar path for module 'nonexistent'" err := "failed to find a dex jar path for module 'nonexistent'"
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("platform:nonexistent")
config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) testNoUpdatableJarsInBootImage(t, err, preparer)
}
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) {
err = "failed to find a dex jar path for module 'nonexistent'" err := "failed to find a dex jar path for module 'nonexistent'"
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("platform:nonexistent")
config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) testNoUpdatableJarsInBootImage(t, err, preparer)
}
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("platform jar in the ART boot image => error", func(t *testing.T) { t.Run("platform jar in the ART boot image => error", func(t *testing.T) {
err = `module "some-platform-lib" is not allowed in the ART boot image` err := `module "some-platform-lib" is not allowed in the ART boot image`
transform = func(config *dexpreopt.GlobalConfig) { // Update the dexpreopt ArtApexJars directly.
config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) preparer := prepareSetArtJars("platform:some-platform-lib")
} testNoUpdatableJarsInBootImage(t, err, preparer)
testNoUpdatableJarsInBootImage(t, err, transform)
}) })
t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
transform = func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("platform:some-platform-lib")
config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) testNoUpdatableJarsInBootImage(t, "", preparer)
}
testNoUpdatableJarsInBootImage(t, "", transform)
}) })
} }
func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) {
transform := func(config *dexpreopt.GlobalConfig) { preparer := java.FixtureConfigureBootJars("myapex:libfoo")
config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"})
}
t.Run("prebuilt no source", func(t *testing.T) { t.Run("prebuilt no source", func(t *testing.T) {
testDexpreoptWithApexes(t, ` testDexpreoptWithApexes(t, `
prebuilt_apex { prebuilt_apex {
@@ -6713,7 +6702,7 @@ func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) {
name: "libfoo", name: "libfoo",
jars: ["libfoo.jar"], jars: ["libfoo.jar"],
} }
`, "", transform) `, "", preparer)
}) })
t.Run("prebuilt no source", func(t *testing.T) { t.Run("prebuilt no source", func(t *testing.T) {
@@ -6735,7 +6724,7 @@ func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) {
name: "libfoo", name: "libfoo",
jars: ["libfoo.jar"], jars: ["libfoo.jar"],
} }
`, "", transform) `, "", preparer)
}) })
} }

View File

@@ -19,7 +19,6 @@ import (
"testing" "testing"
"android/soong/android" "android/soong/android"
"android/soong/dexpreopt"
"android/soong/java" "android/soong/java"
) )
@@ -42,8 +41,7 @@ func TestBootImages(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
prepareForTestWithBootImage, prepareForTestWithBootImage,
// Configure some libraries in the art and framework boot images. // Configure some libraries in the art and framework boot images.
dexpreopt.FixtureSetArtBootJars("com.android.art:baz", "com.android.art:quuz"), java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
prepareForTestWithArtApex, prepareForTestWithArtApex,
java.PrepareForTestWithJavaSdkLibraryFiles, java.PrepareForTestWithJavaSdkLibraryFiles,
@@ -169,7 +167,7 @@ func TestBootImageInArtApex(t *testing.T) {
prepareForTestWithArtApex, prepareForTestWithArtApex,
// Configure some libraries in the art boot image. // Configure some libraries in the art boot image.
dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"), java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
apex { apex {
name: "com.android.art", name: "com.android.art",
@@ -264,7 +262,7 @@ func TestBootImageInPrebuiltArtApex(t *testing.T) {
}), }),
// Configure some libraries in the art boot image. // Configure some libraries in the art boot image.
dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"), java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
prebuilt_apex { prebuilt_apex {
name: "com.android.art", name: "com.android.art",

View File

@@ -18,7 +18,6 @@ import (
"testing" "testing"
"android/soong/android" "android/soong/android"
"android/soong/dexpreopt"
"android/soong/java" "android/soong/java"
"github.com/google/blueprint" "github.com/google/blueprint"
) )
@@ -37,9 +36,8 @@ func TestPlatformBootclasspathDependencies(t *testing.T) {
prepareForTestWithArtApex, prepareForTestWithArtApex,
prepareForTestWithMyapex, prepareForTestWithMyapex,
// Configure some libraries in the art and framework boot images. // Configure some libraries in the art and framework boot images.
dexpreopt.FixtureSetArtBootJars("com.android.art:baz", "com.android.art:quuz"), java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
dexpreopt.FixtureSetBootJars("platform:foo"), java.FixtureConfigureUpdatableBootJars("myapex:bar"),
dexpreopt.FixtureSetUpdatableBootJars("myapex:bar"),
java.PrepareForTestWithJavaSdkLibraryFiles, java.PrepareForTestWithJavaSdkLibraryFiles,
java.FixtureWithLastReleaseApis("foo"), java.FixtureWithLastReleaseApis("foo"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `

View File

@@ -23,12 +23,6 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
func fixtureSetBootJarsProductVariable(bootJars ...string) android.FixturePreparer {
return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.BootJars = android.CreateTestConfiguredJarList(bootJars)
})
}
func fixtureSetPrebuiltHiddenApiDirProductVariable(prebuiltHiddenApiDir *string) android.FixturePreparer { func fixtureSetPrebuiltHiddenApiDirProductVariable(prebuiltHiddenApiDir *string) android.FixturePreparer {
return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.PrebuiltHiddenApiDir = prebuiltHiddenApiDir variables.PrebuiltHiddenApiDir = prebuiltHiddenApiDir
@@ -41,7 +35,7 @@ var hiddenApiFixtureFactory = android.GroupFixturePreparers(
func TestHiddenAPISingleton(t *testing.T) { func TestHiddenAPISingleton(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_library { java_library {
name: "foo", name: "foo",
@@ -61,7 +55,7 @@ func TestHiddenAPIIndexSingleton(t *testing.T) {
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
PrepareForTestWithJavaSdkLibraryFiles, PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("bar"), FixtureWithLastReleaseApis("bar"),
fixtureSetBootJarsProductVariable("platform:foo", "platform:bar"), FixtureConfigureBootJars("platform:foo", "platform:bar"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_library { java_library {
name: "foo", name: "foo",
@@ -119,7 +113,7 @@ func TestHiddenAPISingletonWithSourceAndPrebuiltPreferredButNoDex(t *testing.T)
android.GroupFixturePreparers( android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorMessage)). ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorMessage)).
RunTestWithBp(t, ` RunTestWithBp(t, `
java_library { java_library {
@@ -139,7 +133,7 @@ func TestHiddenAPISingletonWithSourceAndPrebuiltPreferredButNoDex(t *testing.T)
func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { func TestHiddenAPISingletonWithPrebuilt(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_import { java_import {
name: "foo", name: "foo",
@@ -157,7 +151,7 @@ func TestHiddenAPISingletonWithPrebuilt(t *testing.T) {
func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_library { java_library {
name: "foo", name: "foo",
@@ -185,7 +179,7 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) {
func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_library { java_library {
name: "foo", name: "foo",
@@ -295,7 +289,7 @@ func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
hiddenApiFixtureFactory, hiddenApiFixtureFactory,
fixtureSetBootJarsProductVariable("platform:foo"), FixtureConfigureBootJars("platform:foo"),
fixtureSetPrebuiltHiddenApiDirProductVariable(&prebuiltHiddenApiDir), fixtureSetPrebuiltHiddenApiDirProductVariable(&prebuiltHiddenApiDir),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
java_import { java_import {

View File

@@ -31,7 +31,7 @@ var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
func TestPlatformBootclasspath(t *testing.T) { func TestPlatformBootclasspath(t *testing.T) {
preparer := android.GroupFixturePreparers( preparer := android.GroupFixturePreparers(
prepareForTestWithPlatformBootclasspath, prepareForTestWithPlatformBootclasspath,
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), FixtureConfigureBootJars("platform:foo", "platform:bar"),
android.FixtureWithRootAndroidBp(` android.FixtureWithRootAndroidBp(`
platform_bootclasspath { platform_bootclasspath {
name: "platform-bootclasspath", name: "platform-bootclasspath",
@@ -135,7 +135,7 @@ func TestPlatformBootclasspath(t *testing.T) {
func TestPlatformBootclasspath_Dist(t *testing.T) { func TestPlatformBootclasspath_Dist(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
prepareForTestWithPlatformBootclasspath, prepareForTestWithPlatformBootclasspath,
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"), FixtureConfigureBootJars("platform:foo", "platform:bar"),
android.PrepareForTestWithAndroidMk, android.PrepareForTestWithAndroidMk,
android.FixtureWithRootAndroidBp(` android.FixtureWithRootAndroidBp(`
platform_bootclasspath { platform_bootclasspath {

View File

@@ -178,6 +178,43 @@ func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][
return fs return fs
} }
// FixtureConfigureBootJars configures the boot jars in both the dexpreopt.GlobalConfig and
// Config.productVariables structs. As a side effect that enables dexpreopt.
func FixtureConfigureBootJars(bootJars ...string) android.FixturePreparer {
artBootJars := []string{}
for _, j := range bootJars {
artApex := false
for _, artApexName := range artApexNames {
if strings.HasPrefix(j, artApexName+":") {
artApex = true
break
}
}
if artApex {
artBootJars = append(artBootJars, j)
}
}
return android.GroupFixturePreparers(
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.BootJars = android.CreateTestConfiguredJarList(bootJars)
}),
dexpreopt.FixtureSetBootJars(bootJars...),
dexpreopt.FixtureSetArtBootJars(artBootJars...),
)
}
// FixtureConfigureUpdatableBootJars configures the updatable boot jars in both the
// dexpreopt.GlobalConfig and Config.productVariables structs. As a side effect that enables
// dexpreopt.
func FixtureConfigureUpdatableBootJars(bootJars ...string) android.FixturePreparer {
return android.GroupFixturePreparers(
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.UpdatableBootJars = android.CreateTestConfiguredJarList(bootJars)
}),
dexpreopt.FixtureSetUpdatableBootJars(bootJars...),
)
}
// registerRequiredBuildComponentsForTest registers the build components used by // registerRequiredBuildComponentsForTest registers the build components used by
// PrepareForTestWithJavaDefaultModules. // PrepareForTestWithJavaDefaultModules.
// //