| 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" |
| 11 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
| 12 #include "tools/gn/escape.h" | 12 #include "tools/gn/escape.h" |
| 13 #include "tools/gn/filesystem_utils.h" | 13 #include "tools/gn/filesystem_utils.h" |
| 14 #include "tools/gn/ninja_action_target_writer.h" | 14 #include "tools/gn/ninja_action_target_writer.h" |
| 15 #include "tools/gn/ninja_binary_target_writer.h" | 15 #include "tools/gn/ninja_binary_target_writer.h" |
| 16 #include "tools/gn/ninja_bundle_data_target_writer.h" | 16 #include "tools/gn/ninja_bundle_data_target_writer.h" |
| 17 #include "tools/gn/ninja_copy_target_writer.h" | 17 #include "tools/gn/ninja_copy_target_writer.h" |
| 18 #include "tools/gn/ninja_create_bundle_target_writer.h" |
| 18 #include "tools/gn/ninja_group_target_writer.h" | 19 #include "tools/gn/ninja_group_target_writer.h" |
| 19 #include "tools/gn/ninja_utils.h" | 20 #include "tools/gn/ninja_utils.h" |
| 20 #include "tools/gn/output_file.h" | 21 #include "tools/gn/output_file.h" |
| 21 #include "tools/gn/scheduler.h" | 22 #include "tools/gn/scheduler.h" |
| 22 #include "tools/gn/string_utils.h" | 23 #include "tools/gn/string_utils.h" |
| 23 #include "tools/gn/substitution_writer.h" | 24 #include "tools/gn/substitution_writer.h" |
| 24 #include "tools/gn/target.h" | 25 #include "tools/gn/target.h" |
| 25 #include "tools/gn/trace.h" | 26 #include "tools/gn/trace.h" |
| 26 | 27 |
| 27 NinjaTargetWriter::NinjaTargetWriter(const Target* target, | 28 NinjaTargetWriter::NinjaTargetWriter(const Target* target, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 base::CreateDirectory(ninja_file.DirName()); | 55 base::CreateDirectory(ninja_file.DirName()); |
| 55 | 56 |
| 56 // It's ridiculously faster to write to a string and then write that to | 57 // It's ridiculously faster to write to a string and then write that to |
| 57 // disk in one operation than to use an fstream here. | 58 // disk in one operation than to use an fstream here. |
| 58 std::stringstream file; | 59 std::stringstream file; |
| 59 | 60 |
| 60 // Call out to the correct sub-type of writer. | 61 // Call out to the correct sub-type of writer. |
| 61 if (target->output_type() == Target::BUNDLE_DATA) { | 62 if (target->output_type() == Target::BUNDLE_DATA) { |
| 62 NinjaBundleDataTargetWriter writer(target, file); | 63 NinjaBundleDataTargetWriter writer(target, file); |
| 63 writer.Run(); | 64 writer.Run(); |
| 65 } else if (target->output_type() == Target::CREATE_BUNDLE) { |
| 66 NinjaCreateBundleTargetWriter writer(target, file); |
| 67 writer.Run(); |
| 64 } else if (target->output_type() == Target::COPY_FILES) { | 68 } else if (target->output_type() == Target::COPY_FILES) { |
| 65 NinjaCopyTargetWriter writer(target, file); | 69 NinjaCopyTargetWriter writer(target, file); |
| 66 writer.Run(); | 70 writer.Run(); |
| 67 } else if (target->output_type() == Target::ACTION || | 71 } else if (target->output_type() == Target::ACTION || |
| 68 target->output_type() == Target::ACTION_FOREACH) { | 72 target->output_type() == Target::ACTION_FOREACH) { |
| 69 NinjaActionTargetWriter writer(target, file); | 73 NinjaActionTargetWriter writer(target, file); |
| 70 writer.Run(); | 74 writer.Run(); |
| 71 } else if (target->output_type() == Target::GROUP) { | 75 } else if (target->output_type() == Target::GROUP) { |
| 72 NinjaGroupTargetWriter writer(target, file); | 76 NinjaGroupTargetWriter writer(target, file); |
| 73 writer.Run(); | 77 writer.Run(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 162 |
| 159 // Actions get implicit dependencies on the script itself. | 163 // Actions get implicit dependencies on the script itself. |
| 160 if (target_->output_type() == Target::ACTION || | 164 if (target_->output_type() == Target::ACTION || |
| 161 target_->output_type() == Target::ACTION_FOREACH) | 165 target_->output_type() == Target::ACTION_FOREACH) |
| 162 input_deps_sources.push_back(&target_->action_values().script()); | 166 input_deps_sources.push_back(&target_->action_values().script()); |
| 163 | 167 |
| 164 // Input files. | 168 // Input files. |
| 165 for (const auto& input : target_->inputs()) | 169 for (const auto& input : target_->inputs()) |
| 166 input_deps_sources.push_back(&input); | 170 input_deps_sources.push_back(&input); |
| 167 | 171 |
| 168 // For an action (where we run a script only once) and bundle_data target the | 172 // For an action (where we run a script only once) the sources are the same |
| 169 // sources are the same as the inputs. For action_foreach, the sources will | 173 // as the inputs. For action_foreach, the sources will be operated on |
| 170 // be operated on separately so don't handle them here. | 174 // separately so don't handle them here. |
| 171 if (target_->output_type() == Target::ACTION || | 175 if (target_->output_type() == Target::ACTION) { |
| 172 target_->output_type() == Target::BUNDLE_DATA) { | |
| 173 for (const auto& source : target_->sources()) | 176 for (const auto& source : target_->sources()) |
| 174 input_deps_sources.push_back(&source); | 177 input_deps_sources.push_back(&source); |
| 175 } | 178 } |
| 176 | 179 |
| 177 // ---------- | 180 // ---------- |
| 178 // Collect all target input dependencies of this target as was done for the | 181 // Collect all target input dependencies of this target as was done for the |
| 179 // files above. | 182 // files above. |
| 180 std::vector<const Target*> input_deps_targets; | 183 std::vector<const Target*> input_deps_targets; |
| 181 input_deps_targets.reserve(32); | 184 input_deps_targets.reserve(32); |
| 182 | 185 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 << GetNinjaRulePrefixForToolchain(settings_) | 280 << GetNinjaRulePrefixForToolchain(settings_) |
| 278 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); | 281 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); |
| 279 path_output_.WriteFiles(out_, files); | 282 path_output_.WriteFiles(out_, files); |
| 280 | 283 |
| 281 if (!order_only_deps.empty()) { | 284 if (!order_only_deps.empty()) { |
| 282 out_ << " ||"; | 285 out_ << " ||"; |
| 283 path_output_.WriteFiles(out_, order_only_deps); | 286 path_output_.WriteFiles(out_, order_only_deps); |
| 284 } | 287 } |
| 285 out_ << std::endl; | 288 out_ << std::endl; |
| 286 } | 289 } |
| OLD | NEW |