From 817b3967f875944d4514b876bee0a56c0c9f8dea Mon Sep 17 00:00:00 2001 From: Brad King Date: Sun, 2 Feb 2025 07:35:50 -0500 Subject: cmSystemTools: Teach MaybePrependCmdExe to return GetShortPathNameW failure --- Source/cmSystemTools.cxx | 21 +++++++++++---------- Source/cmSystemTools.h | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 54104db..13e3245 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -787,11 +787,13 @@ std::size_t cmSystemTools::CalculateCommandLineLengthLimit() return sz; } -void cmSystemTools::MaybePrependCmdExe(std::vector& cmdLine) +cmsys::Status cmSystemTools::MaybePrependCmdExe( + std::vector& 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& 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(cmdLine); + return cmsys::Status::Success(); #endif } diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 052c917..60a7095 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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& cmdLine); + static cmsys::Status MaybePrependCmdExe(std::vector& cmdLine); /** * Run a single executable command -- cgit v0.12