2022-11-09 03:14:01 +01:00
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
2023-04-22 02:37:11 +02:00
|
|
|
"encoding/json"
|
2022-11-09 03:14:01 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-07-25 00:17:03 +02:00
|
|
|
"reflect"
|
2022-11-09 03:14:01 +01:00
|
|
|
"strings"
|
2023-04-22 02:37:11 +02:00
|
|
|
|
2023-08-31 23:14:01 +02:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/android/soongconfig"
|
|
|
|
"android/soong/starlark_import"
|
|
|
|
|
2023-04-22 02:37:11 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
"go.starlark.net/starlark"
|
2022-11-09 03:14:01 +01:00
|
|
|
)
|
|
|
|
|
2023-09-12 19:07:07 +02:00
|
|
|
type createProductConfigFilesResult struct {
|
|
|
|
injectionFiles []BazelFile
|
|
|
|
bp2buildFiles []BazelFile
|
|
|
|
bp2buildTargets map[string]BazelTargets
|
|
|
|
}
|
|
|
|
|
|
|
|
func createProductConfigFiles(
|
2023-08-04 01:08:09 +02:00
|
|
|
ctx *CodegenContext,
|
2023-09-12 19:07:07 +02:00
|
|
|
metrics CodegenMetrics) (createProductConfigFilesResult, error) {
|
2022-11-09 03:14:01 +01:00
|
|
|
cfg := &ctx.config
|
|
|
|
targetProduct := "unknown"
|
|
|
|
if cfg.HasDeviceProduct() {
|
|
|
|
targetProduct = cfg.DeviceProduct()
|
|
|
|
}
|
|
|
|
targetBuildVariant := "user"
|
|
|
|
if cfg.Eng() {
|
|
|
|
targetBuildVariant = "eng"
|
|
|
|
} else if cfg.Debuggable() {
|
|
|
|
targetBuildVariant = "userdebug"
|
|
|
|
}
|
|
|
|
|
2023-09-12 19:07:07 +02:00
|
|
|
var res createProductConfigFilesResult
|
|
|
|
|
2022-11-09 03:14:01 +01:00
|
|
|
productVariablesFileName := cfg.ProductVariablesFileName
|
|
|
|
if !strings.HasPrefix(productVariablesFileName, "/") {
|
|
|
|
productVariablesFileName = filepath.Join(ctx.topDir, productVariablesFileName)
|
|
|
|
}
|
2023-04-22 02:37:11 +02:00
|
|
|
productVariablesBytes, err := os.ReadFile(productVariablesFileName)
|
|
|
|
if err != nil {
|
2023-09-12 19:07:07 +02:00
|
|
|
return res, err
|
2023-04-22 02:37:11 +02:00
|
|
|
}
|
|
|
|
productVariables := android.ProductVariables{}
|
|
|
|
err = json.Unmarshal(productVariablesBytes, &productVariables)
|
2022-11-09 03:14:01 +01:00
|
|
|
if err != nil {
|
2023-09-12 19:07:07 +02:00
|
|
|
return res, err
|
2022-11-09 03:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(b/249685973): the name is product_config_platforms because product_config
|
|
|
|
// was already used for other files. Deduplicate them.
|
|
|
|
currentProductFolder := fmt.Sprintf("product_config_platforms/products/%s-%s", targetProduct, targetBuildVariant)
|
|
|
|
|
|
|
|
productReplacer := strings.NewReplacer(
|
|
|
|
"{PRODUCT}", targetProduct,
|
|
|
|
"{VARIANT}", targetBuildVariant,
|
|
|
|
"{PRODUCT_FOLDER}", currentProductFolder)
|
|
|
|
|
2023-08-04 01:08:09 +02:00
|
|
|
productsForTestingMap, err := starlark_import.GetStarlarkValue[map[string]map[string]starlark.Value]("products_for_testing")
|
|
|
|
if err != nil {
|
2023-09-12 19:07:07 +02:00
|
|
|
return res, err
|
2023-08-04 01:08:09 +02:00
|
|
|
}
|
|
|
|
productsForTesting := android.SortedKeys(productsForTestingMap)
|
|
|
|
for i := range productsForTesting {
|
|
|
|
productsForTesting[i] = fmt.Sprintf(" \"@//build/bazel/tests/products:%s\",", productsForTesting[i])
|
|
|
|
}
|
|
|
|
|
2023-09-12 19:07:07 +02:00
|
|
|
productLabelsToVariables := make(map[string]*android.ProductVariables)
|
|
|
|
productLabelsToVariables[productReplacer.Replace("@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}")] = &productVariables
|
|
|
|
for product, productVariablesStarlark := range productsForTestingMap {
|
|
|
|
productVariables, err := starlarkMapToProductVariables(productVariablesStarlark)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
productLabelsToVariables["@//build/bazel/tests/products:"+product] = &productVariables
|
|
|
|
}
|
|
|
|
|
|
|
|
res.bp2buildTargets = createTargets(productLabelsToVariables)
|
|
|
|
|
|
|
|
platformMappingContent, err := platformMappingContent(
|
|
|
|
productLabelsToVariables,
|
|
|
|
ctx.Config().Bp2buildSoongConfigDefinitions,
|
|
|
|
metrics.convertedModulePathMap)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res.injectionFiles = []BazelFile{
|
2022-11-09 03:14:01 +01:00
|
|
|
newFile(
|
|
|
|
currentProductFolder,
|
|
|
|
"soong.variables.bzl",
|
2023-04-22 02:37:11 +02:00
|
|
|
`variables = json.decode("""`+strings.ReplaceAll(string(productVariablesBytes), "\\", "\\\\")+`""")`),
|
2022-11-09 03:14:01 +01:00
|
|
|
newFile(
|
|
|
|
currentProductFolder,
|
|
|
|
"BUILD",
|
|
|
|
productReplacer.Replace(`
|
|
|
|
package(default_visibility=[
|
|
|
|
"@soong_injection//product_config_platforms:__subpackages__",
|
|
|
|
"@//build/bazel/product_config:__subpackages__",
|
|
|
|
])
|
|
|
|
load(":soong.variables.bzl", _soong_variables = "variables")
|
2023-03-25 00:03:43 +01:00
|
|
|
load("@//build/bazel/product_config:android_product.bzl", "android_product")
|
2022-11-09 03:14:01 +01:00
|
|
|
|
|
|
|
android_product(
|
|
|
|
name = "{PRODUCT}-{VARIANT}",
|
|
|
|
soong_variables = _soong_variables,
|
|
|
|
)
|
|
|
|
`)),
|
|
|
|
newFile(
|
|
|
|
"product_config_platforms",
|
|
|
|
"BUILD.bazel",
|
|
|
|
productReplacer.Replace(`
|
|
|
|
package(default_visibility = [
|
|
|
|
"@//build/bazel/product_config:__subpackages__",
|
|
|
|
"@soong_injection//product_config_platforms:__subpackages__",
|
|
|
|
])
|
2023-05-30 11:45:23 +02:00
|
|
|
|
|
|
|
load("//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables")
|
|
|
|
load("@//build/bazel/product_config:android_product.bzl", "android_product")
|
|
|
|
|
2023-06-07 00:12:49 +02:00
|
|
|
# Bazel will qualify its outputs by the platform name. When switching between products, this
|
|
|
|
# means that soong-built files that depend on bazel-built files will suddenly get different
|
|
|
|
# dependency files, because the path changes, and they will be rebuilt. In order to avoid this
|
|
|
|
# extra rebuilding, make mixed builds always use a single platform so that the bazel artifacts
|
|
|
|
# are always under the same path.
|
2023-05-30 11:45:23 +02:00
|
|
|
android_product(
|
2023-06-07 00:12:49 +02:00
|
|
|
name = "mixed_builds_product-{VARIANT}",
|
2023-05-30 11:45:23 +02:00
|
|
|
soong_variables = _soong_variables,
|
2023-08-01 18:38:55 +02:00
|
|
|
extra_constraints = ["@//build/bazel/platforms:mixed_builds"],
|
2023-05-30 11:45:23 +02:00
|
|
|
)
|
2023-03-29 23:46:20 +02:00
|
|
|
`)),
|
|
|
|
newFile(
|
|
|
|
"product_config_platforms",
|
|
|
|
"product_labels.bzl",
|
|
|
|
productReplacer.Replace(`
|
|
|
|
# This file keeps a list of all the products in the android source tree, because they're
|
|
|
|
# discovered as part of a preprocessing step before bazel runs.
|
|
|
|
# TODO: When we start generating the platforms for more than just the
|
|
|
|
# currently lunched product, they should all be listed here
|
|
|
|
product_labels = [
|
2023-06-07 00:12:49 +02:00
|
|
|
"@soong_injection//product_config_platforms:mixed_builds_product-{VARIANT}",
|
2023-08-04 01:08:09 +02:00
|
|
|
"@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}",
|
|
|
|
`)+strings.Join(productsForTesting, "\n")+"\n]\n"),
|
2022-11-09 03:14:01 +01:00
|
|
|
newFile(
|
|
|
|
"product_config_platforms",
|
|
|
|
"common.bazelrc",
|
|
|
|
productReplacer.Replace(`
|
2023-04-22 02:37:11 +02:00
|
|
|
build --platform_mappings=platform_mappings
|
2023-06-07 00:12:49 +02:00
|
|
|
build --platforms @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
|
2022-11-09 03:14:01 +01:00
|
|
|
|
2023-06-07 00:12:49 +02:00
|
|
|
build:android --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}
|
2023-08-04 02:04:03 +02:00
|
|
|
build:linux_x86 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86
|
2023-06-07 00:12:49 +02:00
|
|
|
build:linux_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
|
|
|
|
build:linux_bionic_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_bionic_x86_64
|
|
|
|
build:linux_musl_x86 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_musl_x86
|
|
|
|
build:linux_musl_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_musl_x86_64
|
2022-11-09 03:14:01 +01:00
|
|
|
`)),
|
|
|
|
newFile(
|
|
|
|
"product_config_platforms",
|
|
|
|
"linux.bazelrc",
|
|
|
|
productReplacer.Replace(`
|
2023-06-07 00:12:49 +02:00
|
|
|
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
|
2022-11-09 03:14:01 +01:00
|
|
|
`)),
|
|
|
|
newFile(
|
|
|
|
"product_config_platforms",
|
|
|
|
"darwin.bazelrc",
|
|
|
|
productReplacer.Replace(`
|
2023-06-07 00:12:49 +02:00
|
|
|
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_darwin_x86_64
|
2022-11-09 03:14:01 +01:00
|
|
|
`)),
|
|
|
|
}
|
2023-09-12 19:07:07 +02:00
|
|
|
res.bp2buildFiles = []BazelFile{
|
2023-04-22 02:37:11 +02:00
|
|
|
newFile(
|
|
|
|
"",
|
|
|
|
"platform_mappings",
|
|
|
|
platformMappingContent),
|
|
|
|
}
|
2023-09-12 19:07:07 +02:00
|
|
|
|
|
|
|
return res, nil
|
2023-04-22 02:37:11 +02:00
|
|
|
}
|
|
|
|
|
2023-08-04 01:08:09 +02:00
|
|
|
func platformMappingContent(
|
2023-09-12 19:07:07 +02:00
|
|
|
productLabelToVariables map[string]*android.ProductVariables,
|
2023-08-04 01:08:09 +02:00
|
|
|
soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions,
|
|
|
|
convertedModulePathMap map[string]string) (string, error) {
|
2023-07-25 00:17:03 +02:00
|
|
|
var result strings.Builder
|
2023-08-04 01:08:09 +02:00
|
|
|
|
|
|
|
mergedConvertedModulePathMap := make(map[string]string)
|
|
|
|
for k, v := range convertedModulePathMap {
|
|
|
|
mergedConvertedModulePathMap[k] = v
|
|
|
|
}
|
|
|
|
additionalModuleNamesToPackages, err := starlark_import.GetStarlarkValue[map[string]string]("additional_module_names_to_packages")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
for k, v := range additionalModuleNamesToPackages {
|
|
|
|
mergedConvertedModulePathMap[k] = v
|
|
|
|
}
|
|
|
|
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString("platforms:\n")
|
2023-09-12 19:07:07 +02:00
|
|
|
for productLabel, productVariables := range productLabelToVariables {
|
|
|
|
platformMappingSingleProduct(productLabel, productVariables, soongConfigDefinitions, mergedConvertedModulePathMap, &result)
|
2023-04-22 02:37:11 +02:00
|
|
|
}
|
2023-07-25 00:17:03 +02:00
|
|
|
return result.String(), nil
|
2023-04-22 02:37:11 +02:00
|
|
|
}
|
|
|
|
|
2023-07-18 20:05:16 +02:00
|
|
|
var bazelPlatformSuffixes = []string{
|
|
|
|
"",
|
|
|
|
"_darwin_arm64",
|
|
|
|
"_darwin_x86_64",
|
|
|
|
"_linux_bionic_arm64",
|
|
|
|
"_linux_bionic_x86_64",
|
|
|
|
"_linux_musl_x86",
|
|
|
|
"_linux_musl_x86_64",
|
|
|
|
"_linux_x86",
|
|
|
|
"_linux_x86_64",
|
|
|
|
"_windows_x86",
|
|
|
|
"_windows_x86_64",
|
|
|
|
}
|
|
|
|
|
2023-08-04 01:08:09 +02:00
|
|
|
func platformMappingSingleProduct(
|
|
|
|
label string,
|
|
|
|
productVariables *android.ProductVariables,
|
|
|
|
soongConfigDefinitions soongconfig.Bp2BuildSoongConfigDefinitions,
|
|
|
|
convertedModulePathMap map[string]string,
|
|
|
|
result *strings.Builder) {
|
2023-07-25 00:17:03 +02:00
|
|
|
targetBuildVariant := "user"
|
|
|
|
if proptools.Bool(productVariables.Eng) {
|
|
|
|
targetBuildVariant = "eng"
|
|
|
|
} else if proptools.Bool(productVariables.Debuggable) {
|
|
|
|
targetBuildVariant = "userdebug"
|
|
|
|
}
|
|
|
|
|
2023-08-03 22:49:27 +02:00
|
|
|
platform_sdk_version := -1
|
|
|
|
if productVariables.Platform_sdk_version != nil {
|
|
|
|
platform_sdk_version = *productVariables.Platform_sdk_version
|
|
|
|
}
|
|
|
|
|
2023-08-04 01:08:09 +02:00
|
|
|
defaultAppCertificateFilegroup := "//build/bazel/utils:empty_filegroup"
|
|
|
|
if proptools.String(productVariables.DefaultAppCertificate) != "" {
|
2023-09-12 19:07:07 +02:00
|
|
|
defaultAppCertificateFilegroup = "@//" + filepath.Dir(proptools.String(productVariables.DefaultAppCertificate)) + ":generated_android_certificate_directory"
|
2023-08-04 01:08:09 +02:00
|
|
|
}
|
|
|
|
|
2023-07-18 20:05:16 +02:00
|
|
|
for _, suffix := range bazelPlatformSuffixes {
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(" ")
|
|
|
|
result.WriteString(label)
|
|
|
|
result.WriteString(suffix)
|
|
|
|
result.WriteString("\n")
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:always_use_prebuilt_sdks=%t\n", proptools.Bool(productVariables.Always_use_prebuilt_sdks)))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:arc=%t\n", proptools.Bool(productVariables.Arc)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:apex_global_min_sdk_version_override=%s\n", proptools.String(productVariables.ApexGlobalMinSdkVersionOverride)))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:binder32bit=%t\n", proptools.Bool(productVariables.Binder32bit)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_from_text_stub=%t\n", proptools.Bool(productVariables.Build_from_text_stub)))
|
2023-09-06 02:48:11 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_broken_incorrect_partition_images=%t\n", productVariables.BuildBrokenIncorrectPartitionImages))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_id=%s\n", proptools.String(productVariables.BuildId)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:build_version_tags=%s\n", strings.Join(productVariables.BuildVersionTags, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:compressed_apex=%t\n", proptools.Bool(productVariables.CompressedApex)))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:debuggable=%t\n", proptools.Bool(productVariables.Debuggable)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate=%s\n", proptools.String(productVariables.DefaultAppCertificate)))
|
2023-08-04 01:08:09 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:default_app_certificate_filegroup=%s\n", defaultAppCertificateFilegroup))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_max_page_size_supported=%s\n", proptools.String(productVariables.DeviceMaxPageSizeSupported)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_name=%s\n", proptools.String(productVariables.DeviceName)))
|
2023-08-09 17:34:37 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_page_size_agnostic=%t\n", proptools.Bool(productVariables.DevicePageSizeAgnostic)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_product=%s\n", proptools.String(productVariables.DeviceProduct)))
|
2023-09-06 01:07:49 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:device_platform=%s\n", label))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true)))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:enforce_vintf_manifest=%t\n", proptools.Bool(productVariables.Enforce_vintf_manifest)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:eng=%t\n", proptools.Bool(productVariables.Eng)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_not_svelte=%t\n", proptools.Bool(productVariables.Malloc_not_svelte)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_pattern_fill_contents=%t\n", proptools.Bool(productVariables.Malloc_pattern_fill_contents)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:malloc_zero_contents=%t\n", proptools.Bool(productVariables.Malloc_zero_contents)))
|
2023-08-31 23:14:01 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_exclude_paths=%s\n", strings.Join(productVariables.MemtagHeapExcludePaths, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_async_include_paths=%s\n", strings.Join(productVariables.MemtagHeapAsyncIncludePaths, ",")))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:memtag_heap_sync_include_paths=%s\n", strings.Join(productVariables.MemtagHeapSyncIncludePaths, ",")))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:manifest_package_name_overrides=%s\n", strings.Join(productVariables.ManifestPackageNameOverrides, ",")))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:native_coverage=%t\n", proptools.Bool(productVariables.Native_coverage)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_version_name=%s\n", proptools.String(productVariables.Platform_version_name)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_brand=%s\n", productVariables.ProductBrand))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:product_manufacturer=%s\n", productVariables.ProductManufacturer))
|
2023-08-03 22:49:27 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:platform_sdk_version=%d\n", platform_sdk_version))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:safestack=%t\n", proptools.Bool(productVariables.Safestack)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:target_build_variant=%s\n", targetBuildVariant))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:treble_linker_namespaces=%t\n", proptools.Bool(productVariables.Treble_linker_namespaces)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:tidy_checks=%s\n", proptools.String(productVariables.TidyChecks)))
|
2023-07-31 21:10:12 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:uml=%t\n", proptools.Bool(productVariables.Uml)))
|
2023-07-25 00:17:03 +02:00
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build=%t\n", proptools.Bool(productVariables.Unbundled_build)))
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config:unbundled_build_apps=%s\n", strings.Join(productVariables.Unbundled_build_apps, ",")))
|
2023-08-04 01:08:09 +02:00
|
|
|
|
|
|
|
for _, override := range productVariables.CertificateOverrides {
|
|
|
|
parts := strings.SplitN(override, ":", 2)
|
|
|
|
if apexPath, ok := convertedModulePathMap[parts[0]]; ok {
|
|
|
|
if overrideCertPath, ok := convertedModulePathMap[parts[1]]; ok {
|
|
|
|
result.WriteString(fmt.Sprintf(" --%s:%s_certificate_override=%s:%s\n", apexPath, parts[0], overrideCertPath, parts[1]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 21:10:12 +02:00
|
|
|
for namespace, namespaceContents := range productVariables.VendorVars {
|
|
|
|
for variable, value := range namespaceContents {
|
|
|
|
key := namespace + "__" + variable
|
|
|
|
_, hasBool := soongConfigDefinitions.BoolVars[key]
|
|
|
|
_, hasString := soongConfigDefinitions.StringVars[key]
|
|
|
|
_, hasValue := soongConfigDefinitions.ValueVars[key]
|
|
|
|
if !hasBool && !hasString && !hasValue {
|
|
|
|
// Not all soong config variables are defined in Android.bp files. For example,
|
|
|
|
// prebuilt_bootclasspath_fragment uses soong config variables in a nonstandard
|
|
|
|
// way, that causes them to be present in the soong.variables file but not
|
|
|
|
// defined in an Android.bp file. There's also nothing stopping you from setting
|
|
|
|
// a variable in make that doesn't exist in soong. We only generate build
|
|
|
|
// settings for the ones that exist in soong, so skip all others.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if hasBool && hasString || hasBool && hasValue || hasString && hasValue {
|
|
|
|
panic(fmt.Sprintf("Soong config variable %s:%s appears to be of multiple types. bool? %t, string? %t, value? %t", namespace, variable, hasBool, hasString, hasValue))
|
|
|
|
}
|
|
|
|
if hasBool {
|
|
|
|
// Logic copied from soongConfig.Bool()
|
|
|
|
value = strings.ToLower(value)
|
|
|
|
if value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" {
|
|
|
|
value = "true"
|
|
|
|
} else {
|
|
|
|
value = "false"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.WriteString(fmt.Sprintf(" --//build/bazel/product_config/soong_config_variables:%s=%s\n", strings.ToLower(key), value))
|
|
|
|
}
|
|
|
|
}
|
2023-04-22 02:37:11 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-09 03:14:01 +01:00
|
|
|
|
2023-04-22 02:37:11 +02:00
|
|
|
func starlarkMapToProductVariables(in map[string]starlark.Value) (android.ProductVariables, error) {
|
|
|
|
result := android.ProductVariables{}
|
2023-07-25 00:17:03 +02:00
|
|
|
productVarsReflect := reflect.ValueOf(&result).Elem()
|
|
|
|
for i := 0; i < productVarsReflect.NumField(); i++ {
|
|
|
|
field := productVarsReflect.Field(i)
|
|
|
|
fieldType := productVarsReflect.Type().Field(i)
|
|
|
|
name := fieldType.Name
|
2023-07-31 21:10:12 +02:00
|
|
|
if name == "BootJars" || name == "ApexBootJars" || name == "VendorSnapshotModules" ||
|
|
|
|
name == "RecoverySnapshotModules" {
|
2023-07-25 00:17:03 +02:00
|
|
|
// These variables have more complicated types, and we don't need them right now
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, ok := in[name]; ok {
|
2023-07-31 21:10:12 +02:00
|
|
|
if name == "VendorVars" {
|
|
|
|
vendorVars, err := starlark_import.Unmarshal[map[string]map[string]string](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(vendorVars))
|
|
|
|
continue
|
|
|
|
}
|
2023-07-25 00:17:03 +02:00
|
|
|
switch field.Type().Kind() {
|
|
|
|
case reflect.Bool:
|
|
|
|
val, err := starlark_import.Unmarshal[bool](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.SetBool(val)
|
|
|
|
case reflect.String:
|
|
|
|
val, err := starlark_import.Unmarshal[string](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.SetString(val)
|
|
|
|
case reflect.Slice:
|
|
|
|
if field.Type().Elem().Kind() != reflect.String {
|
|
|
|
return result, fmt.Errorf("slices of types other than strings are unimplemented")
|
|
|
|
}
|
|
|
|
val, err := starlark_import.UnmarshalReflect(in[name], field.Type())
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.Set(val)
|
|
|
|
case reflect.Pointer:
|
|
|
|
switch field.Type().Elem().Kind() {
|
|
|
|
case reflect.Bool:
|
|
|
|
val, err := starlark_import.UnmarshalNoneable[bool](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(val))
|
|
|
|
case reflect.String:
|
|
|
|
val, err := starlark_import.UnmarshalNoneable[string](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(val))
|
|
|
|
case reflect.Int:
|
|
|
|
val, err := starlark_import.UnmarshalNoneable[int](in[name])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(val))
|
|
|
|
default:
|
|
|
|
return result, fmt.Errorf("pointers of types other than strings/bools are unimplemented: %s", field.Type().Elem().Kind().String())
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return result, fmt.Errorf("unimplemented type: %s", field.Type().String())
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 16:51:26 +02:00
|
|
|
}
|
2023-07-25 00:17:03 +02:00
|
|
|
|
2023-07-31 21:10:12 +02:00
|
|
|
result.Native_coverage = proptools.BoolPtr(
|
|
|
|
proptools.Bool(result.GcovCoverage) ||
|
|
|
|
proptools.Bool(result.ClangCoverage))
|
|
|
|
|
2022-11-09 03:14:01 +01:00
|
|
|
return result, nil
|
|
|
|
}
|
2023-09-12 19:07:07 +02:00
|
|
|
|
|
|
|
func createTargets(productLabelsToVariables map[string]*android.ProductVariables) map[string]BazelTargets {
|
|
|
|
res := make(map[string]BazelTargets)
|
|
|
|
var allDefaultAppCertificateDirs []string
|
|
|
|
for _, productVariables := range productLabelsToVariables {
|
|
|
|
if proptools.String(productVariables.DefaultAppCertificate) != "" {
|
|
|
|
d := filepath.Dir(proptools.String(productVariables.DefaultAppCertificate))
|
|
|
|
if !android.InList(d, allDefaultAppCertificateDirs) {
|
|
|
|
allDefaultAppCertificateDirs = append(allDefaultAppCertificateDirs, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, dir := range allDefaultAppCertificateDirs {
|
|
|
|
content := fmt.Sprintf(ruleTargetTemplate, "filegroup", "generated_android_certificate_directory", propsToAttributes(map[string]string{
|
|
|
|
"srcs": `glob([
|
|
|
|
"*.pk8",
|
|
|
|
"*.pem",
|
|
|
|
"*.avbpubkey",
|
|
|
|
])`,
|
|
|
|
"visibility": `["//visibility:public"]`,
|
|
|
|
}))
|
|
|
|
res[dir] = append(res[dir], BazelTarget{
|
|
|
|
name: "generated_android_certificate_directory",
|
|
|
|
packageName: dir,
|
|
|
|
content: content,
|
|
|
|
ruleClass: "filegroup",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|