| 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_target_writer.h" | 5 #include "tools/gn/ninja_target_writer.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 NinjaActionTargetWriter writer(target, rules); | 83 NinjaActionTargetWriter writer(target, rules); |
| 84 writer.Run(); | 84 writer.Run(); |
| 85 } else if (target->output_type() == Target::GROUP) { | 85 } else if (target->output_type() == Target::GROUP) { |
| 86 NinjaGroupTargetWriter writer(target, rules); | 86 NinjaGroupTargetWriter writer(target, rules); |
| 87 writer.Run(); | 87 writer.Run(); |
| 88 } else if (target->IsBinary()) { | 88 } else if (target->IsBinary()) { |
| 89 needs_file_write = true; | 89 needs_file_write = true; |
| 90 NinjaBinaryTargetWriter writer(target, rules); | 90 NinjaBinaryTargetWriter writer(target, rules); |
| 91 writer.Run(); | 91 writer.Run(); |
| 92 } else { | 92 } else { |
| 93 CHECK(0) << "Output type of target not handled."; | 93 // Output type of target not handled. |
| 94 CHECK(0); |
| 94 } | 95 } |
| 95 | 96 |
| 96 if (needs_file_write) { | 97 if (needs_file_write) { |
| 97 // Write the ninja file. | 98 // Write the ninja file. |
| 98 SourceFile ninja_file = GetNinjaFileForTarget(target); | 99 SourceFile ninja_file = GetNinjaFileForTarget(target); |
| 99 base::FilePath full_ninja_file = | 100 base::FilePath full_ninja_file = |
| 100 settings->build_settings()->GetFullPath(ninja_file); | 101 settings->build_settings()->GetFullPath(ninja_file); |
| 101 base::CreateDirectory(full_ninja_file.DirName()); | 102 base::CreateDirectory(full_ninja_file.DirName()); |
| 102 WriteFileIfChanged(full_ninja_file, rules.str(), nullptr); | 103 WriteFileIfChanged(full_ninja_file, rules.str(), nullptr); |
| 103 | 104 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 175 } |
| 175 | 176 |
| 176 // If we wrote any vars, separate them from the rest of the file that follows | 177 // If we wrote any vars, separate them from the rest of the file that follows |
| 177 // with a blank line. | 178 // with a blank line. |
| 178 if (written_anything) | 179 if (written_anything) |
| 179 out_ << std::endl; | 180 out_ << std::endl; |
| 180 } | 181 } |
| 181 | 182 |
| 182 OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep( | 183 OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep( |
| 183 const std::vector<const Target*>& extra_hard_deps) const { | 184 const std::vector<const Target*>& extra_hard_deps) const { |
| 184 CHECK(target_->toolchain()) | 185 // Toolchain not set on target |target_->label().GetUserVisibleName(true)|. |
| 185 << "Toolchain not set on target " | 186 CHECK(target_->toolchain()); |
| 186 << target_->label().GetUserVisibleName(true); | |
| 187 | 187 |
| 188 // ---------- | 188 // ---------- |
| 189 // Collect all input files that are input deps of this target. Knowing the | 189 // Collect all input files that are input deps of this target. Knowing the |
| 190 // number before writing allows us to either skip writing the input deps | 190 // number before writing allows us to either skip writing the input deps |
| 191 // stamp or optimize it. Use pointers to avoid copies here. | 191 // stamp or optimize it. Use pointers to avoid copies here. |
| 192 std::vector<const SourceFile*> input_deps_sources; | 192 std::vector<const SourceFile*> input_deps_sources; |
| 193 input_deps_sources.reserve(32); | 193 input_deps_sources.reserve(32); |
| 194 | 194 |
| 195 // Actions get implicit dependencies on the script itself. | 195 // Actions get implicit dependencies on the script itself. |
| 196 if (target_->output_type() == Target::ACTION || | 196 if (target_->output_type() == Target::ACTION || |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 return input_stamp_file; | 295 return input_stamp_file; |
| 296 } | 296 } |
| 297 | 297 |
| 298 void NinjaTargetWriter::WriteStampForTarget( | 298 void NinjaTargetWriter::WriteStampForTarget( |
| 299 const std::vector<OutputFile>& files, | 299 const std::vector<OutputFile>& files, |
| 300 const std::vector<OutputFile>& order_only_deps) { | 300 const std::vector<OutputFile>& order_only_deps) { |
| 301 const OutputFile& stamp_file = target_->dependency_output_file(); | 301 const OutputFile& stamp_file = target_->dependency_output_file(); |
| 302 | 302 |
| 303 // First validate that the target's dependency is a stamp file. Otherwise, | 303 // First validate that the target's dependency is a stamp file. Otherwise, |
| 304 // we shouldn't have gotten here! | 304 // we shouldn't have gotten here! |
| 305 CHECK(base::EndsWith(stamp_file.value(), ".stamp", | 305 LOG_IF(FATAL, !base::EndsWith(stamp_file.value(), ".stamp", |
| 306 base::CompareCase::INSENSITIVE_ASCII)) | 306 base::CompareCase::INSENSITIVE_ASCII)) |
| 307 << "Output should end in \".stamp\" for stamp file output. Instead got: " | 307 << "Output should end in \".stamp\" for stamp file output. Instead got: " |
| 308 << "\"" << stamp_file.value() << "\""; | 308 << "\"" << stamp_file.value() << "\""; |
| 309 | 309 |
| 310 out_ << "build "; | 310 out_ << "build "; |
| 311 path_output_.WriteFile(out_, stamp_file); | 311 path_output_.WriteFile(out_, stamp_file); |
| 312 | 312 |
| 313 out_ << ": " | 313 out_ << ": " |
| 314 << GetNinjaRulePrefixForToolchain(settings_) | 314 << GetNinjaRulePrefixForToolchain(settings_) |
| 315 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); | 315 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); |
| 316 path_output_.WriteFiles(out_, files); | 316 path_output_.WriteFiles(out_, files); |
| 317 | 317 |
| 318 if (!order_only_deps.empty()) { | 318 if (!order_only_deps.empty()) { |
| 319 out_ << " ||"; | 319 out_ << " ||"; |
| 320 path_output_.WriteFiles(out_, order_only_deps); | 320 path_output_.WriteFiles(out_, order_only_deps); |
| 321 } | 321 } |
| 322 out_ << std::endl; | 322 out_ << std::endl; |
| 323 } | 323 } |
| OLD | NEW |