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

Commit 319abae1 authored by Cole Faust's avatar Cole Faust
Browse files

Remove --noexperimental_platform_in_output_dir

This is a followup to aosp/2606989.

This flag is not necessary now that we're using one platform name
for all of mixed builds.

Also rename current_product to mixed_builds_product so that it's clear
that that this platform should only be used for mixed builds.

In addition, make the bazelrc files point to the named products again
instead of the mixed build product so that b builds will still have
qualified outputs, but mixed builds won't.

Test: Presubmit and kernel build tools abtd run
Change-Id: I7f764cf42cd1323f4b495d1320931f59a076ac63
parent f1815ea3
Loading
Loading
Loading
Loading
+14 −20
Original line number Original line Diff line number Diff line
@@ -689,26 +689,20 @@ func (r *builtinBazelRunner) issueBazelCommand(cmdRequest bazel.CmdRequest, path


func (context *mixedBuildBazelContext) createBazelCommand(config Config, runName bazel.RunName, command bazelCommand,
func (context *mixedBuildBazelContext) createBazelCommand(config Config, runName bazel.RunName, command bazelCommand,
	extraFlags ...string) bazel.CmdRequest {
	extraFlags ...string) bazel.CmdRequest {
	if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
		panic("Unknown GOOS: " + runtime.GOOS)
	}
	cmdFlags := []string{
	cmdFlags := []string{
		"--output_base=" + absolutePath(context.paths.outputBase),
		"--output_base=" + absolutePath(context.paths.outputBase),
		command.command,
		command.command,
		command.expression,
		command.expression,
		"--profile=" + shared.BazelMetricsFilename(context.paths, runName),
		"--profile=" + shared.BazelMetricsFilename(context.paths, runName),


		// We don't need to set --host_platforms because it's set in bazelrc files
		"--host_platform=@soong_injection//product_config_platforms:mixed_builds_product-" + context.targetBuildVariant + "_" + runtime.GOOS + "_x86_64",
		// that the bazel shell script wrapper passes
		// Don't specify --platforms, because on some products/branches (like kernel-build-tools)

		// the main platform for mixed_builds_product-variant doesn't exist because an arch isn't
		// Optimize Ninja rebuilds by ensuring Bazel write into product-agnostic
		// specified in product config. The derivative platforms that config_node transitions into
		// output paths for the configured targets that shouldn't be affected by
		// will still work.
		// 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",
@@ -755,9 +749,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 = "current_product-{VARIANT}"
        target = "mixed_builds_product-{VARIANT}"
    else:
    else:
        target = "current_product-{VARIANT}_%s_%s" % (attr.os, attr.arch)
        target = "mixed_builds_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,
@@ -994,9 +988,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("current_product-{TARGET_BUILD_VARIANT}"):
  if not platform_name.startswith("mixed_builds_product-{TARGET_BUILD_VARIANT}"):
    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))
    fail("expected platform name of the form 'mixed_builds_product-{TARGET_BUILD_VARIANT}_android_<arch>' or 'mixed_builds_product-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms))
  platform_name = platform_name.removeprefix("current_product-{TARGET_BUILD_VARIANT}").removeprefix("_")
  platform_name = platform_name.removeprefix("mixed_builds_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"
@@ -1005,7 +999,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 'current_product-{TARGET_BUILD_VARIANT}_android_<arch>' or 'current_product-{TARGET_BUILD_VARIANT}_linux_<arch>', but was " + str(platforms))
    fail("expected platform name of the form 'mixed_builds_product-{TARGET_BUILD_VARIANT}_android_<arch>' or 'mixed_builds_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")
+15 −23
Original line number Original line Diff line number Diff line
@@ -72,8 +72,13 @@ package(default_visibility = [
load("//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables")
load("//{PRODUCT_FOLDER}:soong.variables.bzl", _soong_variables = "variables")
load("@//build/bazel/product_config:android_product.bzl", "android_product")
load("@//build/bazel/product_config:android_product.bzl", "android_product")


# 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.
android_product(
android_product(
    name = "current_product-{VARIANT}",
    name = "mixed_builds_product-{VARIANT}",
    soong_variables = _soong_variables,
    soong_variables = _soong_variables,
)
)
`)),
`)),
@@ -86,7 +91,7 @@ android_product(
# 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_config_platforms:mixed_builds_product-{VARIANT}",
  "@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}"
  "@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}"
]
]
`)),
`)),
@@ -94,38 +99,25 @@ product_labels = [
			"product_config_platforms",
			"product_config_platforms",
			"common.bazelrc",
			"common.bazelrc",
			productReplacer.Replace(`
			productReplacer.Replace(`
# current_product refers to the current TARGET_PRODUCT set, usually through
build --platforms @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
# '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_config_platforms:current_product-{VARIANT}
build:android --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}
build:linux_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_x86_64
build:linux_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
build:linux_bionic_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_bionic_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_config_platforms:current_product-{VARIANT}_linux_musl_x86
build:linux_musl_x86 --platforms=@soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_musl_x86
build:linux_musl_x86_64 --platforms=@soong_injection//product_config_platforms:current_product-{VARIANT}_linux_musl_x86_64
build:linux_musl_x86_64 --platforms=@soong_injection//{PRODUCT_FOLDER}:{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_config_platforms:current_product-{VARIANT}_linux_x86_64
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_linux_x86_64
`)),
`)),
		newFile(
		newFile(
			"product_config_platforms",
			"product_config_platforms",
			"darwin.bazelrc",
			"darwin.bazelrc",
			productReplacer.Replace(`
			productReplacer.Replace(`
build --host_platform product_config_platforms:current_product-{VARIANT}_darwin_x86_64
build --host_platform @soong_injection//{PRODUCT_FOLDER}:{PRODUCT}-{VARIANT}_darwin_x86_64
`)),
		newFile(
			"product_config_platforms",
			"platform_mappings",
			productReplacer.Replace(`
flags:
  --cpu=k8
	@soong_injection//product_config_platforms:current_product-{VARIANT}
`)),
`)),
	}
	}


+35 −0
Original line number Original line Diff line number Diff line
@@ -382,4 +382,39 @@ EOF
  run_bazel build --config=android --config=api_bp2build //foo:libfoo.contribution
  run_bazel build --config=android --config=api_bp2build //foo:libfoo.contribution
}
}


function test_bazel_standalone_output_paths_contain_product_name {
  setup
  mkdir -p a
  cat > a/Android.bp <<EOF
cc_object {
  name: "qq",
  srcs: ["qq.cc"],
  bazel_module: {
    bp2build_available: true,
  },
  stl: "none",
  system_shared_libs: [],
}
EOF

  cat > a/qq.cc <<EOF
#include "qq.h"
int qq() {
  return QQ;
}
EOF

  cat > a/qq.h <<EOF
#define QQ 1
EOF

  export TARGET_PRODUCT=aosp_arm; run_soong bp2build
  local -r output=$(run_bazel cquery //a:qq --output=files --config=android --config=bp2build --config=ci)
  if [[ ! $(echo ${output} | grep "bazel-out/aosp_arm") ]]; then
    fail "Did not find the product name '${TARGET_PRODUCT}' in the output path. This can cause " \
      "unnecessary rebuilds when toggling between products as bazel outputs for different products will " \
      "clobber each other. Output paths are: \n${output}"
  fi
}

scan_and_run_tests
scan_and_run_tests