summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-12-15 09:13:41 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-12-23 13:40:19 (GMT)
commita526f71266c2fed017c65a3d90b63286221476c0 (patch)
treec0aa8bd13b3965480efbd31b5b6c03fd87640970
parent8c9c338e5e297020df0b5cdf9443beef245513de (diff)
downloadCMake-a526f71266c2fed017c65a3d90b63286221476c0.zip
CMake-a526f71266c2fed017c65a3d90b63286221476c0.tar.gz
CMake-a526f71266c2fed017c65a3d90b63286221476c0.tar.bz2
cmGccDepfileReader: Add new function ensuring paths are valid
And cmTransformDepfile now rely on this new function.
-rw-r--r--Source/cmGccDepfileReader.cxx34
-rw-r--r--Source/cmGccDepfileReader.h8
-rw-r--r--Source/cmTransformDepfile.cxx16
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;