You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7KB

  1. #include "./library.hpp"
  2. #include <libman/parse.hpp>
  3. #include <spdlog/spdlog.h>
  4. using namespace lm;
  5. library library::from_file(path_ref fpath) {
  6. auto pairs = parse_file(fpath);
  7. library ret;
  8. std::vector<std::string> uses_strs;
  9. std::vector<std::string> links_strs;
  10. std::string _type_;
  11. read(fmt::format("Reading library manifest file '{}'", fpath.string()),
  12. pairs,
  13. read_required("Type", _type_),
  14. read_check_eq("Type", "Library"),
  15. read_required("Name", ret.name),
  16. read_opt("Path", ret.linkable_path),
  17. read_accumulate("Include-Path", ret.include_paths),
  18. read_accumulate("Preprocessor-Define", ret.preproc_defs),
  19. read_accumulate("Uses", uses_strs),
  20. read_accumulate("Links", links_strs),
  21. read_accumulate("Special-Uses", ret.special_uses));
  22. for (auto&& uses_str : uses_strs) {
  23. ret.uses.push_back(split_usage_string(uses_str));
  24. }
  25. for (auto&& links_str : links_strs) {
  26. ret.links.push_back(split_usage_string(links_str));
  27. }
  28. auto make_absolute = [&](path_ref p) { return fpath.parent_path() / p; };
  29. std::transform(ret.include_paths.begin(),
  30. ret.include_paths.end(),
  31. ret.include_paths.begin(),
  32. make_absolute);
  33. if (ret.linkable_path) {
  34. ret.linkable_path = make_absolute(*ret.linkable_path);
  35. }
  36. return ret;
  37. }
  38. usage lm::split_usage_string(std::string_view str) {
  39. auto sl_pos = str.find('/');
  40. if (sl_pos == str.npos) {
  41. throw std::runtime_error("Invalid Uses/Links specifier: " + std::string(str));
  42. }
  43. auto ns = str.substr(0, sl_pos);
  44. auto name = str.substr(sl_pos + 1);
  45. return usage{std::string(ns), std::string(name)};
  46. }