Hack to make tests work if out is a symlink: see if the current dir is the source root.

Fix some tests that were manually getting sourcedir from DIR_EXE instead of using DIR_SOURCE_ROOT.

BUG=none
TEST=rm -r out, ln -s /somedir/out out, run tests

Review URL: http://codereview.chromium.org/192064

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25898 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 95d050e357cd2f2a226621dd8639baaf30cad544
diff --git a/base/base_paths_linux.cc b/base/base_paths_linux.cc
index 151c411..ca5ca4e 100644
--- a/base/base_paths_linux.cc
+++ b/base/base_paths_linux.cc
@@ -39,12 +39,23 @@
     case base::DIR_SOURCE_ROOT:
       // On linux, unit tests execute two levels deep from the source root.
       // For example:  sconsbuild/{Debug|Release}/net_unittest
-      if (!PathService::Get(base::DIR_EXE, &path))
-        return false;
-      path = path.Append(FilePath::kParentDirectory)
-                 .Append(FilePath::kParentDirectory);
-      *result = path;
-      return true;
+      if (PathService::Get(base::DIR_EXE, &path)) {
+        path = path.DirName().DirName();
+        if (file_util::PathExists(path.Append("base/base_paths_linux.cc"))) {
+          *result = path;
+          return true;
+        }
+      }
+      // If that failed (maybe the build output is symlinked to a different
+      // drive) try assuming the current directory is the source root.
+      if (file_util::GetCurrentDirectory(&path) &&
+          file_util::PathExists(path.Append("base/base_paths_linux.cc"))) {
+        *result = path;
+        return true;
+      }
+      LOG(ERROR) << "Couldn't find your source root.  "
+                 << "Try running from your chromium/src directory.";
+      return false;
   }
   return false;
 }