| 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_action_target_writer.h" | 5 #include "tools/gn/ninja_action_target_writer.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
| 9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
| 10 #include "tools/gn/string_utils.h" | 10 #include "tools/gn/string_utils.h" |
| 11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
| 12 | 12 |
| 13 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target, | 13 NinjaActionTargetWriter::NinjaActionTargetWriter(const Target* target, |
| 14 const Toolchain* toolchain, | 14 const Toolchain* toolchain, |
| 15 std::ostream& out) | 15 std::ostream& out) |
| 16 : NinjaTargetWriter(target, toolchain, out), | 16 : NinjaTargetWriter(target, toolchain, out), |
| 17 path_output_no_escaping_( | 17 path_output_no_escaping_( |
| 18 target->settings()->build_settings()->build_dir(), | 18 target->settings()->build_settings()->build_dir(), |
| 19 ESCAPE_NONE) { | 19 ESCAPE_NONE) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 NinjaActionTargetWriter::~NinjaActionTargetWriter() { | 22 NinjaActionTargetWriter::~NinjaActionTargetWriter() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 void NinjaActionTargetWriter::Run() { | 25 void NinjaActionTargetWriter::Run() { |
| 26 FileTemplate args_template(target_->action_values().args()); | 26 FileTemplate args_template(target_->settings(), |
| 27 target_->action_values().args()); |
| 27 std::string custom_rule_name = WriteRuleDefinition(args_template); | 28 std::string custom_rule_name = WriteRuleDefinition(args_template); |
| 28 | 29 |
| 29 // Collect our deps to pass as "extra hard dependencies" for input deps. This | 30 // Collect our deps to pass as "extra hard dependencies" for input deps. This |
| 30 // will force all of the action's dependencies to be completed before the | 31 // will force all of the action's dependencies to be completed before the |
| 31 // action is run. Usually, if an action has a dependency, it will be | 32 // action is run. Usually, if an action has a dependency, it will be |
| 32 // operating on the result of that previous step, so we need to be sure to | 33 // operating on the result of that previous step, so we need to be sure to |
| 33 // serialize these. | 34 // serialize these. |
| 34 std::vector<const Target*> extra_hard_deps; | 35 std::vector<const Target*> extra_hard_deps; |
| 35 for (size_t i = 0; i < target_->deps().size(); i++) | 36 for (size_t i = 0; i < target_->deps().size(); i++) |
| 36 extra_hard_deps.push_back(target_->deps()[i].ptr); | 37 extra_hard_deps.push_back(target_->deps()[i].ptr); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 out_ << " description = ACTION " << target_label << std::endl; | 130 out_ << " description = ACTION " << target_label << std::endl; |
| 130 out_ << " restat = 1" << std::endl; | 131 out_ << " restat = 1" << std::endl; |
| 131 } | 132 } |
| 132 | 133 |
| 133 return custom_rule_name; | 134 return custom_rule_name; |
| 134 } | 135 } |
| 135 | 136 |
| 136 void NinjaActionTargetWriter::WriteArgsSubstitutions( | 137 void NinjaActionTargetWriter::WriteArgsSubstitutions( |
| 137 const SourceFile& source, | 138 const SourceFile& source, |
| 138 const FileTemplate& args_template) { | 139 const FileTemplate& args_template) { |
| 139 std::ostringstream source_file_stream; | |
| 140 path_output_no_escaping_.WriteFile(source_file_stream, source); | |
| 141 | |
| 142 EscapeOptions template_escape_options; | 140 EscapeOptions template_escape_options; |
| 143 template_escape_options.mode = ESCAPE_NINJA_COMMAND; | 141 template_escape_options.mode = ESCAPE_NINJA_COMMAND; |
| 144 | 142 |
| 145 args_template.WriteNinjaVariablesForSubstitution( | 143 args_template.WriteNinjaVariablesForSubstitution( |
| 146 out_, source_file_stream.str(), template_escape_options); | 144 out_, target_->settings(), source, template_escape_options); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void NinjaActionTargetWriter::WriteSourceRules( | 147 void NinjaActionTargetWriter::WriteSourceRules( |
| 150 const std::string& custom_rule_name, | 148 const std::string& custom_rule_name, |
| 151 const std::string& implicit_deps, | 149 const std::string& implicit_deps, |
| 152 const FileTemplate& args_template, | 150 const FileTemplate& args_template, |
| 153 std::vector<OutputFile>* output_files) { | 151 std::vector<OutputFile>* output_files) { |
| 154 FileTemplate output_template(GetOutputTemplate()); | 152 FileTemplate output_template(GetOutputTemplate()); |
| 155 | 153 |
| 156 const Target::FileList& sources = target_->sources(); | 154 const Target::FileList& sources = target_->sources(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 199 } |
| 202 | 200 |
| 203 out_ << std::endl; | 201 out_ << std::endl; |
| 204 } | 202 } |
| 205 | 203 |
| 206 void NinjaActionTargetWriter::WriteOutputFilesForBuildLine( | 204 void NinjaActionTargetWriter::WriteOutputFilesForBuildLine( |
| 207 const FileTemplate& output_template, | 205 const FileTemplate& output_template, |
| 208 const SourceFile& source, | 206 const SourceFile& source, |
| 209 std::vector<OutputFile>* output_files) { | 207 std::vector<OutputFile>* output_files) { |
| 210 std::vector<std::string> output_template_result; | 208 std::vector<std::string> output_template_result; |
| 211 output_template.ApplyString(source.value(), &output_template_result); | 209 output_template.Apply(source, &output_template_result); |
| 212 for (size_t out_i = 0; out_i < output_template_result.size(); out_i++) { | 210 for (size_t out_i = 0; out_i < output_template_result.size(); out_i++) { |
| 213 OutputFile output_path(output_template_result[out_i]); | 211 OutputFile output_path(output_template_result[out_i]); |
| 214 output_files->push_back(output_path); | 212 output_files->push_back(output_path); |
| 215 out_ << " "; | 213 out_ << " "; |
| 216 path_output_.WriteFile(out_, output_path); | 214 path_output_.WriteFile(out_, output_path); |
| 217 } | 215 } |
| 218 } | 216 } |
| 219 | 217 |
| 220 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { | 218 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { |
| 221 std::vector<std::string> result; | 219 std::vector<std::string> result; |
| 222 GetDepfileTemplate().ApplyString(source.value(), &result); | 220 GetDepfileTemplate().Apply(source, &result); |
| 223 path_output_.WriteFile(out_, OutputFile(result[0])); | 221 path_output_.WriteFile(out_, OutputFile(result[0])); |
| 224 } | 222 } |
| 225 | 223 |
| 226 FileTemplate NinjaActionTargetWriter::GetDepfileTemplate() const { | 224 FileTemplate NinjaActionTargetWriter::GetDepfileTemplate() const { |
| 227 std::vector<std::string> template_args; | 225 std::vector<std::string> template_args; |
| 228 std::string depfile_relative_to_build_dir = | 226 std::string depfile_relative_to_build_dir = |
| 229 RemovePrefix(target_->action_values().depfile().value(), | 227 RemovePrefix(target_->action_values().depfile().value(), |
| 230 settings_->build_settings()->build_dir().value()); | 228 settings_->build_settings()->build_dir().value()); |
| 231 template_args.push_back(depfile_relative_to_build_dir); | 229 template_args.push_back(depfile_relative_to_build_dir); |
| 232 return FileTemplate(template_args); | 230 return FileTemplate(settings_, template_args); |
| 233 } | 231 } |
| OLD | NEW |