From 00f2ee04d7d8488a4213cf20b98c3db72b2b1b60 Mon Sep 17 00:00:00 2001 From: ehmaldonado Date: Fri, 18 Nov 2016 07:06:41 -0800 Subject: [PATCH] Changed the way we find the ProjectRootPath. This was blocking swarming for memcheck. BUG=chromium:497757, webrtc:6727 Review-Url: https://codereview.webrtc.org/2511393002 Cr-Commit-Position: refs/heads/master@{#15153} --- webrtc/test/testsupport/fileutils.cc | 31 ++++++++++--------- webrtc/test/testsupport/fileutils_unittest.cc | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc index fb66a1a95d..97d58eba60 100644 --- a/webrtc/test/testsupport/fileutils.cc +++ b/webrtc/test/testsupport/fileutils.cc @@ -18,6 +18,8 @@ #include #include +#include "Shlwapi.h" + #include "webrtc/system_wrappers/include/utf_util_win.h" #define GET_CURRENT_DIR _getcwd #else @@ -127,24 +129,23 @@ std::string ProjectRootPath() { if (path == kFallbackPath) { return kCannotFindProjectRootDir; } - if (relative_dir_path_set && strcmp(relative_dir_path, ".") != 0) { + if (relative_dir_path_set) { path = path + kPathDelimiter + relative_dir_path; } - // Remove two directory levels from the path, i.e. a path like - // /absolute/path/src/out/Debug will become /absolute/path/src/ - size_t path_delimiter_index = path.find_last_of(kPathDelimiter); - if (path_delimiter_index != std::string::npos) { - // Move up one directory in the directory tree. - path = path.substr(0, path_delimiter_index); - path_delimiter_index = path.find_last_of(kPathDelimiter); - if (path_delimiter_index != std::string::npos) { - // Move up another directory in the directory tree. We should now be at - // the project root. - return path.substr(0, path_delimiter_index) + kPathDelimiter; - } + path = path + kPathDelimiter + ".." + kPathDelimiter + ".."; + char canonical_path[FILENAME_MAX]; +#ifdef WIN32 + bool succeeded = PathCanonicalizeA(canonical_path, path.c_str()); +#else + bool succeeded = realpath(path.c_str(), canonical_path) != NULL; +#endif + if (succeeded) { + path = std::string(canonical_path) + kPathDelimiter; + return path; + } else { + fprintf(stderr, "Cannot find project root directory!\n"); + return kCannotFindProjectRootDir; } - fprintf(stderr, "Cannot find project root directory!\n"); - return kCannotFindProjectRootDir; #endif } diff --git a/webrtc/test/testsupport/fileutils_unittest.cc b/webrtc/test/testsupport/fileutils_unittest.cc index 2677b8c4bb..b9ac913326 100644 --- a/webrtc/test/testsupport/fileutils_unittest.cc +++ b/webrtc/test/testsupport/fileutils_unittest.cc @@ -81,7 +81,7 @@ TEST_F(FileUtilsTest, MAYBE_OutputPathFromUnchangedWorkingDir) { // Tests with current working directory set to a directory higher up in the // directory tree than the project root dir. -#if defined(WEBRTC_ANDROID) +#if defined(WEBRTC_ANDROID) || defined(WIN32) #define MAYBE_OutputPathFromRootWorkingDir DISABLED_OutputPathFromRootWorkingDir #else #define MAYBE_OutputPathFromRootWorkingDir OutputPathFromRootWorkingDir