cmSystemTools: Teach MaybePrependCmdExe to return GetShortPathNameW failure
This commit is contained in:
parent
611a3000f7
commit
817b3967f8
@ -787,11 +787,13 @@ std::size_t cmSystemTools::CalculateCommandLineLengthLimit()
|
||||
return sz;
|
||||
}
|
||||
|
||||
void cmSystemTools::MaybePrependCmdExe(std::vector<std::string>& cmdLine)
|
||||
cmsys::Status cmSystemTools::MaybePrependCmdExe(
|
||||
std::vector<std::string>& cmdLine)
|
||||
{
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
cmsys::Status status;
|
||||
if (!cmdLine.empty()) {
|
||||
auto const& applicationName = cmdLine.at(0);
|
||||
std::string& applicationName = cmdLine.at(0);
|
||||
static cmsys::RegularExpression const winCmdRegex(
|
||||
"\\.([Bb][Aa][Tt]|[Cc][Mm][Dd])$");
|
||||
cmsys::RegularExpressionMatch winCmdMatch;
|
||||
@ -800,22 +802,21 @@ void cmSystemTools::MaybePrependCmdExe(std::vector<std::string>& cmdLine)
|
||||
output.reserve(cmdLine.size() + 2);
|
||||
output.emplace_back(cmSystemTools::GetComspec());
|
||||
output.emplace_back("/c");
|
||||
std::string tmpShortPath;
|
||||
if (applicationName.find(' ') != std::string::npos &&
|
||||
cmSystemTools::GetShortPath(applicationName, tmpShortPath)) {
|
||||
// If the batch file name contains spaces convert it to the windows
|
||||
// short path. Otherwise it might cause issue when running cmd.exe.
|
||||
output.emplace_back(tmpShortPath);
|
||||
} else {
|
||||
output.push_back(applicationName);
|
||||
if (applicationName.find(' ') != std::string::npos) {
|
||||
// Convert the batch file path to a short path to avoid spaces.
|
||||
// Otherwise, cmd.exe may not handle arguments with spaces.
|
||||
status = cmSystemTools::GetShortPath(applicationName, applicationName);
|
||||
}
|
||||
output.push_back(applicationName);
|
||||
std::move(cmdLine.begin() + 1, cmdLine.end(),
|
||||
std::back_inserter(output));
|
||||
cmdLine = std::move(output);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
#else
|
||||
static_cast<void>(cmdLine);
|
||||
return cmsys::Status::Success();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -246,12 +246,12 @@ public:
|
||||
* attempting to execute the batch files.
|
||||
*
|
||||
* Also cmd.exe is unable to parse batch file names correctly if they
|
||||
* contain spaces. This function uses cmSystemTools::GetShortPath conversion
|
||||
* to suppress this behavior.
|
||||
* contain spaces. This function uses cmSystemTools::GetShortPath
|
||||
* conversion to suppress this behavior, and returns its status.
|
||||
*
|
||||
* The function is noop on platforms different from the pure WIN32 one.
|
||||
*/
|
||||
static void MaybePrependCmdExe(std::vector<std::string>& cmdLine);
|
||||
static cmsys::Status MaybePrependCmdExe(std::vector<std::string>& cmdLine);
|
||||
|
||||
/**
|
||||
* Run a single executable command
|
||||
|
Loading…
Reference in New Issue
Block a user