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

Commit 5b0bba9f authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge changes I948c7e51,If917cfbc,I7845b793,Ia815537e

* changes:
  Prevent bootImageVariant.licenseMetadataFile being set twice
  Test bootImageConfig/Variant fields
  Add Config,RunningInsideUnitTest
  Add CommonOs to Config.Targets
parents 55d3e2ba 20d90e3e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -127,6 +127,11 @@ func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation
	return []bootstrap.PrimaryBuilderInvocation{}
}

// RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test.
func (c Config) RunningInsideUnitTest() bool {
	return c.config.TestProductVariables != nil
}

// A DeviceConfig object represents the configuration for a particular device
// being built. For now there will only be one of these, but in the future there
// may be multiple devices being built.
+8 −3
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ func makeVarsSingletonFunc() Singleton {
}

type makeVarsSingleton struct {
	varsForTesting     []makeVarsVariable
	installsForTesting []byte
}

@@ -320,8 +321,12 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
		ctx.Errorf(err.Error())
	}

	// Only save state for tests when testing.
	if ctx.Config().RunningInsideUnitTest() {
		s.varsForTesting = vars
		s.installsForTesting = installsBytes
	}
}

func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
	buf := &bytes.Buffer{}
+3 −0
Original line number Diff line number Diff line
@@ -91,6 +91,9 @@ func modifyTestConfigToSupportArchMutator(testConfig Config) {
		},
	}

	// Make the CommonOS OsType available for all products.
	config.Targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}

	if runtime.GOOS == "darwin" {
		config.Targets[config.BuildOS] = config.Targets[config.BuildOS][:1]
	}
+40 −0
Original line number Diff line number Diff line
@@ -673,6 +673,46 @@ func (ctx *TestContext) InstallMakeRulesForTesting(t *testing.T) []InstallMakeRu
	return parseMkRules(t, ctx.config, nodes)
}

// MakeVarVariable provides access to make vars that will be written by the makeVarsSingleton
type MakeVarVariable interface {
	// Name is the name of the variable.
	Name() string

	// Value is the value of the variable.
	Value() string
}

func (v makeVarsVariable) Name() string {
	return v.name
}

func (v makeVarsVariable) Value() string {
	return v.value
}

// PrepareForTestAccessingMakeVars sets up the test so that MakeVarsForTesting will work.
var PrepareForTestAccessingMakeVars = GroupFixturePreparers(
	PrepareForTestWithAndroidMk,
	PrepareForTestWithMakevars,
)

// MakeVarsForTesting returns a filtered list of MakeVarVariable objects that represent the
// variables that will be written out.
//
// It is necessary to use PrepareForTestAccessingMakeVars in tests that want to call this function.
// Along with any other preparers needed to add the make vars.
func (ctx *TestContext) MakeVarsForTesting(filter func(variable MakeVarVariable) bool) []MakeVarVariable {
	vars := ctx.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).varsForTesting
	result := make([]MakeVarVariable, 0, len(vars))
	for _, v := range vars {
		if filter(v) {
			result = append(result, v)
		}
	}

	return result
}

func (ctx *TestContext) Config() Config {
	return ctx.config
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ bootstrap_go_package {
        "dexpreopt_bootjars.go",
        "dexpreopt_check.go",
        "dexpreopt_config.go",
        "dexpreopt_config_testing.go",
        "droiddoc.go",
        "droidstubs.go",
        "fuzz.go",
@@ -87,6 +88,7 @@ bootstrap_go_package {
        "dex_test.go",
        "dexpreopt_test.go",
        "dexpreopt_bootjars_test.go",
        "dexpreopt_config_test.go",
        "droiddoc_test.go",
        "droidstubs_test.go",
        "genrule_test.go",
Loading