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(string_value, |
75 scope->settings()->build_settings()->root_path_utf8())); | |
75 } else { | 76 } else { |
76 system_path = scope->settings()->build_settings()->GetFullPath( | 77 system_path = scope->settings()->build_settings()->GetFullPath( |
77 from_dir.ResolveRelativeFile(string_value)); | 78 from_dir.ResolveRelativeFile(string_value, |
79 scope->settings()->build_settings()->root_path_utf8())); | |
78 } | 80 } |
79 result = Value(function, FilePathToUTF8(system_path)); | 81 result = Value(function, FilePathToUTF8(system_path)); |
80 if (looks_like_dir) | 82 if (looks_like_dir) |
81 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 83 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
82 return result; | 84 return result; |
83 } | 85 } |
84 | 86 |
85 if (from_dir.is_system_absolute() || to_dir.is_system_absolute()) { | |
86 *err = Err(function, "System-absolute directories are not supported for " | |
87 "the source or dest dir for rebase_path. It would be nice to add this " | |
88 "if you're so inclined!"); | |
89 return result; | |
90 } | |
91 | |
92 result = Value(function, Value::STRING); | 87 result = Value(function, Value::STRING); |
93 if (looks_like_dir) { | 88 if (looks_like_dir) { |
94 result.string_value() = RebaseSourceAbsolutePath( | 89 result.string_value() = RebaseSourceAbsolutePath( |
95 from_dir.ResolveRelativeDir(string_value).value(), | 90 from_dir.ResolveRelativeDir(string_value, |
brettw
2014/11/05 19:59:49
Can you add a quick test for these file and dir ca
zeuthen
2014/11/07 19:24:12
OK, sure thing. Done.
| |
96 to_dir); | 91 scope->settings()->build_settings()->root_path_utf8()).value(), |
92 to_dir, | |
93 scope->settings()->build_settings()->root_path_utf8()); | |
97 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 94 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
98 } else { | 95 } else { |
99 result.string_value() = RebaseSourceAbsolutePath( | 96 result.string_value() = RebaseSourceAbsolutePath( |
100 from_dir.ResolveRelativeFile(string_value).value(), | 97 from_dir.ResolveRelativeFile(string_value, |
101 to_dir); | 98 scope->settings()->build_settings()->root_path_utf8()).value(), |
99 to_dir, | |
100 scope->settings()->build_settings()->root_path_utf8()); | |
102 } | 101 } |
103 | 102 |
104 return result; | 103 return result; |
105 } | 104 } |
106 | 105 |
107 } // namespace | 106 } // namespace |
108 | 107 |
109 const char kRebasePath[] = "rebase_path"; | 108 const char kRebasePath[] = "rebase_path"; |
110 const char kRebasePath_HelpShort[] = | 109 const char kRebasePath_HelpShort[] = |
111 "rebase_path: Rebase a file or directory to another location."; | 110 "rebase_path: Rebase a file or directory to another location."; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 const Value& inputs = args[kArgIndexInputs]; | 225 const Value& inputs = args[kArgIndexInputs]; |
227 | 226 |
228 // To path. | 227 // To path. |
229 bool convert_to_system_absolute = true; | 228 bool convert_to_system_absolute = true; |
230 SourceDir to_dir; | 229 SourceDir to_dir; |
231 const SourceDir& current_dir = scope->GetSourceDir(); | 230 const SourceDir& current_dir = scope->GetSourceDir(); |
232 if (args.size() > kArgIndexDest) { | 231 if (args.size() > kArgIndexDest) { |
233 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) | 232 if (!args[kArgIndexDest].VerifyTypeIs(Value::STRING, err)) |
234 return result; | 233 return result; |
235 if (!args[kArgIndexDest].string_value().empty()) { | 234 if (!args[kArgIndexDest].string_value().empty()) { |
236 to_dir = | 235 to_dir = current_dir.ResolveRelativeDir( |
237 current_dir.ResolveRelativeDir(args[kArgIndexDest].string_value()); | 236 args[kArgIndexDest].string_value(), |
237 scope->settings()->build_settings()->root_path_utf8()); | |
238 convert_to_system_absolute = false; | 238 convert_to_system_absolute = false; |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 // From path. | 242 // From path. |
243 SourceDir from_dir; | 243 SourceDir from_dir; |
244 if (args.size() > kArgIndexFrom) { | 244 if (args.size() > kArgIndexFrom) { |
245 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) | 245 if (!args[kArgIndexFrom].VerifyTypeIs(Value::STRING, err)) |
246 return result; | 246 return result; |
247 from_dir = | 247 from_dir = current_dir.ResolveRelativeDir( |
248 current_dir.ResolveRelativeDir(args[kArgIndexFrom].string_value()); | 248 args[kArgIndexFrom].string_value(), |
249 scope->settings()->build_settings()->root_path_utf8()); | |
249 } else { | 250 } else { |
250 // Default to current directory if unspecified. | 251 // Default to current directory if unspecified. |
251 from_dir = current_dir; | 252 from_dir = current_dir; |
252 } | 253 } |
253 | 254 |
254 // Path conversion. | 255 // Path conversion. |
255 if (inputs.type() == Value::STRING) { | 256 if (inputs.type() == Value::STRING) { |
256 return ConvertOnePath(scope, function, inputs, | 257 return ConvertOnePath(scope, function, inputs, |
257 from_dir, to_dir, convert_to_system_absolute, err); | 258 from_dir, to_dir, convert_to_system_absolute, err); |
258 | 259 |
(...skipping 12 matching lines...) Expand all Loading... | |
271 } | 272 } |
272 return result; | 273 return result; |
273 } | 274 } |
274 | 275 |
275 *err = Err(function->function(), | 276 *err = Err(function->function(), |
276 "rebase_path requires a list or a string."); | 277 "rebase_path requires a list or a string."); |
277 return result; | 278 return result; |
278 } | 279 } |
279 | 280 |
280 } // namespace functions | 281 } // namespace functions |
OLD | NEW |