diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-01-16 16:37:23 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-01-19 12:17:14 (GMT) |
commit | b5c2163293c08e8e53203d86a069713e06874886 (patch) | |
tree | f3d6d249054fee14b6e0122bc021be958c59b3dd /Source | |
parent | 5b9f7a5f285d648698068abe8eb238cd4dda7161 (diff) | |
download | CMake-b5c2163293c08e8e53203d86a069713e06874886.zip CMake-b5c2163293c08e8e53203d86a069713e06874886.tar.gz CMake-b5c2163293c08e8e53203d86a069713e06874886.tar.bz2 |
Ninja: add_custom_command(DEPFILE): Ensure dependencies consistency
Fixes: #21694
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 14 | ||||
-rw-r--r-- | Source/cmDependsCompiler.cxx | 13 | ||||
-rw-r--r-- | Source/cmGccDepfileReader.cxx | 4 | ||||
-rw-r--r-- | Source/cmTransformDepfile.cxx | 41 | ||||
-rw-r--r-- | Source/cmTransformDepfile.h | 4 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 36 |
6 files changed, 72 insertions, 40 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index c67497a..4329caf 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -200,6 +200,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( argv.push_back(cmSystemTools::GetCMakeCommand()); argv.emplace_back("-E"); argv.emplace_back("cmake_transform_depfile"); + argv.push_back(this->LG->GetGlobalGenerator()->GetName()); switch (*this->LG->GetGlobalGenerator()->DepfileFormat()) { case cmDepfileFormat::GccDepfile: argv.emplace_back("gccdepfile"); @@ -208,15 +209,10 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( argv.emplace_back("vstlog"); break; } - if (this->LG->GetCurrentBinaryDirectory() == - this->LG->GetBinaryDirectory()) { - argv.emplace_back("./"); - } else { - argv.push_back(cmStrCat(this->LG->MaybeConvertToRelativePath( - this->LG->GetBinaryDirectory(), - this->LG->GetCurrentBinaryDirectory()), - '/')); - } + argv.push_back(this->LG->GetSourceDirectory()); + argv.push_back(this->LG->GetCurrentSourceDirectory()); + argv.push_back(this->LG->GetBinaryDirectory()); + argv.push_back(this->LG->GetCurrentBinaryDirectory()); argv.push_back(this->GetFullDepfile()); argv.push_back(this->GetInternalDepfile()); diff --git a/Source/cmDependsCompiler.cxx b/Source/cmDependsCompiler.cxx index ec31f68..2b48df9 100644 --- a/Source/cmDependsCompiler.cxx +++ b/Source/cmDependsCompiler.cxx @@ -97,17 +97,8 @@ bool cmDependsCompiler::CheckDependencies( std::vector<std::string> depends; if (format == "custom"_s) { - std::string prefix; - if (this->LocalGenerator->GetCurrentBinaryDirectory() != - this->LocalGenerator->GetBinaryDirectory()) { - prefix = - cmStrCat(this->LocalGenerator->MaybeConvertToRelativePath( - this->LocalGenerator->GetBinaryDirectory(), - this->LocalGenerator->GetCurrentBinaryDirectory()), - '/'); - } - - auto deps = cmReadGccDepfile(depFile.c_str(), prefix); + auto deps = cmReadGccDepfile( + depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory()); if (!deps) { continue; } diff --git a/Source/cmGccDepfileReader.cxx b/Source/cmGccDepfileReader.cxx index 8253375..6436baa 100644 --- a/Source/cmGccDepfileReader.cxx +++ b/Source/cmGccDepfileReader.cxx @@ -24,7 +24,7 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, for (auto& dep : *deps) { for (auto& rule : dep.rules) { if (!prefix.empty() && !cmSystemTools::FileIsFullPath(rule)) { - rule = cmStrCat(prefix, rule); + rule = cmStrCat(prefix, '/', rule); } if (cmSystemTools::FileIsFullPath(rule)) { rule = cmSystemTools::CollapseFullPath(rule); @@ -33,7 +33,7 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, } for (auto& path : dep.paths) { if (!prefix.empty() && !cmSystemTools::FileIsFullPath(path)) { - path = cmStrCat(prefix, path); + path = cmStrCat(prefix, '/', path); } if (cmSystemTools::FileIsFullPath(path)) { path = cmSystemTools::CollapseFullPath(path); diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx index b91e1ce..78aa4b2 100644 --- a/Source/cmTransformDepfile.cxx +++ b/Source/cmTransformDepfile.cxx @@ -13,6 +13,7 @@ #include "cmGccDepfileReader.h" #include "cmGccDepfileReaderTypes.h" +#include "cmLocalGenerator.h" #include "cmSystemTools.h" namespace { @@ -33,8 +34,11 @@ void WriteFilenameGcc(cmsys::ofstream& fout, const std::string& filename) } } -void WriteGccDepfile(cmsys::ofstream& fout, const cmGccDepfileContent& content) +void WriteGccDepfile(cmsys::ofstream& fout, const cmLocalGenerator& lg, + const cmGccDepfileContent& content) { + const auto& binDir = lg.GetBinaryDirectory(); + for (auto const& dep : content) { bool first = true; for (auto const& rule : dep.rules) { @@ -42,19 +46,32 @@ void WriteGccDepfile(cmsys::ofstream& fout, const cmGccDepfileContent& content) fout << " \\\n "; } first = false; - WriteFilenameGcc(fout, rule); + WriteFilenameGcc(fout, lg.MaybeConvertToRelativePath(binDir, rule)); } fout << ':'; for (auto const& path : dep.paths) { fout << " \\\n "; - WriteFilenameGcc(fout, path); + WriteFilenameGcc(fout, lg.MaybeConvertToRelativePath(binDir, path)); } fout << '\n'; } } -void WriteVsTlog(cmsys::ofstream& fout, const cmGccDepfileContent& content) +// tlog format : always windows paths on Windows regardless the generator +std::string ConvertToTLogOutputPath(const std::string& path) { +#if defined(_WIN32) && !defined(__CYGWIN__) + return cmSystemTools::ConvertToWindowsOutputPath(path); +#else + return cmSystemTools::ConvertToOutputPath(path); +#endif +} + +void WriteVsTlog(cmsys::ofstream& fout, const cmLocalGenerator& lg, + const cmGccDepfileContent& content) +{ + const auto& binDir = lg.GetBinaryDirectory(); + for (auto const& dep : content) { fout << '^'; bool first = true; @@ -63,22 +80,26 @@ void WriteVsTlog(cmsys::ofstream& fout, const cmGccDepfileContent& content) fout << '|'; } first = false; - fout << cmSystemTools::ConvertToOutputPath(rule); + fout << ConvertToTLogOutputPath( + lg.MaybeConvertToRelativePath(binDir, rule)); } fout << "\r\n"; for (auto const& path : dep.paths) { - fout << cmSystemTools::ConvertToOutputPath(path) << "\r\n"; + fout << ConvertToTLogOutputPath( + lg.MaybeConvertToRelativePath(binDir, path)) + << "\r\n"; } } } } -bool cmTransformDepfile(cmDepfileFormat format, const std::string& prefix, +bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg, const std::string& infile, const std::string& outfile) { cmGccDepfileContent content; if (cmSystemTools::FileExists(infile)) { - auto result = cmReadGccDepfile(infile.c_str(), prefix); + auto result = + cmReadGccDepfile(infile.c_str(), lg.GetCurrentBinaryDirectory()); if (!result) { return false; } @@ -91,10 +112,10 @@ bool cmTransformDepfile(cmDepfileFormat format, const std::string& prefix, } switch (format) { case cmDepfileFormat::GccDepfile: - WriteGccDepfile(fout, content); + WriteGccDepfile(fout, lg, content); break; case cmDepfileFormat::VsTlog: - WriteVsTlog(fout, content); + WriteVsTlog(fout, lg, content); break; } return true; diff --git a/Source/cmTransformDepfile.h b/Source/cmTransformDepfile.h index 792c1aa..c43a45f 100644 --- a/Source/cmTransformDepfile.h +++ b/Source/cmTransformDepfile.h @@ -10,5 +10,7 @@ enum class cmDepfileFormat VsTlog, }; -bool cmTransformDepfile(cmDepfileFormat format, const std::string& prefix, +class cmLocalGenerator; + +bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg, const std::string& infile, const std::string& outfile); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 851205e..f6d8901 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1522,20 +1522,42 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, #endif // Internal depfile transformation - if (args[1] == "cmake_transform_depfile" && args.size() == 6) { + if (args[1] == "cmake_transform_depfile" && args.size() == 10) { auto format = cmDepfileFormat::GccDepfile; - if (args[2] == "gccdepfile") { + if (args[3] == "gccdepfile") { format = cmDepfileFormat::GccDepfile; - } else if (args[2] == "vstlog") { + } else if (args[3] == "vstlog") { format = cmDepfileFormat::VsTlog; } else { return 1; } - std::string prefix = args[3]; - if (prefix == "./") { - prefix.clear(); + // Create a cmake object instance to process dependencies. + // All we need is the `set` command. + cmake cm(cmake::RoleScript, cmState::Unknown); + std::string homeDir; + std::string startDir; + std::string homeOutDir; + std::string startOutDir; + homeDir = cmSystemTools::CollapseFullPath(args[4]); + startDir = cmSystemTools::CollapseFullPath(args[5]); + homeOutDir = cmSystemTools::CollapseFullPath(args[6]); + startOutDir = cmSystemTools::CollapseFullPath(args[7]); + cm.SetHomeDirectory(homeDir); + cm.SetHomeOutputDirectory(homeOutDir); + cm.GetCurrentSnapshot().SetDefaultDefinitions(); + if (auto ggd = cm.CreateGlobalGenerator(args[2])) { + cm.SetGlobalGenerator(std::move(ggd)); + cmStateSnapshot snapshot = cm.GetCurrentSnapshot(); + snapshot.GetDirectory().SetCurrentBinary(startOutDir); + snapshot.GetDirectory().SetCurrentSource(startDir); + snapshot.GetDirectory().SetRelativePathTopSource(homeDir.c_str()); + snapshot.GetDirectory().SetRelativePathTopBinary(homeOutDir.c_str()); + cmMakefile mf(cm.GetGlobalGenerator(), snapshot); + auto lgd = cm.GetGlobalGenerator()->CreateLocalGenerator(&mf); + + return cmTransformDepfile(format, *lgd, args[8], args[9]) ? 0 : 2; } - return cmTransformDepfile(format, prefix, args[4], args[5]) ? 0 : 1; + return 1; } } |