diff options
Diffstat (limited to 'toolsrc/include')
37 files changed, 724 insertions, 151 deletions
diff --git a/toolsrc/include/BinaryParagraph.h b/toolsrc/include/BinaryParagraph.h index 01979c924..3d9cfb9fb 100644 --- a/toolsrc/include/BinaryParagraph.h +++ b/toolsrc/include/BinaryParagraph.h @@ -2,7 +2,6 @@ #include <unordered_map> #include "SourceParagraph.h" -#include "triplet.h" #include "package_spec.h" namespace vcpkg @@ -10,7 +9,7 @@ namespace vcpkg struct BinaryParagraph { BinaryParagraph(); - explicit BinaryParagraph(const std::unordered_map<std::string, std::string>& fields); + explicit BinaryParagraph(std::unordered_map<std::string, std::string> fields); BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet); std::string displayname() const; diff --git a/toolsrc/include/ImmutableSortedVector.h b/toolsrc/include/ImmutableSortedVector.h new file mode 100644 index 000000000..681f9fd4d --- /dev/null +++ b/toolsrc/include/ImmutableSortedVector.h @@ -0,0 +1,48 @@ +#pragma once + +#include <vector> +#include <algorithm> + +// Add more forwarding functions to the delegate std::vector as needed. +namespace vcpkg +{ + template <class T> + class ImmutableSortedVector + { + public: + static ImmutableSortedVector<T> create(std::vector<T> vector) + { + ImmutableSortedVector out; + out.delegate = std::move(vector); + if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend())) + { + std::sort(out.delegate.begin(), out.delegate.end()); + } + + return out; + } + + typename std::vector<T>::const_iterator begin() const + { + return this->delegate.cbegin(); + } + + typename std::vector<T>::const_iterator end() const + { + return this->delegate.cend(); + } + + typename std::vector<T>::const_iterator cbegin() const + { + return this->delegate.cbegin(); + } + + typename std::vector<T>::const_iterator cend() const + { + return this->delegate.cend(); + } + + private: + std::vector<T> delegate; + }; +} diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h new file mode 100644 index 000000000..761b49759 --- /dev/null +++ b/toolsrc/include/Paragraphs.h @@ -0,0 +1,10 @@ +#pragma once + +#include "filesystem_fs.h" +#include <unordered_map> + +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); +} diff --git a/toolsrc/include/post_build_lint.h b/toolsrc/include/PostBuildLint.h index bc916a7af..215a237aa 100644 --- a/toolsrc/include/post_build_lint.h +++ b/toolsrc/include/PostBuildLint.h @@ -2,7 +2,7 @@ #include "package_spec.h" #include "vcpkg_paths.h" -namespace vcpkg +namespace vcpkg::PostBuildLint { void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths); } diff --git a/toolsrc/include/PostBuildLint_BuildInfo.h b/toolsrc/include/PostBuildLint_BuildInfo.h new file mode 100644 index 000000000..ff996b2b6 --- /dev/null +++ b/toolsrc/include/PostBuildLint_BuildInfo.h @@ -0,0 +1,21 @@ +#pragma once + +#include <unordered_map> +#include "Paragraphs.h" +#include "PostBuildLint_BuildPolicies.h" +#include "opt_bool.h" + +namespace vcpkg::PostBuildLint +{ + struct BuildInfo + { + static BuildInfo create(std::unordered_map<std::string, std::string> pgh); + + std::string crt_linkage; + std::string library_linkage; + + std::map<BuildPolicies::type, opt_bool_t> policies; + }; + + BuildInfo read_build_info(const fs::path& filepath); +} diff --git a/toolsrc/include/PostBuildLint_BuildPolicies.h b/toolsrc/include/PostBuildLint_BuildPolicies.h new file mode 100644 index 000000000..187ba6d64 --- /dev/null +++ b/toolsrc/include/PostBuildLint_BuildPolicies.h @@ -0,0 +1,35 @@ +#pragma once +#include <string> + +namespace vcpkg::PostBuildLint::BuildPolicies +{ + enum class backing_enum_t + { + UNKNOWN = 0, + EMPTY_PACKAGE, + DLLS_WITHOUT_LIBS + }; + + struct type + { + constexpr explicit type(backing_enum_t backing_enum) : backing_enum(backing_enum) { } + constexpr operator backing_enum_t() const { return backing_enum; } + + const std::string& toString() const; + const std::string& cmake_variable() const; + + private: + type(); + backing_enum_t backing_enum; + }; + + static constexpr int value_count = 3; + const std::vector<type>& values(); + + + static constexpr type UNKNOWN(backing_enum_t::UNKNOWN); + static constexpr type EMPTY_PACKAGE(backing_enum_t::EMPTY_PACKAGE); + static constexpr type DLLS_WITHOUT_LIBS(backing_enum_t::DLLS_WITHOUT_LIBS); + + type parse(const std::string& s); +} diff --git a/toolsrc/include/PostBuildLint_BuildType.h b/toolsrc/include/PostBuildLint_BuildType.h new file mode 100644 index 000000000..a5cb24f49 --- /dev/null +++ b/toolsrc/include/PostBuildLint_BuildType.h @@ -0,0 +1,45 @@ +#pragma once +#include "PostBuildLint_ConfigurationType.h" +#include "PostBuildLint_LinkageType.h" +#include <vector> +#include <regex> + +namespace vcpkg::PostBuildLint +{ + struct BuildType + { + static BuildType value_of(const ConfigurationType& config, const LinkageType& linkage); + + static const BuildType DEBUG_STATIC; + static const BuildType DEBUG_DYNAMIC; + static const BuildType RELEASE_STATIC; + static const BuildType RELEASE_DYNAMIC; + + static const std::vector<BuildType>& values() + { + static const std::vector<BuildType> v = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC }; + return v; + } + + BuildType() = delete; + + const ConfigurationType& config() const; + const LinkageType& linkage() const; + std::regex crt_regex() const; + std::string toString() const; + + private: + BuildType(const ConfigurationType& config, const LinkageType& linkage, const std::string& crt_regex_as_string) + : m_config(config), m_linkage(linkage), m_crt_regex_as_string(crt_regex_as_string) + { + } + + ConfigurationType m_config; + LinkageType m_linkage; + std::string m_crt_regex_as_string; + }; + + bool operator ==(const BuildType& lhs, const BuildType& rhs); + + bool operator !=(const BuildType& lhs, const BuildType& rhs); +} diff --git a/toolsrc/include/PostBuildLint_ConfigurationType.h b/toolsrc/include/PostBuildLint_ConfigurationType.h new file mode 100644 index 000000000..55dede921 --- /dev/null +++ b/toolsrc/include/PostBuildLint_ConfigurationType.h @@ -0,0 +1,14 @@ +#pragma once +#pragma once +#include <string> + +namespace vcpkg::PostBuildLint +{ + enum class ConfigurationType + { + DEBUG = 1, + RELEASE = 2 + }; + + std::string to_string(const ConfigurationType& conf); +} diff --git a/toolsrc/include/PostBuildLint_LinkageType.h b/toolsrc/include/PostBuildLint_LinkageType.h new file mode 100644 index 000000000..7cca97639 --- /dev/null +++ b/toolsrc/include/PostBuildLint_LinkageType.h @@ -0,0 +1,16 @@ +#pragma once +#include <string> + +namespace vcpkg::PostBuildLint +{ + enum class LinkageType + { + DYNAMIC, + STATIC, + UNKNOWN + }; + + LinkageType linkage_type_value_of(const std::string& as_string); + + std::string to_string(const LinkageType& build_info); +} diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 72dca8324..5ae9b38b8 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -5,16 +5,31 @@ namespace vcpkg { + struct triplet; + + struct dependency + { + std::string name; + std::string qualifier; + }; + + std::ostream& operator<<(std::ostream& os, const dependency& p); + struct SourceParagraph { SourceParagraph(); - explicit SourceParagraph(const std::unordered_map<std::string, std::string>& fields); + explicit SourceParagraph(std::unordered_map<std::string, std::string> fields); std::string name; std::string version; std::string description; std::string maintainer; - std::vector<std::string> depends; + std::vector<dependency> depends; }; + + std::vector<std::string> filter_dependencies(const std::vector<vcpkg::dependency>& deps, const triplet& t); + + std::vector<vcpkg::dependency> expand_qualified_dependencies(const std::vector<std::string>& depends); + std::vector<std::string> parse_depends(const std::string& depends_string); } diff --git a/toolsrc/include/StatusParagraphs.h b/toolsrc/include/StatusParagraphs.h index 9446d432c..11491cf4e 100644 --- a/toolsrc/include/StatusParagraphs.h +++ b/toolsrc/include/StatusParagraphs.h @@ -1,6 +1,7 @@ #pragma once #include "StatusParagraph.h" #include <memory> +#include <iterator> namespace vcpkg { @@ -13,6 +14,10 @@ namespace vcpkg using iterator = container::reverse_iterator; using const_iterator = container::const_reverse_iterator; + const_iterator find(const package_spec& spec) const + { + return find(spec.name(), spec.target_triplet()); + } const_iterator find(const std::string& name, const triplet& target_triplet) const; iterator find(const std::string& name, const triplet& target_triplet); iterator find_installed(const std::string& name, const triplet& target_triplet); @@ -21,22 +26,22 @@ namespace vcpkg friend std::ostream& operator<<(std::ostream&, const StatusParagraphs&); - auto end() + iterator end() { return paragraphs.rend(); } - auto end() const + const_iterator end() const { return paragraphs.rend(); } - auto begin() + iterator begin() { return paragraphs.rbegin(); } - auto begin() const + const_iterator begin() const { return paragraphs.rbegin(); } diff --git a/toolsrc/include/coff_file_reader.h b/toolsrc/include/coff_file_reader.h index 81f107f10..24fbf4576 100644 --- a/toolsrc/include/coff_file_reader.h +++ b/toolsrc/include/coff_file_reader.h @@ -1,12 +1,10 @@ #pragma once #include <vector> #include "MachineType.h" -#include <filesystem> +#include "filesystem_fs.h" -namespace vcpkg {namespace COFFFileReader +namespace vcpkg::COFFFileReader { - namespace fs = std::tr2::sys; - struct dll_info { MachineType machine_type; @@ -17,7 +15,7 @@ namespace vcpkg {namespace COFFFileReader std::vector<MachineType> machine_types; }; - dll_info read_dll(const fs::path path); + dll_info read_dll(const fs::path& path); - lib_info read_lib(const fs::path path); -}} + lib_info read_lib(const fs::path& path); +} diff --git a/toolsrc/include/expected.h b/toolsrc/include/expected.h index affabcc02..cbb513b22 100644 --- a/toolsrc/include/expected.h +++ b/toolsrc/include/expected.h @@ -1,5 +1,6 @@ #pragma once +#include <system_error> #include "vcpkg_Checks.h" namespace vcpkg diff --git a/toolsrc/include/filesystem_fs.h b/toolsrc/include/filesystem_fs.h new file mode 100644 index 000000000..ece485c23 --- /dev/null +++ b/toolsrc/include/filesystem_fs.h @@ -0,0 +1,5 @@ +#pragma once + +#include <filesystem> + +namespace fs = std::tr2::sys;
\ No newline at end of file diff --git a/toolsrc/include/metrics.h b/toolsrc/include/metrics.h index 52662cd97..a0f4fc61d 100644 --- a/toolsrc/include/metrics.h +++ b/toolsrc/include/metrics.h @@ -13,6 +13,7 @@ namespace vcpkg void TrackProperty(const std::string& name, const std::string& value); void TrackProperty(const std::string& name, const std::wstring& value); bool GetCompiledMetricsEnabled(); + std::wstring GetSQMUser(); void Upload(const std::string& payload); void Flush(); diff --git a/toolsrc/include/opt_bool.h b/toolsrc/include/opt_bool.h index 3856366c8..06642a399 100644 --- a/toolsrc/include/opt_bool.h +++ b/toolsrc/include/opt_bool.h @@ -1,11 +1,33 @@ #pragma once -namespace vcpkg +#include <string> +#include <map> + +namespace vcpkg::opt_bool { - enum class opt_bool + enum class type { - unspecified, - enabled, - disabled + UNSPECIFIED = 0, + ENABLED, + DISABLED }; + + type parse(const std::string& s); + + template <class T> + type from_map(const std::map<T, std::string>& map, const T& key) + { + auto it = map.find(key); + if (it == map.cend()) + { + return type::UNSPECIFIED; + } + + return parse(*it); + } } + +namespace vcpkg +{ + using opt_bool_t = opt_bool::type; +}
\ No newline at end of file diff --git a/toolsrc/include/package_spec.h b/toolsrc/include/package_spec.h index 30dfca5c7..1bc493756 100644 --- a/toolsrc/include/package_spec.h +++ b/toolsrc/include/package_spec.h @@ -1,5 +1,4 @@ #pragma once -#include <string> #include "package_spec_parse_result.h" #include "triplet.h" #include "expected.h" @@ -16,15 +15,17 @@ namespace vcpkg const triplet& target_triplet() const; + std::string display_name() const; + std::string dir() const; + std::string toString() const; + private: std::string m_name; triplet m_target_triplet; }; - std::string to_string(const package_spec& spec); - std::string to_printf_arg(const package_spec& spec); bool operator==(const package_spec& left, const package_spec& right); diff --git a/toolsrc/include/pch.h b/toolsrc/include/pch.h new file mode 100644 index 000000000..56f24f161 --- /dev/null +++ b/toolsrc/include/pch.h @@ -0,0 +1,42 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include <Windows.h> +#include <shellapi.h> +#include <Shlobj.h> +#include <winhttp.h> + +#include <cassert> +#include <stdexcept> +#include <system_error> + +#include <array> +#include <vector> +#include <set> +#include <map> +#include <unordered_set> +#include <unordered_map> + +#include <string> +#include <regex> + +#include <filesystem> +#include <iostream> +#include <fstream> +#include <memory> +#include <iomanip> + +#include <algorithm> +#include <functional> +#include <iterator> +#include <utility> + +#include <cstdarg> +#include <codecvt> +#include <cctype> +#include <cstdint> + +#include <sys/timeb.h> +#include <time.h> +#include <chrono> diff --git a/toolsrc/include/triplet.h b/toolsrc/include/triplet.h index bc99a17df..32ea2e711 100644 --- a/toolsrc/include/triplet.h +++ b/toolsrc/include/triplet.h @@ -8,20 +8,12 @@ namespace vcpkg { static triplet from_canonical_name(const std::string& triplet_as_string); - enum class BuildType - { - DYNAMIC, - STATIC - }; - static const triplet X86_WINDOWS; static const triplet X64_WINDOWS; static const triplet X86_UWP; static const triplet X64_UWP; static const triplet ARM_UWP; - BuildType build_type() const; - const std::string& canonical_name() const; std::string architecture() const; diff --git a/toolsrc/include/vcpkg.h b/toolsrc/include/vcpkg.h deleted file mode 100644 index a4a0682cf..000000000 --- a/toolsrc/include/vcpkg.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include <filesystem> -#include <vector> -#include <unordered_map> -#include "package_spec.h" -#include "BinaryParagraph.h" -#include "StatusParagraphs.h" -#include "vcpkg_paths.h" - -namespace vcpkg -{ - namespace fs = std::tr2::sys; - - extern bool g_do_dry_run; - - 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); - std::string shorten_description(const std::string& desc); - - StatusParagraphs database_load_check(const vcpkg_paths& paths); - - std::vector<std::string> get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db); - - void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db); - void deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db); - - void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db); - - void binary_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data); - - const std::string& version(); -} // namespace vcpkg diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 9d9b21ed6..a58b38ac0 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -2,7 +2,7 @@ #include "vcpkg_Strings.h" -namespace vcpkg {namespace Checks +namespace vcpkg::Checks { __declspec(noreturn) void unreachable(); @@ -46,4 +46,4 @@ namespace vcpkg {namespace Checks exit_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); } } -}} +} diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index 978519820..8d772b255 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/include/vcpkg_Commands.h @@ -3,42 +3,112 @@ #include "vcpkg_cmd_arguments.h" #include "vcpkg_paths.h" -namespace vcpkg +namespace vcpkg::Commands { - extern const char*const INTEGRATE_COMMAND_HELPSTRING; + using command_type_a = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + using command_type_b = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + using command_type_c = void(*)(const vcpkg_cmd_arguments& args); + + namespace Build + { + void build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir); + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + } + + namespace BuildExternal + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + } - void print_usage(); - void print_example(const char* command_and_arguments); - std::string create_example_string(const char* command_and_arguments); - void update_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + namespace Install + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + } - void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); - void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); - void install_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); - void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + namespace Remove + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); + } - void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + namespace Update + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void internal_test_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + namespace Create + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + namespace Edit + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - void integrate_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + namespace Search + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - void help_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - void help_topic_valid_triplet(const vcpkg_paths& paths); + namespace List + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - void version_command(const vcpkg_cmd_arguments& args); - void contact_command(const vcpkg_cmd_arguments& args); + namespace Import + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } - using command_type_a = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet); - using command_type_b = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); - using command_type_c = void(*)(const vcpkg_cmd_arguments& args); + namespace Owns + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } + + namespace Cache + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } + + namespace Integrate + { + extern const char*const INTEGRATE_COMMAND_HELPSTRING; + + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } + + namespace PortsDiff + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + } + + namespace Help + { + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths); + + void help_topic_valid_triplet(const vcpkg_paths& paths); + + void print_usage(); + + void print_example(const std::string& command_and_arguments); + + std::string create_example_string(const std::string& command_and_arguments); + } + + namespace Version + { + void perform_and_exit(const vcpkg_cmd_arguments& args); + } + + namespace Contact + { + void perform_and_exit(const vcpkg_cmd_arguments& args); + } + + namespace Hash + { + void perform_and_exit(const vcpkg_cmd_arguments& args); + } template <class T> struct package_name_and_function @@ -52,7 +122,7 @@ namespace vcpkg const std::vector<package_name_and_function<command_type_c>>& get_available_commands_type_c(); template <typename T> - T find_command(const std::string& command_name, const std::vector<package_name_and_function<T>> available_commands) + T find(const std::string& command_name, const std::vector<package_name_and_function<T>> available_commands) { for (const package_name_and_function<T>& cmd : available_commands) { diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h index 9dc32fc41..b63816089 100644 --- a/toolsrc/include/vcpkg_Dependencies.h +++ b/toolsrc/include/vcpkg_Dependencies.h @@ -2,12 +2,78 @@ #include <vector> #include "package_spec.h" #include "StatusParagraphs.h" -#include <unordered_set> #include "vcpkg_paths.h" +#include "vcpkg_optional.h" -namespace vcpkg {namespace Dependencies +namespace vcpkg::Dependencies { - std::vector<package_spec> create_dependency_ordered_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db); + enum class request_type + { + UNKNOWN, + USER_REQUESTED, + AUTO_SELECTED + }; - std::unordered_set<package_spec> find_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db); -}} + enum class install_plan_type + { + UNKNOWN, + BUILD_AND_INSTALL, + INSTALL, + ALREADY_INSTALLED + }; + + struct install_plan_action + { + install_plan_action(); + install_plan_action(const install_plan_type& plan_type, optional<BinaryParagraph> binary_pgh, optional<SourceParagraph> source_pgh); + install_plan_action(const install_plan_action&) = delete; + install_plan_action(install_plan_action&&) = default; + install_plan_action& operator=(const install_plan_action&) = delete; + install_plan_action& operator=(install_plan_action&&) = default; + + install_plan_type plan_type; + optional<BinaryParagraph> binary_pgh; + optional<SourceParagraph> source_pgh; + }; + + struct package_spec_with_install_plan + { + package_spec_with_install_plan(const package_spec& spec, install_plan_action&& plan); + + package_spec spec; + install_plan_action plan; + }; + + enum class remove_plan_type + { + UNKNOWN, + NOT_INSTALLED, + REMOVE + }; + + struct remove_plan_action + { + remove_plan_action(); + remove_plan_action(const remove_plan_type& plan_type, const request_type& request_type); + remove_plan_action(const remove_plan_action&) = delete; + remove_plan_action(remove_plan_action&&) = default; + remove_plan_action& operator=(const remove_plan_action&) = delete; + remove_plan_action& operator=(remove_plan_action&&) = default; + + + remove_plan_type plan_type; + request_type request_type; + }; + + struct package_spec_with_remove_plan + { + package_spec_with_remove_plan(const package_spec& spec, remove_plan_action&& plan); + + package_spec spec; + remove_plan_action plan; + }; + + std::vector<package_spec_with_install_plan> create_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db); + + std::vector<package_spec_with_remove_plan> create_remove_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db); +} diff --git a/toolsrc/include/vcpkg_Environment.h b/toolsrc/include/vcpkg_Environment.h index 877ac7deb..e4dd47472 100644 --- a/toolsrc/include/vcpkg_Environment.h +++ b/toolsrc/include/vcpkg_Environment.h @@ -1,7 +1,7 @@ #pragma once #include "vcpkg_paths.h" -namespace vcpkg {namespace Environment +namespace vcpkg::Environment { void ensure_nuget_on_path(const vcpkg_paths& paths); @@ -14,4 +14,14 @@ namespace vcpkg {namespace Environment ensure_cmake_on_path(paths); ensure_git_on_path(paths); } -}} + + const fs::path& get_dumpbin_exe(const vcpkg_paths& paths); + + struct vcvarsall_and_platform_toolset + { + fs::path path; + std::wstring platform_toolset; + }; + + const vcvarsall_and_platform_toolset& get_vcvarsall_bat(const vcpkg_paths& paths); +} diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h index 445713965..3f9570946 100644 --- a/toolsrc/include/vcpkg_Files.h +++ b/toolsrc/include/vcpkg_Files.h @@ -1,17 +1,56 @@ #pragma once #include "expected.h" -#include <filesystem> +#include "filesystem_fs.h" +#include <iterator> -namespace vcpkg {namespace Files +namespace vcpkg::Files { static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; - void check_is_directory(const std::tr2::sys::path& dirpath); + void check_is_directory(const fs::path& dirpath); - bool has_invalid_chars_for_filesystem(const std::string s); + bool has_invalid_chars_for_filesystem(const std::string& s); - expected<std::string> get_contents(const std::tr2::sys::path& file_path) noexcept; + expected<std::string> read_contents(const fs::path& file_path) noexcept; - std::tr2::sys::path find_file_recursively_up(const std::tr2::sys::path& starting_dir, const std::string& filename); -}} + expected<std::vector<std::string>> read_all_lines(const fs::path& file_path); + + void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines); + + fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename); + + template <class Pred> + void non_recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output) + { + std::copy_if(fs::directory_iterator(dir), fs::directory_iterator(), std::back_inserter(*output), predicate); + } + + template <class Pred> + void recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output) + { + std::copy_if(fs::recursive_directory_iterator(dir), fs::recursive_directory_iterator(), std::back_inserter(*output), predicate); + } + + template <class Pred> + std::vector<fs::path> recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate) + { + std::vector<fs::path> v; + recursive_find_matching_paths_in_dir(dir, predicate, &v); + return v; + } + + void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector<fs::path>* output); + + std::vector<fs::path> recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension); + + void recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output); + + std::vector<fs::path> recursive_find_all_files_in_dir(const fs::path& dir); + + void non_recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output); + + std::vector<fs::path> non_recursive_find_all_files_in_dir(const fs::path& dir); + + void print_paths(const std::vector<fs::path>& paths); +} diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h index 81b189f0e..933d9ac67 100644 --- a/toolsrc/include/vcpkg_Graphs.h +++ b/toolsrc/include/vcpkg_Graphs.h @@ -1,8 +1,9 @@ #pragma once #include <unordered_map> +#include <unordered_set> -namespace vcpkg { namespace Graphs +namespace vcpkg::Graphs { enum class ExplorationStatus { @@ -21,7 +22,7 @@ namespace vcpkg { namespace Graphs { static void find_topological_sort_internal(V vertex, ExplorationStatus& status, - const std::unordered_map<V, std::vector<V>>& adjacency_list, + const std::unordered_map<V, std::unordered_set<V>>& adjacency_list, std::unordered_map<V, ExplorationStatus>& exploration_status, std::vector<V>& sorted) { @@ -63,7 +64,7 @@ namespace vcpkg { namespace Graphs void add_edge(V u, V v) { this->vertices[v]; - this->vertices[u].push_back(v); + this->vertices[u].insert(v); } std::vector<V> find_topological_sort() const @@ -108,12 +109,12 @@ namespace vcpkg { namespace Graphs return indegrees; } - const std::unordered_map<V, std::vector<V>>& adjacency_list() const + const std::unordered_map<V, std::unordered_set<V>>& adjacency_list() const { return this->vertices; } private: - std::unordered_map<V, std::vector<V>> vertices; + std::unordered_map<V, std::unordered_set<V>> vertices; }; -}} +} diff --git a/toolsrc/include/vcpkg_Input.h b/toolsrc/include/vcpkg_Input.h index bbf3adfbf..96cbeecc3 100644 --- a/toolsrc/include/vcpkg_Input.h +++ b/toolsrc/include/vcpkg_Input.h @@ -3,13 +3,13 @@ #include "package_spec.h" #include "vcpkg_paths.h" -namespace vcpkg {namespace Input +namespace vcpkg::Input { - package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text); + package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text); - std::vector<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text); + std::vector<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const std::string& example_text); void check_triplet(const triplet& t, const vcpkg_paths& paths); - void check_triplets(std::vector<package_spec> triplets, const vcpkg_paths& paths); -}} + void check_triplets(const std::vector<package_spec>& triplets, const vcpkg_paths& paths); +} diff --git a/toolsrc/include/vcpkg_Maps.h b/toolsrc/include/vcpkg_Maps.h index 5b7b8ed46..5e2f92f55 100644 --- a/toolsrc/include/vcpkg_Maps.h +++ b/toolsrc/include/vcpkg_Maps.h @@ -2,8 +2,9 @@ #include <unordered_map> #include <unordered_set> +#include <map> -namespace vcpkg { namespace Maps +namespace vcpkg::Maps { template <typename K, typename V> std::unordered_set<K> extract_key_set(const std::unordered_map<K, V>& input_map) @@ -15,4 +16,26 @@ namespace vcpkg { namespace Maps } return key_set; } -}} + + template <typename K, typename V> + std::vector<K> extract_keys(const std::unordered_map<K, V>& input_map) + { + std::vector<K> key_set; + for (auto const& element : input_map) + { + key_set.push_back(element.first); + } + return key_set; + } + + template <typename K, typename V> + std::vector<K> extract_keys(const std::map<K, V>& input_map) + { + std::vector<K> key_set; + for (auto const& element : input_map) + { + key_set.push_back(element.first); + } + return key_set; + } +} diff --git a/toolsrc/include/vcpkg_Sets.h b/toolsrc/include/vcpkg_Sets.h index 7b330f31c..ec4800864 100644 --- a/toolsrc/include/vcpkg_Sets.h +++ b/toolsrc/include/vcpkg_Sets.h @@ -3,15 +3,15 @@ #include "vcpkg_Checks.h" #include <unordered_set> -namespace vcpkg { namespace Sets +namespace vcpkg::Sets { template <typename T, typename Container> void remove_all(std::unordered_set<T>* input_set, Container remove_these) { - Checks::check_throw(input_set != nullptr, "Input set cannot be null"); + Checks::check_exit(input_set != nullptr, "Input set cannot be null"); for (const T& r : remove_these) { input_set->erase(r); } } -}} +} diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 70526198c..8d5d7135b 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -1,8 +1,8 @@ #pragma once -#include <string> +#include <vector> -namespace vcpkg {namespace Strings {namespace details +namespace vcpkg::Strings::details { inline const char* to_printf_arg(const std::string& s) { @@ -42,9 +42,9 @@ namespace vcpkg {namespace Strings {namespace details } std::wstring wformat_internal(const wchar_t* fmtstr, ...); -}}} +} -namespace vcpkg {namespace Strings +namespace vcpkg::Strings { template <class...Args> std::string format(const char* fmtstr, const Args&...args) @@ -67,4 +67,62 @@ namespace vcpkg {namespace Strings std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern); std::string ascii_to_lowercase(const std::string& input); -}} + + template <class T, class Transformer> + static std::string join(const std::vector<T>& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix, Transformer transformer) + { + if (v.empty()) + { + return std::string(); + } + + std::string output; + size_t size = v.size(); + + output.append(prefix); + output.append(transformer(v.at(0))); + + for (size_t i = 1; i < size; ++i) + { + output.append(delimiter); + output.append(transformer(v.at(i))); + } + + output.append(suffix); + return output; + } + + static std::string join(const std::vector<std::string>& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix); + + class Joiner + { + public: + static Joiner on(const std::string& delimiter); + + Joiner& prefix(const std::string& prefix); + Joiner& suffix(const std::string& suffix); + + std::string join(const std::vector<std::string>& v) const; + + template <class T, class Transformer> + std::string join(const std::vector<T>& v, Transformer transformer) const + { + return Strings::join(v, this->m_prefix, this->m_delimiter, this->m_suffix, transformer); + } + + private: + explicit Joiner(const std::string& delimiter); + + std::string m_prefix; + std::string m_delimiter; + std::string m_suffix; + }; + + void trim(std::string* s); + + std::string trimmed(const std::string& s); + + void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings); + + std::vector<std::string> split(const std::string& s, const std::string& delimiter); +} diff --git a/toolsrc/include/vcpkg_System.h b/toolsrc/include/vcpkg_System.h index c420464c1..c9195163c 100644 --- a/toolsrc/include/vcpkg_System.h +++ b/toolsrc/include/vcpkg_System.h @@ -1,12 +1,11 @@ #pragma once #include "vcpkg_Strings.h" +#include "filesystem_fs.h" -#include <filesystem> - -namespace vcpkg {namespace System +namespace vcpkg::System { - std::tr2::sys::path get_exe_path_of_current_process(); + fs::path get_exe_path_of_current_process(); struct exit_code_and_output { @@ -37,8 +36,28 @@ namespace vcpkg {namespace System void print(const char* message); void println(const char* message); - void print(color c, const char* message); - void println(color c, const char* message); + void print(const color c, const char* message); + void println(const color c, const char* message); + + inline void print(const std::string& message) + { + return print(message.c_str()); + } + + inline void println(const std::string& message) + { + return println(message.c_str()); + } + + inline void print(const color c, const std::string& message) + { + return print(c, message.c_str()); + } + + inline void println(const color c, const std::string& message) + { + return println(c, message.c_str()); + } template <class...Args> void print(const char* messageTemplate, const Args&... messageArgs) @@ -47,7 +66,7 @@ namespace vcpkg {namespace System } template <class...Args> - void print(color c, const char* messageTemplate, const Args&... messageArgs) + void print(const color c, const char* messageTemplate, const Args&... messageArgs) { return print(c, Strings::format(messageTemplate, messageArgs...).c_str()); } @@ -59,7 +78,7 @@ namespace vcpkg {namespace System } template <class...Args> - void println(color c, const char* messageTemplate, const Args&... messageArgs) + void println(const color c, const char* messageTemplate, const Args&... messageArgs) { return println(c, Strings::format(messageTemplate, messageArgs...).c_str()); } @@ -74,4 +93,4 @@ namespace vcpkg {namespace System }; std::wstring wdupenv_str(const wchar_t* varname) noexcept; -}} +} diff --git a/toolsrc/include/vcpkg_cmd_arguments.h b/toolsrc/include/vcpkg_cmd_arguments.h index 95feb4814..91f7de8ac 100644 --- a/toolsrc/include/vcpkg_cmd_arguments.h +++ b/toolsrc/include/vcpkg_cmd_arguments.h @@ -4,7 +4,6 @@ #include <vector> #include <unordered_set> #include "opt_bool.h" -#include "vcpkg_paths.h" namespace vcpkg { @@ -15,20 +14,20 @@ namespace vcpkg std::unique_ptr<std::string> vcpkg_root_dir; std::unique_ptr<std::string> target_triplet; - opt_bool debug = opt_bool::unspecified; - opt_bool sendmetrics = opt_bool::unspecified; - opt_bool printmetrics = opt_bool::unspecified; + opt_bool_t debug = opt_bool_t::UNSPECIFIED; + opt_bool_t sendmetrics = opt_bool_t::UNSPECIFIED; + opt_bool_t printmetrics = opt_bool_t::UNSPECIFIED; std::string command; std::vector<std::string> command_arguments; std::unordered_set<std::string> check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) const; void check_max_arg_count(const size_t expected_arg_count) const; - void check_max_arg_count(const size_t expected_arg_count, const char* example_text) const; + void check_max_arg_count(const size_t expected_arg_count, const std::string& example_text) const; void check_min_arg_count(const size_t expected_arg_count) const; - void check_min_arg_count(const size_t expected_arg_count, const char* example_text) const; + void check_min_arg_count(const size_t expected_arg_count, const std::string& example_text) const; void check_exact_arg_count(const size_t expected_arg_count) const; - void check_exact_arg_count(const size_t expected_arg_count, const char* example_text) const; + void check_exact_arg_count(const size_t expected_arg_count, const std::string& example_text) const; private: std::unordered_set<std::string> optional_command_arguments; diff --git a/toolsrc/include/vcpkg_info.h b/toolsrc/include/vcpkg_info.h new file mode 100644 index 000000000..5380e0158 --- /dev/null +++ b/toolsrc/include/vcpkg_info.h @@ -0,0 +1,10 @@ +#pragma once + +#include <string> + +namespace vcpkg::Info +{ + const std::string& version(); + + const std::string& email(); +} diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h new file mode 100644 index 000000000..7b935bea9 --- /dev/null +++ b/toolsrc/include/vcpkg_optional.h @@ -0,0 +1,5 @@ +#pragma once +#include <memory> + +template<class T> +using optional = std::unique_ptr<T>; diff --git a/toolsrc/include/vcpkg_paths.h b/toolsrc/include/vcpkg_paths.h index 046b6836c..ba6defb9f 100644 --- a/toolsrc/include/vcpkg_paths.h +++ b/toolsrc/include/vcpkg_paths.h @@ -1,18 +1,20 @@ #pragma once -#include <filesystem> +#include "filesystem_fs.h" #include "expected.h" #include "package_spec.h" +#include "BinaryParagraph.h" namespace vcpkg { - namespace fs = std::tr2::sys; - struct vcpkg_paths { static expected<vcpkg_paths> create(const fs::path& vcpkg_root_dir); fs::path package_dir(const package_spec& spec) const; fs::path port_dir(const package_spec& spec) const; + fs::path build_info_file_path(const package_spec& spec) const; + fs::path listfile_path(const BinaryParagraph& pgh) const; + bool is_valid_triplet(const triplet& t) const; fs::path root; @@ -22,6 +24,7 @@ namespace vcpkg fs::path ports; fs::path installed; fs::path triplets; + fs::path scripts; fs::path buildsystems; fs::path buildsystems_msbuild_targets; diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h new file mode 100644 index 000000000..b1653d197 --- /dev/null +++ b/toolsrc/include/vcpkglib.h @@ -0,0 +1,31 @@ +#pragma once + +#include "package_spec.h" +#include "BinaryParagraph.h" +#include "StatusParagraphs.h" +#include "vcpkg_paths.h" +#include "ImmutableSortedVector.h" + +namespace vcpkg +{ + StatusParagraphs database_load_check(const vcpkg_paths& paths); + + void write_update(const vcpkg_paths& paths, const StatusParagraph& p); + + struct StatusParagraph_and_associated_files + { + StatusParagraph pgh; + ImmutableSortedVector<std::string> files; + }; + + 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); + + inline expected<SourceParagraph> try_load_port(const vcpkg_paths& paths, const std::string& name) + { + return try_load_port(paths.ports / name); + } + + expected<BinaryParagraph> try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec); +} // namespace vcpkg diff --git a/toolsrc/include/vcpkglib_helpers.h b/toolsrc/include/vcpkglib_helpers.h index 72711d63b..8a08513f3 100644 --- a/toolsrc/include/vcpkglib_helpers.h +++ b/toolsrc/include/vcpkglib_helpers.h @@ -2,11 +2,13 @@ #include <unordered_map> -namespace vcpkg {namespace details +namespace vcpkg::details { std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname); + std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname); std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname); + std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname); - std::vector<std::string> parse_depends(const std::string& depends_string); -}} + std::string shorten_description(const std::string& desc); +} |
