| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/create_bundle_target_generator.h" | 5 #include "tools/gn/create_bundle_target_generator.h" |
| 6 | 6 |
| 7 #include "tools/gn/filesystem_utils.h" | 7 #include "tools/gn/filesystem_utils.h" |
| 8 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
| 9 #include "tools/gn/scope.h" | 9 #include "tools/gn/scope.h" |
| 10 #include "tools/gn/substitution_type.h" | 10 #include "tools/gn/substitution_type.h" |
| 11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
| 12 #include "tools/gn/value.h" | 12 #include "tools/gn/value.h" |
| 13 #include "tools/gn/variables.h" | 13 #include "tools/gn/variables.h" |
| 14 | 14 |
| 15 CreateBundleTargetGenerator::CreateBundleTargetGenerator( | 15 CreateBundleTargetGenerator::CreateBundleTargetGenerator( |
| 16 Target* target, | 16 Target* target, |
| 17 Scope* scope, | 17 Scope* scope, |
| 18 const FunctionCallNode* function_call, | 18 const FunctionCallNode* function_call, |
| 19 Err* err) | 19 Err* err) |
| 20 : TargetGenerator(target, scope, function_call, err) {} | 20 : TargetGenerator(target, scope, function_call, err) {} |
| 21 | 21 |
| 22 CreateBundleTargetGenerator::~CreateBundleTargetGenerator() {} | 22 CreateBundleTargetGenerator::~CreateBundleTargetGenerator() {} |
| 23 | 23 |
| 24 void CreateBundleTargetGenerator::DoRun() { | 24 void CreateBundleTargetGenerator::DoRun() { |
| 25 target_->set_output_type(Target::CREATE_BUNDLE); | 25 target_->set_output_type(Target::CREATE_BUNDLE); |
| 26 | 26 |
| 27 BundleData& bundle_data = target_->bundle_data(); | 27 BundleData& bundle_data = target_->bundle_data(); |
| 28 if (!GetBundleDir(std::string(), | 28 if (!GetBundleDir(SourceDir(), |
| 29 variables::kBundleRootDir, | 29 variables::kBundleRootDir, |
| 30 &bundle_data.root_dir())) | 30 &bundle_data.root_dir())) |
| 31 return; | 31 return; |
| 32 if (!GetBundleDir(bundle_data.root_dir(), | 32 if (!GetBundleDir(bundle_data.root_dir(), |
| 33 variables::kBundleResourcesDir, | 33 variables::kBundleResourcesDir, |
| 34 &bundle_data.resources_dir())) | 34 &bundle_data.resources_dir())) |
| 35 return; | 35 return; |
| 36 if (!GetBundleDir(bundle_data.root_dir(), | 36 if (!GetBundleDir(bundle_data.root_dir(), |
| 37 variables::kBundleExecutableDir, | 37 variables::kBundleExecutableDir, |
| 38 &bundle_data.executable_dir())) | 38 &bundle_data.executable_dir())) |
| 39 return; | 39 return; |
| 40 if (!GetBundleDir(bundle_data.root_dir(), | 40 if (!GetBundleDir(bundle_data.root_dir(), |
| 41 variables::kBundlePlugInsDir, | 41 variables::kBundlePlugInsDir, |
| 42 &bundle_data.plugins_dir())) | 42 &bundle_data.plugins_dir())) |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool CreateBundleTargetGenerator::GetBundleDir( | 46 bool CreateBundleTargetGenerator::GetBundleDir( |
| 47 const std::string& bundle_root_dir, | 47 const SourceDir& bundle_root_dir, |
| 48 const base::StringPiece& name, | 48 const base::StringPiece& name, |
| 49 std::string* bundle_dir) { | 49 SourceDir* bundle_dir) { |
| 50 const Value* value = scope_->GetValue(name, true); | 50 const Value* value = scope_->GetValue(name, true); |
| 51 if (!value) | 51 if (!value) |
| 52 return true; | 52 return true; |
| 53 if (!value->VerifyTypeIs(Value::STRING, err_)) | 53 if (!value->VerifyTypeIs(Value::STRING, err_)) |
| 54 return false; | 54 return false; |
| 55 const std::string& str = value->string_value(); | 55 std::string str = value->string_value(); |
| 56 if (!EnsureStringIsInOutputDir(GetBuildSettings()->build_dir(), str, | 56 if (!EnsureStringIsInOutputDir(GetBuildSettings()->build_dir(), str, |
| 57 value->origin(), err_)) | 57 value->origin(), err_)) |
| 58 return false; | 58 return false; |
| 59 if (str != bundle_root_dir && | 59 if (str != bundle_root_dir.value() && |
| 60 !IsStringInOutputDir(SourceDir(bundle_root_dir), str)) { | 60 !IsStringInOutputDir(bundle_root_dir, str)) { |
| 61 *err_ = Err(value->origin(), "Path is not in bundle root dir.", | 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" | 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" | 63 "Normally you would do \"$bundle_root_dir/foo\". I interpreted this\n" |
| 64 "as \"" + str + "\"."); | 64 "as \"" + str + "\"."); |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 bundle_dir->assign(value->string_value()); | 67 bundle_dir->SwapValue(&str); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| OLD | NEW |