Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8479ea29 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge "Allow createGlobalSoongConfig() to be used from tests"

parents c44075b7 9f045246
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -5957,7 +5957,6 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreopt

	ctx.Register()

	_ = dexpreopt.GlobalSoongConfigForTests(config)
	dexpreopt.RegisterToolModulesForTest(ctx)
	pathCtx := android.PathContextForTesting(config)
	dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
+11 −23
Original line number Diff line number Diff line
@@ -363,13 +363,6 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
// createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
// Should not be used in dexpreopt_gen.
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{
		Profman:          ctx.Config().HostToolPath(ctx, "profman"),
		Dex2oat:          dex2oatPathFromDep(ctx),
@@ -389,8 +382,7 @@ func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
// being at least one ordinary module with a Dex2oatDepTag dependency.
//
// TODO(b/147613152): Implement a way to deal with dependencies from singletons,
// and then possibly remove this cache altogether (but the use in
// GlobalSoongConfigForTests also needs to be rethought).
// and then possibly remove this cache altogether.
var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")

// 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 {
	// 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{} {
func globalSoongConfigForTests() *GlobalSoongConfig {
	return &GlobalSoongConfig{
		Profman:          android.PathForTesting("profman"),
		Dex2oat:          android.PathForTesting("dex2oat"),
@@ -563,5 +552,4 @@ func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig {
		ManifestCheck:    android.PathForTesting("manifest_check"),
		ConstructContext: android.PathForTesting("construct_context"),
	}
	}).(*GlobalSoongConfig)
}
+3 −3
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleCo
func TestDexPreopt(t *testing.T) {
	config := android.TestConfig("out", nil, "", nil)
	ctx := android.BuilderContextForTesting(config)
	globalSoong := GlobalSoongConfigForTests(config)
	globalSoong := globalSoongConfigForTests()
	global := GlobalConfigForTests(ctx)
	module := testSystemModuleConfig(ctx, "test")

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

+1 −7
Original line number Diff line number Diff line
@@ -61,13 +61,7 @@ func TestMain(m *testing.M) {
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
	bp += dexpreopt.BpToolModulesForTest()

	config := 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
	return TestConfig(buildDir, env, bp, fs)
}

func testContext(config android.Config) *android.TestContext {