Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: tools/gn/ninja_build_writer.cc

Issue 232063002: GN: Don't write duplicate phony rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/ninja_build_writer.h" 5 #include "tools/gn/ninja_build_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <map>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/path_service.h" 12 #include "base/path_service.h"
12 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "tools/gn/build_settings.h" 16 #include "tools/gn/build_settings.h"
16 #include "tools/gn/escape.h" 17 #include "tools/gn/escape.h"
17 #include "tools/gn/filesystem_utils.h" 18 #include "tools/gn/filesystem_utils.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 path_output_.WriteFile(out_, 170 path_output_.WriteFile(out_,
170 helper_.GetNinjaFileForToolchain(all_settings_[i])); 171 helper_.GetNinjaFileForToolchain(all_settings_[i]));
171 out_ << std::endl; 172 out_ << std::endl;
172 } 173 }
173 out_ << std::endl; 174 out_ << std::endl;
174 } 175 }
175 176
176 void NinjaBuildWriter::WritePhonyAndAllRules() { 177 void NinjaBuildWriter::WritePhonyAndAllRules() {
177 std::string all_rules; 178 std::string all_rules;
178 179
179 // Write phony rules for the default toolchain (don't do other toolchains or 180 // Write phony rules for all uniquely-named targets in the default toolchain.
180 // we'll get naming conflicts). 181 // Don't do other toolchains or we'll get naming conflicts, and if the name
182 // isn't unique, also skip it.
183 std::map<std::string, int> small_name_count;
184 for (size_t i = 0; i < default_toolchain_targets_.size(); i++)
185 small_name_count[default_toolchain_targets_[i]->label().name()]++;
186
181 for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { 187 for (size_t i = 0; i < default_toolchain_targets_.size(); i++) {
182 const Target* target = default_toolchain_targets_[i]; 188 const Target* target = default_toolchain_targets_[i];
183 189
184 OutputFile target_file = helper_.GetTargetOutputFile(target); 190 OutputFile target_file = helper_.GetTargetOutputFile(target);
185 if (target_file.value() != target->label().name()) { 191 if (target_file.value() != target->label().name() &&
192 small_name_count[default_toolchain_targets_[i]->label().name()] == 1) {
186 out_ << "build " << target->label().name() << ": phony "; 193 out_ << "build " << target->label().name() << ": phony ";
187 path_output_.WriteFile(out_, target_file); 194 path_output_.WriteFile(out_, target_file);
188 out_ << std::endl; 195 out_ << std::endl;
189 } 196 }
190 197
191 if (!all_rules.empty()) 198 if (!all_rules.empty())
192 all_rules.append(" $\n "); 199 all_rules.append(" $\n ");
193 all_rules.append(target_file.value()); 200 all_rules.append(target_file.value());
194 } 201 }
195 202
196 if (!all_rules.empty()) { 203 if (!all_rules.empty()) {
197 out_ << "\nbuild all: phony " << all_rules << std::endl; 204 out_ << "\nbuild all: phony " << all_rules << std::endl;
198 out_ << "default all" << std::endl; 205 out_ << "default all" << std::endl;
199 } 206 }
200 } 207 }
201 208
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698