Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "tools/gn/ninja_create_bundle_target_writer.h" | |
| 6 | |
| 7 #include "tools/gn/filesystem_utils.h" | |
| 8 #include "tools/gn/ninja_utils.h" | |
| 9 #include "tools/gn/output_file.h" | |
| 10 #include "tools/gn/scheduler.h" | |
| 11 #include "tools/gn/substitution_writer.h" | |
| 12 #include "tools/gn/target.h" | |
| 13 #include "tools/gn/toolchain.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 void FailWithMissingToolError(Toolchain::ToolType tool, | |
| 18 const Target* target) { | |
| 19 const std::string& tool_name = Toolchain::ToolTypeToName(tool); | |
| 20 g_scheduler->FailWithError(Err( | |
| 21 nullptr, tool_name + " tool not defined", | |
| 22 "The toolchain " + | |
| 23 target->toolchain()->label().GetUserVisibleName(false) + "\n" | |
| 24 "used by target " + target->label().GetUserVisibleName(false) + "\n" | |
| 25 "doesn't define a \"" + tool_name + "\" tool.")); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 NinjaCreateBundleTargetWriter::NinjaCreateBundleTargetWriter( | |
| 31 const Target* target, | |
| 32 std::ostream& out) | |
| 33 : NinjaTargetWriter(target, out) {} | |
| 34 | |
| 35 NinjaCreateBundleTargetWriter::~NinjaCreateBundleTargetWriter() {} | |
| 36 | |
| 37 void NinjaCreateBundleTargetWriter::Run() { | |
| 38 if (!target_->toolchain()->GetTool(Toolchain::TYPE_COPY_BUNDLE_DATA)) { | |
|
brettw
2016/03/02 21:12:42
We should have a unit test file for this like we d
sdefresne
2016/03/07 20:47:35
Done.
| |
| 39 FailWithMissingToolError(Toolchain::TYPE_COPY_BUNDLE_DATA, target_); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 if (!target_->toolchain()->GetTool(Toolchain::TYPE_COMPILE_XCASSETS)) { | |
| 44 FailWithMissingToolError(Toolchain::TYPE_COMPILE_XCASSETS, target_); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 if (!target_->toolchain()->GetTool(Toolchain::TYPE_STAMP)) { | |
| 49 FailWithMissingToolError(Toolchain::TYPE_STAMP, target_); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 std::vector<OutputFile> output_files; | |
| 54 OutputFile input_dep = | |
| 55 WriteInputDepsStampAndGetDep(std::vector<const Target*>()); | |
| 56 | |
| 57 for (const BundleFileRule& file_rule : target_->bundle_data().file_rules()) { | |
| 58 for (const SourceFile& source_file : file_rule.sources()) { | |
| 59 OutputFile output_file = file_rule.ApplyPatternToSourceAsOutputFile( | |
| 60 settings_, target_->bundle_data(), source_file); | |
| 61 output_files.push_back(output_file); | |
| 62 | |
| 63 out_ << "build "; | |
| 64 path_output_.WriteFile(out_, output_file); | |
| 65 out_ << ": " | |
| 66 << GetNinjaRulePrefixForToolchain(settings_) | |
| 67 << Toolchain::ToolTypeToName(Toolchain::TYPE_COPY_BUNDLE_DATA) | |
| 68 << " "; | |
| 69 path_output_.WriteFile(out_, source_file); | |
| 70 if (!input_dep.value().empty()) { | |
| 71 out_ << " || "; | |
| 72 path_output_.WriteFile(out_, input_dep); | |
| 73 } | |
| 74 out_ << std::endl; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 if (!target_->bundle_data().asset_catalog_sources().empty()) { | |
| 79 OutputFile output_file( | |
| 80 settings_->build_settings(), | |
| 81 target_->bundle_data().GetCompiledAssetCatalogPath()); | |
| 82 output_files.push_back(output_file); | |
| 83 | |
| 84 out_ << "build "; | |
| 85 path_output_.WriteFile(out_, output_file); | |
| 86 out_ << ": " | |
| 87 << GetNinjaRulePrefixForToolchain(settings_) | |
| 88 << Toolchain::ToolTypeToName(Toolchain::TYPE_COMPILE_XCASSETS); | |
| 89 | |
| 90 std::set<SourceFile> asset_catalog_bundles; | |
| 91 for (const auto& source : target_->bundle_data().asset_catalog_sources()) { | |
| 92 SourceFile asset_catalog_bundle; | |
| 93 CHECK(IsSourceFileFromAssetCatalog(source, &asset_catalog_bundle)); | |
| 94 if (asset_catalog_bundles.find(asset_catalog_bundle) != | |
| 95 asset_catalog_bundles.end()) | |
| 96 continue; | |
| 97 out_ << " "; | |
| 98 path_output_.WriteFile(out_, asset_catalog_bundle); | |
| 99 asset_catalog_bundles.insert(asset_catalog_bundle); | |
| 100 } | |
| 101 | |
| 102 out_ << " |"; | |
| 103 for (const auto& source : target_->bundle_data().asset_catalog_sources()) { | |
| 104 out_ << " "; | |
| 105 path_output_.WriteFile(out_, source); | |
| 106 } | |
| 107 if (!input_dep.value().empty()) { | |
| 108 out_ << " || "; | |
| 109 path_output_.WriteFile(out_, input_dep); | |
| 110 } | |
| 111 out_ << std::endl; | |
| 112 } | |
| 113 | |
| 114 out_ << std::endl; | |
| 115 WriteStampForTarget(output_files, std::vector<OutputFile>()); | |
| 116 } | |
| OLD | NEW |