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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/create_bundle_target_generator.h"
6
7 #include "tools/gn/filesystem_utils.h"
8 #include "tools/gn/parse_tree.h"
9 #include "tools/gn/scope.h"
10 #include "tools/gn/substitution_type.h"
11 #include "tools/gn/target.h"
12 #include "tools/gn/value.h"
13 #include "tools/gn/variables.h"
14
15 CreateBundleTargetGenerator::CreateBundleTargetGenerator(
16 Target* target,
17 Scope* scope,
18 const FunctionCallNode* function_call,
19 Err* err)
20 : TargetGenerator(target, scope, function_call, err) {}
21
22 CreateBundleTargetGenerator::~CreateBundleTargetGenerator() {}
23
24 void CreateBundleTargetGenerator::DoRun() {
25 target_->set_output_type(Target::CREATE_BUNDLE);
26
27 BundleData& bundle_data = target_->bundle_data();
28 if (!GetBundleDir(std::string(),
29 variables::kBundleRootDir,
30 &bundle_data.root_dir()))
31 return;
32 if (!GetBundleDir(bundle_data.root_dir(),
33 variables::kBundleResourcesDir,
34 &bundle_data.resources_dir()))
35 return;
36 if (!GetBundleDir(bundle_data.root_dir(),
37 variables::kBundleExecutableDir,
38 &bundle_data.executable_dir()))
39 return;
40 if (!GetBundleDir(bundle_data.root_dir(),
41 variables::kBundlePlugInsDir,
42 &bundle_data.plugins_dir()))
43 return;
44 }
45
46 bool CreateBundleTargetGenerator::GetBundleDir(
47 const std::string& bundle_root_dir,
48 const base::StringPiece& name,
49 std::string* bundle_dir) {
50 const Value* value = scope_->GetValue(name, true);
51 if (!value)
52 return true;
53 if (!value->VerifyTypeIs(Value::STRING, err_))
54 return false;
55 const std::string& str = value->string_value();
56 if (!EnsureStringIsInOutputDir(GetBuildSettings()->build_dir(), str,
57 value->origin(), err_))
58 return false;
59 if (str != bundle_root_dir &&
60 !IsStringInOutputDir(SourceDir(bundle_root_dir), str)) {
61 *err_ = Err(value->origin(), "Path is not in bundle root dir.",
62 "The given file should be in the bundle root directory or below.\n"
63 "Normally you would do \"$bundle_root_dir/foo\". I interpreted this\n"
64 "as \"" + str + "\".");
65 return false;
66 }
67 bundle_dir->assign(value->string_value());
68 return true;
69 }
OLDNEW
« 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