From 165e7684a1c05d118baaf16449d97f895855db80 Mon Sep 17 00:00:00 2001 From: hvd Date: Mon, 27 Mar 2023 02:40:54 -0700 Subject: [PATCH] Fix windows launcher maker compilation with mingw-gcc src/tools/launcher/launcher_maker.cc : fix paths passed to fstream() src/main/cpp/util/file_windows.cc : Using quotes to split integer literals is a c++14 feature src/main/cpp/util/port.h : `pid_t` is already defined with mingw src/main/cpp/util/strings.h : `std::to_string` has been added to mingw, workaround is no longer necessary Closes #17879. PiperOrigin-RevId: 519664019 Change-Id: I291e0979bded511ad1c437f2aeb9671e6f80800f --- src/main/cpp/util/file_windows.cc | 2 +- src/main/cpp/util/port.h | 2 ++ src/main/cpp/util/strings.h | 2 +- src/tools/launcher/launcher_maker.cc | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc index e49a1a863a84b7..33eba1f40122c4 100644 --- a/src/main/cpp/util/file_windows.cc +++ b/src/main/cpp/util/file_windows.cc @@ -216,7 +216,7 @@ FILETIME WindowsFileMtime::GetFuture(WORD years) { GetSystemTimeAsFileTime(&result); // 1 year in FILETIME. - constexpr ULONGLONG kOneYear = 365ULL * 24 * 60 * 60 * 10'000'000; + constexpr ULONGLONG kOneYear = 365ULL * 24 * 60 * 60 * 10000000; ULARGE_INTEGER result_value; result_value.LowPart = result.dwLowDateTime; diff --git a/src/main/cpp/util/port.h b/src/main/cpp/util/port.h index efd0b9511e2d62..a526209e01b9ff 100644 --- a/src/main/cpp/util/port.h +++ b/src/main/cpp/util/port.h @@ -140,7 +140,9 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; // wherever else it appears. Find some way to not have to declare a pid_t here, // either by making PID handling platform-independent or some other idea; remove // the following typedef afterwards. +#ifndef __MINGW32__ typedef int pid_t; +#endif // __MINGW32__ #endif // _WIN32 #endif // BAZEL_SRC_MAIN_CPP_UTIL_PORT_H_ diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h index a9557f8abea3eb..3a92f5d4acd164 100644 --- a/src/main/cpp/util/strings.h +++ b/src/main/cpp/util/strings.h @@ -29,7 +29,7 @@ namespace blaze_util { // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015. template std::string ToString(const T &value) { -#if defined(__CYGWIN__) || defined(__MINGW32__) +#if defined(__CYGWIN__) std::ostringstream oss; oss << value; return oss.str(); diff --git a/src/tools/launcher/launcher_maker.cc b/src/tools/launcher/launcher_maker.cc index 70811d047ebaea..02ec529f67532b 100644 --- a/src/tools/launcher/launcher_maker.cc +++ b/src/tools/launcher/launcher_maker.cc @@ -54,13 +54,13 @@ int main(int argc, char** argv) { std::wstring winfo_params = windows_path(argv[2]); std::wstring woutput_path = windows_path(argv[3]); - std::ifstream src(wlauncher_path, std::ios::binary); + std::ifstream src(wlauncher_path.c_str(), std::ios::binary); if (!src.good()) { fprintf(stderr, "Failed to open %ls: %s\n", wlauncher_path.c_str(), strerror(errno)); return 1; } - std::ofstream dst(woutput_path, std::ios::binary); + std::ofstream dst(woutput_path.c_str(), std::ios::binary); if (!dst.good()) { fprintf(stderr, "Failed to create %ls: %s\n", woutput_path.c_str(), strerror(errno)); @@ -68,7 +68,7 @@ int main(int argc, char** argv) { } dst << src.rdbuf(); - std::ifstream info_file(winfo_params); + std::ifstream info_file(winfo_params.c_str()); if (!info_file.good()) { fprintf(stderr, "Failed to open %ls: %s\n", winfo_params.c_str(), strerror(errno));