diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-27 15:45:56 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-27 15:45:56 -0800 |
| commit | c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6 (patch) | |
| tree | 460db03fec88a2a9ed55a5f55a1d8b732c20d299 /toolsrc/src/Paragraphs.cpp | |
| parent | 00737588cc6155776734c5a5261c9b08f9446eb4 (diff) | |
| download | vcpkg-c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6.tar.gz vcpkg-c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6.zip | |
Move some functions from vcpkglib.h to Paragraphs.h
Diffstat (limited to 'toolsrc/src/Paragraphs.cpp')
| -rw-r--r-- | toolsrc/src/Paragraphs.cpp | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index 0c41e0b5c..fdb583bcc 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -6,9 +6,7 @@ namespace vcpkg::Paragraphs { struct Parser { - Parser(const char* c, const char* e) : cur(c), end(e) - { - } + Parser(const char* c, const char* e) : cur(c), end(e) { } private: const char* cur; @@ -167,4 +165,56 @@ namespace vcpkg::Paragraphs { return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); } + + expected<SourceParagraph> try_load_port(const fs::path& path) + { + try + { + auto pghs = get_paragraphs(path / "CONTROL"); + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); + return SourceParagraph(pghs[0]); + } + catch (std::runtime_error const&) {} + + return std::errc::no_such_file_or_directory; + } + + expected<BinaryParagraph> try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec) + { + const fs::path path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::read_contents(path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector<std::unordered_map<std::string, std::string>> pghs; + try + { + pghs = parse_paragraphs(*control_contents); + } + catch (std::runtime_error) {} + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", path.string()); + return BinaryParagraph(pghs[0]); + } + return control_contents_maybe.error_code(); + } + + std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir) + { + std::vector<SourceParagraph> output; + for (auto it = fs::directory_iterator(ports_dir); it != fs::directory_iterator(); ++it) + { + const fs::path& path = it->path(); + expected<SourceParagraph> source_paragraph = try_load_port(path); + if (auto srcpgh = source_paragraph.get()) + { + output.emplace_back(std::move(*srcpgh)); + } + else + { + Checks::exit_with_message("Error loading port from %s: %s", path.generic_string(), source_paragraph.error_code().message()); + } + } + + return output; + } } |
