Merge "Create a "current_product" named platform."

This commit is contained in:
Treehugger Robot
2023-05-31 08:00:12 +00:00
committed by Gerrit Code Review
2 changed files with 42 additions and 16 deletions

View File

@@ -674,6 +674,18 @@ func (context *mixedBuildBazelContext) createBazelCommand(config Config, runName
// We don't need to set --host_platforms because it's set in bazelrc files // We don't need to set --host_platforms because it's set in bazelrc files
// that the bazel shell script wrapper passes // that the bazel shell script wrapper passes
// Optimize Ninja rebuilds by ensuring Bazel write into product-agnostic
// output paths for the configured targets that shouldn't be affected by
// TARGET_PRODUCT. Otherwise product agnostic modules will be rebuilt by
// Ninja when the product changes, unconditionally.
//
// For example, Mainline APEXes should be identical regardless of the
// product (modulo arch/cpu).
//
// This flag forcibly disables the platform prefix in the intermediate
// outputs during a mixed build.
"--noexperimental_platform_in_output_dir",
// Suppress noise // Suppress noise
"--ui_event_filters=-INFO", "--ui_event_filters=-INFO",
"--noshow_progress", "--noshow_progress",
@@ -719,9 +731,9 @@ func (context *mixedBuildBazelContext) mainBzlFileContents() []byte {
##################################################### #####################################################
def _config_node_transition_impl(settings, attr): def _config_node_transition_impl(settings, attr):
if attr.os == "android" and attr.arch == "target": if attr.os == "android" and attr.arch == "target":
target = "{PRODUCT}-{VARIANT}" target = "current_product-{VARIANT}"
else: else:
target = "{PRODUCT}-{VARIANT}_%s_%s" % (attr.os, attr.arch) target = "current_product-{VARIANT}_%s_%s" % (attr.os, attr.arch)
apex_name = "" apex_name = ""
if attr.within_apex: if attr.within_apex:
# //build/bazel/rules/apex:apex_name has to be set to a non_empty value, # //build/bazel/rules/apex:apex_name has to be set to a non_empty value,
@@ -732,7 +744,7 @@ def _config_node_transition_impl(settings, attr):
# value here. # value here.
apex_name = "dcla_apex" apex_name = "dcla_apex"
outputs = { outputs = {
"//command_line_option:platforms": "@soong_injection//product_config_platforms/products/{PRODUCT}-{VARIANT}:%s" % target, "//command_line_option:platforms": "@soong_injection//product_config_platforms:%s" % target,
"@//build/bazel/rules/apex:within_apex": attr.within_apex, "@//build/bazel/rules/apex:within_apex": attr.within_apex,
"@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version, "@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version,
"@//build/bazel/rules/apex:apex_name": apex_name, "@//build/bazel/rules/apex:apex_name": apex_name,
@@ -958,9 +970,9 @@ def get_arch(target):
platform_name = platforms[0].name platform_name = platforms[0].name
if platform_name == "host": if platform_name == "host":
return "HOST" return "HOST"
if not platform_name.startswith("{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}"): if not platform_name.startswith("current_product-{TARGET_BUILD_VARIANT}"):
fail("expected platform name of the form '{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}_android_<arch>' or '{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms)) fail("expected platform name of the form 'current_product-{TARGET_BUILD_VARIANT}_android_<arch>' or 'current_product-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms))
platform_name = platform_name.removeprefix("{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}").removeprefix("_") platform_name = platform_name.removeprefix("current_product-{TARGET_BUILD_VARIANT}").removeprefix("_")
config_key = "" config_key = ""
if not platform_name: if not platform_name:
config_key = "target|android" config_key = "target|android"
@@ -969,7 +981,7 @@ def get_arch(target):
elif platform_name.startswith("linux_"): elif platform_name.startswith("linux_"):
config_key = platform_name.removeprefix("linux_") + "|linux" config_key = platform_name.removeprefix("linux_") + "|linux"
else: else:
fail("expected platform name of the form '{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}_android_<arch>' or '{TARGET_PRODUCT}-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms)) fail("expected platform name of the form 'current_product-{TARGET_BUILD_VARIANT}_android_<arch>' or 'current_product-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms))
within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex") within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex")
apex_sdk_version = buildoptions.get("//build/bazel/rules/apex:min_sdk_version") apex_sdk_version = buildoptions.get("//build/bazel/rules/apex:min_sdk_version")

View File

@@ -68,6 +68,14 @@ package(default_visibility = [
"@//build/bazel/product_config:__subpackages__", "@//build/bazel/product_config:__subpackages__",
"@soong_injection//product_config_platforms:__subpackages__", "@soong_injection//product_config_platforms:__subpackages__",
]) ])
load("//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables")
load("@//build/bazel/product_config:android_product.bzl", "android_product")
android_product(
name = "current_product-{VARIANT}",
soong_variables = _soong_variables,
)
`)), `)),
newFile( newFile(
"product_config_platforms", "product_config_platforms",
@@ -78,6 +86,7 @@ package(default_visibility = [
# TODO: When we start generating the platforms for more than just the # TODO: When we start generating the platforms for more than just the
# currently lunched product, they should all be listed here # currently lunched product, they should all be listed here
product_labels = [ product_labels = [
"@soong_injection//product_config_platforms:current_product-{VARIANT}",
"@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}" "@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}"
] ]
`)), `)),
@@ -85,25 +94,30 @@ product_labels = [
"product_config_platforms", "product_config_platforms",
"common.bazelrc", "common.bazelrc",
productReplacer.Replace(` productReplacer.Replace(`
build --platforms @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64 # current_product refers to the current TARGET_PRODUCT set, usually through
# 'lunch' or 'banchan'. Every build will have a primary TARGET_PRODUCT, but
# bazel supports using other products in tests or configuration transitions. The
# other products can be found in
# @soong_injection//product_config_platforms/products/...
build --platforms @soong_injection//product_config_platforms:current_product-{VARIANT}_linux_x86_64
build:android --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT} build:android --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}
build:linux_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64 build:linux_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_x86_64
build:linux_bionic_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_bionic_x86_64 build:linux_bionic_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_bionic_x86_64
build:linux_musl_x86 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_musl_x86 build:linux_musl_x86 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_musl_x86
build:linux_musl_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_musl_x86_64 build:linux_musl_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_musl_x86_64
`)), `)),
newFile( newFile(
"product_config_platforms", "product_config_platforms",
"linux.bazelrc", "linux.bazelrc",
productReplacer.Replace(` productReplacer.Replace(`
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64 build --host_platform @soong_injection//product_config_platforms:current_product-{VARIANT}_linux_x86_64
`)), `)),
newFile( newFile(
"product_config_platforms", "product_config_platforms",
"darwin.bazelrc", "darwin.bazelrc",
productReplacer.Replace(` productReplacer.Replace(`
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_darwin_x86_64 build --host_platform product_config_platforms:current_product-{VARIANT}_darwin_x86_64
`)), `)),
newFile( newFile(
"product_config_platforms", "product_config_platforms",
@@ -111,7 +125,7 @@ build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_dar
productReplacer.Replace(` productReplacer.Replace(`
flags: flags:
--cpu=k8 --cpu=k8
@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT} @soong_injection//product_config_platforms:current_product-{VARIANT}
`)), `)),
} }