From 3bb2aa4a7bd3c14b89e576dd8c553f6f6158d7a5 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Thu, 30 Apr 2026 19:00:30 +0000 Subject: [PATCH] Add build opt to enable all host substitutions by default Bug: b/507966746 Test: Add an extra LOG() statement to assemble_cvd. ``` bazel run //cuttlefish/package:cvd \ -- create ``` and confirm it does not show the log. ``` bazel run //cuttlefish/package:cvd \ --//cuttlefish/host/commands/cvd:all_host_substitutions=true \ -- create ``` and confirm it does show the log. --- base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel | 13 +++++++++++++ .../host/commands/cvd/cli/commands/BUILD.bazel | 6 ++++++ .../host/commands/cvd/cli/commands/start.cpp | 3 +++ .../cuttlefish/host/commands/cvd/fetch/BUILD.bazel | 6 ++++++ .../host/commands/cvd/fetch/fetch_cvd_parser.cc | 4 ++++ 5 files changed, 32 insertions(+) diff --git a/base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel index 94c919dc180..f27f6a6d7d1 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("//:build_variables.bzl", "COPTS") load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library") @@ -5,6 +6,18 @@ package( default_visibility = ["//:android_cuttlefish"], ) +bool_flag( + name = "all_host_substitutions", + build_setting_default = False, +) + +config_setting( + name = "all_host_substitutions_enabled", + flag_values = { + ":all_host_substitutions": "true", + }, +) + cf_cc_library( name = "libcvd", srcs = ["cvd.cpp"], diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel index 099a9d90956..5366f6f51e3 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel @@ -357,6 +357,12 @@ cf_cc_library( name = "start", srcs = ["start.cpp"], hdrs = ["start.h"], + local_defines = select({ + "//cuttlefish/host/commands/cvd:all_host_substitutions_enabled": [ + "CUTTLEFISH_ENABLE_ALL_HOST_SUBSTITUTIONS_BY_DEFAULT", + ], + "//conditions:default": [], + }), deps = [ "//cuttlefish/common/libs/utils:contains", "//cuttlefish/common/libs/utils:files", diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp index 750cf34340b..9841055feb1 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp @@ -458,6 +458,9 @@ Result CvdStartCommandHandler::Handle(const CommandRequest& request) { const auto bin = CF_EXPECT(FindStartBin(group.HostArtifactsPath())); std::vector host_substitutions; +#if defined(CUTTLEFISH_ENABLE_ALL_HOST_SUBSTITUTIONS_BY_DEFAULT) + host_substitutions.push_back("all"); +#endif Flag host_substitutions_flag = GflagsCompatFlag("host_substitutions", host_substitutions); diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel index 7cc4528febb..dfcbec1e5ed 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel @@ -218,6 +218,12 @@ cf_cc_library( name = "fetch_cvd_parser", srcs = ["fetch_cvd_parser.cc"], hdrs = ["fetch_cvd_parser.h"], + local_defines = select({ + "//cuttlefish/host/commands/cvd:all_host_substitutions_enabled": [ + "CUTTLEFISH_ENABLE_ALL_HOST_SUBSTITUTIONS_BY_DEFAULT", + ], + "//conditions:default": [], + }), deps = [ "//cuttlefish/common/libs/utils:files", "//cuttlefish/common/libs/utils:flag_parser", diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.cc b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.cc index 84440e0f659..c7a0eae22a8 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.cc +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.cc @@ -84,6 +84,10 @@ std::vector GetFlagsVector(FetchFlags& fetch_flags, Result FetchFlags::Parse(std::vector& args) { FetchFlags fetch_flags; +#if defined(CUTTLEFISH_ENABLE_ALL_HOST_SUBSTITUTIONS_BY_DEFAULT) + fetch_flags.host_substitutions.push_back("all"); +#endif + std::string directory; std::vector flags = GetFlagsVector(fetch_flags, directory); CF_EXPECT(ConsumeFlags(flags, args), "Could not process command line flags.");