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

Unified Diff: tools/gn/create_bundle_target_generator.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
« no previous file with comments | « tools/gn/create_bundle_target_generator.h ('k') | tools/gn/docs/reference.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/create_bundle_target_generator.cc
diff --git a/tools/gn/create_bundle_target_generator.cc b/tools/gn/create_bundle_target_generator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..206a91861e92cc6529f2477fc508d764c94fe16e
--- /dev/null
+++ b/tools/gn/create_bundle_target_generator.cc
@@ -0,0 +1,69 @@
+// 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/create_bundle_target_generator.h"
+
+#include "tools/gn/filesystem_utils.h"
+#include "tools/gn/parse_tree.h"
+#include "tools/gn/scope.h"
+#include "tools/gn/substitution_type.h"
+#include "tools/gn/target.h"
+#include "tools/gn/value.h"
+#include "tools/gn/variables.h"
+
+CreateBundleTargetGenerator::CreateBundleTargetGenerator(
+ Target* target,
+ Scope* scope,
+ const FunctionCallNode* function_call,
+ Err* err)
+ : TargetGenerator(target, scope, function_call, err) {}
+
+CreateBundleTargetGenerator::~CreateBundleTargetGenerator() {}
+
+void CreateBundleTargetGenerator::DoRun() {
+ target_->set_output_type(Target::CREATE_BUNDLE);
+
+ BundleData& bundle_data = target_->bundle_data();
+ if (!GetBundleDir(std::string(),
+ variables::kBundleRootDir,
+ &bundle_data.root_dir()))
+ return;
+ if (!GetBundleDir(bundle_data.root_dir(),
+ variables::kBundleResourcesDir,
+ &bundle_data.resources_dir()))
+ return;
+ if (!GetBundleDir(bundle_data.root_dir(),
+ variables::kBundleExecutableDir,
+ &bundle_data.executable_dir()))
+ return;
+ if (!GetBundleDir(bundle_data.root_dir(),
+ variables::kBundlePlugInsDir,
+ &bundle_data.plugins_dir()))
+ return;
+}
+
+bool CreateBundleTargetGenerator::GetBundleDir(
+ const std::string& bundle_root_dir,
+ const base::StringPiece& name,
+ std::string* bundle_dir) {
+ const Value* value = scope_->GetValue(name, true);
+ if (!value)
+ return true;
+ if (!value->VerifyTypeIs(Value::STRING, err_))
+ return false;
+ const std::string& str = value->string_value();
+ if (!EnsureStringIsInOutputDir(GetBuildSettings()->build_dir(), str,
+ value->origin(), err_))
+ return false;
+ if (str != bundle_root_dir &&
+ !IsStringInOutputDir(SourceDir(bundle_root_dir), str)) {
+ *err_ = Err(value->origin(), "Path is not in bundle root dir.",
+ "The given file should be in the bundle root directory or below.\n"
+ "Normally you would do \"$bundle_root_dir/foo\". I interpreted this\n"
+ "as \"" + str + "\".");
+ return false;
+ }
+ bundle_dir->assign(value->string_value());
+ return true;
+}
« no previous file with comments | « tools/gn/create_bundle_target_generator.h ('k') | tools/gn/docs/reference.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698