Index: tools/gn/source_dir.cc |
diff --git a/tools/gn/source_dir.cc b/tools/gn/source_dir.cc |
index c59cf88cd61136bc4e1fa6db7620b8c55e736736..97247ffd90ae23cbd12c91f334ec011e47377347 100644 |
--- a/tools/gn/source_dir.cc |
+++ b/tools/gn/source_dir.cc |
@@ -41,7 +41,7 @@ SourceDir::~SourceDir() { |
SourceFile SourceDir::ResolveRelativeFile( |
const base::StringPiece& p, |
- const base::StringPiece& source_root) const { |
+ const base::FilePath& source_root) const { |
SourceFile ret; |
// It's an error to resolve an empty string or one that is a directory |
@@ -56,7 +56,8 @@ SourceFile SourceDir::ResolveRelativeFile( |
return ret; |
} else if (IsPathAbsolute(p)) { |
if (source_root.empty() || |
- !MakeAbsolutePathRelativeIfPossible(source_root, p, &ret.value_)) { |
+ !MakeAbsolutePathRelativeIfPossible(source_root.value(), p, |
+ &ret.value_)) { |
#if defined(OS_WIN) |
// On Windows we'll accept "C:\foo" as an absolute path, which we want |
// to convert to "/C:..." here. |
@@ -69,17 +70,28 @@ SourceFile SourceDir::ResolveRelativeFile( |
return ret; |
} |
+ if (!source_root.empty()) { |
brettw
2014/10/07 23:55:06
Are these blocks necessary? Are you trying to hand
zeuthen
2014/10/08 15:21:06
I tried commenting this out and without it, the bu
|
+ std::string absolute = Resolve(source_root).Append(p.as_string()).value(); |
+ NormalizePath(&absolute); |
+ if (!MakeAbsolutePathRelativeIfPossible(source_root.value(), absolute, |
+ &ret.value_)) |
+ ret.value_ = absolute; |
+ return ret; |
+ } |
+ |
+ // With no source_root_, there's nothing we can do about |
+ // e.g. p=../../../path/to/file and value_=//source and we'll |
+ // errornously return //file. |
ret.value_.reserve(value_.size() + p.size()); |
ret.value_.assign(value_); |
ret.value_.append(p.data(), p.size()); |
- |
NormalizePath(&ret.value_); |
return ret; |
} |
SourceDir SourceDir::ResolveRelativeDir( |
const base::StringPiece& p, |
- const base::StringPiece& source_root) const { |
+ const base::FilePath& source_root) const { |
SourceDir ret; |
if (p.empty()) |
@@ -93,7 +105,8 @@ SourceDir SourceDir::ResolveRelativeDir( |
return ret; |
} else if (IsPathAbsolute(p)) { |
if (source_root.empty() || |
- !MakeAbsolutePathRelativeIfPossible(source_root, p, &ret.value_)) { |
+ !MakeAbsolutePathRelativeIfPossible(source_root.value(), p, |
+ &ret.value_)) { |
#if defined(OS_WIN) |
if (p[0] != '/') // See the file case for why we do this check. |
ret.value_ = "/"; |
@@ -106,6 +119,17 @@ SourceDir SourceDir::ResolveRelativeDir( |
return ret; |
} |
+ if (!source_root.empty()) { |
+ std::string absolute = Resolve(source_root).Append(p.as_string()).value(); |
+ NormalizePath(&absolute); |
+ if (!MakeAbsolutePathRelativeIfPossible(source_root.value(), absolute, |
+ &ret.value_)) |
+ ret.value_ = absolute; |
+ if (!EndsWithSlash(ret.value_)) |
+ ret.value_.push_back('/'); |
+ return ret; |
+ } |
+ |
ret.value_.reserve(value_.size() + p.size()); |
ret.value_.assign(value_); |
ret.value_.append(p.data(), p.size()); |