From 588a803d586447582b8398a92c3d93808f80e285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei-Yin=20Chen=20=28=E9=99=B3=E5=A8=81=E5=B0=B9=29?= Date: Fri, 19 Aug 2016 15:25:54 -0700 Subject: [PATCH 1/4] Support Unicode build on Windows --- appveyor.bat | 2 +- appveyor.yml | 1 + cmake/CMakeLists.txt | 4 ++++ src/google/protobuf/testing/file.cc | 16 ++++++++-------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/appveyor.bat b/appveyor.bat index 0e6dd520..58cc9355 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -10,7 +10,7 @@ goto :error echo Building C++ mkdir build_msvc cd build_msvc -cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% ../cmake +cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -DUNICODE=%UNICODE% ../cmake msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error cd %configuration% tests.exe || goto error diff --git a/appveyor.yml b/appveyor.yml index 2ea3cb78..20fc8ade 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,6 +11,7 @@ environment: matrix: - language: cpp BUILD_DLL: ON + UNICODE: ON - language: csharp diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f947b741..8c374b7e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -159,6 +159,10 @@ else (MSVC) set(LIB_PREFIX) endif (MSVC) +if (UNICODE) + add_definitions(-DUNICODE -D_UNICODE) +endif (UNICODE) + include(libprotobuf-lite.cmake) include(libprotobuf.cmake) include(libprotoc.cmake) diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index bc76c844..470512ed 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -141,12 +141,12 @@ void File::DeleteRecursively(const string& name, #ifdef _MSC_VER // This interface is so weird. - WIN32_FIND_DATA find_data; - HANDLE find_handle = FindFirstFile((name + "/*").c_str(), &find_data); + WIN32_FIND_DATAA find_data; + HANDLE find_handle = FindFirstFileA((name + "/*").c_str(), &find_data); if (find_handle == INVALID_HANDLE_VALUE) { // Just delete it, whatever it is. - DeleteFile(name.c_str()); - RemoveDirectory(name.c_str()); + DeleteFileA(name.c_str()); + RemoveDirectoryA(name.c_str()); return; } @@ -156,15 +156,15 @@ void File::DeleteRecursively(const string& name, string path = name + "/" + entry_name; if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { DeleteRecursively(path, NULL, NULL); - RemoveDirectory(path.c_str()); + RemoveDirectoryA(path.c_str()); } else { - DeleteFile(path.c_str()); + DeleteFileA(path.c_str()); } } - } while(FindNextFile(find_handle, &find_data)); + } while(FindNextFileA(find_handle, &find_data)); FindClose(find_handle); - RemoveDirectory(name.c_str()); + RemoveDirectoryA(name.c_str()); #else // Use opendir()! Yay! // lstat = Don't follow symbolic links. From 11d6cb56d0df8427dd1a768d39a9717c2c4a7e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei-Yin=20Chen=20=28=E9=99=B3=E5=A8=81=E5=B0=B9=29?= Date: Fri, 19 Aug 2016 16:40:57 -0700 Subject: [PATCH 2/4] Add test for Win32ErrorMessage --- .../protobuf/compiler/command_line_interface_unittest.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 0ebf9b6a..dee438c6 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -719,6 +719,11 @@ TEST_F(CommandLineInterfaceTest, TrailingBackslash) { ExpectGenerated("test_generator", "", "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, Win32ErrorMessage) { + EXPECT_EQ("The system cannot find the file specified.\r\n", + Subprocess::Win32ErrorMessage(ERROR_FILE_NOT_FOUND)); +} + #endif // defined(_WIN32) || defined(__CYGWIN__) TEST_F(CommandLineInterfaceTest, PathLookup) { From 48811b2eddadf723b0685934025735163c74362f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei-Yin=20Chen=20=28=E9=99=B3=E5=A8=81=E5=B0=B9=29?= Date: Fri, 19 Aug 2016 16:41:55 -0700 Subject: [PATCH 3/4] Fix Win32ErrorMessage on Unicode build --- src/google/protobuf/compiler/subprocess.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 6e258664..e929e4fb 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -261,12 +261,12 @@ string Subprocess::Win32ErrorMessage(DWORD error_code) { char* message; // WTF? - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error_code, 0, - (LPTSTR)&message, // NOT A BUG! - 0, NULL); + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, error_code, 0, + (LPSTR)&message, // NOT A BUG! + 0, NULL); string result = message; LocalFree(message); From a7eaf3696725d22e40ef2689bd2e8f32749d2df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei-Yin=20Chen=20=28=E9=99=B3=E5=A8=81=E5=B0=B9=29?= Date: Thu, 1 Sep 2016 17:12:49 -0700 Subject: [PATCH 4/4] Rename UNICODE to protobuf_UNICODE --- appveyor.bat | 2 +- cmake/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.bat b/appveyor.bat index 58cc9355..916f4434 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -10,7 +10,7 @@ goto :error echo Building C++ mkdir build_msvc cd build_msvc -cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -DUNICODE=%UNICODE% ../cmake +cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% ../cmake msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error cd %configuration% tests.exe || goto error diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 8c374b7e..df3b2012 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -159,9 +159,9 @@ else (MSVC) set(LIB_PREFIX) endif (MSVC) -if (UNICODE) +if (protobuf_UNICODE) add_definitions(-DUNICODE -D_UNICODE) -endif (UNICODE) +endif (protobuf_UNICODE) include(libprotobuf-lite.cmake) include(libprotobuf.cmake)