mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-06 14:19:59 -05:00
cmcmd: Simplify vs_link_{exe,dll} output encoding logic
Revise commit7e359823c9(MSVC: Preserve linker output encoding, 2018-08-03, v3.13.0-rc1~223^2) using the approach from commitf7a5f28318(cmake: Fix '-E cat' command for binary files on Windows, 2020-10-13, v3.18.5~5^2).
This commit is contained in:
+15
-13
@@ -19,6 +19,7 @@
|
|||||||
#include "cmList.h"
|
#include "cmList.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
|
#include "cmProcessOutput.h"
|
||||||
#include "cmQtAutoMocUic.h"
|
#include "cmQtAutoMocUic.h"
|
||||||
#include "cmQtAutoRcc.h"
|
#include "cmQtAutoRcc.h"
|
||||||
#include "cmRange.h"
|
#include "cmRange.h"
|
||||||
@@ -1463,11 +1464,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args[1] == "vs_link_exe") {
|
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") {
|
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") {
|
if (args[1] == "cmake_llvm_rc") {
|
||||||
@@ -2219,19 +2220,16 @@ private:
|
|||||||
// For visual studio 2005 and newer manifest files need to be embedded into
|
// 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
|
// exe and dll's. This code does that in such a way that incremental linking
|
||||||
// still works.
|
// 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)
|
||||||
{
|
{
|
||||||
// MSVC tools print output in the language specified by the VSLANG
|
// MSVC tools print output in the language specified by the VSLANG
|
||||||
// environment variable, and encoded in the console output code page.
|
// environment variable, and encoded in the console output code page.
|
||||||
// RunCommand captures and converts it to our internal UTF-8 encoding.
|
// Since vs_link_{exe,dll} just wraps these, pass through that encoding.
|
||||||
// Then we print it as output through cmConsoleBuf:
|
// RunCommand tells RunSingleCommand to *not* convert encoding, so
|
||||||
// - NMake: Our output goes to a real console. cmConsoleBuf writes
|
// we buffer the output in its original encoding instead of UTF-8.
|
||||||
// with WriteConsoleW, so no narrow encoding code page is needed.
|
// Drop our output encoding conversion so we print with original encoding.
|
||||||
// - Ninja: Our output goes to a pipe that ninja buffers and prints again.
|
consoleBuf.reset();
|
||||||
// It does not convert encoding, so we must print in the console output
|
|
||||||
// code page even though it goes to a pipe.
|
|
||||||
// Both cases can be handled using a cmConsoleBuf without SetUTF8Pipes.
|
|
||||||
cmConsoleBuf consoleBuf;
|
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -2291,6 +2289,9 @@ static bool RunCommand(char const* comment,
|
|||||||
NumberFormat exitFormat, int* retCodeOut = nullptr,
|
NumberFormat exitFormat, int* retCodeOut = nullptr,
|
||||||
bool (*retCodeOkay)(int) = nullptr)
|
bool (*retCodeOkay)(int) = nullptr)
|
||||||
{
|
{
|
||||||
|
// See comment in VisualStudioLink for why we suppress encoding conversion.
|
||||||
|
cmProcessOutput::Encoding const encoding = cmProcessOutput::None;
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cout << comment << ":\n";
|
std::cout << comment << ":\n";
|
||||||
std::cout << cmJoin(command, " ") << '\n';
|
std::cout << cmJoin(command, " ") << '\n';
|
||||||
@@ -2298,7 +2299,8 @@ static bool RunCommand(char const* comment,
|
|||||||
std::string output;
|
std::string output;
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
bool commandResult = cmSystemTools::RunSingleCommand(
|
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 =
|
bool const retCodeSuccess =
|
||||||
retCode == 0 || (retCodeOkay && retCodeOkay(retCode));
|
retCode == 0 || (retCodeOkay && retCodeOkay(retCode));
|
||||||
bool const success = commandResult && retCodeSuccess;
|
bool const success = commandResult && retCodeSuccess;
|
||||||
|
|||||||
+2
-1
@@ -39,5 +39,6 @@ protected:
|
|||||||
static int RunPreprocessor(std::vector<std::string> const& command,
|
static int RunPreprocessor(std::vector<std::string> const& command,
|
||||||
std::string const& intermediate_file);
|
std::string const& intermediate_file);
|
||||||
static int RunLLVMRC(std::vector<std::string> const& args);
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user