| OLD | NEW |
| 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 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Pick up phony rules for the toplevel targets with non-unique names (which | 249 // Pick up phony rules for the toplevel targets with non-unique names (which |
| 250 // would have been skipped in the above loop). | 250 // would have been skipped in the above loop). |
| 251 for (size_t i = 0; i < toplevel_targets.size(); i++) { | 251 for (size_t i = 0; i < toplevel_targets.size(); i++) { |
| 252 if (small_name_count[toplevel_targets[i]->label().name()] > 1) { | 252 if (small_name_count[toplevel_targets[i]->label().name()] > 1) { |
| 253 const Target* target = toplevel_targets[i]; | 253 const Target* target = toplevel_targets[i]; |
| 254 WritePhonyRule(target, target->dependency_output_file(), | 254 WritePhonyRule(target, target->dependency_output_file(), |
| 255 target->label().name()); | 255 target->label().name()); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Figure out if the BUILD file wants to declare a custom "default" |
| 260 // target (rather than building 'all' by default). By convention |
| 261 // we use group("default") but it doesn't have to be a group. |
| 262 bool default_target_exists = false; |
| 263 for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { |
| 264 const Label& label = default_toolchain_targets_[i]->label(); |
| 265 if (label.dir().value() == "//" && label.name() == "default") |
| 266 default_target_exists = true; |
| 267 } |
| 268 |
| 259 if (!all_rules.empty()) { | 269 if (!all_rules.empty()) { |
| 260 out_ << "\nbuild all: phony " << all_rules << std::endl; | 270 out_ << "\nbuild all: phony " << all_rules << std::endl; |
| 271 } |
| 272 |
| 273 if (default_target_exists) { |
| 274 out_ << "default default" << std::endl; |
| 275 } else if (!all_rules.empty()) { |
| 261 out_ << "default all" << std::endl; | 276 out_ << "default all" << std::endl; |
| 262 } | 277 } |
| 278 |
| 263 return true; | 279 return true; |
| 264 } | 280 } |
| 265 | 281 |
| 266 void NinjaBuildWriter::WritePhonyRule(const Target* target, | 282 void NinjaBuildWriter::WritePhonyRule(const Target* target, |
| 267 const OutputFile& target_file, | 283 const OutputFile& target_file, |
| 268 const std::string& phony_name) { | 284 const std::string& phony_name) { |
| 269 if (target_file.value() == phony_name) | 285 if (target_file.value() == phony_name) |
| 270 return; // No need for a phony rule. | 286 return; // No need for a phony rule. |
| 271 | 287 |
| 272 EscapeOptions ninja_escape; | 288 EscapeOptions ninja_escape; |
| 273 ninja_escape.mode = ESCAPE_NINJA; | 289 ninja_escape.mode = ESCAPE_NINJA; |
| 274 | 290 |
| 275 // Escape for special chars Ninja will handle. | 291 // Escape for special chars Ninja will handle. |
| 276 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); | 292 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); |
| 277 | 293 |
| 278 out_ << "build " << escaped << ": phony "; | 294 out_ << "build " << escaped << ": phony "; |
| 279 path_output_.WriteFile(out_, target_file); | 295 path_output_.WriteFile(out_, target_file); |
| 280 out_ << std::endl; | 296 out_ << std::endl; |
| 281 } | 297 } |
| OLD | NEW |