cmake/Source/cmGccDepfileReader.cxx

49 lines
1.4 KiB
C++
Raw Normal View History

2020-08-30 11:54:41 +02:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGccDepfileReader.h"
#include <type_traits>
#include <utility>
2021-09-14 00:13:48 +02:00
#include <vector>
#include <cm/optional>
2020-08-30 11:54:41 +02:00
#include "cmGccDepfileLexerHelper.h"
2021-09-14 00:13:48 +02:00
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
2020-08-30 11:54:41 +02:00
2021-09-14 00:13:48 +02:00
cm::optional<cmGccDepfileContent> cmReadGccDepfile(
const char* filePath, const std::string& prefix,
GccDepfilePrependPaths prependPaths)
2020-08-30 11:54:41 +02:00
{
cmGccDepfileLexerHelper helper;
2021-09-14 00:13:48 +02:00
if (!helper.readFile(filePath)) {
return cm::nullopt;
}
auto deps = cm::make_optional(std::move(helper).extractContent());
for (auto& dep : *deps) {
for (auto& rule : dep.rules) {
if (prependPaths == GccDepfilePrependPaths::All && !prefix.empty() &&
!cmSystemTools::FileIsFullPath(rule)) {
rule = cmStrCat(prefix, '/', rule);
}
if (cmSystemTools::FileIsFullPath(rule)) {
rule = cmSystemTools::CollapseFullPath(rule);
}
cmSystemTools::ConvertToLongPath(rule);
}
for (auto& path : dep.paths) {
if (!prefix.empty() && !cmSystemTools::FileIsFullPath(path)) {
path = cmStrCat(prefix, '/', path);
}
if (cmSystemTools::FileIsFullPath(path)) {
path = cmSystemTools::CollapseFullPath(path);
}
cmSystemTools::ConvertToLongPath(path);
}
2020-08-30 11:54:41 +02:00
}
2021-09-14 00:13:48 +02:00
return deps;
2020-08-30 11:54:41 +02:00
}