diff --git a/docs/reference.md b/docs/reference.md index d8d2a6aa..0c7600cb 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -7828,6 +7828,14 @@ A boolean flag that can be set to generate Ninja files that use phony rules instead of stamp files whenever possible. This results in smaller Ninja build plans, but requires at least Ninja 1.11. + + experimental_collect_validations_metadata [optional] + NOTE: This flag is experimental and will be removed in the future. + + A boolean flag that determines whether generated_file() metadata walks + should include validations targets's metadata. This is false by default + but may be required temporarily by the Fuchsia build. See + https://gn.g-issues.chromium.org/issues/566346002 for details. ``` #### **Example .gn file contents** @@ -8880,6 +8888,7 @@ * --dotfile: Override the name of the ".gn" file. * --enumerate-files-with-git: Use git to list files. * --error-limit: Limit the number of errors or warnings to print. + * --experimental-collect-validations-metadata: Collect metadata from validations. * --fail-on-unused-args: Treat unused build args as fatal errors. * --format-width: Set the formatting width (default is 80) * --markdown: Write help output in the Markdown format. diff --git a/src/gn/build_settings.h b/src/gn/build_settings.h index 1c248522..8330c7d0 100644 --- a/src/gn/build_settings.h +++ b/src/gn/build_settings.h @@ -165,6 +165,15 @@ class BuildSettings { allow_circular_includes_from_allowlist_ = std::move(list); } + // If true, all generated_file() metadata walks include metadata from + // validations targets. + bool experimental_collect_validations_metadata() const { + return experimental_collect_validations_metadata_; + } + void set_experimental_collect_validations_metadata(bool value) { + experimental_collect_validations_metadata_ = value; + } + private: Label root_target_label_; std::vector root_patterns_; @@ -178,6 +187,7 @@ class BuildSettings { // See 40045b9 for the reason behind using 1.7.2 as the default version. Version ninja_required_version_{1, 7, 2}; bool no_stamp_files_ = true; + bool experimental_collect_validations_metadata_ = false; SourceFile build_config_file_; SourceFile arg_file_template_path_; diff --git a/src/gn/setup.cc b/src/gn/setup.cc index abb28c5b..26a805c9 100644 --- a/src/gn/setup.cc +++ b/src/gn/setup.cc @@ -260,6 +260,14 @@ Variables rules instead of stamp files whenever possible. This results in smaller Ninja build plans, but requires at least Ninja 1.11. + experimental_collect_validations_metadata [optional] + NOTE: This flag is experimental and will be removed in the future. + + A boolean flag that determines whether generated_file() metadata walks + should include validations targets's metadata. This is false by default + but may be required temporarily by the Fuchsia build. See + https://gn.g-issues.chromium.org/issues/566346002 for details. + Example .gn file contents buildconfig = "//build/config/BUILDCONFIG.gn" @@ -1302,5 +1310,23 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline, Err* err) { export_compile_commands_.push_back(std::move(pat)); } + // Collect validations metadata during generate_file() walks. + // See https://gn.g-issues.chromium.org/issues/566346002 + if (cmdline.HasSwitch(switches::kExperimentalCollectValidationsMetadata)) { + build_settings_.set_experimental_collect_validations_metadata(true); + } else { + const Value* experimental_collect_validations_metadata_value = + dotfile_scope_.GetValue("experimental_collect_validations_metadata", + true); + if (experimental_collect_validations_metadata_value) { + if (!experimental_collect_validations_metadata_value->VerifyTypeIs( + Value::BOOLEAN, err)) { + return false; + } + build_settings_.set_experimental_collect_validations_metadata( + experimental_collect_validations_metadata_value->boolean_value()); + } + } + return true; } diff --git a/src/gn/switches.cc b/src/gn/switches.cc index 27f30fd7..e1b5b3c5 100644 --- a/src/gn/switches.cc +++ b/src/gn/switches.cc @@ -88,6 +88,20 @@ const char kErrorLimit_Help[] = and warnings without any limit. )"; +const char kExperimentalCollectValidationsMetadata[] = + "experimental-collect-validations-metadata"; +const char kExperimentalCollectValidationsMetadata_HelpShort[] = + "--experimental-collect-validations-metadata: Collect metadata from " + "validations."; +const char kExperimentalCollectValidationsMetadata_Help[] = + R"(--experimental-collect-validations-metadata: Collect metadata from validations. + + Sets the default value of generated_file() collect_validations_metadata + argument to true (default is false). + + This switch is experimental and will be removed in the future. + See https://issuetracker.google.com/566346002. +)"; const char kFailOnUnusedArgs[] = "fail-on-unused-args"; const char kFailOnUnusedArgs_HelpShort[] = "--fail-on-unused-args: Treat unused build args as fatal errors."; @@ -373,6 +387,7 @@ const SwitchInfoMap& GetSwitches() { INSERT_VARIABLE(Dotfile) INSERT_VARIABLE(EnumerateFilesWithGit) INSERT_VARIABLE(ErrorLimit) + INSERT_VARIABLE(ExperimentalCollectValidationsMetadata) INSERT_VARIABLE(FailOnUnusedArgs) INSERT_VARIABLE(FormatWidth) INSERT_VARIABLE(Markdown) diff --git a/src/gn/switches.h b/src/gn/switches.h index 70f0f192..9fe9d21a 100644 --- a/src/gn/switches.h +++ b/src/gn/switches.h @@ -46,6 +46,10 @@ extern const char kErrorLimit[]; extern const char kErrorLimit_HelpShort[]; extern const char kErrorLimit_Help[]; +extern const char kExperimentalCollectValidationsMetadata[]; +extern const char kExperimentalCollectValidationsMetadata_HelpShort[]; +extern const char kExperimentalCollectValidationsMetadata_Help[]; + extern const char kFailOnUnusedArgs[]; extern const char kFailOnUnusedArgs_HelpShort[]; extern const char kFailOnUnusedArgs_Help[];