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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
8 #include "tools/gn/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
9 #include "tools/gn/functions.h" | 9 #include "tools/gn/functions.h" |
10 #include "tools/gn/parse_tree.h" | 10 #include "tools/gn/parse_tree.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 result = Value(function, Value::STRING); | 92 result = Value(function, Value::STRING); |
93 if (looks_like_dir) { | 93 if (looks_like_dir) { |
94 result.string_value() = RebasePath( | 94 result.string_value() = RebasePath( |
95 from_dir.ResolveRelativeDir(value, err, | 95 from_dir.ResolveRelativeDir(value, err, |
96 scope->settings()->build_settings()->root_path_utf8()).value(), | 96 scope->settings()->build_settings()->root_path_utf8()).value(), |
97 to_dir, | 97 to_dir, |
98 scope->settings()->build_settings()->root_path_utf8()); | 98 scope->settings()->build_settings()->root_path_utf8()); |
99 MakeSlashEndingMatchInput(string_value, &result.string_value()); | 99 MakeSlashEndingMatchInput(string_value, &result.string_value()); |
100 } else { | 100 } else { |
101 result.string_value() = RebasePath( | 101 SourceFile resolved_file = |
102 from_dir.ResolveRelativeFile(value, err, | 102 from_dir.ResolveRelativeFile(value, err, |
103 scope->settings()->build_settings()->root_path_utf8()).value(), | 103 scope->settings()->build_settings()->root_path_utf8()); |
104 to_dir, | |
105 scope->settings()->build_settings()->root_path_utf8()); | |
106 if (err->has_error()) | 104 if (err->has_error()) |
107 return Value(); | 105 return Value(); |
| 106 // Special case: |
| 107 // rebase_path("//foo", "//bar") ==> "../foo" |
| 108 // rebase_path("//foo", "//foo") ==> "." and not "../foo" |
| 109 if (resolved_file.value() == |
| 110 to_dir.value().substr(0, to_dir.value().size() - 1)) { |
| 111 result.string_value() = "."; |
| 112 } else { |
| 113 result.string_value() = RebasePath( |
| 114 resolved_file.value(), |
| 115 to_dir, |
| 116 scope->settings()->build_settings()->root_path_utf8()); |
| 117 } |
108 } | 118 } |
109 | 119 |
110 return result; | 120 return result; |
111 } | 121 } |
112 | 122 |
113 } // namespace | 123 } // namespace |
114 | 124 |
115 const char kRebasePath[] = "rebase_path"; | 125 const char kRebasePath[] = "rebase_path"; |
116 const char kRebasePath_HelpShort[] = | 126 const char kRebasePath_HelpShort[] = |
117 "rebase_path: Rebase a file or directory to another location."; | 127 "rebase_path: Rebase a file or directory to another location."; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 290 } |
281 return result; | 291 return result; |
282 } | 292 } |
283 | 293 |
284 *err = Err(function->function(), | 294 *err = Err(function->function(), |
285 "rebase_path requires a list or a string."); | 295 "rebase_path requires a list or a string."); |
286 return result; | 296 return result; |
287 } | 297 } |
288 | 298 |
289 } // namespace functions | 299 } // namespace functions |
OLD | NEW |