From 2d262efd296dfd1802631978d9b9ab23fdf135a4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Feb 2026 15:05:21 -0500 Subject: [PATCH] cmNinjaTargetGenerator: Factor out helper for shell path arguments --- Source/cmNinjaTargetGenerator.cxx | 57 ++++++++++++++----------------- Source/cmNinjaTargetGenerator.h | 4 +++ 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 653466b524..7ef33a9603 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -517,6 +517,13 @@ std::string cmNinjaTargetGenerator::GetTargetName() const return this->GeneratorTarget->GetName(); } +std::string cmNinjaTargetGenerator::ConvertToOutputFormatForShell( + cm::string_view path) const +{ + return this->LocalGenerator->ConvertToOutputFormat(path, + cmOutputConverter::SHELL); +} + bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable( cmNinjaVars& vars, std::string const& config) const { @@ -534,11 +541,10 @@ bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable( this->GeneratorTarget->GetPDBName(config)); } - vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(pdbPath), cmOutputConverter::SHELL); - vars["TARGET_COMPILE_PDB"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(compilePdbPath), cmOutputConverter::SHELL); + vars["TARGET_PDB"] = + this->ConvertToOutputFormatForShell(this->ConvertToNinjaPath(pdbPath)); + vars["TARGET_COMPILE_PDB"] = this->ConvertToOutputFormatForShell( + this->ConvertToNinjaPath(compilePdbPath)); this->EnsureParentDirectoryExists(pdbPath); this->EnsureParentDirectoryExists(compilePdbPath); @@ -693,9 +699,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(std::string const& lang, auto rulePlaceholderExpander = this->GetLocalGenerator()->CreateRulePlaceholderExpander(); - std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)), - cmLocalGenerator::SHELL); + std::string const tdi = this->ConvertToOutputFormatForShell( + this->ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config))); std::string launcher; std::string val = this->GetLocalGenerator()->GetRuleLauncher( @@ -705,8 +710,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(std::string const& lang, } std::string const cmakeCmd = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); + this->ConvertToOutputFormatForShell(cmSystemTools::GetCMakeCommand()); if (withScanning == WithScanning::Yes) { auto const& scanDepType = this->GetMakefile()->GetSafeDefinition( @@ -1298,8 +1302,7 @@ void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap( this->LocalGenerator->AppendFlags(flags, "-output-file-map"); this->LocalGenerator->AppendFlags( flags, - this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(mapFilePath), cmOutputConverter::SHELL)); + this->ConvertToOutputFormatForShell(ConvertToNinjaPath(mapFilePath))); } namespace { @@ -1442,8 +1445,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( : this->GetGeneratorTarget()->GetPropertyAsBool("SKIP_LINTING"); if (!skipCodeCheck) { - auto const cmakeCmd = this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); + auto const cmakeCmd = + this->ConvertToOutputFormatForShell(cmSystemTools::GetCMakeCommand()); vars["CODE_CHECK"] = this->GenerateCodeCheckRules(*source, compilerLauncher, cmakeCmd, config, [this](std::string const& path) { @@ -1659,13 +1662,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( this->EnsureParentDirectoryExists(objectFileName); - vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - objectDir, cmOutputConverter::SHELL); + vars["OBJECT_DIR"] = this->ConvertToOutputFormatForShell(objectDir); vars["TARGET_SUPPORT_DIR"] = - this->GetLocalGenerator()->ConvertToOutputFormat(targetSupportDir, - cmOutputConverter::SHELL); - vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - objectFileDir, cmOutputConverter::SHELL); + this->ConvertToOutputFormatForShell(targetSupportDir); + vars["OBJECT_FILE_DIR"] = this->ConvertToOutputFormatForShell(objectFileDir); this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), source, vars); @@ -1724,9 +1724,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( } } - vars["ISPC_HEADER_FILE"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - ispcHeader, cmOutputConverter::SHELL); + vars["ISPC_HEADER_FILE"] = this->ConvertToOutputFormatForShell(ispcHeader); } else { auto headers = this->GeneratorTarget->GetGeneratedISPCHeaders(config); if (!headers.empty()) { @@ -1890,13 +1888,10 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement( this->EnsureParentDirectoryExists(bmiFileName); - vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - bmiDir, cmOutputConverter::SHELL); + vars["OBJECT_DIR"] = this->ConvertToOutputFormatForShell(bmiDir); vars["TARGET_SUPPORT_DIR"] = - this->GetLocalGenerator()->ConvertToOutputFormat(targetSupportDir, - cmOutputConverter::SHELL); - vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( - bmiFileDir, cmOutputConverter::SHELL); + this->ConvertToOutputFormatForShell(targetSupportDir); + vars["OBJECT_FILE_DIR"] = this->ConvertToOutputFormatForShell(bmiFileDir); this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), source, vars); @@ -2530,9 +2525,7 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()( void cmNinjaTargetGenerator::AddDepfileBinding(cmNinjaVars& vars, std::string depfile) const { - std::string depfileForShell = - this->GetLocalGenerator()->ConvertToOutputFormat(depfile, - cmOutputConverter::SHELL); + std::string depfileForShell = this->ConvertToOutputFormatForShell(depfile); if (depfile != depfileForShell) { vars["depfile"] = std::move(depfile); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index c4dc51f930..81f945acd1 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include "cmCommonTargetGenerator.h" @@ -42,6 +44,8 @@ public: std::string GetTargetName() const; + std::string ConvertToOutputFormatForShell(cm::string_view path) const; + void AddDepfileBinding(cmNinjaVars& vars, std::string depfile) const; void RemoveDepfileBinding(cmNinjaVars& vars) const;