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/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 } |
OLD | NEW |