| Index: tools/gn/source_dir.cc
|
| diff --git a/tools/gn/source_dir.cc b/tools/gn/source_dir.cc
|
| index c59cf88cd61136bc4e1fa6db7620b8c55e736736..81e5dc51a8f0eca54e55d196dbba9da5e17e9a34 100644
|
| --- a/tools/gn/source_dir.cc
|
| +++ b/tools/gn/source_dir.cc
|
| @@ -44,6 +44,8 @@ SourceFile SourceDir::ResolveRelativeFile(
|
| const base::StringPiece& source_root) const {
|
| SourceFile ret;
|
|
|
| + DCHECK(source_root.empty() || !source_root.ends_with("/"));
|
| +
|
| // It's an error to resolve an empty string or one that is a directory
|
| // (indicated by a trailing slash) because this is the function that expects
|
| // to return a file.
|
| @@ -69,6 +71,20 @@ SourceFile SourceDir::ResolveRelativeFile(
|
| return ret;
|
| }
|
|
|
| + if (!source_root.empty()) {
|
| + std::string absolute =
|
| + Resolve(base::FilePath(source_root.data()))
|
| + .Append(p.as_string()).value();
|
| + NormalizePath(&absolute);
|
| + if (!MakeAbsolutePathRelativeIfPossible(source_root, 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());
|
| @@ -82,6 +98,8 @@ SourceDir SourceDir::ResolveRelativeDir(
|
| const base::StringPiece& source_root) const {
|
| SourceDir ret;
|
|
|
| + DCHECK(source_root.empty() || !source_root.ends_with("/"));
|
| +
|
| if (p.empty())
|
| return ret;
|
| if (p.size() >= 2 && p[0] == '/' && p[1] == '/') {
|
| @@ -106,6 +124,18 @@ SourceDir SourceDir::ResolveRelativeDir(
|
| return ret;
|
| }
|
|
|
| + if (!source_root.empty()) {
|
| + std::string absolute =
|
| + Resolve(base::FilePath(source_root.data()))
|
| + .Append(p.as_string()).value();
|
| + NormalizePath(&absolute);
|
| + if (!MakeAbsolutePathRelativeIfPossible(source_root, 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());
|
|
|