Browse Source

Merge branch 'backport-3.20-makefile-normalize-depfile'

Brad King 4 years ago
parent
commit
6bc6ffb9a9
3 changed files with 17 additions and 6 deletions
  1. 3 1
      Source/cmDependsCompiler.cxx
  2. 5 3
      Source/cmGccDepfileReader.cxx
  3. 9 2
      Source/cmGccDepfileReader.h

+ 3 - 1
Source/cmDependsCompiler.cxx

@@ -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;
           }

+ 5 - 3
Source/cmGccDepfileReader.cxx

@@ -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)) {

+ 9 - 2
Source/cmGccDepfileReader.h

@@ -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);