Bladeren bron

Merge topic 'msvc-link-i18n'

89899c3ad2 cmcmd: Simplify vs_link_{exe,dll} output encoding logic
c11c86c098 cmcmd: Clarify comment explaining vs_link_{exe,dll} output encoding

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10675
Brad King 7 maanden geleden
bovenliggende
commit
812fc9d8fa
2 gewijzigde bestanden met toevoegingen van 19 en 10 verwijderingen
  1. 17 9
      Source/cmcmd.cxx
  2. 2 1
      Source/cmcmd.h

+ 17 - 9
Source/cmcmd.cxx

@@ -19,6 +19,7 @@
 #include "cmList.h"
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
+#include "cmProcessOutput.h"
 #include "cmQtAutoMocUic.h"
 #include "cmQtAutoRcc.h"
 #include "cmRange.h"
@@ -1463,11 +1464,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
     }
 
     if (args[1] == "vs_link_exe") {
-      return cmcmd::VisualStudioLink(args, 1);
+      return cmcmd::VisualStudioLink(args, 1, std::move(consoleBuf));
     }
 
     if (args[1] == "vs_link_dll") {
-      return cmcmd::VisualStudioLink(args, 2);
+      return cmcmd::VisualStudioLink(args, 2, std::move(consoleBuf));
     }
 
     if (args[1] == "cmake_llvm_rc") {
@@ -2219,13 +2220,16 @@ private:
 // For visual studio 2005 and newer manifest files need to be embedded into
 // exe and dll's.  This code does that in such a way that incremental linking
 // still works.
-int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type)
+int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type,
+                            std::unique_ptr<cmConsoleBuf> consoleBuf)
 {
-  // Replace streambuf so we output in the system codepage. CMake is set up
-  // to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker
-  // outputs using the system codepage so we need to change behavior when
-  // we run the link command.
-  cmConsoleBuf consoleBuf;
+  // MSVC tools print output in the language specified by the VSLANG
+  // environment variable, and encoded in the console output code page.
+  // Since vs_link_{exe,dll} just wraps these, pass through that encoding.
+  // RunCommand tells RunSingleCommand to *not* convert encoding, so
+  // we buffer the output in its original encoding instead of UTF-8.
+  // Drop our output encoding conversion so we print with original encoding.
+  consoleBuf.reset();
 
   if (args.size() < 2) {
     return -1;
@@ -2285,6 +2289,9 @@ static bool RunCommand(char const* comment,
                        NumberFormat exitFormat, int* retCodeOut = nullptr,
                        bool (*retCodeOkay)(int) = nullptr)
 {
+  // See comment in VisualStudioLink for why we suppress encoding conversion.
+  cmProcessOutput::Encoding const encoding = cmProcessOutput::None;
+
   if (verbose) {
     std::cout << comment << ":\n";
     std::cout << cmJoin(command, " ") << '\n';
@@ -2292,7 +2299,8 @@ static bool RunCommand(char const* comment,
   std::string output;
   int retCode = 0;
   bool commandResult = cmSystemTools::RunSingleCommand(
-    command, &output, &output, &retCode, nullptr, cmSystemTools::OUTPUT_NONE);
+    command, &output, &output, &retCode, nullptr, cmSystemTools::OUTPUT_NONE,
+    cmDuration::zero(), encoding);
   bool const retCodeSuccess =
     retCode == 0 || (retCodeOkay && retCodeOkay(retCode));
   bool const success = commandResult && retCodeSuccess;

+ 2 - 1
Source/cmcmd.h

@@ -39,5 +39,6 @@ protected:
   static int RunPreprocessor(std::vector<std::string> const& command,
                              std::string const& intermediate_file);
   static int RunLLVMRC(std::vector<std::string> const& args);
-  static int VisualStudioLink(std::vector<std::string> const& args, int type);
+  static int VisualStudioLink(std::vector<std::string> const& args, int type,
+                              std::unique_ptr<cmConsoleBuf> consoleBuf);
 };