From ab689a4f50c56521396eeab8deb9f8c6945d3c88 Mon Sep 17 00:00:00 2001 From: dpranke Date: Fri, 24 Apr 2015 17:29:36 -0700 Subject: [PATCH] GN: Generate phony rules for unique executables. Prior to this CL, if there were multiple targets ina GN build with the name 'unit_tests', we would not generate a top-level phony ninja target for them; you would have to specify either the full path to the output or the label name. This is confusing for things like 'browser_tests' and 'unit_tests', where in Chromium we might have multiple targets with that name, but only one of those is an executable (at least in the default toolchain). This CL adds logic to handle that case (so that 'unit_tests' does work). R=brettw@chromium.org BUG=480042 Review URL: https://codereview.chromium.org/1101323005 Cr-Commit-Position: refs/heads/master@{#326942} --- tools/gn/ninja_build_writer.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/gn/ninja_build_writer.cc b/tools/gn/ninja_build_writer.cc index 3ed0a6270c142c..248a45a2a674f1 100644 --- a/tools/gn/ninja_build_writer.cc +++ b/tools/gn/ninja_build_writer.cc @@ -191,6 +191,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { // isn't unique, also skip it. The exception is for the toplevel targets // which we also find. std::map small_name_count; + std::map exe_count; std::vector toplevel_targets; base::hash_set target_files; for (const auto& target : default_toolchain_targets_) { @@ -208,6 +209,11 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { dir_string[dir_string.size() - 1] == '/' && // "/" at end. dir_string.compare(2, label.name().size(), label.name()) == 0) toplevel_targets.push_back(target); + + // Look for executables; later we will generate phony rules for them + // even if there are non-executable targets with the same name. + if (target->output_type() == Target::EXECUTABLE) + exe_count[label.name()]++; } for (const auto& target : default_toolchain_targets_) { @@ -236,9 +242,13 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { WritePhonyRule(target, target_file, medium_name); } - // Write short names for ones which are unique. - if (small_name_count[label.name()] == 1) + // Write short names for ones which are either completely unique or there + // at least only one of them in the default toolchain that is an exe. + if (small_name_count[label.name()] == 1 || + (target->output_type() == Target::EXECUTABLE && + exe_count[label.name()] == 1)) { WritePhonyRule(target, target_file, label.name()); + } if (!all_rules.empty()) all_rules.append(" $\n ");