From ef553410e24959dac8413a7f2277d42530fbc0f7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 May 2021 14:21:56 -0400 Subject: Ninja/Swift: Remove redundant calls to ConvertToNinjaPath `GetSourceFilePath` already handles converting to a Ninja path. --- Source/cmNinjaNormalTargetGenerator.cxx | 8 +++----- Source/cmNinjaTargetGenerator.cxx | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 1b514b8..e443981 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -1072,9 +1072,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( cmLocalGenerator const* LocalGen = this->GetLocalGenerator(); for (const auto& source : sources) { oss << " " - << LocalGen->ConvertToOutputFormat( - this->ConvertToNinjaPath(this->GetSourceFilePath(source)), - cmOutputConverter::SHELL); + << LocalGen->ConvertToOutputFormat(this->GetSourceFilePath(source), + cmOutputConverter::SHELL); } return oss.str(); }(); @@ -1094,8 +1093,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( for (const auto& source : sources) { linkBuild.Outputs.push_back( this->ConvertToNinjaPath(this->GetObjectFilePath(source, config))); - linkBuild.ExplicitDeps.push_back( - this->ConvertToNinjaPath(this->GetSourceFilePath(source))); + linkBuild.ExplicitDeps.emplace_back(this->GetSourceFilePath(source)); } linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]); } else { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 3ebf364..669953f 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1575,8 +1575,7 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang, void cmNinjaTargetGenerator::EmitSwiftDependencyInfo( cmSourceFile const* source, const std::string& config) { - std::string const sourceFilePath = - this->ConvertToNinjaPath(this->GetSourceFilePath(source)); + std::string const sourceFilePath = this->GetSourceFilePath(source); std::string const objectFilePath = this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)); std::string const swiftDepsPath = [source, objectFilePath]() -> std::string { -- cgit v0.12 From 51116c3ea9d9d69c9c71cf736225f1ef0e927593 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 19 May 2021 13:58:46 -0400 Subject: cmLocalNinjaGenerator: Remove unnecessary CollapseFullPath call `ConvertToIncludeReference` is only called with absolute paths. One branch already assumed this. --- Source/cmLocalNinjaGenerator.cxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index fb6c730..22a1a1a 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -209,9 +209,7 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference( cmOutputConverter::OutputFormat format) { if (pathStyle == IncludePathStyle::Absolute) { - return this->ConvertToOutputFormat( - cmSystemTools::CollapseFullPath(path, this->GetCurrentBinaryDirectory()), - format); + return this->ConvertToOutputFormat(path, format); } return this->ConvertToOutputFormat(this->MaybeRelativeToTopBinDir(path), format); -- cgit v0.12 From dfc98774a2bca87bf6c2b986389763100fd59037 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 19 May 2021 14:29:52 -0400 Subject: cmNinjaTargetGenerator: Rename local variable for clarity --- Source/cmNinjaTargetGenerator.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 669953f..b22f8f7 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1199,7 +1199,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( const std::string& fileConfig, bool firstForConfig) { std::string const language = source->GetLanguage(); - std::string const sourceFileName = + std::string const sourceFilePath = language == "RC" ? source->GetFullPath() : this->GetSourceFilePath(source); std::string const objectDir = this->ConvertToNinjaPath( cmStrCat(this->GeneratorTarget->GetSupportDirectory(), @@ -1251,7 +1251,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( } this->ExportObjectCompileCommand( - language, sourceFileName, objectDir, objectFileName, objectFileDir, + language, sourceFilePath, objectDir, objectFileName, objectFileDir, vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"], config); objBuild.Outputs.push_back(objectFileName); @@ -1265,7 +1265,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( } } - objBuild.ExplicitDeps.push_back(sourceFileName); + objBuild.ExplicitDeps.push_back(sourceFilePath); // Add precompile headers dependencies std::vector depList; @@ -1323,9 +1323,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (source->GetIsGenerated() && !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") && !source->GetCustomCommand() && - !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) { + !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFilePath)) { this->GetGlobalGenerator()->AddAssumedSourceDependencies( - sourceFileName, objBuild.OrderOnlyDeps); + sourceFilePath, objBuild.OrderOnlyDeps); } // For some cases we scan to dynamically discover dependencies. -- cgit v0.12 From 0f2b1c9d1bc4f802a4ecb647f2ca7258fc378df5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 May 2021 14:16:09 -0400 Subject: cmNinjaTargetGenerator: Remove GetSourceFilePath call with different semantics Reference external object files using `ConvertToNinjaPath` directly. `GetSourceFilePath` is meant to reference source files to be compiled. --- Source/cmNinjaTargetGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b22f8f7..5c365c4 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -987,7 +987,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( this->GeneratorTarget->GetExternalObjects(externalObjects, config); for (cmSourceFile const* sf : externalObjects) { auto objectFileName = this->GetGlobalGenerator()->ExpandCFGIntDir( - this->GetSourceFilePath(sf), config); + this->ConvertToNinjaPath(sf->GetFullPath()), config); if (!cmSystemTools::StringEndsWith(objectFileName, cmToCStr(pchExtension))) { this->Configs[config].Objects.push_back(objectFileName); -- cgit v0.12 From fb3a57575aa91c636963a12b7d0b6ec64bfce241 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 19 May 2021 14:14:53 -0400 Subject: cmNinjaTargetGenerator: Rename source file path lookup method for clarity The `GetSourceFilePath` method is meant only for compiled sources, and automatically handles converting it to a path for the Ninja build manifest. Rename the method to clarify both. --- Source/cmNinjaNormalTargetGenerator.cxx | 8 +++++--- Source/cmNinjaTargetGenerator.cxx | 9 +++++---- Source/cmNinjaTargetGenerator.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index e443981..e5e57d2 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -1072,8 +1072,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( cmLocalGenerator const* LocalGen = this->GetLocalGenerator(); for (const auto& source : sources) { oss << " " - << LocalGen->ConvertToOutputFormat(this->GetSourceFilePath(source), - cmOutputConverter::SHELL); + << LocalGen->ConvertToOutputFormat( + this->GetCompiledSourceNinjaPath(source), + cmOutputConverter::SHELL); } return oss.str(); }(); @@ -1093,7 +1094,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( for (const auto& source : sources) { linkBuild.Outputs.push_back( this->ConvertToNinjaPath(this->GetObjectFilePath(source, config))); - linkBuild.ExplicitDeps.emplace_back(this->GetSourceFilePath(source)); + linkBuild.ExplicitDeps.emplace_back( + this->GetCompiledSourceNinjaPath(source)); } linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]); } else { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5c365c4..5499ff7 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -379,7 +379,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps( return result; } -std::string cmNinjaTargetGenerator::GetSourceFilePath( +std::string cmNinjaTargetGenerator::GetCompiledSourceNinjaPath( cmSourceFile const* source) const { return this->ConvertToNinjaPath(source->GetFullPath()); @@ -1199,8 +1199,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( const std::string& fileConfig, bool firstForConfig) { std::string const language = source->GetLanguage(); - std::string const sourceFilePath = - language == "RC" ? source->GetFullPath() : this->GetSourceFilePath(source); + std::string const sourceFilePath = language == "RC" + ? source->GetFullPath() + : this->GetCompiledSourceNinjaPath(source); std::string const objectDir = this->ConvertToNinjaPath( cmStrCat(this->GeneratorTarget->GetSupportDirectory(), this->GetGlobalGenerator()->ConfigDirectory(config))); @@ -1575,7 +1576,7 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang, void cmNinjaTargetGenerator::EmitSwiftDependencyInfo( cmSourceFile const* source, const std::string& config) { - std::string const sourceFilePath = this->GetSourceFilePath(source); + std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source); std::string const objectFilePath = this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)); std::string const swiftDepsPath = [source, objectFilePath]() -> std::string { diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 3a28cef..72f6b5f 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -116,7 +116,7 @@ protected: bool ignoreType = false) const; /// @return the source file path for the given @a source. - std::string GetSourceFilePath(cmSourceFile const* source) const; + std::string GetCompiledSourceNinjaPath(cmSourceFile const* source) const; /// @return the object file path for the given @a source. std::string GetObjectFilePath(cmSourceFile const* source, -- cgit v0.12 From efb8d7b4a1d82f2ce4bb01f200367679a6dc46c4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 May 2021 14:39:43 -0400 Subject: cmNinjaTargetGenerator: Reduce string copies in ConvertToNinjaPath wrapper The global generator's method returns a reference to a cached value. Return that from the wrapper too. --- Source/cmNinjaTargetGenerator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 72f6b5f..daf7817 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -101,7 +101,7 @@ protected: const std::string& language, const std::string& config); - std::string ConvertToNinjaPath(const std::string& path) const + std::string const& ConvertToNinjaPath(const std::string& path) const { return this->GetGlobalGenerator()->ConvertToNinjaPath(path); } -- cgit v0.12 From 18408c0b88423a40d239705eb28b65b481cf0973 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 May 2021 14:36:58 -0400 Subject: cmGlobalNinjaGenerator: Add helper to compute absolute paths for build.ninja --- Source/cmGlobalNinjaGenerator.cxx | 9 +++++++++ Source/cmGlobalNinjaGenerator.h | 1 + Source/cmNinjaTargetGenerator.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 6034434..09cbaec 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1160,6 +1160,15 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath( .first->second; } +std::string cmGlobalNinjaGenerator::ConvertToNinjaAbsPath( + std::string path) const +{ +#ifdef _WIN32 + std::replace(path.begin(), path.end(), '/', '\\'); +#endif + return path; +} + void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName, const std::string& config) { diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 7a3674e..bb4ce2b 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -261,6 +261,7 @@ public: } std::string const& ConvertToNinjaPath(const std::string& path) const; + std::string ConvertToNinjaAbsPath(std::string path) const; struct MapToNinjaPathImpl { diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index daf7817..4b4cf8d 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -110,6 +110,11 @@ protected: return this->GetGlobalGenerator()->MapToNinjaPath(); } + std::string ConvertToNinjaAbsPath(std::string path) const + { + return this->GetGlobalGenerator()->ConvertToNinjaAbsPath(std::move(path)); + } + /// @return the list of link dependency for the given target @a target. cmNinjaDeps ComputeLinkDeps(const std::string& linkLanguage, const std::string& config, -- cgit v0.12 From 48471cfd18d5b2b6b4fd7270d21732335156d086 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 May 2021 16:52:54 -0400 Subject: cmNinjaNormalTargetGenerator: Factor out build event byproduct collection This was left out of commit 68e5f92cad (cmGlobalNinjaGenerator: Factor out custom command output collection, 2021-05-18). --- Source/cmNinjaNormalTargetGenerator.cxx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index e5e57d2..4c33334 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -1195,7 +1195,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( } } - cmNinjaDeps byproducts; + cmGlobalNinjaGenerator::CCOutputs byproducts(this->GetGlobalGenerator()); if (!tgtNames.ImportLibrary.empty()) { const std::string impLibPath = localGen.ConvertToOutputFormat( @@ -1203,7 +1203,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( vars["TARGET_IMPLIB"] = impLibPath; this->EnsureParentDirectoryExists(impLibPath); if (gt->HasImportLibrary(config)) { - byproducts.push_back(targetOutputImplib); + // Some linkers may update a binary without touching its import lib. + byproducts.ExplicitOuts.emplace_back(targetOutputImplib); if (firstForConfig) { globalGen->GetByproductsForCleanTarget(config).push_back( targetOutputImplib); @@ -1261,8 +1262,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( true, config); localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]); std::vector const& ccByproducts = ccg.GetByproducts(); - std::transform(ccByproducts.begin(), ccByproducts.end(), - std::back_inserter(byproducts), this->MapToNinjaPath()); + byproducts.Add(ccByproducts); std::transform( ccByproducts.begin(), ccByproducts.end(), std::back_inserter(globalGen->GetByproductsForCleanTarget()), @@ -1382,12 +1382,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( } // Ninja should restat after linking if and only if there are byproducts. - vars["RESTAT"] = byproducts.empty() ? "" : "1"; + vars["RESTAT"] = byproducts.ExplicitOuts.empty() ? "" : "1"; - for (std::string const& o : byproducts) { - globalGen->SeenCustomCommandOutput(o); - linkBuild.Outputs.push_back(o); - } + linkBuild.Outputs.reserve(linkBuild.Outputs.size() + + byproducts.ExplicitOuts.size()); + std::move(byproducts.ExplicitOuts.begin(), byproducts.ExplicitOuts.end(), + std::back_inserter(linkBuild.Outputs)); + linkBuild.WorkDirOuts = std::move(byproducts.WorkDirOuts); // Write the build statement for this target. bool usedResponseFile = false; -- cgit v0.12 From eb98d4511146db844029c809fde81982d3928e54 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 25 May 2021 10:40:15 -0400 Subject: Ninja: Handle depfiles with absolute paths to generated files in Ninja < 1.7 Extend the change from commit 2725ecff38 (Ninja: Handle depfiles with absolute paths to generated files, 2021-05-19) to work on versions of Ninja that do not support implicit outputs. Specify the absolute paths as normal outputs on such versions. Issue: #13894, #21865 --- Source/cmGlobalNinjaGenerator.cxx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 09cbaec..a8a49a0 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -222,7 +222,9 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, } } // Write implicit outputs - if (!build.ImplicitOuts.empty() || !build.WorkDirOuts.empty()) { + if (!build.ImplicitOuts.empty()) { + // Assume Ninja is new enough to support implicit outputs. + // Callers should not populate this field otherwise. buildStr = cmStrCat(buildStr, " |"); for (std::string const& implicitOut : build.ImplicitOuts) { buildStr = cmStrCat(buildStr, ' ', this->EncodePath(implicitOut)); @@ -230,11 +232,18 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, this->CombinedBuildOutputs.insert(implicitOut); } } + } + + // Repeat some outputs, but expressed as absolute paths. + // This helps Ninja handle absolute paths found in a depfile. + // FIXME: Unfortunately this causes Ninja to stat the file twice. + // We could avoid this if Ninja Issue 1251 were fixed. + if (!build.WorkDirOuts.empty()) { + if (this->SupportsImplicitOuts() && build.ImplicitOuts.empty()) { + // Make them implicit outputs if supported by this version of Ninja. + buildStr = cmStrCat(buildStr, " |"); + } for (std::string const& workdirOut : build.WorkDirOuts) { - // Repeat some outputs, but expressed as absolute paths. - // This helps Ninja handle absolute paths found in a depfile. - // FIXME: Unfortunately this causes Ninja to stat the file twice. - // We could avoid this if Ninja Issue 1251 were fixed. buildStr = cmStrCat(buildStr, " ${cmake_ninja_workdir}", this->EncodePath(workdirOut)); } @@ -322,8 +331,7 @@ void cmGlobalNinjaGenerator::CCOutputs::Add( { for (std::string const& path : paths) { std::string out = this->GG->ConvertToNinjaPath(path); - if (this->GG->SupportsImplicitOuts() && - !cmSystemTools::FileIsFullPath(out)) { + if (!cmSystemTools::FileIsFullPath(out)) { // This output is expressed as a relative path. Repeat it, // but expressed as an absolute path for Ninja Issue 1251. this->WorkDirOuts.emplace_back(out); -- cgit v0.12 From c564a3e3fff52ef811291c5ba8fb07a5a1b47f97 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 19 May 2021 14:27:04 -0400 Subject: Ninja: Always compile sources using absolute paths The Ninja generator traditionally referenced source files and include directories using paths relative to the build directory if they could be expressed without a `../` sequence that leaves the build and source directories. For example, when using a `build/` directory inside the source tree, sources would be compiled as `-c ../src.c` and include directories would be referenced as `-I ../include`. This approach matches the traditional Ninja convention of using relative paths whenever possible, but has undesirable side effects such as: * Compiler diagnostic messages may not use absolute paths, making it harder for IDEs/editors to find the referenced sources or headers. * Debug symbols may not use absolute paths, making it harder for debuggers to find the referenced sources or headers. * Different results depending on the path to the build tree relative to the source tree. * Inconsistent with the Makefile generators, which use absolute paths. Switch to always using absolute paths to reference source files and include directories on compiler command lines. While alternative solutions for diagnostic messages and debug symbols may exist with specific tooling, this is the simplest and most consistent approach. Note that a previous attempt to do this in commit 955c2a630a (Ninja: Use full path for all source files, 2016-08-05, v3.7.0-rc1~275^2) was reverted by commit 666ad1df2d (Revert "Ninja: Use full path for all source files", 2017-02-24, v3.8.0-rc2~9^2) due to problems hooking up depfile dependencies on generated files. This time, the changes in commit 2725ecff38 (Ninja: Handle depfiles with absolute paths to generated files, 2021-05-19) should avoid those problems. Fixes: #13894, #17450 --- Help/release/dev/ninja-absolute-paths.rst | 6 ++++++ Source/cmGlobalNinjaGenerator.cxx | 1 + Source/cmLocalNinjaGenerator.cxx | 8 +++----- Source/cmNinjaTargetGenerator.cxx | 7 +++---- Tests/RunCMake/Ninja/RunCMakeTest.cmake | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 Help/release/dev/ninja-absolute-paths.rst diff --git a/Help/release/dev/ninja-absolute-paths.rst b/Help/release/dev/ninja-absolute-paths.rst new file mode 100644 index 0000000..2dfc1b7 --- /dev/null +++ b/Help/release/dev/ninja-absolute-paths.rst @@ -0,0 +1,6 @@ +ninja-absolute-paths +-------------------- + +* The :ref:`Ninja Generators` now pass source files and include directories + to the compiler using absolute paths. This makes diagnostic messages and + debug symbols more consistent, and matches the :ref:`Makefile Generators`. diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index a8a49a0..cbe1bc8 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -335,6 +335,7 @@ void cmGlobalNinjaGenerator::CCOutputs::Add( // This output is expressed as a relative path. Repeat it, // but expressed as an absolute path for Ninja Issue 1251. this->WorkDirOuts.emplace_back(out); + this->GG->SeenCustomCommandOutput(this->GG->ConvertToNinjaAbsPath(path)); } this->GG->SeenCustomCommandOutput(out); this->ExplicitOuts.emplace_back(std::move(out)); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 22a1a1a..8142599 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -208,11 +208,9 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference( std::string const& path, IncludePathStyle pathStyle, cmOutputConverter::OutputFormat format) { - if (pathStyle == IncludePathStyle::Absolute) { - return this->ConvertToOutputFormat(path, format); - } - return this->ConvertToOutputFormat(this->MaybeRelativeToTopBinDir(path), - format); + // FIXME: Remove IncludePathStyle infrastructure. It is no longer used. + static_cast(pathStyle); + return this->ConvertToOutputFormat(path, format); } // Private methods. diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5499ff7..4feb0bb 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -382,7 +382,8 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps( std::string cmNinjaTargetGenerator::GetCompiledSourceNinjaPath( cmSourceFile const* source) const { - return this->ConvertToNinjaPath(source->GetFullPath()); + // Pass source files to the compiler by absolute path. + return this->ConvertToNinjaAbsPath(source->GetFullPath()); } std::string cmNinjaTargetGenerator::GetObjectFilePath( @@ -1199,9 +1200,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( const std::string& fileConfig, bool firstForConfig) { std::string const language = source->GetLanguage(); - std::string const sourceFilePath = language == "RC" - ? source->GetFullPath() - : this->GetCompiledSourceNinjaPath(source); + std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source); std::string const objectDir = this->ConvertToNinjaPath( cmStrCat(this->GeneratorTarget->GetSupportDirectory(), this->GetGlobalGenerator()->ConfigDirectory(config))); diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 1350326..8c91b34 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -163,12 +163,12 @@ run_LooseObjectDepends() function (run_AssumedSources) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AssumedSources-build) run_cmake(AssumedSources) - run_ninja("${RunCMake_TEST_BINARY_DIR}" "target.c") + run_ninja("${RunCMake_TEST_BINARY_DIR}" "${RunCMake_TEST_BINARY_DIR}/target.c") if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/target.c") message(FATAL_ERROR "Dependencies for an assumed source did not hook up properly for 'target.c'.") endif () - run_ninja("${RunCMake_TEST_BINARY_DIR}" "target-no-depends.c") + run_ninja("${RunCMake_TEST_BINARY_DIR}" "${RunCMake_TEST_BINARY_DIR}/target-no-depends.c") if (EXISTS "${RunCMake_TEST_BINARY_DIR}/target-no-depends.c") message(FATAL_ERROR "Dependencies for an assumed source were magically hooked up for 'target-no-depends.c'.") -- cgit v0.12