Move some functions from vcpkglib.h to Paragraphs.h
MODIFY
include/Paragraphs.h
include/Paragraphs.h
#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);
}

MODIFY
include/vcpkglib.h
include/vcpkglib.h
#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

MODIFY
src/Paragraphs.cpp
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;
+ }
}

MODIFY
src/commands_build.cpp
src/commands_build.cpp
#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();

MODIFY
src/commands_ci.cpp
src/commands_ci.cpp
#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);
}

MODIFY
src/commands_install.cpp
src/commands_install.cpp
#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);
}

MODIFY
src/commands_portsdiff.cpp
src/commands_portsdiff.cpp
#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));

MODIFY
src/commands_search.cpp
src/commands_search.cpp
#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);

MODIFY
src/vcpkg_Dependencies.cpp
src/vcpkg_Dependencies.cpp
#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()));

MODIFY
src/vcpkglib.cpp
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;
- }
}

Move some functions from vcpkglib.h to Paragraphs.h