| 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/deps_iterator.h" | 8 #include "tools/gn/deps_iterator.h" |
| 9 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
| 10 #include "tools/gn/settings.h" | 10 #include "tools/gn/settings.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 WriteDepfile(SourceFile()); | 73 WriteDepfile(SourceFile()); |
| 74 out_ << std::endl; | 74 out_ << std::endl; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 out_ << std::endl; | 77 out_ << std::endl; |
| 78 | 78 |
| 79 // Write the stamp, which also depends on all data deps. These are needed at | 79 // Write the stamp, which also depends on all data deps. These are needed at |
| 80 // runtime and should be compiled when the action is, but don't need to be | 80 // runtime and should be compiled when the action is, but don't need to be |
| 81 // done before we run the action. | 81 // done before we run the action. |
| 82 std::vector<OutputFile> data_outs; | 82 std::vector<OutputFile> data_outs; |
| 83 for (size_t i = 0; i < target_->data_deps().size(); i++) | 83 for (const auto& dep : target_->data_deps()) |
| 84 data_outs.push_back(target_->data_deps()[i].ptr->dependency_output_file()); | 84 data_outs.push_back(dep.ptr->dependency_output_file()); |
| 85 WriteStampForTarget(output_files, data_outs); | 85 WriteStampForTarget(output_files, data_outs); |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string NinjaActionTargetWriter::WriteRuleDefinition() { | 88 std::string NinjaActionTargetWriter::WriteRuleDefinition() { |
| 89 // Make a unique name for this rule. | 89 // Make a unique name for this rule. |
| 90 // | 90 // |
| 91 // Use a unique name for the response file when there are multiple build | 91 // Use a unique name for the response file when there are multiple build |
| 92 // steps so that they don't stomp on each other. When there are no sources, | 92 // steps so that they don't stomp on each other. When there are no sources, |
| 93 // there will be only one invocation so we can use a simple name. | 93 // there will be only one invocation so we can use a simple name. |
| 94 std::string target_label = target_->label().GetUserVisibleName(true); | 94 std::string target_label = target_->label().GetUserVisibleName(true); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 117 << std::endl; | 117 << std::endl; |
| 118 out_ << " description = ACTION " << target_label << std::endl; | 118 out_ << " description = ACTION " << target_label << std::endl; |
| 119 out_ << " restat = 1" << std::endl; | 119 out_ << " restat = 1" << std::endl; |
| 120 out_ << " rspfile = " << rspfile << std::endl; | 120 out_ << " rspfile = " << rspfile << std::endl; |
| 121 | 121 |
| 122 // The build command goes in the rsp file. | 122 // The build command goes in the rsp file. |
| 123 out_ << " rspfile_content = "; | 123 out_ << " rspfile_content = "; |
| 124 path_output_.WriteFile(out_, settings_->build_settings()->python_path()); | 124 path_output_.WriteFile(out_, settings_->build_settings()->python_path()); |
| 125 out_ << " "; | 125 out_ << " "; |
| 126 path_output_.WriteFile(out_, target_->action_values().script()); | 126 path_output_.WriteFile(out_, target_->action_values().script()); |
| 127 for (size_t i = 0; i < args.list().size(); i++) { | 127 for (const auto& arg : args.list()) { |
| 128 out_ << " "; | 128 out_ << " "; |
| 129 SubstitutionWriter::WriteWithNinjaVariables( | 129 SubstitutionWriter::WriteWithNinjaVariables( |
| 130 args.list()[i], args_escape_options, out_); | 130 arg, args_escape_options, out_); |
| 131 } | 131 } |
| 132 out_ << std::endl; | 132 out_ << std::endl; |
| 133 } else { | 133 } else { |
| 134 // Posix can execute Python directly. | 134 // Posix can execute Python directly. |
| 135 out_ << "rule " << custom_rule_name << std::endl; | 135 out_ << "rule " << custom_rule_name << std::endl; |
| 136 out_ << " command = "; | 136 out_ << " command = "; |
| 137 path_output_.WriteFile(out_, settings_->build_settings()->python_path()); | 137 path_output_.WriteFile(out_, settings_->build_settings()->python_path()); |
| 138 out_ << " "; | 138 out_ << " "; |
| 139 path_output_.WriteFile(out_, target_->action_values().script()); | 139 path_output_.WriteFile(out_, target_->action_values().script()); |
| 140 for (size_t i = 0; i < args.list().size(); i++) { | 140 for (const auto& arg : args.list()) { |
| 141 out_ << " "; | 141 out_ << " "; |
| 142 SubstitutionWriter::WriteWithNinjaVariables( | 142 SubstitutionWriter::WriteWithNinjaVariables( |
| 143 args.list()[i], args_escape_options, out_); | 143 arg, args_escape_options, out_); |
| 144 } | 144 } |
| 145 out_ << std::endl; | 145 out_ << std::endl; |
| 146 out_ << " description = ACTION " << target_label << std::endl; | 146 out_ << " description = ACTION " << target_label << std::endl; |
| 147 out_ << " restat = 1" << std::endl; | 147 out_ << " restat = 1" << std::endl; |
| 148 } | 148 } |
| 149 | 149 |
| 150 return custom_rule_name; | 150 return custom_rule_name; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void NinjaActionTargetWriter::WriteSourceRules( | 153 void NinjaActionTargetWriter::WriteSourceRules( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 out_ << " "; | 208 out_ << " "; |
| 209 path_output_.WriteFile(out_, (*output_files)[i]); | 209 path_output_.WriteFile(out_, (*output_files)[i]); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { | 213 void NinjaActionTargetWriter::WriteDepfile(const SourceFile& source) { |
| 214 path_output_.WriteFile(out_, | 214 path_output_.WriteFile(out_, |
| 215 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( | 215 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( |
| 216 settings_, target_->action_values().depfile(), source)); | 216 settings_, target_->action_values().depfile(), source)); |
| 217 } | 217 } |
| OLD | NEW |