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

Commit f8231dd0 authored by Cole Faust's avatar Cole Faust
Browse files

Platform mapping-based product config

This allows us to set product variables as build settings instead
of loading them from a target's provider, which further allows us
to read product config variables in transitions.

Bug: 287539062
Bug: 269577299
Test: Presubmits
Change-Id: I8497703f706162572ceb3486240e1eb02a37f5f6
parent adb892c5
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -202,10 +202,10 @@ type VendorConfig soongconfig.SoongConfig
// product configuration values are read from Kati-generated soong.variables.
type config struct {
	// Options configurable with soong.variables
	productVariables productVariables
	productVariables ProductVariables

	// Only available on configs created by TestConfig
	TestProductVariables *productVariables
	TestProductVariables *ProductVariables

	// A specialized context object for Bazel/Soong mixed builds and migration
	// purposes.
@@ -321,7 +321,7 @@ func loadConfig(config *config) error {

// loadFromConfigFile loads and decodes configuration options from a JSON file
// in the current working directory.
func loadFromConfigFile(configurable *productVariables, filename string) error {
func loadFromConfigFile(configurable *ProductVariables, filename string) error {
	// Try to open the file
	configFileReader, err := os.Open(filename)
	defer configFileReader.Close()
@@ -373,7 +373,7 @@ func loadFromConfigFile(configurable *productVariables, filename string) error {

// atomically writes the config file in case two copies of soong_build are running simultaneously
// (for example, docs generation and ninja manifest generation)
func saveToConfigFile(config *productVariables, filename string) error {
func saveToConfigFile(config *ProductVariables, filename string) error {
	data, err := json.MarshalIndent(&config, "", "    ")
	if err != nil {
		return fmt.Errorf("cannot marshal config data: %s", err.Error())
@@ -402,7 +402,7 @@ func saveToConfigFile(config *productVariables, filename string) error {
	return nil
}

func saveToBazelConfigFile(config *productVariables, outDir string) error {
func saveToBazelConfigFile(config *ProductVariables, outDir string) error {
	dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
	err := createDirIfNonexistent(dir, os.ModePerm)
	if err != nil {
+5 −5
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ Did you mean to use an annotation of ",omitempty"?

// run validateConfigAnnotations against each type that might have json annotations
func TestProductConfigAnnotations(t *testing.T) {
	err := validateConfigAnnotations(&productVariables{})
	err := validateConfigAnnotations(&ProductVariables{})
	if err != nil {
		t.Errorf(err.Error())
	}
@@ -88,7 +88,7 @@ func TestMissingVendorConfig(t *testing.T) {
	}
}

func verifyProductVariableMarshaling(t *testing.T, v productVariables) {
func verifyProductVariableMarshaling(t *testing.T, v ProductVariables) {
	dir := t.TempDir()
	path := filepath.Join(dir, "test.variables")
	err := saveToConfigFile(&v, path)
@@ -96,20 +96,20 @@ func verifyProductVariableMarshaling(t *testing.T, v productVariables) {
		t.Errorf("Couldn't save default product config: %q", err)
	}

	var v2 productVariables
	var v2 ProductVariables
	err = loadFromConfigFile(&v2, path)
	if err != nil {
		t.Errorf("Couldn't load default product config: %q", err)
	}
}
func TestDefaultProductVariableMarshaling(t *testing.T) {
	v := productVariables{}
	v := ProductVariables{}
	v.SetDefaultConfig()
	verifyProductVariableMarshaling(t, v)
}

func TestBootJarsMarshaling(t *testing.T) {
	v := productVariables{}
	v := ProductVariables{}
	v.SetDefaultConfig()
	v.BootJars = ConfiguredJarList{
		apexes: []string{"apex"},
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import (
func TestOverrideConfiguredJarLocationFor(t *testing.T) {
	cfg := NullConfig("", "")

	cfg.productVariables = productVariables{
	cfg.productVariables = ProductVariables{
		ConfiguredJarLocationOverrides: []string{
			"platform:libfoo-old:com.android.foo:libfoo-new",
			"com.android.bar:libbar-old:platform:libbar-new",
+1 −1
Original line number Diff line number Diff line
@@ -369,7 +369,7 @@ func FixtureModifyEnv(mutator func(env map[string]string)) FixturePreparer {

// Allow access to the product variables when preparing the fixture.
type FixtureProductVariables struct {
	*productVariables
	*ProductVariables
}

// Modify product variables.
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ func TestSdkSpecFrom(t *testing.T) {

	config := NullConfig("", "")

	config.productVariables = productVariables{
	config.productVariables = ProductVariables{
		Platform_sdk_version:              intPtr(31),
		Platform_sdk_codename:             stringPtr("Tiramisu"),
		Platform_version_active_codenames: []string{"Tiramisu"},
Loading