2019-11-23 01:03:51 +01:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package android
|
|
|
|
|
|
|
|
// This file provides module types that implement wrapper module types that add conditionals on
|
|
|
|
// Soong config variables.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2023-01-09 16:42:57 +01:00
|
|
|
"reflect"
|
2019-11-23 01:03:51 +01:00
|
|
|
"strings"
|
2023-01-09 16:42:57 +01:00
|
|
|
"sync"
|
2019-11-23 01:03:51 +01:00
|
|
|
"text/scanner"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/parser"
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android/soongconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-01-09 15:02:06 +01:00
|
|
|
RegisterSoongConfigModuleBuildComponents(InitRegistrationContext)
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
|
|
|
|
2023-01-09 15:02:06 +01:00
|
|
|
func RegisterSoongConfigModuleBuildComponents(ctx RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("soong_config_module_type_import", SoongConfigModuleTypeImportFactory)
|
|
|
|
ctx.RegisterModuleType("soong_config_module_type", SoongConfigModuleTypeFactory)
|
|
|
|
ctx.RegisterModuleType("soong_config_string_variable", SoongConfigStringVariableDummyFactory)
|
|
|
|
ctx.RegisterModuleType("soong_config_bool_variable", SoongConfigBoolVariableDummyFactory)
|
2024-01-12 23:02:47 +01:00
|
|
|
ctx.RegisterModuleType("soong_config_value_variable", SoongConfigValueVariableDummyFactory)
|
2023-01-09 15:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var PrepareForTestWithSoongConfigModuleBuildComponents = FixtureRegisterWithContext(RegisterSoongConfigModuleBuildComponents)
|
|
|
|
|
2019-11-23 01:03:51 +01:00
|
|
|
type soongConfigModuleTypeImport struct {
|
|
|
|
ModuleBase
|
|
|
|
properties soongConfigModuleTypeImportProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
type soongConfigModuleTypeImportProperties struct {
|
|
|
|
From string
|
|
|
|
Module_types []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// soong_config_module_type_import imports module types with conditionals on Soong config
|
|
|
|
// variables from another Android.bp file. The imported module type will exist for all
|
|
|
|
// modules after the import in the Android.bp file.
|
|
|
|
//
|
2020-12-16 21:42:02 +01:00
|
|
|
// Each soong_config_variable supports an additional value `conditions_default`. The properties
|
|
|
|
// specified in `conditions_default` will only be used under the following conditions:
|
|
|
|
// bool variable: the variable is unspecified or not set to a true value
|
|
|
|
// value variable: the variable is unspecified
|
|
|
|
// string variable: the variable is unspecified or the variable is set to a string unused in the
|
|
|
|
// given module. For example, string variable `test` takes values: "a" and "b",
|
|
|
|
// if the module contains a property `a` and `conditions_default`, when test=b,
|
|
|
|
// the properties under `conditions_default` will be used. To specify that no
|
|
|
|
// properties should be amended for `b`, you can set `b: {},`.
|
|
|
|
//
|
2019-11-23 01:03:51 +01:00
|
|
|
// For example, an Android.bp file could have:
|
|
|
|
//
|
|
|
|
// soong_config_module_type_import {
|
2020-02-04 22:17:24 +01:00
|
|
|
// from: "device/acme/Android.bp",
|
2019-11-23 01:03:51 +01:00
|
|
|
// module_types: ["acme_cc_defaults"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// acme_cc_defaults {
|
|
|
|
// name: "acme_defaults",
|
|
|
|
// cflags: ["-DGENERIC"],
|
|
|
|
// soong_config_variables: {
|
|
|
|
// board: {
|
|
|
|
// soc_a: {
|
|
|
|
// cflags: ["-DSOC_A"],
|
|
|
|
// },
|
|
|
|
// soc_b: {
|
|
|
|
// cflags: ["-DSOC_B"],
|
|
|
|
// },
|
2020-12-16 21:42:02 +01:00
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DSOC_DEFAULT"],
|
|
|
|
// },
|
2019-11-23 01:03:51 +01:00
|
|
|
// },
|
|
|
|
// feature: {
|
|
|
|
// cflags: ["-DFEATURE"],
|
2020-12-16 21:42:02 +01:00
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DFEATURE_DEFAULT"],
|
|
|
|
// },
|
2019-11-23 01:03:51 +01:00
|
|
|
// },
|
soong config: add value_variable substitution
There are some cases that aren't handled with the existing variable
types for booleans or known lists of strings. Similarly to our
product_variables that uses %s / %d for things like
PLATFORM_SDK_VERSION, allow vendors to define their own config variables
to be substituted into properties.
For example, some of the makefiles that I've attempted to convert had
the option to pass in version numbers from the board, or the default
display size:
-DDISPLAY_VERSION=550
-DDISP_H=1080
These examples happen to be integers, but since our configuration
language (make) doesn't support numbers, %s works just as well.
This change will allow the above to be represented using:
soong_config_module_type {
name: "acme_cc_defaults",
module_type: "cc_defaults",
config_namespace: "acme",
value_variables: [
"DISPLAY_VERSION",
"DISP_H",
],
properties: ["cflags"],
}
acme_cc_defaults {
name: "my_defaults",
soong_config_variables: {
DISPLAY_VERSION: {
cflags: ["-DDISPLAY_VERSION=%s"],
},
DISP_H: {
cflags: ["-DDISP_H=%s"],
}
},
}
Test: built-in tests
Change-Id: I18f35746b5cc39c304a136980249e886d38c6df6
2020-03-24 03:42:18 +01:00
|
|
|
// width: {
|
|
|
|
// cflags: ["-DWIDTH=%s"],
|
2020-12-16 21:42:02 +01:00
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DWIDTH=DEFAULT"],
|
|
|
|
// },
|
soong config: add value_variable substitution
There are some cases that aren't handled with the existing variable
types for booleans or known lists of strings. Similarly to our
product_variables that uses %s / %d for things like
PLATFORM_SDK_VERSION, allow vendors to define their own config variables
to be substituted into properties.
For example, some of the makefiles that I've attempted to convert had
the option to pass in version numbers from the board, or the default
display size:
-DDISPLAY_VERSION=550
-DDISP_H=1080
These examples happen to be integers, but since our configuration
language (make) doesn't support numbers, %s works just as well.
This change will allow the above to be represented using:
soong_config_module_type {
name: "acme_cc_defaults",
module_type: "cc_defaults",
config_namespace: "acme",
value_variables: [
"DISPLAY_VERSION",
"DISP_H",
],
properties: ["cflags"],
}
acme_cc_defaults {
name: "my_defaults",
soong_config_variables: {
DISPLAY_VERSION: {
cflags: ["-DDISPLAY_VERSION=%s"],
},
DISP_H: {
cflags: ["-DDISP_H=%s"],
}
},
}
Test: built-in tests
Change-Id: I18f35746b5cc39c304a136980249e886d38c6df6
2020-03-24 03:42:18 +01:00
|
|
|
// },
|
2019-11-23 01:03:51 +01:00
|
|
|
// },
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// cc_library {
|
|
|
|
// name: "libacme_foo",
|
|
|
|
// defaults: ["acme_defaults"],
|
|
|
|
// srcs: ["*.cpp"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// And device/acme/Android.bp could have:
|
|
|
|
//
|
|
|
|
// soong_config_module_type {
|
|
|
|
// name: "acme_cc_defaults",
|
|
|
|
// module_type: "cc_defaults",
|
|
|
|
// config_namespace: "acme",
|
2020-03-24 03:39:34 +01:00
|
|
|
// variables: ["board"],
|
|
|
|
// bool_variables: ["feature"],
|
soong config: add value_variable substitution
There are some cases that aren't handled with the existing variable
types for booleans or known lists of strings. Similarly to our
product_variables that uses %s / %d for things like
PLATFORM_SDK_VERSION, allow vendors to define their own config variables
to be substituted into properties.
For example, some of the makefiles that I've attempted to convert had
the option to pass in version numbers from the board, or the default
display size:
-DDISPLAY_VERSION=550
-DDISP_H=1080
These examples happen to be integers, but since our configuration
language (make) doesn't support numbers, %s works just as well.
This change will allow the above to be represented using:
soong_config_module_type {
name: "acme_cc_defaults",
module_type: "cc_defaults",
config_namespace: "acme",
value_variables: [
"DISPLAY_VERSION",
"DISP_H",
],
properties: ["cflags"],
}
acme_cc_defaults {
name: "my_defaults",
soong_config_variables: {
DISPLAY_VERSION: {
cflags: ["-DDISPLAY_VERSION=%s"],
},
DISP_H: {
cflags: ["-DDISP_H=%s"],
}
},
}
Test: built-in tests
Change-Id: I18f35746b5cc39c304a136980249e886d38c6df6
2020-03-24 03:42:18 +01:00
|
|
|
// value_variables: ["width"],
|
2019-11-23 01:03:51 +01:00
|
|
|
// properties: ["cflags", "srcs"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// soong_config_string_variable {
|
|
|
|
// name: "board",
|
2020-12-16 21:42:02 +01:00
|
|
|
// values: ["soc_a", "soc_b", "soc_c"],
|
2019-11-23 01:03:51 +01:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If an acme BoardConfig.mk file contained:
|
2021-08-24 23:05:19 +02:00
|
|
|
// $(call add_sonng_config_namespace, acme)
|
|
|
|
// $(call add_soong_config_var_value, acme, board, soc_a)
|
|
|
|
// $(call add_soong_config_var_value, acme, feature, true)
|
|
|
|
// $(call add_soong_config_var_value, acme, width, 200)
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
soong config: add value_variable substitution
There are some cases that aren't handled with the existing variable
types for booleans or known lists of strings. Similarly to our
product_variables that uses %s / %d for things like
PLATFORM_SDK_VERSION, allow vendors to define their own config variables
to be substituted into properties.
For example, some of the makefiles that I've attempted to convert had
the option to pass in version numbers from the board, or the default
display size:
-DDISPLAY_VERSION=550
-DDISP_H=1080
These examples happen to be integers, but since our configuration
language (make) doesn't support numbers, %s works just as well.
This change will allow the above to be represented using:
soong_config_module_type {
name: "acme_cc_defaults",
module_type: "cc_defaults",
config_namespace: "acme",
value_variables: [
"DISPLAY_VERSION",
"DISP_H",
],
properties: ["cflags"],
}
acme_cc_defaults {
name: "my_defaults",
soong_config_variables: {
DISPLAY_VERSION: {
cflags: ["-DDISPLAY_VERSION=%s"],
},
DISP_H: {
cflags: ["-DDISP_H=%s"],
}
},
}
Test: built-in tests
Change-Id: I18f35746b5cc39c304a136980249e886d38c6df6
2020-03-24 03:42:18 +01:00
|
|
|
// Then libacme_foo would build with cflags "-DGENERIC -DSOC_A -DFEATURE -DWIDTH=200".
|
2020-12-16 21:42:02 +01:00
|
|
|
//
|
|
|
|
// Alternatively, if acme BoardConfig.mk file contained:
|
|
|
|
//
|
|
|
|
// SOONG_CONFIG_NAMESPACES += acme
|
|
|
|
// SOONG_CONFIG_acme += \
|
|
|
|
// board \
|
|
|
|
// feature \
|
|
|
|
//
|
|
|
|
// SOONG_CONFIG_acme_feature := false
|
|
|
|
//
|
|
|
|
// Then libacme_foo would build with cflags:
|
|
|
|
// "-DGENERIC -DSOC_DEFAULT -DFEATURE_DEFAULT -DSIZE=DEFAULT".
|
|
|
|
//
|
|
|
|
// Similarly, if acme BoardConfig.mk file contained:
|
|
|
|
//
|
|
|
|
// SOONG_CONFIG_NAMESPACES += acme
|
|
|
|
// SOONG_CONFIG_acme += \
|
|
|
|
// board \
|
|
|
|
// feature \
|
|
|
|
//
|
|
|
|
// SOONG_CONFIG_acme_board := soc_c
|
|
|
|
//
|
|
|
|
// Then libacme_foo would build with cflags:
|
|
|
|
// "-DGENERIC -DSOC_DEFAULT -DFEATURE_DEFAULT -DSIZE=DEFAULT".
|
|
|
|
|
2021-11-02 17:43:57 +01:00
|
|
|
func SoongConfigModuleTypeImportFactory() Module {
|
2019-11-23 01:03:51 +01:00
|
|
|
module := &soongConfigModuleTypeImport{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
AddLoadHook(module, func(ctx LoadHookContext) {
|
|
|
|
importModuleTypes(ctx, module.properties.From, module.properties.Module_types...)
|
|
|
|
})
|
|
|
|
|
|
|
|
initAndroidModuleBase(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *soongConfigModuleTypeImport) Name() string {
|
2020-03-11 00:10:06 +01:00
|
|
|
// The generated name is non-deterministic, but it does not
|
|
|
|
// matter because this module does not emit any rules.
|
|
|
|
return soongconfig.CanonicalizeToProperty(m.properties.From) +
|
|
|
|
"soong_config_module_type_import_" + fmt.Sprintf("%p", m)
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
|
|
|
|
2022-06-23 01:44:07 +02:00
|
|
|
func (*soongConfigModuleTypeImport) Namespaceless() {}
|
2019-11-23 01:03:51 +01:00
|
|
|
func (*soongConfigModuleTypeImport) GenerateAndroidBuildActions(ModuleContext) {}
|
|
|
|
|
|
|
|
// Create dummy modules for soong_config_module_type and soong_config_*_variable
|
|
|
|
|
|
|
|
type soongConfigModuleTypeModule struct {
|
|
|
|
ModuleBase
|
|
|
|
properties soongconfig.ModuleTypeProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
// soong_config_module_type defines module types with conditionals on Soong config
|
2020-02-04 22:17:24 +01:00
|
|
|
// variables. The new module type will exist for all modules after the definition
|
|
|
|
// in an Android.bp file, and can be imported into other Android.bp files using
|
|
|
|
// soong_config_module_type_import.
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
2020-12-16 21:42:02 +01:00
|
|
|
// Each soong_config_variable supports an additional value `conditions_default`. The properties
|
|
|
|
// specified in `conditions_default` will only be used under the following conditions:
|
2022-08-16 19:27:33 +02:00
|
|
|
//
|
|
|
|
// bool variable: the variable is unspecified or not set to a true value
|
|
|
|
// value variable: the variable is unspecified
|
|
|
|
// string variable: the variable is unspecified or the variable is set to a string unused in the
|
|
|
|
// given module. For example, string variable `test` takes values: "a" and "b",
|
|
|
|
// if the module contains a property `a` and `conditions_default`, when test=b,
|
|
|
|
// the properties under `conditions_default` will be used. To specify that no
|
|
|
|
// properties should be amended for `b`, you can set `b: {},`.
|
2020-12-16 21:42:02 +01:00
|
|
|
//
|
2019-11-23 01:03:51 +01:00
|
|
|
// For example, an Android.bp file could have:
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// soong_config_module_type {
|
|
|
|
// name: "acme_cc_defaults",
|
|
|
|
// module_type: "cc_defaults",
|
|
|
|
// config_namespace: "acme",
|
|
|
|
// variables: ["board"],
|
|
|
|
// bool_variables: ["feature"],
|
|
|
|
// value_variables: ["width"],
|
|
|
|
// properties: ["cflags", "srcs"],
|
|
|
|
// }
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// soong_config_string_variable {
|
|
|
|
// name: "board",
|
|
|
|
// values: ["soc_a", "soc_b"],
|
|
|
|
// }
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// acme_cc_defaults {
|
|
|
|
// name: "acme_defaults",
|
|
|
|
// cflags: ["-DGENERIC"],
|
|
|
|
// soong_config_variables: {
|
|
|
|
// board: {
|
|
|
|
// soc_a: {
|
|
|
|
// cflags: ["-DSOC_A"],
|
|
|
|
// },
|
|
|
|
// soc_b: {
|
|
|
|
// cflags: ["-DSOC_B"],
|
|
|
|
// },
|
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DSOC_DEFAULT"],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// feature: {
|
|
|
|
// cflags: ["-DFEATURE"],
|
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DFEATURE_DEFAULT"],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// width: {
|
|
|
|
// cflags: ["-DWIDTH=%s"],
|
|
|
|
// conditions_default: {
|
|
|
|
// cflags: ["-DWIDTH=DEFAULT"],
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// }
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// cc_library {
|
|
|
|
// name: "libacme_foo",
|
|
|
|
// defaults: ["acme_defaults"],
|
|
|
|
// srcs: ["*.cpp"],
|
|
|
|
// }
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
|
|
|
// If an acme BoardConfig.mk file contained:
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// SOONG_CONFIG_NAMESPACES += acme
|
|
|
|
// SOONG_CONFIG_acme += \
|
|
|
|
// board \
|
|
|
|
// feature \
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// SOONG_CONFIG_acme_board := soc_a
|
|
|
|
// SOONG_CONFIG_acme_feature := true
|
|
|
|
// SOONG_CONFIG_acme_width := 200
|
2019-11-23 01:03:51 +01:00
|
|
|
//
|
|
|
|
// Then libacme_foo would build with cflags "-DGENERIC -DSOC_A -DFEATURE".
|
2021-11-02 17:43:57 +01:00
|
|
|
func SoongConfigModuleTypeFactory() Module {
|
2019-11-23 01:03:51 +01:00
|
|
|
module := &soongConfigModuleTypeModule{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
AddLoadHook(module, func(ctx LoadHookContext) {
|
|
|
|
// A soong_config_module_type module should implicitly import itself.
|
|
|
|
importModuleTypes(ctx, ctx.BlueprintsFile(), module.properties.Name)
|
|
|
|
})
|
|
|
|
|
|
|
|
initAndroidModuleBase(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *soongConfigModuleTypeModule) Name() string {
|
2022-06-23 01:44:07 +02:00
|
|
|
return m.properties.Name + fmt.Sprintf("%p", m)
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
2022-06-23 01:44:07 +02:00
|
|
|
func (*soongConfigModuleTypeModule) Namespaceless() {}
|
2019-11-23 01:03:51 +01:00
|
|
|
func (*soongConfigModuleTypeModule) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
|
|
|
|
|
|
|
type soongConfigStringVariableDummyModule struct {
|
|
|
|
ModuleBase
|
|
|
|
properties soongconfig.VariableProperties
|
|
|
|
stringProperties soongconfig.StringVariableProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
type soongConfigBoolVariableDummyModule struct {
|
|
|
|
ModuleBase
|
|
|
|
properties soongconfig.VariableProperties
|
|
|
|
}
|
|
|
|
|
2024-01-12 23:02:47 +01:00
|
|
|
type soongConfigValueVariableDummyModule struct {
|
|
|
|
ModuleBase
|
|
|
|
properties soongconfig.VariableProperties
|
|
|
|
}
|
|
|
|
|
2019-11-23 01:03:51 +01:00
|
|
|
// soong_config_string_variable defines a variable and a set of possible string values for use
|
|
|
|
// in a soong_config_module_type definition.
|
2021-11-02 17:43:57 +01:00
|
|
|
func SoongConfigStringVariableDummyFactory() Module {
|
2019-11-23 01:03:51 +01:00
|
|
|
module := &soongConfigStringVariableDummyModule{}
|
|
|
|
module.AddProperties(&module.properties, &module.stringProperties)
|
|
|
|
initAndroidModuleBase(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
// soong_config_string_variable defines a variable with true or false values for use
|
|
|
|
// in a soong_config_module_type definition.
|
2021-11-02 17:43:57 +01:00
|
|
|
func SoongConfigBoolVariableDummyFactory() Module {
|
2019-11-23 01:03:51 +01:00
|
|
|
module := &soongConfigBoolVariableDummyModule{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
initAndroidModuleBase(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2024-01-12 23:02:47 +01:00
|
|
|
// soong_config_value_variable defines a variable whose value can be expanded into
|
|
|
|
// the value of a string property.
|
|
|
|
func SoongConfigValueVariableDummyFactory() Module {
|
|
|
|
module := &soongConfigValueVariableDummyModule{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
initAndroidModuleBase(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-11-23 01:03:51 +01:00
|
|
|
func (m *soongConfigStringVariableDummyModule) Name() string {
|
2022-06-23 01:44:07 +02:00
|
|
|
return m.properties.Name + fmt.Sprintf("%p", m)
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
2022-06-23 01:44:07 +02:00
|
|
|
func (*soongConfigStringVariableDummyModule) Namespaceless() {}
|
2019-11-23 01:03:51 +01:00
|
|
|
func (*soongConfigStringVariableDummyModule) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
|
|
|
|
|
|
|
func (m *soongConfigBoolVariableDummyModule) Name() string {
|
2022-06-23 01:44:07 +02:00
|
|
|
return m.properties.Name + fmt.Sprintf("%p", m)
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
2022-06-23 01:44:07 +02:00
|
|
|
func (*soongConfigBoolVariableDummyModule) Namespaceless() {}
|
2019-11-23 01:03:51 +01:00
|
|
|
func (*soongConfigBoolVariableDummyModule) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
|
|
|
|
2024-01-12 23:02:47 +01:00
|
|
|
func (m *soongConfigValueVariableDummyModule) Name() string {
|
|
|
|
return m.properties.Name + fmt.Sprintf("%p", m)
|
|
|
|
}
|
|
|
|
func (*soongConfigValueVariableDummyModule) Namespaceless() {}
|
|
|
|
func (*soongConfigValueVariableDummyModule) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
|
|
|
|
2021-11-02 17:43:57 +01:00
|
|
|
// importModuleTypes registers the module factories for a list of module types defined
|
|
|
|
// in an Android.bp file. These module factories are scoped for the current Android.bp
|
|
|
|
// file only.
|
2019-11-23 01:03:51 +01:00
|
|
|
func importModuleTypes(ctx LoadHookContext, from string, moduleTypes ...string) {
|
|
|
|
from = filepath.Clean(from)
|
|
|
|
if filepath.Ext(from) != ".bp" {
|
|
|
|
ctx.PropertyErrorf("from", "%q must be a file with extension .bp", from)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(from, "../") {
|
|
|
|
ctx.PropertyErrorf("from", "%q must not use ../ to escape the source tree",
|
|
|
|
from)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
moduleTypeDefinitions := loadSoongConfigModuleTypeDefinition(ctx, from)
|
|
|
|
if moduleTypeDefinitions == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, moduleType := range moduleTypes {
|
|
|
|
if factory, ok := moduleTypeDefinitions[moduleType]; ok {
|
|
|
|
ctx.registerScopedModuleType(moduleType, factory)
|
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("module_types", "module type %q not defined in %q",
|
|
|
|
moduleType, from)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loadSoongConfigModuleTypeDefinition loads module types from an Android.bp file. It caches the
|
|
|
|
// result so each file is only parsed once.
|
|
|
|
func loadSoongConfigModuleTypeDefinition(ctx LoadHookContext, from string) map[string]blueprint.ModuleFactory {
|
|
|
|
type onceKeyType string
|
|
|
|
key := NewCustomOnceKey(onceKeyType(filepath.Clean(from)))
|
|
|
|
|
|
|
|
reportErrors := func(ctx LoadHookContext, filename string, errs ...error) {
|
|
|
|
for _, err := range errs {
|
|
|
|
if parseErr, ok := err.(*parser.ParseError); ok {
|
|
|
|
ctx.Errorf(parseErr.Pos, "%s", parseErr.Err)
|
|
|
|
} else {
|
|
|
|
ctx.Errorf(scanner.Position{Filename: filename}, "%s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.Config().Once(key, func() interface{} {
|
2020-02-06 01:26:19 +01:00
|
|
|
ctx.AddNinjaFileDeps(from)
|
2019-11-23 01:03:51 +01:00
|
|
|
r, err := ctx.Config().fs.Open(from)
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("from", "failed to open %q: %s", from, err)
|
|
|
|
return (map[string]blueprint.ModuleFactory)(nil)
|
|
|
|
}
|
2022-02-07 16:17:35 +01:00
|
|
|
defer r.Close()
|
2019-11-23 01:03:51 +01:00
|
|
|
|
|
|
|
mtDef, errs := soongconfig.Parse(r, from)
|
|
|
|
if len(errs) > 0 {
|
|
|
|
reportErrors(ctx, from, errs...)
|
|
|
|
return (map[string]blueprint.ModuleFactory)(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
globalModuleTypes := ctx.moduleFactories()
|
|
|
|
|
|
|
|
factories := make(map[string]blueprint.ModuleFactory)
|
|
|
|
|
|
|
|
for name, moduleType := range mtDef.ModuleTypes {
|
|
|
|
factory := globalModuleTypes[moduleType.BaseModuleType]
|
|
|
|
if factory != nil {
|
2023-12-07 22:10:56 +01:00
|
|
|
factories[name] = configModuleFactory(factory, moduleType)
|
2019-11-23 01:03:51 +01:00
|
|
|
} else {
|
|
|
|
reportErrors(ctx, from,
|
|
|
|
fmt.Errorf("missing global module type factory for %q", moduleType.BaseModuleType))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Failed() {
|
|
|
|
return (map[string]blueprint.ModuleFactory)(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
return factories
|
|
|
|
}).(map[string]blueprint.ModuleFactory)
|
|
|
|
}
|
|
|
|
|
2023-05-15 11:06:31 +02:00
|
|
|
// tracingConfig is a wrapper to soongconfig.SoongConfig which records all accesses to SoongConfig.
|
|
|
|
type tracingConfig struct {
|
|
|
|
config soongconfig.SoongConfig
|
|
|
|
boolSet map[string]bool
|
|
|
|
stringSet map[string]string
|
|
|
|
isSetSet map[string]bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *tracingConfig) Bool(name string) bool {
|
|
|
|
c.boolSet[name] = c.config.Bool(name)
|
|
|
|
return c.boolSet[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *tracingConfig) String(name string) string {
|
|
|
|
c.stringSet[name] = c.config.String(name)
|
|
|
|
return c.stringSet[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *tracingConfig) IsSet(name string) bool {
|
|
|
|
c.isSetSet[name] = c.config.IsSet(name)
|
|
|
|
return c.isSetSet[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *tracingConfig) getTrace() soongConfigTrace {
|
|
|
|
ret := soongConfigTrace{}
|
|
|
|
|
|
|
|
for k, v := range c.boolSet {
|
|
|
|
ret.Bools = append(ret.Bools, fmt.Sprintf("%q:%t", k, v))
|
|
|
|
}
|
|
|
|
for k, v := range c.stringSet {
|
|
|
|
ret.Strings = append(ret.Strings, fmt.Sprintf("%q:%q", k, v))
|
|
|
|
}
|
|
|
|
for k, v := range c.isSetSet {
|
|
|
|
ret.IsSets = append(ret.IsSets, fmt.Sprintf("%q:%t", k, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTracingConfig(config soongconfig.SoongConfig) *tracingConfig {
|
|
|
|
c := tracingConfig{
|
|
|
|
config: config,
|
|
|
|
boolSet: make(map[string]bool),
|
|
|
|
stringSet: make(map[string]string),
|
|
|
|
isSetSet: make(map[string]bool),
|
|
|
|
}
|
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ soongconfig.SoongConfig = (*tracingConfig)(nil)
|
|
|
|
|
2021-11-02 17:43:57 +01:00
|
|
|
// configModuleFactory takes an existing soongConfigModuleFactory and a
|
|
|
|
// ModuleType to create a new ModuleFactory that uses a custom loadhook.
|
2023-12-07 22:10:56 +01:00
|
|
|
func configModuleFactory(factory blueprint.ModuleFactory, moduleType *soongconfig.ModuleType) blueprint.ModuleFactory {
|
2023-01-09 16:42:57 +01:00
|
|
|
// Defer creation of conditional properties struct until the first call from the factory
|
|
|
|
// method. That avoids having to make a special call to the factory to create the properties
|
|
|
|
// structs from which the conditional properties struct is created. This is needed in order to
|
|
|
|
// allow singleton modules to be customized by soong_config_module_type as the
|
|
|
|
// SingletonModuleFactoryAdaptor factory registers a load hook for the singleton module
|
|
|
|
// everytime that it is called. Calling the factory twice causes a build failure as the load
|
|
|
|
// hook is called twice, the first time it updates the singleton module to indicate that it has
|
|
|
|
// been registered as a module, and the second time it fails because it thinks it has been
|
|
|
|
// registered again and a singleton module can only be registered once.
|
|
|
|
//
|
|
|
|
// This is an issue for singleton modules because:
|
|
|
|
// * Load hooks are registered on the module object and are only called when the module object
|
|
|
|
// is created by Blueprint while processing the Android.bp file.
|
|
|
|
// * The module factory for a singleton module returns the same module object each time it is
|
|
|
|
// called, and registers its load hook on that same module object.
|
|
|
|
// * When the module factory is called by Blueprint it then calls all the load hooks that have
|
|
|
|
// been registered for every call to that module factory.
|
|
|
|
//
|
|
|
|
// It is not an issue for normal modules because they return a new module object each time the
|
|
|
|
// factory is called and so any load hooks registered on module objects which are discarded will
|
|
|
|
// not be run.
|
|
|
|
once := &sync.Once{}
|
|
|
|
conditionalFactoryProps := reflect.Value{}
|
|
|
|
getConditionalFactoryProps := func(props []interface{}) reflect.Value {
|
|
|
|
once.Do(func() {
|
|
|
|
conditionalFactoryProps = soongconfig.CreateProperties(props, moduleType)
|
|
|
|
})
|
|
|
|
return conditionalFactoryProps
|
2021-11-02 17:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return func() (blueprint.Module, []interface{}) {
|
|
|
|
module, props := factory()
|
2023-01-09 16:42:57 +01:00
|
|
|
conditionalFactoryProps := getConditionalFactoryProps(props)
|
|
|
|
if !conditionalFactoryProps.IsValid() {
|
|
|
|
return module, props
|
|
|
|
}
|
|
|
|
|
2021-11-02 17:43:57 +01:00
|
|
|
conditionalProps := proptools.CloneEmptyProperties(conditionalFactoryProps)
|
|
|
|
props = append(props, conditionalProps.Interface())
|
|
|
|
|
2023-12-07 22:10:56 +01:00
|
|
|
// Regular Soong operation wraps the existing module factory with a
|
|
|
|
// conditional on Soong config variables by reading the product
|
|
|
|
// config variables from Make.
|
|
|
|
AddLoadHook(module, func(ctx LoadHookContext) {
|
|
|
|
tracingConfig := newTracingConfig(ctx.Config().VendorConfig(moduleType.ConfigNamespace))
|
|
|
|
newProps, err := soongconfig.PropertiesToApply(moduleType, conditionalProps, tracingConfig)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, ps := range newProps {
|
|
|
|
ctx.AppendProperties(ps)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.(Module).base().commonProperties.SoongConfigTrace = tracingConfig.getTrace()
|
|
|
|
})
|
2021-11-02 17:43:57 +01:00
|
|
|
return module, props
|
2019-11-23 01:03:51 +01:00
|
|
|
}
|
|
|
|
}
|