summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-08-10 15:29:12 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-08-10 15:29:36 (GMT)
commitc65f6a524e3a782877e6747194a92dbf85184999 (patch)
tree16f6bf722ca2a33657f4f7e08dd4d86eb8987129
parent32ad8a86a27ecf472a64342b4b336c6b7feebf80 (diff)
parent37a279f8d11c0a8d9aefad770412108742ddaed7 (diff)
downloadCMake-c65f6a524e3a782877e6747194a92dbf85184999.zip
CMake-c65f6a524e3a782877e6747194a92dbf85184999.tar.gz
CMake-c65f6a524e3a782877e6747194a92dbf85184999.tar.bz2
Merge topic 'ninja-msvc-deps-prefix'
37a279f8d1 Ninja: Write msvc_deps_prefix as UTF-8 when console codepage is UTF-8 67599c7ada cmGeneratedFileStream: Add WriteRaw method Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5089
-rw-r--r--Source/cmGeneratedFileStream.cxx14
-rw-r--r--Source/cmGeneratedFileStream.h10
-rw-r--r--Source/cmLocalNinjaGenerator.cxx22
3 files changed, 43 insertions, 3 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 345f0ba..2768547 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -14,10 +14,11 @@
#endif
cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding)
+ : OriginalLocale(getloc())
{
#ifndef CMAKE_BOOTSTRAP
if (encoding != codecvt::None) {
- imbue(std::locale(getloc(), new codecvt(encoding)));
+ imbue(std::locale(OriginalLocale, new codecvt(encoding)));
}
#else
static_cast<void>(encoding);
@@ -228,3 +229,14 @@ void cmGeneratedFileStream::SetTempExt(std::string const& ext)
{
this->TempExt = ext;
}
+
+void cmGeneratedFileStream::WriteRaw(std::string const& data)
+{
+#ifndef CMAKE_BOOTSTRAP
+ std::locale activeLocale = this->imbue(this->OriginalLocale);
+ this->write(data.data(), data.size());
+ this->imbue(activeLocale);
+#else
+ this->write(data.data(), data.size());
+#endif
+}
diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h
index 3dee142..f6da86e 100644
--- a/Source/cmGeneratedFileStream.h
+++ b/Source/cmGeneratedFileStream.h
@@ -147,6 +147,16 @@ public:
* This does not work if the file was opened by the constructor.
*/
void SetTempExt(std::string const& ext);
+
+ /**
+ * Writes the given string directly to the file without changing the
+ * encoding.
+ */
+ void WriteRaw(std::string const& data);
+
+private:
+ // The original locale of the stream (performs no encoding conversion).
+ std::locale OriginalLocale;
};
#endif
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index ef34953..eb841d9 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -84,8 +84,26 @@ void cmLocalNinjaGenerator::Generate()
if (!showIncludesPrefix.empty()) {
cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(),
"localized /showIncludes string");
- this->GetRulesFileStream()
- << "msvc_deps_prefix = " << showIncludesPrefix << "\n\n";
+ 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->GetRulesFileStream().WriteRaw(showIncludesPrefix);
+ } else {
+ this->GetRulesFileStream() << showIncludesPrefix;
+ }
+#else
+ // It's safe to use the standard encoding on other platforms.
+ this->GetRulesFileStream() << showIncludesPrefix;
+#endif
+ this->GetRulesFileStream() << "\n\n";
}
}