Improve fileutils_override implementation internal API.
Use absl::optional instead of special constant to show, that we failed to get OutputPath in fileutils_override Bug: webrtc:9792 Change-Id: Ice19a9bf425e88a747dd9b07e82dbb5bdc59685b Reviewed-on: https://webrtc-review.googlesource.com/c/107630 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25331}
This commit is contained in:
@ -37,6 +37,7 @@
|
|||||||
#include "test/testsupport/macfileutils.h"
|
#include "test/testsupport/macfileutils.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/arraysize.h"
|
#include "rtc_base/arraysize.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/stringutils.h"
|
#include "rtc_base/stringutils.h"
|
||||||
@ -68,11 +69,9 @@ const char* kResourcesDirName = "resources";
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
|
|
||||||
|
|
||||||
// Finds the WebRTC src dir.
|
// Finds the WebRTC src dir.
|
||||||
// The returned path always ends with a path separator.
|
// The returned path always ends with a path separator.
|
||||||
std::string ProjectRootPath() {
|
absl::optional<std::string> ProjectRootPath() {
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
return kAndroidChromiumTestsRoot;
|
return kAndroidChromiumTestsRoot;
|
||||||
#elif defined WEBRTC_IOS
|
#elif defined WEBRTC_IOS
|
||||||
@ -89,7 +88,7 @@ std::string ProjectRootPath() {
|
|||||||
ssize_t count = ::readlink("/proc/self/exe", buf, arraysize(buf));
|
ssize_t count = ::readlink("/proc/self/exe", buf, arraysize(buf));
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
RTC_NOTREACHED() << "Unable to resolve /proc/self/exe.";
|
RTC_NOTREACHED() << "Unable to resolve /proc/self/exe.";
|
||||||
return kCannotFindProjectRootDir;
|
return absl::nullopt;
|
||||||
}
|
}
|
||||||
// On POSIX, tests execute in out/Whatever, so src is two levels up.
|
// On POSIX, tests execute in out/Whatever, so src is two levels up.
|
||||||
std::string exe_dir = DirName(std::string(buf, count));
|
std::string exe_dir = DirName(std::string(buf, count));
|
||||||
@ -98,7 +97,7 @@ std::string ProjectRootPath() {
|
|||||||
wchar_t buf[MAX_PATH];
|
wchar_t buf[MAX_PATH];
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
if (GetModuleFileName(NULL, buf, MAX_PATH) == 0)
|
if (GetModuleFileName(NULL, buf, MAX_PATH) == 0)
|
||||||
return kCannotFindProjectRootDir;
|
return absl::nullopt;
|
||||||
|
|
||||||
std::string exe_path = rtc::ToUtf8(std::wstring(buf));
|
std::string exe_path = rtc::ToUtf8(std::wstring(buf));
|
||||||
std::string exe_dir = DirName(exe_path);
|
std::string exe_dir = DirName(exe_path);
|
||||||
@ -112,9 +111,9 @@ std::string OutputPath() {
|
|||||||
#elif defined(WEBRTC_ANDROID)
|
#elif defined(WEBRTC_ANDROID)
|
||||||
return kAndroidChromiumTestsRoot;
|
return kAndroidChromiumTestsRoot;
|
||||||
#else
|
#else
|
||||||
std::string path = ProjectRootPath();
|
absl::optional<std::string> path_opt = ProjectRootPath();
|
||||||
RTC_DCHECK_NE(path, kCannotFindProjectRootDir);
|
RTC_DCHECK(path_opt);
|
||||||
path += "out";
|
std::string path = *path_opt + "out";
|
||||||
if (!CreateDir(path)) {
|
if (!CreateDir(path)) {
|
||||||
return "./";
|
return "./";
|
||||||
}
|
}
|
||||||
@ -140,8 +139,9 @@ std::string ResourcePath(const std::string& name,
|
|||||||
#if defined(WEBRTC_IOS)
|
#if defined(WEBRTC_IOS)
|
||||||
return IOSResourcePath(name, extension);
|
return IOSResourcePath(name, extension);
|
||||||
#else
|
#else
|
||||||
std::string resources_path =
|
absl::optional<std::string> path_opt = ProjectRootPath();
|
||||||
ProjectRootPath() + kResourcesDirName + kPathDelimiter;
|
RTC_DCHECK(path_opt);
|
||||||
|
std::string resources_path = *path_opt + kResourcesDirName + kPathDelimiter;
|
||||||
return resources_path + name + "." + extension;
|
return resources_path + name + "." + extension;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user