From 8b28b8017f31183f24fa2815bd4d3d57b03a8060 Mon Sep 17 00:00:00 2001 From: ehmaldonado Date: Thu, 15 Sep 2016 04:45:48 -0700 Subject: [PATCH] Assume ProjectRootPath() equals ../.. in Desktop This way we don't have to rely on the existence of DEPS, and the tests can be run in swarming bots (which don't have a checkout and therefore don't have a DEPS file). This seems to be where Chromium is assumming the project root path to be. NOTRY=True BUG=chromium:497757 Review-Url: https://codereview.webrtc.org/2340773002 Cr-Commit-Position: refs/heads/master@{#14230} --- webrtc/test/testsupport/fileutils.cc | 19 +++++++++---------- webrtc/test/testsupport/fileutils.h | 9 +++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc index 4bf8c5fa19..ef8e5d5c8d 100644 --- a/webrtc/test/testsupport/fileutils.cc +++ b/webrtc/test/testsupport/fileutils.cc @@ -59,8 +59,6 @@ const char* kPathDelimiter = "/"; #ifdef WEBRTC_ANDROID const char* kRootDirName = "/sdcard/chromium_tests_root/"; #else -// The file we're looking for to identify the project root dir. -const char* kProjectRootFileName = "DEPS"; #if !defined(WEBRTC_IOS) const char* kOutputDirName = "out"; #endif @@ -125,21 +123,22 @@ std::string ProjectRootPath() { if (path == kFallbackPath) { return kCannotFindProjectRootDir; } - if (relative_dir_path_set) { + if (relative_dir_path_set && strcmp(relative_dir_path, ".") != 0) { path = path + kPathDelimiter + relative_dir_path; } - // Check for our file that verifies the root dir. + // 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); - while (path_delimiter_index != std::string::npos) { - std::string root_filename = path + kPathDelimiter + kProjectRootFileName; - if (FileExists(root_filename)) { - return path + 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; + } } - // Reached the root directory. fprintf(stderr, "Cannot find project root directory!\n"); return kCannotFindProjectRootDir; } diff --git a/webrtc/test/testsupport/fileutils.h b/webrtc/test/testsupport/fileutils.h index 78789fa870..482b1874a7 100644 --- a/webrtc/test/testsupport/fileutils.h +++ b/webrtc/test/testsupport/fileutils.h @@ -75,10 +75,11 @@ extern const char* kCannotFindProjectRootDir; // Finds the root dir of the project, to be able to set correct paths to // resource files used by tests. -// The implementation is simple: it just looks for the file defined by -// kProjectRootFileName, starting in the current directory (the working -// directory) and then steps upward until it is found (or it is at the root of -// the file system). +// For desktop, we assume that the project root is two levels above (i.e. the +// current working directory + /../../) +// For Android, it is assumed to be /sdcard/chromium_tests_root/ +// For iOS, the resource files are assumed to be included in the test's .app +// bundle. // If the current working directory is above the project root dir, it will not // be found. //