Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1590)

Unified Diff: tools/gn/source_dir.cc

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch that compiles and passes unit tests on both Windows and Linux Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/setup.cc ('k') | tools/gn/source_dir_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/source_dir.cc
diff --git a/tools/gn/source_dir.cc b/tools/gn/source_dir.cc
index c59cf88cd61136bc4e1fa6db7620b8c55e736736..9f6c74575b186b8a0e625d403a699610118b6cb3 100644
--- a/tools/gn/source_dir.cc
+++ b/tools/gn/source_dir.cc
@@ -12,7 +12,12 @@ namespace {
void AssertValueSourceDirString(const std::string& s) {
if (!s.empty()) {
+#if defined(OS_WIN)
+ DCHECK(s[0] == '/' ||
+ (s.size() > 2 && s[0] != '/' && s[1] == ':' && IsSlash(s[2])));
+#else
DCHECK(s[0] == '/');
+#endif
DCHECK(EndsWithSlash(s));
}
}
@@ -44,6 +49,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 +76,20 @@ SourceFile SourceDir::ResolveRelativeFile(
return ret;
}
+ if (!source_root.empty()) {
+ std::string absolute =
+ FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII(
+ 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 +103,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 +129,18 @@ SourceDir SourceDir::ResolveRelativeDir(
return ret;
}
+ if (!source_root.empty()) {
+ std::string absolute =
+ FilePathToUTF8(Resolve(UTF8ToFilePath(source_root)).AppendASCII(
+ 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());
« no previous file with comments | « tools/gn/setup.cc ('k') | tools/gn/source_dir_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698