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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/ninja_create_bundle_target_writer.cc
diff --git a/tools/gn/ninja_create_bundle_target_writer.cc b/tools/gn/ninja_create_bundle_target_writer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b92001d6089a9ff871bfc5d6df6efbf817311936
--- /dev/null
+++ b/tools/gn/ninja_create_bundle_target_writer.cc
@@ -0,0 +1,115 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/ninja_create_bundle_target_writer.h"
+
+#include "tools/gn/filesystem_utils.h"
+#include "tools/gn/ninja_utils.h"
+#include "tools/gn/output_file.h"
+#include "tools/gn/scheduler.h"
+#include "tools/gn/substitution_writer.h"
+#include "tools/gn/target.h"
+#include "tools/gn/toolchain.h"
+
+namespace {
+
+void FailWithMissingToolError(Toolchain::ToolType tool, const Target* target) {
+ const std::string& tool_name = Toolchain::ToolTypeToName(tool);
+ g_scheduler->FailWithError(Err(
+ nullptr, tool_name + " tool not defined",
+ "The toolchain " +
+ target->toolchain()->label().GetUserVisibleName(false) + "\n"
+ "used by target " + target->label().GetUserVisibleName(false) + "\n"
+ "doesn't define a \"" + tool_name + "\" tool."));
+}
+
+} // namespace
+
+NinjaCreateBundleTargetWriter::NinjaCreateBundleTargetWriter(
+ const Target* target,
+ std::ostream& out)
+ : NinjaTargetWriter(target, out) {}
+
+NinjaCreateBundleTargetWriter::~NinjaCreateBundleTargetWriter() {}
+
+void NinjaCreateBundleTargetWriter::Run() {
+ if (!target_->toolchain()->GetTool(Toolchain::TYPE_COPY_BUNDLE_DATA)) {
+ FailWithMissingToolError(Toolchain::TYPE_COPY_BUNDLE_DATA, target_);
+ return;
+ }
+
+ if (!target_->toolchain()->GetTool(Toolchain::TYPE_COMPILE_XCASSETS)) {
+ FailWithMissingToolError(Toolchain::TYPE_COMPILE_XCASSETS, target_);
+ return;
+ }
+
+ if (!target_->toolchain()->GetTool(Toolchain::TYPE_STAMP)) {
+ FailWithMissingToolError(Toolchain::TYPE_STAMP, target_);
+ return;
+ }
+
+ std::vector<OutputFile> output_files;
+ OutputFile input_dep =
+ WriteInputDepsStampAndGetDep(std::vector<const Target*>());
+
+ for (const BundleFileRule& file_rule : target_->bundle_data().file_rules()) {
+ for (const SourceFile& source_file : file_rule.sources()) {
+ OutputFile output_file = file_rule.ApplyPatternToSourceAsOutputFile(
+ settings_, target_->bundle_data(), source_file);
+ output_files.push_back(output_file);
+
+ out_ << "build ";
+ path_output_.WriteFile(out_, output_file);
+ out_ << ": "
+ << GetNinjaRulePrefixForToolchain(settings_)
+ << Toolchain::ToolTypeToName(Toolchain::TYPE_COPY_BUNDLE_DATA)
+ << " ";
+ path_output_.WriteFile(out_, source_file);
+ if (!input_dep.value().empty()) {
+ out_ << " || ";
+ path_output_.WriteFile(out_, input_dep);
+ }
+ out_ << std::endl;
+ }
+ }
+
+ if (!target_->bundle_data().asset_catalog_sources().empty()) {
+ OutputFile output_file(
+ settings_->build_settings(),
+ target_->bundle_data().GetCompiledAssetCatalogPath());
+ output_files.push_back(output_file);
+
+ out_ << "build ";
+ path_output_.WriteFile(out_, output_file);
+ out_ << ": "
+ << GetNinjaRulePrefixForToolchain(settings_)
+ << Toolchain::ToolTypeToName(Toolchain::TYPE_COMPILE_XCASSETS);
+
+ std::set<SourceFile> asset_catalog_bundles;
+ for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
+ SourceFile asset_catalog_bundle;
+ CHECK(IsSourceFileFromAssetCatalog(source, &asset_catalog_bundle));
+ if (asset_catalog_bundles.find(asset_catalog_bundle) !=
+ asset_catalog_bundles.end())
+ continue;
+ out_ << " ";
+ path_output_.WriteFile(out_, asset_catalog_bundle);
+ asset_catalog_bundles.insert(asset_catalog_bundle);
+ }
+
+ out_ << " |";
+ for (const auto& source : target_->bundle_data().asset_catalog_sources()) {
+ out_ << " ";
+ path_output_.WriteFile(out_, source);
+ }
+ if (!input_dep.value().empty()) {
+ out_ << " || ";
+ path_output_.WriteFile(out_, input_dep);
+ }
+ out_ << std::endl;
+ }
+
+ out_ << std::endl;
+ WriteStampForTarget(output_files, std::vector<OutputFile>());
+}
« 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