add_custom_command(DEPFILE): ensure all dependencies are taken into account

This commit is contained in:
Marc Chevrier
2022-01-16 14:04:05 +01:00
parent e04a352cca
commit 0b65a2b253
3 changed files with 36 additions and 30 deletions

View File

@@ -4,6 +4,7 @@
#include "cmDependsCompiler.h"
#include <algorithm>
#include <iterator>
#include <map>
#include <memory>
#include <string>
@@ -111,9 +112,13 @@ bool cmDependsCompiler::CheckDependencies(
// copy depends for each target, except first one, which can be
// moved
for (auto index = entry.rules.size() - 1; index > 0; --index) {
dependencies[entry.rules[index]] = depends;
auto& rule_deps = dependencies[entry.rules[index]];
rule_deps.insert(rule_deps.end(), depends.cbegin(),
depends.cend());
}
dependencies[entry.rules.front()] = std::move(depends);
auto& rule_deps = dependencies[entry.rules.front()];
std::move(depends.cbegin(), depends.cend(),
std::back_inserter(rule_deps));
}
} else {
if (format == "msvc"_s) {

View File

@@ -113,6 +113,24 @@ void cmGccDepfileLexerHelper::addToCurrentPath(const char* s)
void cmGccDepfileLexerHelper::sanitizeContent()
{
for (auto it = this->Content.begin(); it != this->Content.end();) {
// Remove empty paths and normalize windows paths
for (auto pit = it->paths.begin(); pit != it->paths.end();) {
if (pit->empty()) {
pit = it->paths.erase(pit);
} else {
#if defined(_WIN32)
// Unescape the colon following the drive letter.
// Some versions of GNU compilers can escape this character.
// c\:\path must be transformed to c:\path
if (pit->size() >= 3 && std::toupper((*pit)[0]) >= 'A' &&
std::toupper((*pit)[0]) <= 'Z' && (*pit)[1] == '\\' &&
(*pit)[2] == ':') {
pit->erase(1, 1);
}
#endif
++pit;
}
}
// Remove empty rules
for (auto rit = it->rules.begin(); rit != it->rules.end();) {
if (rit->empty()) {
@@ -121,28 +139,10 @@ void cmGccDepfileLexerHelper::sanitizeContent()
++rit;
}
}
// Remove the entry if rules are empty
if (it->rules.empty()) {
// Remove the entry if rules are empty or do not have any paths
if (it->rules.empty() || it->paths.empty()) {
it = this->Content.erase(it);
} else {
// Remove empty paths and normalize windows paths
for (auto pit = it->paths.begin(); pit != it->paths.end();) {
if (pit->empty()) {
pit = it->paths.erase(pit);
} else {
#if defined(_WIN32)
// Unescape the colon following the drive letter.
// Some versions of GNU compilers can escape this character.
// c\:\path must be transformed to c:\path
if (pit->size() >= 3 && std::toupper((*pit)[0]) >= 'A' &&
std::toupper((*pit)[0]) <= 'Z' && (*pit)[1] == '\\' &&
(*pit)[2] == ':') {
pit->erase(1, 1);
}
#endif
++pit;
}
}
++it;
}
}

View File

@@ -4,7 +4,6 @@
#include <algorithm>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
@@ -95,14 +94,16 @@ void WriteMSBuildAdditionalInputs(cmsys::ofstream& fout,
// Write the format expected by MSBuild CustomBuild AdditionalInputs.
const char* sep = "";
for (std::string path : content.front().paths) {
if (!cmSystemTools::FileIsFullPath(path)) {
path =
cmSystemTools::CollapseFullPath(path, lg.GetCurrentBinaryDirectory());
for (const auto& c : content) {
for (std::string path : c.paths) {
if (!cmSystemTools::FileIsFullPath(path)) {
path = cmSystemTools::CollapseFullPath(path,
lg.GetCurrentBinaryDirectory());
}
std::replace(path.begin(), path.end(), '/', '\\');
fout << sep << path;
sep = ";";
}
std::replace(path.begin(), path.end(), '/', '\\');
fout << sep << path;
sep = ";";
}
fout << "\n";
}