| 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 } | 80 } |
| 81 if (err->has_error()) |
| 82 return Value(); |
| 83 |
| 81 result = Value(function, FilePathToUTF8(system_path)); | 84 result = Value(function, FilePathToUTF8(system_path)); |
| 82 if (looks_like_dir) | 85 if (looks_like_dir) |
| 83 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 86 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
| 84 return result; | 87 return result; |
| 85 } | 88 } |
| 86 | 89 |
| 87 result = Value(function, Value::STRING); | 90 result = Value(function, Value::STRING); |
| 88 if (looks_like_dir) { | 91 if (looks_like_dir) { |
| 89 result.string_value() = RebasePath( | 92 result.string_value() = RebasePath( |
| 90 from_dir.ResolveRelativeDir(string_value, | 93 from_dir.ResolveRelativeDir(value, err, |
| 91 scope->settings()->build_settings()->root_path_utf8()).value(), | 94 scope->settings()->build_settings()->root_path_utf8()).value(), |
| 92 to_dir, | 95 to_dir, |
| 93 scope->settings()->build_settings()->root_path_utf8()); | 96 scope->settings()->build_settings()->root_path_utf8()); |
| 94 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 97 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
| 95 } else { | 98 } else { |
| 96 result.string_value() = RebasePath( | 99 result.string_value() = RebasePath( |
| 97 from_dir.ResolveRelativeFile(string_value, | 100 from_dir.ResolveRelativeFile(value, err, |
| 98 scope->settings()->build_settings()->root_path_utf8()).value(), | 101 scope->settings()->build_settings()->root_path_utf8()).value(), |
| 99 to_dir, | 102 to_dir, |
| 100 scope->settings()->build_settings()->root_path_utf8()); | 103 scope->settings()->build_settings()->root_path_utf8()); |
| 104 if (err->has_error()) |
| 105 return Value(); |
| 101 } | 106 } |
| 102 | 107 |
| 103 return result; | 108 return result; |
| 104 } | 109 } |
| 105 | 110 |
| 106 } // namespace | 111 } // namespace |
| 107 | 112 |
| 108 const char kRebasePath[] = "rebase_path"; | 113 const char kRebasePath[] = "rebase_path"; |
| 109 const char kRebasePath_HelpShort[] = | 114 const char kRebasePath_HelpShort[] = |
| 110 "rebase_path: Rebase a file or directory to another location."; | 115 "rebase_path: Rebase a file or directory to another location."; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 222 |
| 218 // To path. | 223 // To path. |
| 219 bool convert_to_system_absolute = true; | 224 bool convert_to_system_absolute = true; |
| 220 SourceDir to_dir; | 225 SourceDir to_dir; |
| 221 const SourceDir& current_dir = scope->GetSourceDir(); | 226 const SourceDir& current_dir = scope->GetSourceDir(); |
| 222 if (args.size() > kArgIndexDest) { | 227 if (args.size() > kArgIndexDest) { |
| 223 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) | 228 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) |
| 224 return result; | 229 return result; |
| 225 if (!args[kArgIndexDest].string_value().empty()) { | 230 if (!args[kArgIndexDest].string_value().empty()) { |
| 226 to_dir = current_dir.ResolveRelativeDir( | 231 to_dir = current_dir.ResolveRelativeDir( |
| 227 args[kArgIndexDest].string_value(), | 232 args[kArgIndexDest], err, |
| 228 scope->settings()->build_settings()->root_path_utf8()); | 233 scope->settings()->build_settings()->root_path_utf8()); |
| 234 if (err->has_error()) |
| 235 return Value(); |
| 229 convert_to_system_absolute = false; | 236 convert_to_system_absolute = false; |
| 230 } | 237 } |
| 231 } | 238 } |
| 232 | 239 |
| 233 // From path. | 240 // From path. |
| 234 SourceDir from_dir; | 241 SourceDir from_dir; |
| 235 if (args.size() > kArgIndexFrom) { | 242 if (args.size() > kArgIndexFrom) { |
| 236 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) | 243 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) |
| 237 return result; | 244 return result; |
| 238 from_dir = current_dir.ResolveRelativeDir( | 245 from_dir = current_dir.ResolveRelativeDir( |
| 239 args[kArgIndexFrom].string_value(), | 246 args[kArgIndexFrom], err, |
| 240 scope->settings()->build_settings()->root_path_utf8()); | 247 scope->settings()->build_settings()->root_path_utf8()); |
| 248 if (err->has_error()) |
| 249 return Value(); |
| 241 } else { | 250 } else { |
| 242 // Default to current directory if unspecified. | 251 // Default to current directory if unspecified. |
| 243 from_dir = current_dir; | 252 from_dir = current_dir; |
| 244 } | 253 } |
| 245 | 254 |
| 246 // Path conversion. | 255 // Path conversion. |
| 247 if (inputs.type() == Value::STRING) { | 256 if (inputs.type() == Value::STRING) { |
| 248 return ConvertOnePath(scope, function, inputs, | 257 return ConvertOnePath(scope, function, inputs, |
| 249 from_dir, to_dir, convert_to_system_absolute, err); | 258 from_dir, to_dir, convert_to_system_absolute, err); |
| 250 | 259 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 263 } | 272 } |
| 264 return result; | 273 return result; |
| 265 } | 274 } |
| 266 | 275 |
| 267 *err = Err(function->function(), | 276 *err = Err(function->function(), |
| 268 "rebase_path requires a list or a string."); | 277 "rebase_path requires a list or a string."); |
| 269 return result; | 278 return result; |
| 270 } | 279 } |
| 271 | 280 |
| 272 } // namespace functions | 281 } // namespace functions |
| OLD | NEW |