| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/build_settings.h" | 5 #include "tools/gn/build_settings.h" |
| 6 #include "tools/gn/filesystem_utils.h" | 6 #include "tools/gn/filesystem_utils.h" |
| 7 #include "tools/gn/functions.h" | 7 #include "tools/gn/functions.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/settings.h" | 10 #include "tools/gn/settings.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return result; | 64 return result; |
| 65 const std::string& string_value = value.string_value(); | 65 const std::string& string_value = value.string_value(); |
| 66 | 66 |
| 67 bool looks_like_dir = ValueLooksLikeDir(string_value); | 67 bool looks_like_dir = ValueLooksLikeDir(string_value); |
| 68 | 68 |
| 69 // System-absolute output special case. | 69 // System-absolute output special case. |
| 70 if (convert_to_system_absolute) { | 70 if (convert_to_system_absolute) { |
| 71 base::FilePath system_path; | 71 base::FilePath system_path; |
| 72 if (looks_like_dir) { | 72 if (looks_like_dir) { |
| 73 system_path = scope->settings()->build_settings()->GetFullPath( | 73 system_path = scope->settings()->build_settings()->GetFullPath( |
| 74 from_dir.ResolveRelativeDir(string_value, | 74 from_dir.ResolveRelativeDir(value, err, |
| 75 scope->settings()->build_settings()->root_path_utf8())); | 75 scope->settings()->build_settings()->root_path_utf8())); |
| 76 } else { | 76 } else { |
| 77 system_path = scope->settings()->build_settings()->GetFullPath( | 77 system_path = scope->settings()->build_settings()->GetFullPath( |
| 78 from_dir.ResolveRelativeFile(string_value, | 78 from_dir.ResolveRelativeFile(value, err, |
| 79 scope->settings()->build_settings()->root_path_utf8())); | 79 scope->settings()->build_settings()->root_path_utf8())); |
| 80 if (err->has_error()) |
| 81 return Value(); |
| 80 } | 82 } |
| 81 result = Value(function, FilePathToUTF8(system_path)); | 83 result = Value(function, FilePathToUTF8(system_path)); |
| 82 if (looks_like_dir) | 84 if (looks_like_dir) |
| 83 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 85 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
| 84 return result; | 86 return result; |
| 85 } | 87 } |
| 86 | 88 |
| 87 result = Value(function, Value::STRING); | 89 result = Value(function, Value::STRING); |
| 88 if (looks_like_dir) { | 90 if (looks_like_dir) { |
| 89 result.string_value() = RebasePath( | 91 result.string_value() = RebasePath( |
| 90 from_dir.ResolveRelativeDir(string_value, | 92 from_dir.ResolveRelativeDir(value, err, |
| 91 scope->settings()->build_settings()->root_path_utf8()).value(), | 93 scope->settings()->build_settings()->root_path_utf8()).value(), |
| 92 to_dir, | 94 to_dir, |
| 93 scope->settings()->build_settings()->root_path_utf8()); | 95 scope->settings()->build_settings()->root_path_utf8()); |
| 94 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 96 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
| 95 } else { | 97 } else { |
| 96 result.string_value() = RebasePath( | 98 result.string_value() = RebasePath( |
| 97 from_dir.ResolveRelativeFile(string_value, | 99 from_dir.ResolveRelativeFile(value, err, |
| 98 scope->settings()->build_settings()->root_path_utf8()).value(), | 100 scope->settings()->build_settings()->root_path_utf8()).value(), |
| 99 to_dir, | 101 to_dir, |
| 100 scope->settings()->build_settings()->root_path_utf8()); | 102 scope->settings()->build_settings()->root_path_utf8()); |
| 103 if (err->has_error()) |
| 104 return Value(); |
| 101 } | 105 } |
| 102 | 106 |
| 103 return result; | 107 return result; |
| 104 } | 108 } |
| 105 | 109 |
| 106 } // namespace | 110 } // namespace |
| 107 | 111 |
| 108 const char kRebasePath[] = "rebase_path"; | 112 const char kRebasePath[] = "rebase_path"; |
| 109 const char kRebasePath_HelpShort[] = | 113 const char kRebasePath_HelpShort[] = |
| 110 "rebase_path: Rebase a file or directory to another location."; | 114 "rebase_path: Rebase a file or directory to another location."; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 221 |
| 218 // To path. | 222 // To path. |
| 219 bool convert_to_system_absolute = true; | 223 bool convert_to_system_absolute = true; |
| 220 SourceDir to_dir; | 224 SourceDir to_dir; |
| 221 const SourceDir& current_dir = scope->GetSourceDir(); | 225 const SourceDir& current_dir = scope->GetSourceDir(); |
| 222 if (args.size() > kArgIndexDest) { | 226 if (args.size() > kArgIndexDest) { |
| 223 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) | 227 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) |
| 224 return result; | 228 return result; |
| 225 if (!args[kArgIndexDest].string_value().empty()) { | 229 if (!args[kArgIndexDest].string_value().empty()) { |
| 226 to_dir = current_dir.ResolveRelativeDir( | 230 to_dir = current_dir.ResolveRelativeDir( |
| 227 args[kArgIndexDest].string_value(), | 231 args[kArgIndexDest], err, |
| 228 scope->settings()->build_settings()->root_path_utf8()); | 232 scope->settings()->build_settings()->root_path_utf8()); |
| 229 convert_to_system_absolute = false; | 233 convert_to_system_absolute = false; |
| 230 } | 234 } |
| 231 } | 235 } |
| 232 | 236 |
| 233 // From path. | 237 // From path. |
| 234 SourceDir from_dir; | 238 SourceDir from_dir; |
| 235 if (args.size() > kArgIndexFrom) { | 239 if (args.size() > kArgIndexFrom) { |
| 236 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) | 240 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) |
| 237 return result; | 241 return result; |
| 238 from_dir = current_dir.ResolveRelativeDir( | 242 from_dir = current_dir.ResolveRelativeDir( |
| 239 args[kArgIndexFrom].string_value(), | 243 args[kArgIndexFrom], err, |
| 240 scope->settings()->build_settings()->root_path_utf8()); | 244 scope->settings()->build_settings()->root_path_utf8()); |
| 241 } else { | 245 } else { |
| 242 // Default to current directory if unspecified. | 246 // Default to current directory if unspecified. |
| 243 from_dir = current_dir; | 247 from_dir = current_dir; |
| 244 } | 248 } |
| 245 | 249 |
| 246 // Path conversion. | 250 // Path conversion. |
| 247 if (inputs.type() == Value::STRING) { | 251 if (inputs.type() == Value::STRING) { |
| 248 return ConvertOnePath(scope, function, inputs, | 252 return ConvertOnePath(scope, function, inputs, |
| 249 from_dir, to_dir, convert_to_system_absolute, err); | 253 from_dir, to_dir, convert_to_system_absolute, err); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 263 } | 267 } |
| 264 return result; | 268 return result; |
| 265 } | 269 } |
| 266 | 270 |
| 267 *err = Err(function->function(), | 271 *err = Err(function->function(), |
| 268 "rebase_path requires a list or a string."); | 272 "rebase_path requires a list or a string."); |
| 269 return result; | 273 return result; |
| 270 } | 274 } |
| 271 | 275 |
| 272 } // namespace functions | 276 } // namespace functions |
| OLD | NEW |