Commit ab689a4f authored by dpranke's avatar dpranke Committed by Commit bot

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}
parent 47466950
...@@ -191,6 +191,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -191,6 +191,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
// isn't unique, also skip it. The exception is for the toplevel targets // isn't unique, also skip it. The exception is for the toplevel targets
// which we also find. // which we also find.
std::map<std::string, int> small_name_count; std::map<std::string, int> small_name_count;
std::map<std::string, int> exe_count;
std::vector<const Target*> toplevel_targets; std::vector<const Target*> toplevel_targets;
base::hash_set<std::string> target_files; base::hash_set<std::string> target_files;
for (const auto& target : default_toolchain_targets_) { for (const auto& target : default_toolchain_targets_) {
...@@ -208,6 +209,11 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -208,6 +209,11 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
dir_string[dir_string.size() - 1] == '/' && // "/" at end. dir_string[dir_string.size() - 1] == '/' && // "/" at end.
dir_string.compare(2, label.name().size(), label.name()) == 0) dir_string.compare(2, label.name().size(), label.name()) == 0)
toplevel_targets.push_back(target); 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_) { for (const auto& target : default_toolchain_targets_) {
...@@ -236,9 +242,13 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -236,9 +242,13 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
WritePhonyRule(target, target_file, medium_name); WritePhonyRule(target, target_file, medium_name);
} }
// Write short names for ones which are unique. // Write short names for ones which are either completely unique or there
if (small_name_count[label.name()] == 1) // 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()); WritePhonyRule(target, target_file, label.name());
}
if (!all_rules.empty()) if (!all_rules.empty())
all_rules.append(" $\n "); all_rules.append(" $\n ");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment