cmGccDepfileReader.cxx 1.4 KB

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