Skip to content

Commit

Permalink
GN: Generate phony rules for unique executables.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
dpranke authored and Commit bot committed Apr 25, 2015
1 parent 4746695 commit ab689a4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/gn/ninja_build_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, int> small_name_count;
std::map<std::string, int> exe_count;
std::vector<const Target*> toplevel_targets;
base::hash_set<std::string> target_files;
for (const auto& target : default_toolchain_targets_) {
Expand All @@ -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_) {
Expand Down Expand Up @@ -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 ");
Expand Down

0 comments on commit ab689a4

Please sign in to comment.