Move --resources_dir to its right place.

We needed a hack in test_main_lib.cc to ensure fileutils were always
linked with test binaries downstream. When I removed the hack, it
broke the binaries that were _not_ using fileutils because a certain
bazel rule expects to be able to pass the flag to all test binaries.

The solution is to move the flag to test_main_lib.cc. This is the
right place for it since it's apparently in the contract of a WebRTC
test binary to support this flag. We then have to pass the value
down to the override, which is why I add a new function for that.
I leave the flag unimplemented in OSS because no one is using it
here anyway. It will be implemented downstream.

Bug: webrtc:9792
Change-Id: I21b3deb43bf0cd56d6aa2622dc5519370a0307a9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156568
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29474}
diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc
index bb41e65..1650d2a 100644
--- a/test/test_main_lib.cc
+++ b/test/test_main_lib.cc
@@ -28,6 +28,7 @@
 #include "test/gmock.h"
 #include "test/gtest.h"
 #include "test/testsupport/file_utils.h"
+#include "test/testsupport/file_utils_override.h"
 #include "test/testsupport/perf_test.h"
 
 #if defined(WEBRTC_WIN)
@@ -80,6 +81,14 @@
 
 #endif
 
+ABSL_FLAG(std::string,
+          resources_dir,
+          "",
+          "Where to look for the runtime dependencies. If not specified, we "
+          "will use a reasonable default depending on where we are running. "
+          "This flag is useful if we copy over test resources to a phone and "
+          "need to tell the tests where their resources are.");
+
 ABSL_FLAG(bool, logs, true, "print logs to stderr");
 ABSL_FLAG(bool, verbose, false, "verbose logs to stderr");
 
@@ -106,6 +115,10 @@
     ::testing::InitGoogleMock(argc, argv);
     absl::ParseCommandLine(*argc, argv);
 
+    std::string resources_dir = absl::GetFlag(FLAGS_resources_dir);
+    if (!resources_dir.empty())
+      test::internal::OverrideResourcesDir(resources_dir);
+
     // Default to LS_INFO, even for release builds to provide better test
     // logging.
     if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO)