Extend libuv file translate mode workaround to all executables

Since libuv commit v1.14.1~7 (win: add uv__once_init() calls,
2017-08-30) the libuv initialization of the file translate mode may take
place even if we do not use a uv loop.  This change was included in our
libuv update commit f4a26c748b (libuv 2018-01-19).  Therefore use of
libuv even through `cmSystemTools::GetRealPath` in any executable may
trigger its file translate mode setting.

Factor out the logic added to `cmake.exe` by commit v3.9.0-rc4~10^2
(cmake: Fix default file translate mode when using libuv, 2017-06-13)
and re-use to initialize all executables.

Issue: #16962
This commit is contained in:
Brad King
2018-01-23 08:55:58 -05:00
parent 3b588ac582
commit 98628de812
7 changed files with 26 additions and 16 deletions
+1
View File
@@ -99,6 +99,7 @@ int main(int argc, char const* const* argv)
argv = args.argv(); argv = args.argv();
cmSystemTools::EnableMSVCDebugHook(); cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]); cmSystemTools::FindCMakeResources(argv[0]);
cmCPackLog log; cmCPackLog log;
+1
View File
@@ -75,6 +75,7 @@ int main(int argc, char const* const* argv)
argc = encoding_args.argc(); argc = encoding_args.argc();
argv = encoding_args.argv(); argv = encoding_args.argv();
cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]); cmSystemTools::FindCMakeResources(argv[0]);
cmDocumentation doc; cmDocumentation doc;
doc.addCMakeStandardDocSections(); doc.addCMakeStandardDocSections();
+1
View File
@@ -55,6 +55,7 @@ int main(int argc, char** argv)
int argc2 = encoding_args.argc(); int argc2 = encoding_args.argc();
char const* const* argv2 = encoding_args.argv(); char const* const* argv2 = encoding_args.argv();
cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv2[0]); cmSystemTools::FindCMakeResources(argv2[0]);
// check docs first so that X is not need to get docs // check docs first so that X is not need to get docs
// do docs, if args were given // do docs, if args were given
+17
View File
@@ -51,6 +51,8 @@
// include wincrypt.h after windows.h // include wincrypt.h after windows.h
#include <wincrypt.h> #include <wincrypt.h>
#include <fcntl.h> /* _O_TEXT */
#include "cm_uv.h" #include "cm_uv.h"
#else #else
#include <sys/time.h> #include <sys/time.h>
@@ -980,6 +982,21 @@ std::string cmSystemTools::GetRealPath(const std::string& path,
} }
#endif #endif
void cmSystemTools::InitializeLibUV()
{
#if defined(_WIN32)
// Perform libuv one-time initialization now, and then un-do its
// global _fmode setting so that using libuv does not change the
// default file text/binary mode. See libuv issue 840.
uv_loop_close(uv_default_loop());
#ifdef _MSC_VER
_set_fmode(_O_TEXT);
#else
_fmode = _O_TEXT;
#endif
#endif
}
bool cmSystemTools::RenameFile(const char* oldname, const char* newname) bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
{ {
#ifdef _WIN32 #ifdef _WIN32
+4
View File
@@ -503,6 +503,10 @@ public:
static std::string GetRealPath(const std::string& path, static std::string GetRealPath(const std::string& path,
std::string* errorMessage = 0); std::string* errorMessage = 0);
#endif #endif
/** Perform one-time initialization of libuv. */
static void InitializeLibUV();
private: private:
static bool s_ForceUnixPaths; static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole; static bool s_RunCommandHideConsole;
+1 -16
View File
@@ -16,10 +16,6 @@
#include "cmDynamicLoader.h" #include "cmDynamicLoader.h"
#endif #endif
#ifdef _WIN32
#include <fcntl.h> /* _O_TEXT */
#include <stdlib.h> /* _set_fmode, _fmode */
#endif
#include "cm_uv.h" #include "cm_uv.h"
#include "cmsys/Encoding.hxx" #include "cmsys/Encoding.hxx"
@@ -170,19 +166,8 @@ int main(int ac, char const* const* av)
ac = args.argc(); ac = args.argc();
av = args.argv(); av = args.argv();
#if defined(_WIN32)
// Perform libuv one-time initialization now, and then un-do its
// global _fmode setting so that using libuv does not change the
// default file text/binary mode. See libuv issue 840.
uv_loop_close(uv_default_loop());
#ifdef _MSC_VER
_set_fmode(_O_TEXT);
#else
_fmode = _O_TEXT;
#endif
#endif
cmSystemTools::EnableMSVCDebugHook(); cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(av[0]); cmSystemTools::FindCMakeResources(av[0]);
if (ac > 1) { if (ac > 1) {
if (strcmp(av[1], "--build") == 0) { if (strcmp(av[1], "--build") == 0) {
+1
View File
@@ -137,6 +137,7 @@ int main(int argc, char const* const* argv)
cmSystemTools::DoNotInheritStdPipes(); cmSystemTools::DoNotInheritStdPipes();
cmSystemTools::EnableMSVCDebugHook(); cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]); cmSystemTools::FindCMakeResources(argv[0]);
// Dispatch 'ctest --launch' mode directly. // Dispatch 'ctest --launch' mode directly.