| 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_copy_target_writer.h" | 5 #include "tools/gn/ninja_copy_target_writer.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "tools/gn/file_template.h" | 8 #include "tools/gn/file_template.h" |
| 9 #include "tools/gn/string_utils.h" | 9 #include "tools/gn/string_utils.h" |
| 10 | 10 |
| 11 NinjaCopyTargetWriter::NinjaCopyTargetWriter(const Target* target, | 11 NinjaCopyTargetWriter::NinjaCopyTargetWriter(const Target* target, |
| 12 const Toolchain* toolchain, | 12 const Toolchain* toolchain, |
| 13 std::ostream& out) | 13 std::ostream& out) |
| 14 : NinjaTargetWriter(target, toolchain, out) { | 14 : NinjaTargetWriter(target, toolchain, out) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 NinjaCopyTargetWriter::~NinjaCopyTargetWriter() { | 17 NinjaCopyTargetWriter::~NinjaCopyTargetWriter() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void NinjaCopyTargetWriter::Run() { | 20 void NinjaCopyTargetWriter::Run() { |
| 21 CHECK(target_->action_values().outputs().size() == 1); | 21 CHECK(target_->action_values().outputs().size() == 1); |
| 22 FileTemplate output_template(GetOutputTemplate()); | 22 FileTemplate output_template(GetOutputTemplate()); |
| 23 | 23 |
| 24 std::vector<OutputFile> output_files; | 24 std::vector<OutputFile> output_files; |
| 25 | 25 |
| 26 std::string rule_prefix = helper_.GetRulePrefix(target_->settings()); | 26 std::string rule_prefix = helper_.GetRulePrefix(target_->settings()); |
| 27 | 27 |
| 28 std::string implicit_deps = |
| 29 WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
| 30 |
| 28 for (size_t i = 0; i < target_->sources().size(); i++) { | 31 for (size_t i = 0; i < target_->sources().size(); i++) { |
| 29 const SourceFile& input_file = target_->sources()[i]; | 32 const SourceFile& input_file = target_->sources()[i]; |
| 30 | 33 |
| 31 // Make the output file from the template. | 34 // Make the output file from the template. |
| 32 std::vector<std::string> template_result; | 35 std::vector<std::string> template_result; |
| 33 output_template.Apply(input_file, &template_result); | 36 output_template.Apply(input_file, &template_result); |
| 34 CHECK(template_result.size() == 1); | 37 CHECK(template_result.size() == 1); |
| 35 OutputFile output_file(template_result[0]); | 38 OutputFile output_file(template_result[0]); |
| 36 | 39 |
| 37 output_files.push_back(output_file); | 40 output_files.push_back(output_file); |
| 38 | 41 |
| 39 out_ << "build "; | 42 out_ << "build "; |
| 40 path_output_.WriteFile(out_, output_file); | 43 path_output_.WriteFile(out_, output_file); |
| 41 out_ << ": " << rule_prefix << "copy "; | 44 out_ << ": " << rule_prefix << "copy "; |
| 42 path_output_.WriteFile(out_, input_file); | 45 path_output_.WriteFile(out_, input_file); |
| 43 out_ << std::endl; | 46 out_ << implicit_deps << std::endl; |
| 44 } | 47 } |
| 45 | 48 |
| 46 // Write out the rule for the target to copy all of them. | 49 // Write out the rule for the target to copy all of them. |
| 47 out_ << std::endl << "build "; | 50 out_ << std::endl << "build "; |
| 48 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); | 51 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); |
| 49 out_ << ": " << rule_prefix << "stamp"; | 52 out_ << ": " << rule_prefix << "stamp"; |
| 50 for (size_t i = 0; i < output_files.size(); i++) { | 53 for (size_t i = 0; i < output_files.size(); i++) { |
| 51 out_ << " "; | 54 out_ << " "; |
| 52 path_output_.WriteFile(out_, output_files[i]); | 55 path_output_.WriteFile(out_, output_files[i]); |
| 53 } | 56 } |
| 54 out_ << std::endl; | 57 out_ << std::endl; |
| 55 } | 58 } |
| OLD | NEW |