Use Chromium's code for locating the src dir.
This code is much more sophisticated in that it doesn't rely
on argv[0], but rather asks the OS where our executable is.
We can then simply go two steps up since we count on running
in out/Whatever relative to the src dir. This is how Chromium
does it.
The aim here is to get rid of SetExecutablePath, which will
be the next CL.
Bug: webrtc:9792
Change-Id: I7da027b7391e759b1f612de12f27a244fe884c09
Reviewed-on: https://webrtc-review.googlesource.com/c/103121
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25017}
diff --git a/test/testsupport/fileutils.h b/test/testsupport/fileutils.h
index 8cef0e3..5ff0196 100644
--- a/test/testsupport/fileutils.h
+++ b/test/testsupport/fileutils.h
@@ -25,11 +25,14 @@
// to find the project root.
extern const char* kCannotFindProjectRootDir;
-// Creates and returns the absolute path to the output directory where log files
-// and other test artifacts should be put. The output directory is generally a
-// directory named "out" at the top-level of the project, i.e. a subfolder to
-// the path returned by ProjectRootPath(). The exception is Android where we use
-// /sdcard/ instead.
+// Returns the absolute path to the output directory where log files and other
+// test artifacts should be put. The output directory is generally a directory
+// named "out" at the project root. This root is assumed to be two levels above
+// where the test binary is located; this is because tests execute in a dir
+// out/Whatever relative to the project root. This convention is also followed
+// in Chromium.
+//
+// The exception is Android where we use /sdcard/ instead.
//
// If symbolic links occur in the path they will be resolved and the actual
// directory will be returned.
@@ -100,6 +103,9 @@
// Checks if a directory exists.
bool DirExists(const std::string& directory_name);
+// Strips the rightmost path segment from a path.
+std::string DirName(const std::string& path);
+
// File size of the supplied file in bytes. Will return 0 if the file is
// empty or if the file does not exist/is readable.
size_t GetFileSize(const std::string& filename);
@@ -110,6 +116,7 @@
// the argv[0] being sent into the main function to make it possible for
// fileutils.h to find the correct project paths even when the working directory
// is outside the project tree (which happens in some cases).
+// TODO(bugs.webrtc.org/9792): Deprecated - going away soon.
void SetExecutablePath(const std::string& path_to_executable);
} // namespace test