base: Move OpenFile to file_utils.h and fix IWYU
This CL mainly moves base::OpenFile from
base/scoped_file.h to base/file_utils.h. There are
two reasons for this:
1. aosp/1519760 is introducing PlatformHandle to
deal with Windows non-FD resources. We can't just
put that in scoped_file.h as well as that file
becomes a random catch-all.
2. In general, it feels like OpenFile has always been
misplaced, give that Close, Read and the others are
in file_utils.h
This CL also de-inlines some functions to avoid leaking too
many platform headers around the codebase. Windows.h is a
monster header which includes a tree of other headers. It
can cause compatibility issues in other projects by
redefining things like min/max (which then require the
embedder to pass cflags like -DNOINTMINMAX to work around).
This CL also cleans up a bunch of related places by wrapping
common filesystem operations to avoid dealing with <unistd.h>
vs <io.h>.
This cleanup also unveiled some IWYU mishaps which are
being cleaned up.
Bug: 174454879
Change-Id: Icda08404cb8349f28ac08617381a285e82a23b6c
diff --git a/src/trace_processor/trace_processor_shell.cc b/src/trace_processor/trace_processor_shell.cc
index 33cb488..d504aaf 100644
--- a/src/trace_processor/trace_processor_shell.cc
+++ b/src/trace_processor/trace_processor_shell.cc
@@ -76,6 +76,11 @@
#include <getopt.h>
#endif
+#if PERFETTO_BUILDFLAG(PERFETTO_TP_LINENOISE) && \
+ !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+#include <unistd.h> // For getuid() in GetConfigPath().
+#endif
+
namespace perfetto {
namespace trace_processor {
@@ -94,8 +99,15 @@
std::string GetConfigPath() {
const char* homedir = getenv("HOME");
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
if (homedir == nullptr)
homedir = getpwuid(getuid())->pw_dir;
+#elif PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+ if (homedir == nullptr)
+ homedir = getenv("USERPROFILE");
+#endif
if (homedir == nullptr)
return "";
return std::string(homedir) + "/.config";