aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-02-27 15:45:56 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2017-02-27 15:45:56 -0800
commitc0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6 (patch)
tree460db03fec88a2a9ed55a5f55a1d8b732c20d299
parent00737588cc6155776734c5a5261c9b08f9446eb4 (diff)
downloadvcpkg-c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6.tar.gz
vcpkg-c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6.zip
Move some functions from vcpkglib.h to Paragraphs.h
-rw-r--r--toolsrc/include/Paragraphs.h9
-rw-r--r--toolsrc/include/vcpkglib.h8
-rw-r--r--toolsrc/src/Paragraphs.cpp56
-rw-r--r--toolsrc/src/commands_build.cpp3
-rw-r--r--toolsrc/src/commands_ci.cpp3
-rw-r--r--toolsrc/src/commands_install.cpp3
-rw-r--r--toolsrc/src/commands_portsdiff.cpp4
-rw-r--r--toolsrc/src/commands_search.cpp3
-rw-r--r--toolsrc/src/vcpkg_Dependencies.cpp6
-rw-r--r--toolsrc/src/vcpkglib.cpp52
10 files changed, 74 insertions, 73 deletions
diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h
index 761b49759..9564d2290 100644
--- a/toolsrc/include/Paragraphs.h
+++ b/toolsrc/include/Paragraphs.h
@@ -2,9 +2,18 @@
#include "filesystem_fs.h"
#include <unordered_map>
+#include "expected.h"
+#include "BinaryParagraph.h"
+#include "vcpkg_paths.h"
namespace vcpkg::Paragraphs
{
std::vector<std::unordered_map<std::string, std::string>> get_paragraphs(const fs::path& control_path);
std::vector<std::unordered_map<std::string, std::string>> parse_paragraphs(const std::string& str);
+
+ expected<SourceParagraph> try_load_port(const fs::path& control_path);
+
+ expected<BinaryParagraph> try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec);
+
+ std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir);
}
diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h
index 69cde7ea2..1ce55bd8a 100644
--- a/toolsrc/include/vcpkglib.h
+++ b/toolsrc/include/vcpkglib.h
@@ -1,7 +1,5 @@
#pragma once
-#include "package_spec.h"
-#include "BinaryParagraph.h"
#include "StatusParagraphs.h"
#include "vcpkg_paths.h"
#include "ImmutableSortedVector.h"
@@ -19,10 +17,4 @@ namespace vcpkg
};
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db);
-
- expected<SourceParagraph> try_load_port(const fs::path& control_path);
-
- expected<BinaryParagraph> try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec);
-
- std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir);
} // namespace vcpkg
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;
+ }
}
diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp
index 98f0cbbb0..310a9c829 100644
--- a/toolsrc/src/commands_build.cpp
+++ b/toolsrc/src/commands_build.cpp
@@ -9,6 +9,7 @@
#include "vcpkg_Environment.h"
#include "metrics.h"
#include "vcpkg_Enums.h"
+#include "PostBuildLint_BuildInfo.h"
namespace vcpkg::Commands::Build
{
@@ -127,7 +128,7 @@ namespace vcpkg::Commands::Build
exit(EXIT_SUCCESS);
}
- const expected<SourceParagraph> maybe_spgh = try_load_port(port_dir);
+ const expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(port_dir);
Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message());
const SourceParagraph& spgh = *maybe_spgh.get();
diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp
index db37db123..d75d4b787 100644
--- a/toolsrc/src/commands_ci.cpp
+++ b/toolsrc/src/commands_ci.cpp
@@ -7,6 +7,7 @@
#include "vcpkg_Dependencies.h"
#include "vcpkg_Input.h"
#include "vcpkg_Chrono.h"
+#include "PostBuildLint_BuildInfo.h"
namespace vcpkg::Commands::CI
{
@@ -70,7 +71,7 @@ namespace vcpkg::Commands::CI
System::println(System::color::error, Build::create_error_message(result, action.spec));
continue;
}
- const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw();
+ const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw();
Install::install_package(paths, bpgh, &status_db);
System::println(System::color::success, "Package %s is installed", action.spec);
}
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index 4ae311f83..283de8785 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -7,6 +7,7 @@
#include "vcpkg_System.h"
#include "vcpkg_Dependencies.h"
#include "vcpkg_Input.h"
+#include "PostBuildLint_BuildInfo.h"
namespace vcpkg::Commands::Install
{
@@ -224,7 +225,7 @@ namespace vcpkg::Commands::Install
System::println(Build::create_user_troubleshooting_message(action.spec));
exit(EXIT_FAILURE);
}
- const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw();
+ const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw();
install_package(paths, bpgh, &status_db);
System::println(System::color::success, "Package %s is installed", action.spec);
}
diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp
index 2edb3fb3f..a927f145d 100644
--- a/toolsrc/src/commands_portsdiff.cpp
+++ b/toolsrc/src/commands_portsdiff.cpp
@@ -4,7 +4,7 @@
#include "vcpkg_Maps.h"
#include "SourceParagraph.h"
#include "vcpkg_Environment.h"
-#include "vcpkglib.h"
+#include "PostBuildLint_BuildInfo.h"
namespace vcpkg::Commands::PortsDiff
{
@@ -44,7 +44,7 @@ namespace vcpkg::Commands::PortsDiff
{
std::map<std::string, std::string> names_and_versions;
- std::vector<SourceParagraph> ports = load_all_ports(ports_folder_path);
+ std::vector<SourceParagraph> ports = Paragraphs::load_all_ports(ports_folder_path);
for (SourceParagraph& port : ports)
{
names_and_versions.emplace(std::move(port.name), std::move(port.version));
diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp
index c5f2210c8..8bac858f1 100644
--- a/toolsrc/src/commands_search.cpp
+++ b/toolsrc/src/commands_search.cpp
@@ -4,7 +4,6 @@
#include "Paragraphs.h"
#include "vcpkglib_helpers.h"
#include "SourceParagraph.h"
-#include "vcpkglib.h"
namespace vcpkg::Commands::Search
{
@@ -60,7 +59,7 @@ namespace vcpkg::Commands::Search
args.check_max_arg_count(1, example);
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_GRAPH });
- const std::vector<SourceParagraph> source_paragraphs = load_all_ports(paths.ports);
+ const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports);
if (options.find(OPTION_GRAPH) != options.cend())
{
const std::string graph_as_string = create_graph_as_string(source_paragraphs);
diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp
index b255cc77b..e9c88523e 100644
--- a/toolsrc/src/vcpkg_Dependencies.cpp
+++ b/toolsrc/src/vcpkg_Dependencies.cpp
@@ -5,7 +5,7 @@
#include "package_spec.h"
#include "StatusParagraphs.h"
#include "vcpkg_Files.h"
-#include "vcpkglib.h"
+#include "PostBuildLint_BuildInfo.h"
namespace vcpkg::Dependencies
{
@@ -72,7 +72,7 @@ namespace vcpkg::Dependencies
continue;
}
- expected<BinaryParagraph> maybe_bpgh = try_load_cached_package(paths, spec);
+ expected<BinaryParagraph> maybe_bpgh = Paragraphs::try_load_cached_package(paths, spec);
if (BinaryParagraph* bpgh = maybe_bpgh.get())
{
process_dependencies(bpgh->depends);
@@ -80,7 +80,7 @@ namespace vcpkg::Dependencies
continue;
}
- expected<SourceParagraph> maybe_spgh = try_load_port(paths.port_dir(spec));
+ expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.port_dir(spec));
SourceParagraph* spgh = maybe_spgh.get();
Checks::check_exit(spgh != nullptr, "Cannot find package %s", spec.name());
process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet()));
diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp
index d453f1dc9..2415372db 100644
--- a/toolsrc/src/vcpkglib.cpp
+++ b/toolsrc/src/vcpkglib.cpp
@@ -200,56 +200,4 @@ namespace vcpkg
return installed_files;
}
-
- expected<SourceParagraph> try_load_port(const fs::path& path)
- {
- try
- {
- auto pghs = Paragraphs::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 = Paragraphs::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;
- }
}