Remove SetExecutablePath, simplify ResourcePath
SetExecutablePath isn't used anymore.
Nobody was using the fancy select-per-platform functionality, and the
documentation was wrong anyway. In the cases somebody needed an
override per platform, they were using defines in their own test
instead. I think that is more verbose but more predictable and easy
to understand (see how it's done in audio_processing_unittest.cc
when loading output_data_mac, for instance).
Bug: webrtc:9792
Change-Id: I7289bf5883fe43852638922d7c7583eae0c08601
Reviewed-on: https://webrtc-review.googlesource.com/c/104482
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25062}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 666e3c0..a393448 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -208,12 +208,17 @@
]
deps = [
":field_trial",
- ":fileutils",
":perf_test",
"../rtc_base:rtc_base",
"../system_wrappers:field_trial",
"../system_wrappers:metrics",
"//testing/gtest",
+
+ # TODO(bugs.webrtc.org/9792): This is needed for downstream projects on
+ # Android, where it's replaced by an internal version of fileutils that
+ # has a certain flag. Remove this once the internal fileutils has been
+ # eliminated.
+ "../test:fileutils",
]
}
diff --git a/test/test_main.cc b/test/test_main.cc
index c8d0b1b..ec32f2d 100644
--- a/test/test_main.cc
+++ b/test/test_main.cc
@@ -86,7 +86,13 @@
return 0;
}
- webrtc::test::SetExecutablePath(argv[0]);
+ // TODO(bugs.webrtc.org/9792): we need to reference something from fileutils.h
+ // so that our downstream hack where we replace fileutils.cc works. Otherwise
+ // the downstream flag implementation will take over and botch the flag
+ // introduced by the hack. Remove this awful thing once the downstream
+ // implementation has been eliminated.
+ (void)webrtc::test::JoinFilename("horrible", "hack");
+
webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc
index cb88472..ba1e793 100644
--- a/test/testsupport/fileutils.cc
+++ b/test/testsupport/fileutils.cc
@@ -81,9 +81,6 @@
const char* kResourcesDirName = "resources";
#endif
-char relative_dir_path[FILENAME_MAX];
-bool relative_dir_path_set = false;
-
} // namespace
const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
@@ -101,27 +98,6 @@
return result.substr(0, result.find_last_of(kPathDelimiter));
}
-void SetExecutablePath(const std::string& path) {
- std::string working_dir = WorkingDir();
- std::string temp_path = path;
-
- // Handle absolute paths; convert them to relative paths to the working dir.
- if (path.find(working_dir) != std::string::npos) {
- temp_path = path.substr(working_dir.length() + 1);
- }
-// On Windows, when tests are run under memory tools like DrMemory and TSan,
-// slashes occur in the path as directory separators. Make sure we replace
-// such cases with backslashes in order for the paths to be correct.
-#ifdef WIN32
- std::replace(temp_path.begin(), temp_path.end(), '/', '\\');
-#endif
-
- // Trim away the executable name; only store the relative dir path.
- temp_path = DirName(temp_path);
- strncpy(relative_dir_path, temp_path.c_str(), FILENAME_MAX);
- relative_dir_path_set = true;
-}
-
bool FileExists(const std::string& file_name) {
struct stat file_info = {0};
return stat(file_name.c_str(), &file_info) == 0;
@@ -325,27 +301,10 @@
#if defined(WEBRTC_IOS)
return IOSResourcePath(name, extension);
#else
- std::string platform = "win";
-#ifdef WEBRTC_LINUX
- platform = "linux";
-#endif // WEBRTC_LINUX
-#ifdef WEBRTC_MAC
- platform = "mac";
-#endif // WEBRTC_MAC
-#ifdef WEBRTC_ANDROID
- platform = "android";
-#endif // WEBRTC_ANDROID
-
std::string resources_path =
ProjectRootPath() + kResourcesDirName + kPathDelimiter;
- std::string resource_file =
- resources_path + name + "_" + platform + "." + extension;
- if (FileExists(resource_file)) {
- return resource_file;
- }
- // Fall back on name without platform.
return resources_path + name + "." + extension;
-#endif // defined (WEBRTC_IOS)
+#endif
}
std::string JoinFilename(const std::string& dir, const std::string& name) {
diff --git a/test/testsupport/fileutils.h b/test/testsupport/fileutils.h
index 5ff0196..693944e 100644
--- a/test/testsupport/fileutils.h
+++ b/test/testsupport/fileutils.h
@@ -51,18 +51,8 @@
std::string GenerateTempFilename(const std::string& dir,
const std::string& prefix);
-// Returns a path to a resource file for the currently executing platform.
-// Adapts to what filenames are currently present in the
-// [project-root]/resources/ dir.
-// Returns an absolute path according to this priority list (the directory
-// part of the path is left out for readability):
-// 1. [name]_[platform]_[architecture].[extension]
-// 2. [name]_[platform].[extension]
-// 3. [name]_[architecture].[extension]
-// 4. [name].[extension]
-// Where
-// * platform is either of "win", "mac" or "linux".
-// * architecture is either of "32" or "64".
+// Returns a path to a resource file in [project-root]/resources/ dir.
+// Returns an absolute path
//
// Arguments:
// name - Name of the resource file. If a plain filename (no directory path)
@@ -110,15 +100,6 @@
// empty or if the file does not exist/is readable.
size_t GetFileSize(const std::string& filename);
-// Sets the executable path, i.e. the path to the executable that is being used
-// when launching it. This is usually the path relative to the working directory
-// but can also be an absolute path. The intention with this function is to pass
-// 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
} // namespace webrtc