/src/CMake/Source/cmGccDepfileReader.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmGccDepfileReader.h" |
4 | | |
5 | | #include <utility> |
6 | | #include <vector> |
7 | | |
8 | | #include <cm/optional> |
9 | | |
10 | | #include "cmGccDepfileLexerHelper.h" |
11 | | #include "cmStringAlgorithms.h" |
12 | | #include "cmSystemTools.h" |
13 | | |
14 | | cm::optional<cmGccDepfileContent> cmReadGccDepfile( |
15 | | char const* filePath, std::string const& prefix, |
16 | | GccDepfilePrependPaths prependPaths) |
17 | 5.67k | { |
18 | 5.67k | cmGccDepfileLexerHelper helper; |
19 | 5.67k | if (!helper.readFile(filePath)) { |
20 | 64 | return cm::nullopt; |
21 | 64 | } |
22 | 5.61k | auto deps = cm::make_optional(std::move(helper).extractContent()); |
23 | | |
24 | 45.4k | for (auto& dep : *deps) { |
25 | 62.5k | for (auto& rule : dep.rules) { |
26 | 62.5k | if (prependPaths == GccDepfilePrependPaths::All && !prefix.empty() && |
27 | 0 | !cmSystemTools::FileIsFullPath(rule)) { |
28 | 0 | rule = cmStrCat(prefix, '/', rule); |
29 | 0 | } |
30 | 62.5k | if (cmSystemTools::FileIsFullPath(rule)) { |
31 | 42.3k | rule = cmSystemTools::CollapseFullPath(rule); |
32 | 42.3k | } |
33 | 62.5k | cmSystemTools::ConvertToLongPath(rule); |
34 | 62.5k | } |
35 | 70.8k | for (auto& path : dep.paths) { |
36 | 70.8k | if (!prefix.empty() && !cmSystemTools::FileIsFullPath(path)) { |
37 | 0 | path = cmStrCat(prefix, '/', path); |
38 | 0 | } |
39 | 70.8k | if (cmSystemTools::FileIsFullPath(path)) { |
40 | 5.36k | path = cmSystemTools::CollapseFullPath(path); |
41 | 5.36k | } |
42 | 70.8k | cmSystemTools::ConvertToLongPath(path); |
43 | 70.8k | } |
44 | 45.4k | } |
45 | | |
46 | 5.61k | return deps; |
47 | 5.67k | } |