mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
cmGccDepfileReader: Add new function ensuring paths are valid
And cmTransformDepfile now rely on this new function.
This commit is contained in:
@@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <cm/optional>
|
#include <cm/optional>
|
||||||
|
|
||||||
#include "cmGccDepfileLexerHelper.h"
|
#include "cmGccDepfileLexerHelper.h"
|
||||||
|
#include "cmStringAlgorithms.h"
|
||||||
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath)
|
cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath)
|
||||||
{
|
{
|
||||||
@@ -17,3 +20,34 @@ cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath)
|
|||||||
}
|
}
|
||||||
return cm::nullopt;
|
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;
|
||||||
|
}
|
||||||
|
@@ -2,8 +2,16 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <cm/optional>
|
#include <cm/optional>
|
||||||
|
|
||||||
#include "cmGccDepfileReaderTypes.h"
|
#include "cmGccDepfileReaderTypes.h"
|
||||||
|
|
||||||
cm::optional<cmGccDepfileContent> cmReadGccDepfile(const char* filePath);
|
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);
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "cmGccDepfileReader.h"
|
#include "cmGccDepfileReader.h"
|
||||||
#include "cmGccDepfileReaderTypes.h"
|
#include "cmGccDepfileReaderTypes.h"
|
||||||
#include "cmStringAlgorithms.h"
|
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -79,26 +78,13 @@ bool cmTransformDepfile(cmDepfileFormat format, const std::string& prefix,
|
|||||||
{
|
{
|
||||||
cmGccDepfileContent content;
|
cmGccDepfileContent content;
|
||||||
if (cmSystemTools::FileExists(infile)) {
|
if (cmSystemTools::FileExists(infile)) {
|
||||||
auto result = cmReadGccDepfile(infile.c_str());
|
auto result = cmReadGccDepfile(infile.c_str(), prefix);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
content = *std::move(result);
|
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());
|
cmsys::ofstream fout(outfile.c_str());
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user