Move ToString into strings.h

This seems like the obvious place for it, plus I'm hacking around at some
changes that would appreciate having it there.

PiperOrigin-RevId: 303373826
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 44879c0..63007b6 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -432,7 +432,7 @@
   // is actually a list of parseable startup options.
   if (!startup_options.batch) {
     result.push_back("--max_idle_secs=" +
-                     ToString(startup_options.max_idle_secs));
+                     blaze_util::ToString(startup_options.max_idle_secs));
     if (startup_options.shutdown_on_low_sys_mem) {
       result.push_back("--shutdown_on_low_sys_mem");
     } else {
@@ -446,11 +446,11 @@
 
   if (startup_options.command_port != 0) {
     result.push_back("--command_port=" +
-                     ToString(startup_options.command_port));
+                     blaze_util::ToString(startup_options.command_port));
   }
 
   result.push_back("--connect_timeout_secs=" +
-                   ToString(startup_options.connect_timeout_secs));
+                   blaze_util::ToString(startup_options.connect_timeout_secs));
 
   result.push_back("--output_user_root=" +
                    blaze_util::ConvertPath(startup_options.output_user_root));
@@ -494,7 +494,8 @@
     result.push_back("--noexperimental_oom_more_eagerly");
   }
   result.push_back("--experimental_oom_more_eagerly_threshold=" +
-                   ToString(startup_options.oom_more_eagerly_threshold));
+                   blaze_util::ToString(
+                       startup_options.oom_more_eagerly_threshold));
 
   if (startup_options.write_command_log) {
     result.push_back("--write_command_log");
@@ -582,20 +583,21 @@
                            vector<string> *args) {
   // The time in ms the launcher spends before sending the request to the blaze
   // server.
-  args->push_back("--startup_time=" + ToString(client_startup_duration.millis));
+  args->push_back("--startup_time=" +
+                  blaze_util::ToString(client_startup_duration.millis));
 
   // The time in ms a command had to wait on a busy Blaze server process.
   // This is part of startup_time.
   if (command_wait_duration_ms.IsKnown()) {
     args->push_back("--command_wait_time=" +
-                    ToString(command_wait_duration_ms.millis));
+                    blaze_util::ToString(command_wait_duration_ms.millis));
   }
 
   // The time in ms spent on extracting the new blaze version.
   // This is part of startup_time.
   if (extract_data_duration.IsKnown()) {
     args->push_back("--extract_data_time=" +
-                    ToString(extract_data_duration.millis));
+                    blaze_util::ToString(extract_data_duration.millis));
   }
   if (logging_info.restart_reason != NO_RESTART) {
     args->push_back(string("--restart_reason=") +
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index f91ee50..ed358d1 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -90,20 +90,6 @@
 // time, if the server process remains, the client will die.
 extern const unsigned int kPostKillGracePeriodSeconds;
 
-// Returns the string representation of `value`.
-// Workaround for mingw where std::to_string is not implemented.
-// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015.
-template <typename T>
-std::string ToString(const T &value) {
-#if defined(__CYGWIN__) || defined(__MINGW32__)
-  std::ostringstream oss;
-  oss << value;
-  return oss.str();
-#else
-  return std::to_string(value);
-#endif
-}
-
 // Control the output of debug information by debug_log.
 // Revisit once client logging is fixed (b/32939567).
 void SetDebugLog(bool enabled);
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index ef9a3e1..6d131ba 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -119,7 +119,7 @@
 std::unique_ptr<blaze_util::Path> GetProcessCWD(int pid) {
   char server_cwd[PATH_MAX] = {};
   if (readlink(
-          ("/proc/" + ToString(pid) + "/cwd").c_str(),
+          ("/proc/" + blaze_util::ToString(pid) + "/cwd").c_str(),
           server_cwd, sizeof(server_cwd)) < 0) {
     return nullptr;
   }
@@ -191,7 +191,7 @@
 
 void WriteSystemSpecificProcessIdentifier(const blaze_util::Path &server_dir,
                                           pid_t server_pid) {
-  string pid_string = ToString(server_pid);
+  string pid_string = blaze_util::ToString(server_pid);
 
   string start_time;
   if (!GetStartTime(pid_string, &start_time)) {
@@ -213,7 +213,7 @@
 // than there are PIDs available within a single jiffy.
 bool VerifyServerProcess(int pid, const blaze_util::Path &output_base) {
   string start_time;
-  if (!GetStartTime(ToString(pid), &start_time)) {
+  if (!GetStartTime(blaze_util::ToString(pid), &start_time)) {
     // Cannot read PID file from /proc . Process died meantime, all is good. No
     // stale server is present.
     return false;
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index 25f57b3..1cbea52 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -211,7 +211,7 @@
 }
 
 string GetProcessIdAsString() {
-  return ToString(getpid());
+  return blaze_util::ToString(getpid());
 }
 
 string GetHomeDir() { return GetPathEnv("HOME"); }
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index e01e052..c1194c4 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -380,7 +380,7 @@
 void WarnFilesystemType(const blaze_util::Path& output_base) {}
 
 string GetProcessIdAsString() {
-  return ToString(GetCurrentProcessId());
+  return blaze_util::ToString(GetCurrentProcessId());
 }
 
 string GetSelfPath(const char* argv0) {
@@ -554,7 +554,8 @@
   }
 
   blaze_util::Path start_time_file = server_dir.GetRelative("server.starttime");
-  if (!blaze_util::WriteFile(ToString(start_time), start_time_file)) {
+  if (!blaze_util::WriteFile(blaze_util::ToString(start_time),
+                             start_time_file)) {
     BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
         << "WriteProcessStartupTime(" << server_dir.AsPrintablePath()
         << "): WriteFile(" << start_time_file.AsPrintablePath()
@@ -729,7 +730,7 @@
   // Pass ownership of processInfo.hProcess
   *server_startup = new ProcessHandleBlazeServerStartup(processInfo.hProcess);
 
-  string pid_string = ToString(processInfo.dwProcessId);
+  string pid_string = blaze_util::ToString(processInfo.dwProcessId);
   blaze_util::Path pid_file = server_dir.GetRelative(kServerPidFile);
   if (!blaze_util::WriteFile(pid_string, pid_file)) {
     // Not a lot we can do if this fails
@@ -854,7 +855,8 @@
 
   // If start time file got deleted, but PID file didn't, assume that this is an
   // old Bazel process that doesn't know how to write start time files yet.
-  return !file_present || recorded_start_time == ToString(start_time);
+  return !file_present ||
+      recorded_start_time == blaze_util::ToString(start_time);
 }
 
 bool KillServerProcess(int pid, const blaze_util::Path& output_base) {
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index e44af24..69b73a8 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -642,9 +642,9 @@
   std::vector<std::string> result = {
       "--rc_source=client",
       "--default_override=0:common=--isatty=" +
-          ToString(IsStandardTerminal()),
+          blaze_util::ToString(IsStandardTerminal()),
       "--default_override=0:common=--terminal_columns=" +
-          ToString(GetTerminalColumns())};
+          blaze_util::ToString(GetTerminalColumns())};
   if (IsEmacsTerminal()) {
     result.push_back("--default_override=0:common=--emacs");
   }
diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h
index f92ec4c..3b89016 100644
--- a/src/main/cpp/util/strings.h
+++ b/src/main/cpp/util/strings.h
@@ -24,6 +24,20 @@
 
 namespace blaze_util {
 
+// Returns the string representation of `value`.
+// Workaround for mingw where std::to_string is not implemented.
+// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015.
+template <typename T>
+std::string ToString(const T &value) {
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+  std::ostringstream oss;
+  oss << value;
+  return oss.str();
+#else
+  return std::to_string(value);
+#endif
+}
+
 // Space characters according to Python: chr(i).isspace()
 static inline bool ascii_isspace(unsigned char c) {
   return c == 9       // TAB