| 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 <fstream> | 7 #include <fstream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 writer.Run(); | 77 writer.Run(); |
| 78 } else { | 78 } else { |
| 79 CHECK(0); | 79 CHECK(0); |
| 80 } | 80 } |
| 81 | 81 |
| 82 std::string contents = file.str(); | 82 std::string contents = file.str(); |
| 83 base::WriteFile(ninja_file, contents.c_str(), | 83 base::WriteFile(ninja_file, contents.c_str(), |
| 84 static_cast<int>(contents.size())); | 84 static_cast<int>(contents.size())); |
| 85 } | 85 } |
| 86 | 86 |
| 87 std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep() const { | 87 std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep( |
| 88 const std::vector<const Target*>& extra_hard_deps) const { |
| 88 // For an action (where we run a script only once) the sources are the same | 89 // For an action (where we run a script only once) the sources are the same |
| 89 // as the source prereqs. | 90 // as the source prereqs. |
| 90 bool list_sources_as_input_deps = target_->output_type() == Target::ACTION; | 91 bool list_sources_as_input_deps = target_->output_type() == Target::ACTION; |
| 91 | 92 |
| 92 if (target_->source_prereqs().empty() && | 93 if (extra_hard_deps.empty() && |
| 94 target_->source_prereqs().empty() && |
| 93 target_->recursive_hard_deps().empty() && | 95 target_->recursive_hard_deps().empty() && |
| 94 (!list_sources_as_input_deps || target_->sources().empty())) | 96 (!list_sources_as_input_deps || target_->sources().empty())) |
| 95 return std::string(); // No input/hard deps. | 97 return std::string(); // No input/hard deps. |
| 96 | 98 |
| 97 // One potential optimization is if there are few input dependencies (or | 99 // One potential optimization is if there are few input dependencies (or |
| 98 // potentially few sources that depend on these) it's better to just write | 100 // potentially few sources that depend on these) it's better to just write |
| 99 // all hard deps on each sources line than have this intermediate stamp. We | 101 // all hard deps on each sources line than have this intermediate stamp. We |
| 100 // do the stamp file because duplicating all the order-only deps for each | 102 // do the stamp file because duplicating all the order-only deps for each |
| 101 // source file can really explode the ninja file but this won't be the most | 103 // source file can really explode the ninja file but this won't be the most |
| 102 // optimal thing in all cases. | 104 // optimal thing in all cases. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 126 } | 128 } |
| 127 | 129 |
| 128 // Add on any hard deps that are direct or indirect dependencies. | 130 // Add on any hard deps that are direct or indirect dependencies. |
| 129 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); | 131 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); |
| 130 for (std::set<const Target*>::const_iterator i = hard_deps.begin(); | 132 for (std::set<const Target*>::const_iterator i = hard_deps.begin(); |
| 131 i != hard_deps.end(); ++i) { | 133 i != hard_deps.end(); ++i) { |
| 132 out_ << " "; | 134 out_ << " "; |
| 133 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(*i)); | 135 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(*i)); |
| 134 } | 136 } |
| 135 | 137 |
| 138 // Extra hard deps passed in. |
| 139 for (size_t i = 0; i < extra_hard_deps.size(); i++) { |
| 140 out_ << " "; |
| 141 path_output_.WriteFile(out_, |
| 142 helper_.GetTargetOutputFile(extra_hard_deps[i])); |
| 143 } |
| 144 |
| 136 out_ << "\n"; | 145 out_ << "\n"; |
| 137 return " | " + stamp_file_string; | 146 return " | " + stamp_file_string; |
| 138 } | 147 } |
| 139 | 148 |
| 140 FileTemplate NinjaTargetWriter::GetOutputTemplate() const { | 149 FileTemplate NinjaTargetWriter::GetOutputTemplate() const { |
| 141 const Target::FileList& outputs = target_->action_values().outputs(); | 150 const Target::FileList& outputs = target_->action_values().outputs(); |
| 142 std::vector<std::string> output_template_args; | 151 std::vector<std::string> output_template_args; |
| 143 for (size_t i = 0; i < outputs.size(); i++) { | 152 for (size_t i = 0; i < outputs.size(); i++) { |
| 144 // All outputs should be in the output dir. | 153 // All outputs should be in the output dir. |
| 145 output_template_args.push_back( | 154 output_template_args.push_back( |
| 146 RemovePrefix(outputs[i].value(), | 155 RemovePrefix(outputs[i].value(), |
| 147 settings_->build_settings()->build_dir().value())); | 156 settings_->build_settings()->build_dir().value())); |
| 148 } | 157 } |
| 149 return FileTemplate(output_template_args); | 158 return FileTemplate(output_template_args); |
| 150 } | 159 } |
| OLD | NEW |