Index: tools/gn/filesystem_utils.cc |
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc |
index a3455fdf088b6829e63fa94e2551699694879858..48a47fee1731797c1d3deb7c1a9f233dabc33ec2 100644 |
--- a/tools/gn/filesystem_utils.cc |
+++ b/tools/gn/filesystem_utils.cc |
@@ -377,7 +377,7 @@ bool MakeAbsolutePathRelativeIfPossible(const base::StringPiece& source_root, |
#endif |
} |
-void NormalizePath(std::string* path) { |
+void NormalizePath(std::string* path, const base::StringPiece& source_root) { |
char* pathbuf = path->empty() ? nullptr : &(*path)[0]; |
// top_index is the first character we can modify in the path. Anything |
@@ -433,9 +433,29 @@ void NormalizePath(std::string* path) { |
// up more levels. Otherwise "../.." would collapse to |
// nothing. |
top_index = dest_i; |
+ } else if (top_index == 2 && !source_root.empty()) { |
+ // |path| was passed in as a source-absolute path. Prepend |
+ // |source_root| to make |path| absolute. |
+ const size_t len = source_root.ends_with("/") |
brettw
2015/12/01 01:21:22
I think we can know whether the source_root ends i
slan
2015/12/01 22:15:03
Done.
|
+ ? source_root.size() - 1 |
+ : source_root.size(); |
+ path->insert(0, source_root.data(), len); |
+ pathbuf = &(*path)[0]; |
+ |
+ // |path| is now absolute, so |top_index| is 1. |dest_i| and |
+ // |src_i| should be incremented to keep the same relative |
+ // position. Comsume the leading "//" by decrementing |dest_i|. |
+ top_index = 1; |
+ dest_i += len - 2; |
+ src_i += len; |
+ |
+ // Just find the previous slash or the beginning of input. |
+ while (dest_i > 0 && !IsSlash(pathbuf[dest_i - 1])) |
+ dest_i--; |
} |
- // Otherwise we're at the beginning of an absolute path. Don't |
- // allow ".." to go up another level and just eat it. |
+ // Otherwise we're at the beginning of a system-absolute path, or |
+ // a source-absolute path for which we don't know the absolute |
+ // path. Don't allow ".." to go up another level, and just eat it. |
} else { |
// Just find the previous slash or the beginning of input. |
while (dest_i > 0 && !IsSlash(pathbuf[dest_i - 1])) |