Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: tools/gn/ninja_create_bundle_target_writer.cc

Issue 1752033002: Add "create_bundle" target in order to support bundle with gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-bundle-data
Patch Set: Add unit tests, address comments, update docs and format with clang-format Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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, const Target* target) {
18 const std::string& tool_name = Toolchain::ToolTypeToName(tool);
19 g_scheduler->FailWithError(Err(
20 nullptr, tool_name + " tool not defined",
21 "The toolchain " +
22 target->toolchain()->label().GetUserVisibleName(false) + "\n"
23 "used by target " + target->label().GetUserVisibleName(false) + "\n"
24 "doesn't define a \"" + tool_name + "\" tool."));
25 }
26
27 } // namespace
28
29 NinjaCreateBundleTargetWriter::NinjaCreateBundleTargetWriter(
30 const Target* target,
31 std::ostream& out)
32 : NinjaTargetWriter(target, out) {}
33
34 NinjaCreateBundleTargetWriter::~NinjaCreateBundleTargetWriter() {}
35
36 void NinjaCreateBundleTargetWriter::Run() {
37 if (!target_->toolchain()->GetTool(Toolchain::TYPE_COPY_BUNDLE_DATA)) {
38 FailWithMissingToolError(Toolchain::TYPE_COPY_BUNDLE_DATA, target_);
39 return;
40 }
41
42 if (!target_->toolchain()->GetTool(Toolchain::TYPE_COMPILE_XCASSETS)) {
43 FailWithMissingToolError(Toolchain::TYPE_COMPILE_XCASSETS, target_);
44 return;
45 }
46
47 if (!target_->toolchain()->GetTool(Toolchain::TYPE_STAMP)) {
48 FailWithMissingToolError(Toolchain::TYPE_STAMP, target_);
49 return;
50 }
51
52 std::vector<OutputFile> output_files;
53 OutputFile input_dep =
54 WriteInputDepsStampAndGetDep(std::vector<const Target*>());
55
56 for (const BundleFileRule& file_rule : target_->bundle_data().file_rules()) {
57 for (const SourceFile& source_file : file_rule.sources()) {
58 OutputFile output_file = file_rule.ApplyPatternToSourceAsOutputFile(
59 settings_, target_->bundle_data(), source_file);
60 output_files.push_back(output_file);
61
62 out_ << "build ";
63 path_output_.WriteFile(out_, output_file);
64 out_ << ": "
65 << GetNinjaRulePrefixForToolchain(settings_)
66 << Toolchain::ToolTypeToName(Toolchain::TYPE_COPY_BUNDLE_DATA)
67 << " ";
68 path_output_.WriteFile(out_, source_file);
69 if (!input_dep.value().empty()) {
70 out_ << " || ";
71 path_output_.WriteFile(out_, input_dep);
72 }
73 out_ << std::endl;
74 }
75 }
76
77 if (!target_->bundle_data().asset_catalog_sources().empty()) {
78 OutputFile output_file(
79 settings_->build_settings(),
80 target_->bundle_data().GetCompiledAssetCatalogPath());
81 output_files.push_back(output_file);
82
83 out_ << "build ";
84 path_output_.WriteFile(out_, output_file);
85 out_ << ": "
86 << GetNinjaRulePrefixForToolchain(settings_)
87 << Toolchain::ToolTypeToName(Toolchain::TYPE_COMPILE_XCASSETS);
88
89 std::set<SourceFile> asset_catalog_bundles;
90 for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
91 SourceFile asset_catalog_bundle;
92 CHECK(IsSourceFileFromAssetCatalog(source, &asset_catalog_bundle));
93 if (asset_catalog_bundles.find(asset_catalog_bundle) !=
94 asset_catalog_bundles.end())
95 continue;
96 out_ << " ";
97 path_output_.WriteFile(out_, asset_catalog_bundle);
98 asset_catalog_bundles.insert(asset_catalog_bundle);
99 }
100
101 out_ << " |";
102 for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
103 out_ << " ";
104 path_output_.WriteFile(out_, source);
105 }
106 if (!input_dep.value().empty()) {
107 out_ << " || ";
108 path_output_.WriteFile(out_, input_dep);
109 }
110 out_ << std::endl;
111 }
112
113 out_ << std::endl;
114 WriteStampForTarget(output_files, std::vector<OutputFile>());
115 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_create_bundle_target_writer.h ('k') | tools/gn/ninja_create_bundle_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698