Skip to content
Snippets Groups Projects
Commit 6a6efdca authored by Marc Chevrier's avatar Marc Chevrier Committed by Brad King
Browse files

Makefiles: Normalize compiler-generated depfile paths

Even though Makefile generators pass source files and include
directories by absolute path to the compiler, the compiler may generate
depfile paths relative to the current working directory.  For example,
`ccache` with `CCACHE_BASEDIR` may transform paths this way.  When
reading a depfile, convert relative dependencies to absolute paths
before placing them in `compiler_depend.make`, which is later evaluated
in the top-level build directory.

Fixes: #22364
parent efa5e1f3
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,9 @@ bool cmDependsCompiler::CheckDependencies(
depends.emplace_back(std::move(line));
}
} else if (format == "gcc"_s) {
auto deps = cmReadGccDepfile(depFile.c_str());
auto deps = cmReadGccDepfile(
depFile.c_str(), this->LocalGenerator->GetCurrentBinaryDirectory(),
GccDepfilePrependPaths::Deps);
if (!deps) {
continue;
}
......
......@@ -12,8 +12,9 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath,
const std::string& prefix)
cm::optional<cmGccDepfileContent> cmReadGccDepfile(
const char* filePath, const std::string& prefix,
GccDepfilePrependPaths prependPaths)
{
cmGccDepfileLexerHelper helper;
if (!helper.readFile(filePath)) {
......@@ -23,7 +24,8 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath,
for (auto& dep : *deps) {
for (auto& rule : dep.rules) {
if (!prefix.empty() && !cmSystemTools::FileIsFullPath(rule)) {
if (prependPaths == GccDepfilePrependPaths::All && !prefix.empty() &&
!cmSystemTools::FileIsFullPath(rule)) {
rule = cmStrCat(prefix, '/', rule);
}
if (cmSystemTools::FileIsFullPath(rule)) {
......
......@@ -8,8 +8,15 @@
#include "cmGccDepfileReaderTypes.h"
enum class GccDepfilePrependPaths
{
All,
Deps,
};
/*
* Read dependencies file and append prefix to all relative paths
* Read dependencies file and prepend prefix to all relative paths
*/
cm::optional<cmGccDepfileContent> cmReadGccDepfile(
const char* filePath, const std::string& prefix = {});
const char* filePath, const std::string& prefix = {},
GccDepfilePrependPaths prependPaths = GccDepfilePrependPaths::All);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment