diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratedFileStream.cxx | 12 | ||||
-rw-r--r-- | Source/cmGeneratedFileStream.h | 10 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 26 | ||||
-rw-r--r-- | Source/cm_codecvt.cxx | 6 | ||||
-rw-r--r-- | Source/cm_codecvt.hxx | 3 |
5 files changed, 23 insertions, 34 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 6212bbd..c72d6a7 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -14,11 +14,10 @@ #endif cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding) - : OriginalLocale(this->getloc()) { #ifndef CMAKE_BOOTSTRAP if (encoding != codecvt::None) { - this->imbue(std::locale(this->OriginalLocale, new codecvt(encoding))); + this->imbue(std::locale(this->getloc(), new codecvt(encoding))); } #else static_cast<void>(encoding); @@ -239,13 +238,16 @@ void cmGeneratedFileStream::SetTempExt(std::string const& ext) this->TempExt = ext; } -void cmGeneratedFileStream::WriteRaw(std::string const& data) +void cmGeneratedFileStream::WriteAltEncoding(std::string const& data, + Encoding encoding) { #ifndef CMAKE_BOOTSTRAP - std::locale activeLocale = this->imbue(this->OriginalLocale); + std::locale prevLocale = + this->imbue(std::locale(this->getloc(), new codecvt(encoding))); this->write(data.data(), data.size()); - this->imbue(activeLocale); + this->imbue(prevLocale); #else + static_cast<void>(encoding); this->write(data.data(), data.size()); #endif } diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index bb7e3bf..bfc121f 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -148,12 +148,8 @@ public: void SetTempExt(std::string const& ext); /** - * Writes the given string directly to the file without changing the - * encoding. + * Write a specific string using an alternate encoding. + * Afterward, the original encoding is restored. */ - void WriteRaw(std::string const& data); - -private: - // The original locale of the stream (performs no encoding conversion). - std::locale OriginalLocale; + void WriteAltEncoding(std::string const& data, Encoding encoding); }; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 106f76b..c11f5b4 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -88,27 +88,11 @@ void cmLocalNinjaGenerator::Generate() cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(), "localized /showIncludes string"); this->GetRulesFileStream() << "msvc_deps_prefix = "; -#ifdef _WIN32 - // Ninja uses the ANSI Windows APIs, so strings in the rules file - // typically need to be ANSI encoded. However, in this case the compiler - // is being invoked using the UTF-8 codepage so the /showIncludes prefix - // will be UTF-8 encoded on stdout. Ninja can't successfully compare this - // UTF-8 encoded prefix to the ANSI encoded msvc_deps_prefix if it - // contains any non-ASCII characters and dependency checking will fail. - // As a workaround, leave the msvc_deps_prefix UTF-8 encoded even though - // the rest of the file is ANSI encoded. - if (GetConsoleOutputCP() == CP_UTF8 && GetACP() != CP_UTF8 && - this->GetGlobalGenerator()->GetMakefileEncoding() != codecvt::None) { - this->GetRulesFileStream().WriteRaw(showIncludesPrefix); - } else { - // Ninja 1.11 and above uses the UTF-8 code page if it's supported, so - // in that case we can write it normally without using raw bytes. - this->GetRulesFileStream() << showIncludesPrefix; - } -#else - // It's safe to use the standard encoding on other platforms. - this->GetRulesFileStream() << showIncludesPrefix; -#endif + // 'cl /showIncludes' encodes output in the console output code page. + // It may differ from the encoding used for file paths in 'build.ninja'. + // Ninja matches the showIncludes prefix using its raw byte sequence. + this->GetRulesFileStream().WriteAltEncoding( + showIncludesPrefix, cmGeneratedFileStream::Encoding::ConsoleOutput); this->GetRulesFileStream() << "\n\n"; } } diff --git a/Source/cm_codecvt.cxx b/Source/cm_codecvt.cxx index 8115306..2d2a377 100644 --- a/Source/cm_codecvt.cxx +++ b/Source/cm_codecvt.cxx @@ -19,6 +19,12 @@ codecvt::codecvt(Encoding e) #endif { switch (e) { + case codecvt::ConsoleOutput: +#if defined(_WIN32) + m_noconv = false; + m_codepage = GetConsoleOutputCP(); + break; +#endif case codecvt::ANSI: #if defined(_WIN32) m_noconv = false; diff --git a/Source/cm_codecvt.hxx b/Source/cm_codecvt.hxx index 9af083f..f628de7 100644 --- a/Source/cm_codecvt.hxx +++ b/Source/cm_codecvt.hxx @@ -15,7 +15,8 @@ public: None, UTF8, UTF8_WITH_BOM, - ANSI + ANSI, + ConsoleOutput, }; #ifndef CMAKE_BOOTSTRAP |