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

Commit e10dfa4e authored by Paul Duffin's avatar Paul Duffin
Browse files

Cleanup usages of CreateConfiguredJarList

After previous refactorings the CreateConfiguredJarList function is now
only used in tests and are supplied with a PathContext that will cause
ReportPathErrorf() to panic. So, this change removes the ctx parameter,
calls panic directly on any error and renames the method to make it
clear that it is for testing only.

Bug: 171479578
Test: m nothing
Change-Id: Icfb4bdfe720afa855b64ecf0e74a0b030882d029
parent 7ccacaed
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1497,10 +1497,10 @@ func splitConfiguredJarPair(str string) (string, string, error) {
	}
}

func CreateConfiguredJarList(ctx PathContext, list []string) ConfiguredJarList {
func CreateTestConfiguredJarList(list []string) ConfiguredJarList {
	apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
	if err != nil {
		ReportPathErrorf(ctx, "%s", err)
		panic(err)
	}

	return ConfiguredJarList{apexes, jars}
+11 −14
Original line number Diff line number Diff line
@@ -5791,12 +5791,9 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
	var err string
	var transform func(*dexpreopt.GlobalConfig)

	config := android.TestArchConfig(buildDir, nil, "", nil)
	ctx := android.PathContextForTesting(config)

	t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"})
			config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.something:some-art-lib"})
		}
		testNoUpdatableJarsInBootImage(t, "", transform)
	})
@@ -5804,7 +5801,7 @@ func TestNoUpdatableJarsInBootImage(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.something"\] is not allowed in the framework boot image`
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"})
			config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.something:some-art-lib"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})
@@ -5812,7 +5809,7 @@ func TestNoUpdatableJarsInBootImage(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`
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"})
			config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})
@@ -5820,7 +5817,7 @@ func TestNoUpdatableJarsInBootImage(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`
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
			config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})
@@ -5828,14 +5825,14 @@ func TestNoUpdatableJarsInBootImage(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`
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"})
			config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})

	t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = android.CreateConfiguredJarList(ctx, []string{"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, "", transform)
	})
@@ -5843,7 +5840,7 @@ func TestNoUpdatableJarsInBootImage(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'"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"})
			config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})
@@ -5851,7 +5848,7 @@ func TestNoUpdatableJarsInBootImage(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'"
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"})
			config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})
@@ -5859,14 +5856,14 @@ func TestNoUpdatableJarsInBootImage(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`
		transform = func(config *dexpreopt.GlobalConfig) {
			config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"})
			config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"})
		}
		testNoUpdatableJarsInBootImage(t, err, transform)
	})

	t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
		transform = func(config *dexpreopt.GlobalConfig) {
			config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"})
			config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"})
		}
		testNoUpdatableJarsInBootImage(t, "", transform)
	})
@@ -5905,7 +5902,7 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar
	for _, apexBootJar := range apexBootJars {
		updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
	}
	config.TestProductVariables.UpdatableBootJars = android.CreateConfiguredJarList(nil, updatableBootJars)
	config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars)

	ctx.Register(config)

+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu

	pathCtx := android.PathContextForTesting(config)
	dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
	dexpreoptConfig.BootJars = android.CreateConfiguredJarList(pathCtx, []string{"platform:foo", "platform:bar", "platform:baz"})
	dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList([]string{"platform:foo", "platform:bar", "platform:baz"})
	dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)

	ctx := testContext()
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import (

func testConfigWithBootJars(bp string, bootJars []string) android.Config {
	config := testConfig(nil, bp, nil)
	config.TestProductVariables.BootJars = android.CreateConfiguredJarList(nil, bootJars)
	config.TestProductVariables.BootJars = android.CreateTestConfiguredJarList(bootJars)
	return config
}