Merge "Allow createGlobalSoongConfig() to be used from tests" am: 8479ea296d am: 64b8cd1b52

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8d8189912ea8fcb54950821119fe0583ceacca83
This commit is contained in:
Paul Duffin
2021-01-22 18:45:48 +00:00
committed by Automerger Merge Worker
4 changed files with 15 additions and 34 deletions

View File

@@ -5957,7 +5957,6 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreopt
ctx.Register() ctx.Register()
_ = dexpreopt.GlobalSoongConfigForTests(config)
dexpreopt.RegisterToolModulesForTest(ctx) dexpreopt.RegisterToolModulesForTest(ctx)
pathCtx := android.PathContextForTesting(config) pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)

View File

@@ -363,13 +363,6 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
// createGlobalSoongConfig creates a GlobalSoongConfig from the current context. // createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
// Should not be used in dexpreopt_gen. // Should not be used in dexpreopt_gen.
func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig { func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
if ctx.Config().TestProductVariables != nil {
// If we're called in a test there'll be a confusing error from the path
// functions below that gets reported without a stack trace, so let's panic
// properly with a more helpful message.
panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.")
}
return &GlobalSoongConfig{ return &GlobalSoongConfig{
Profman: ctx.Config().HostToolPath(ctx, "profman"), Profman: ctx.Config().HostToolPath(ctx, "profman"),
Dex2oat: dex2oatPathFromDep(ctx), Dex2oat: dex2oatPathFromDep(ctx),
@@ -389,8 +382,7 @@ func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
// being at least one ordinary module with a Dex2oatDepTag dependency. // being at least one ordinary module with a Dex2oatDepTag dependency.
// //
// TODO(b/147613152): Implement a way to deal with dependencies from singletons, // TODO(b/147613152): Implement a way to deal with dependencies from singletons,
// and then possibly remove this cache altogether (but the use in // and then possibly remove this cache altogether.
// GlobalSoongConfigForTests also needs to be rethought).
var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig") var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
@@ -550,10 +542,7 @@ func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig {
} }
} }
func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig { func globalSoongConfigForTests() *GlobalSoongConfig {
// Install the test GlobalSoongConfig in the Once cache so that later calls to
// Get(Cached)GlobalSoongConfig returns it without trying to create a real one.
return config.Once(globalSoongConfigOnceKey, func() interface{} {
return &GlobalSoongConfig{ return &GlobalSoongConfig{
Profman: android.PathForTesting("profman"), Profman: android.PathForTesting("profman"),
Dex2oat: android.PathForTesting("dex2oat"), Dex2oat: android.PathForTesting("dex2oat"),
@@ -563,5 +552,4 @@ func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig {
ManifestCheck: android.PathForTesting("manifest_check"), ManifestCheck: android.PathForTesting("manifest_check"),
ConstructContext: android.PathForTesting("construct_context"), ConstructContext: android.PathForTesting("construct_context"),
} }
}).(*GlobalSoongConfig)
} }

View File

@@ -61,7 +61,7 @@ func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleCo
func TestDexPreopt(t *testing.T) { func TestDexPreopt(t *testing.T) {
config := android.TestConfig("out", nil, "", nil) config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config) ctx := android.BuilderContextForTesting(config)
globalSoong := GlobalSoongConfigForTests(config) globalSoong := globalSoongConfigForTests()
global := GlobalConfigForTests(ctx) global := GlobalConfigForTests(ctx)
module := testSystemModuleConfig(ctx, "test") module := testSystemModuleConfig(ctx, "test")
@@ -83,7 +83,7 @@ func TestDexPreopt(t *testing.T) {
func TestDexPreoptSystemOther(t *testing.T) { func TestDexPreoptSystemOther(t *testing.T) {
config := android.TestConfig("out", nil, "", nil) config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config) ctx := android.BuilderContextForTesting(config)
globalSoong := GlobalSoongConfigForTests(config) globalSoong := globalSoongConfigForTests()
global := GlobalConfigForTests(ctx) global := GlobalConfigForTests(ctx)
systemModule := testSystemModuleConfig(ctx, "Stest") systemModule := testSystemModuleConfig(ctx, "Stest")
systemProductModule := testSystemProductModuleConfig(ctx, "SPtest") systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
@@ -143,7 +143,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
func TestDexPreoptProfile(t *testing.T) { func TestDexPreoptProfile(t *testing.T) {
config := android.TestConfig("out", nil, "", nil) config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config) ctx := android.BuilderContextForTesting(config)
globalSoong := GlobalSoongConfigForTests(config) globalSoong := globalSoongConfigForTests()
global := GlobalConfigForTests(ctx) global := GlobalConfigForTests(ctx)
module := testSystemModuleConfig(ctx, "test") module := testSystemModuleConfig(ctx, "test")

View File

@@ -61,13 +61,7 @@ func TestMain(m *testing.M) {
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
bp += dexpreopt.BpToolModulesForTest() bp += dexpreopt.BpToolModulesForTest()
config := TestConfig(buildDir, env, bp, fs) return TestConfig(buildDir, env, bp, fs)
// Set up the global Once cache used for dexpreopt.GlobalSoongConfig, so that
// it doesn't create a real one, which would fail.
_ = dexpreopt.GlobalSoongConfigForTests(config)
return config
} }
func testContext(config android.Config) *android.TestContext { func testContext(config android.Config) *android.TestContext {