[gn] Fix broken Windows builds
https://gn-review.googlesource.com/c/gn/+/14320 was submitted through CQ
despite failing to build on Windows. This fixes the broken bits.
Change-Id: Ibfd04f1480c9798c6ce8f68630fe4179f1b0eee2
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/14340
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/src/base/files/file_util_win.cc b/src/base/files/file_util_win.cc
index 150ddf6..c808bde 100644
--- a/src/base/files/file_util_win.cc
+++ b/src/base/files/file_util_win.cc
@@ -300,23 +300,25 @@
// Although it is nearly impossible to get a duplicate name with GUID, we
// still use a loop here in case it happens.
for (int i = 0; i < 100; ++i) {
- temp_name = dir.Append(FormatTemporaryFileName(UTF8ToWide(GenerateGUID())));
+ temp_name = dir.Append(
+ FilePath(UTF8ToUTF16(GenerateGUID()) + FILE_PATH_LITERAL(".tmp")));
file.Initialize(temp_name, kFlags);
if (file.IsValid())
break;
}
if (!file.IsValid()) {
- DPLOG(WARNING) << "Failed to get temporary file name in " << dir.value();
+ DPLOG(WARNING) << "Failed to get temporary file name in "
+ << UTF16ToUTF8(dir.value());
return file;
}
- wchar_t long_temp_name[MAX_PATH + 1];
- const DWORD long_name_len =
- GetLongPathName(temp_name.value().c_str(), long_temp_name, MAX_PATH);
+ char16_t long_temp_name[MAX_PATH + 1];
+ const DWORD long_name_len = GetLongPathName(
+ ToWCharT(temp_name.value().c_str()), ToWCharT(long_temp_name), MAX_PATH);
if (long_name_len != 0 && long_name_len <= MAX_PATH) {
*temp_file =
- FilePath(FilePath::StringPieceType(long_temp_name, long_name_len));
+ FilePath(FilePath::StringViewType(long_temp_name, long_name_len));
} else {
// GetLongPathName() failed, but we still have a temporary file.
*temp_file = std::move(temp_name);
diff --git a/src/gn/command_clean.cc b/src/gn/command_clean.cc
index 8261845..e6c52fc 100644
--- a/src/gn/command_clean.cc
+++ b/src/gn/command_clean.cc
@@ -51,7 +51,8 @@
base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES);
for (base::FilePath current = traversal.Next(); !current.empty();
current = traversal.Next()) {
- std::string basename = base::ToLowerASCII(current.BaseName().value());
+ base::FilePath::StringType basename =
+ base::ToLowerASCII(current.BaseName().value());
if (std::none_of(std::begin(remaining), std::end(remaining),
[&](auto rem) { return basename == rem; })) {
base::DeleteFile(current, true);
diff --git a/src/gn/commands.cc b/src/gn/commands.cc
index 3840761..030f2d5 100644
--- a/src/gn/commands.cc
+++ b/src/gn/commands.cc
@@ -12,6 +12,7 @@
#include "base/files/file_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "gn/builder.h"
#include "gn/config_values_extractors.h"
@@ -329,6 +330,14 @@
return std::nullopt;
}
+std::string ToUTF8(base::FilePath::StringType in) {
+#if defined(OS_WIN)
+ return base::UTF16ToUTF8(in);
+#else
+ return in;
+#endif
+}
+
} // namespace
CommandInfo::CommandInfo()
@@ -495,7 +504,7 @@
// for ninja to call GN and regenerate ninja files.
base::FilePath build_ninja_path(settings->GetFullPath(
SourceFile(settings->build_dir().value() + "build.ninja")));
- std::ifstream build_ninja_file(build_ninja_path.value());
+ std::ifstream build_ninja_file(ToUTF8(build_ninja_path.value()));
if (!build_ninja_file) {
// Couldn't open the build.ninja file.
Err(Location(), "Couldn't open build.ninja in this directory.",