diff options
-rw-r--r-- | Source/cmGccDepfileReader.cxx | 34 | ||||
-rw-r--r-- | Source/cmGccDepfileReader.h | 8 | ||||
-rw-r--r-- | Source/cmTransformDepfile.cxx | 16 |
3 files changed, 43 insertions, 15 deletions
diff --git a/Source/cmGccDepfileReader.cxx b/Source/cmGccDepfileReader.cxx index eb3511a..96a562e 100644 --- a/Source/cmGccDepfileReader.cxx +++ b/Source/cmGccDepfileReader.cxx @@ -4,10 +4,13 @@ #include <type_traits> #include <utility> +#include <vector> #include <cm/optional> #include "cmGccDepfileLexerHelper.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath) { @@ -17,3 +20,34 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath) } return cm::nullopt; } + +cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, + const std::string& prefix) +{ + auto deps = cmReadGccDepfile(filePath); + + if (prefix.empty() || !deps) { + return deps; + } + + for (auto& dep : *deps) { + for (auto& rule : dep.rules) { + if (!cmSystemTools::FileIsFullPath(rule)) { + rule = cmStrCat(prefix, rule); + } + if (cmSystemTools::FileIsFullPath(rule)) { + rule = cmSystemTools::CollapseFullPath(rule); + } + } + for (auto& path : dep.paths) { + if (!cmSystemTools::FileIsFullPath(path)) { + path = cmStrCat(prefix, path); + } + if (cmSystemTools::FileIsFullPath(path)) { + path = cmSystemTools::CollapseFullPath(path); + } + } + } + + return deps; +} diff --git a/Source/cmGccDepfileReader.h b/Source/cmGccDepfileReader.h index 59ed7fd..66ff75d 100644 --- a/Source/cmGccDepfileReader.h +++ b/Source/cmGccDepfileReader.h @@ -2,8 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #pragma once +#include <string> + #include <cm/optional> #include "cmGccDepfileReaderTypes.h" cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath); + +/* + * Read dependencies file and append prefix to all relative paths + */ +cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath, + const std::string& prefix); diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx index 163d7e0..b91e1ce 100644 --- a/Source/cmTransformDepfile.cxx +++ b/Source/cmTransformDepfile.cxx @@ -13,7 +13,6 @@ #include "cmGccDepfileReader.h" #include "cmGccDepfileReaderTypes.h" -#include "cmStringAlgorithms.h" #include "cmSystemTools.h" namespace { @@ -79,26 +78,13 @@ bool cmTransformDepfile(cmDepfileFormat format, const std::string& prefix, { cmGccDepfileContent content; if (cmSystemTools::FileExists(infile)) { - auto result = cmReadGccDepfile(infile.c_str()); + auto result = cmReadGccDepfile(infile.c_str(), prefix); if (!result) { return false; } content = *std::move(result); } - for (auto& dep : content) { - for (auto& rule : dep.rules) { - if (!cmSystemTools::FileIsFullPath(rule)) { - rule = cmStrCat(prefix, rule); - } - } - for (auto& path : dep.paths) { - if (!cmSystemTools::FileIsFullPath(path)) { - path = cmStrCat(prefix, path); - } - } - } - cmsys::ofstream fout(outfile.c_str()); if (!fout) { return false; |