From ba0cc3f1d7edb7e2fee271761b2f37d0c740604f Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Mon, 28 Aug 2017 13:54:19 +0300 Subject: WIP: Export IFW Add export to binary crossplatform repository/installer with GUI based on QtIFW: http://doc.qt.io/qtinstallerframework/ifw-overview.html For correct operation of these changes, you must use the corrected QtIFW: https://codereview.qt-project.org/#/c/203958 --- toolsrc/include/vcpkg_Commands_Export_IFW.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 toolsrc/include/vcpkg_Commands_Export_IFW.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Commands_Export_IFW.h b/toolsrc/include/vcpkg_Commands_Export_IFW.h new file mode 100644 index 000000000..b25e943eb --- /dev/null +++ b/toolsrc/include/vcpkg_Commands_Export_IFW.h @@ -0,0 +1,13 @@ +#pragma once + +#include "vcpkg_Files.h" +#include "vcpkg_Dependencies.h" + +namespace vcpkg::Commands::Export::IFW +{ + fs::path export_real_package(const fs::path &raw_exported_dir_path, const Dependencies::ExportPlanAction& action, Files::Filesystem& fs); + void export_unique_packages(const fs::path &raw_exported_dir_path, std::map unique_packages, Files::Filesystem& fs); + void export_unique_triplets(const fs::path &raw_exported_dir_path, std::set unique_triplets, Files::Filesystem& fs); + void export_integration(const fs::path &raw_exported_dir_path, Files::Filesystem& fs); + void export_config(const fs::path &raw_exported_dir_path, const std::string ifw_repository_url, Files::Filesystem& fs); +} -- cgit v1.2.3 From 68b9c2d8b9119acb48643447a7561a5c2b733d25 Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Fri, 22 Sep 2017 02:16:14 +0300 Subject: [vcpkg-export-ifw] Separate IFW loop Separate IFW loop compatible with main export loop Fixed mistakes in templates Set current date to ReleaseDate tag --- toolsrc/include/vcpkg_Commands_Export.h | 14 ++++++++++++++ toolsrc/include/vcpkg_Commands_Export_IFW.h | 13 ++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 toolsrc/include/vcpkg_Commands_Export.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Commands_Export.h b/toolsrc/include/vcpkg_Commands_Export.h new file mode 100644 index 000000000..31003422d --- /dev/null +++ b/toolsrc/include/vcpkg_Commands_Export.h @@ -0,0 +1,14 @@ +#pragma once + +#include "StatusParagraphs.h" +#include "VcpkgCmdArguments.h" +#include "VcpkgPaths.h" +#include "VersionT.h" +#include "vcpkg_Build.h" +#include "vcpkg_Dependencies.h" +#include + +namespace vcpkg::Commands::Export +{ + void export_integration_files(const fs::path &raw_exported_dir_path, const VcpkgPaths& paths); +} diff --git a/toolsrc/include/vcpkg_Commands_Export_IFW.h b/toolsrc/include/vcpkg_Commands_Export_IFW.h index b25e943eb..881bbaf63 100644 --- a/toolsrc/include/vcpkg_Commands_Export_IFW.h +++ b/toolsrc/include/vcpkg_Commands_Export_IFW.h @@ -5,9 +5,12 @@ namespace vcpkg::Commands::Export::IFW { - fs::path export_real_package(const fs::path &raw_exported_dir_path, const Dependencies::ExportPlanAction& action, Files::Filesystem& fs); - void export_unique_packages(const fs::path &raw_exported_dir_path, std::map unique_packages, Files::Filesystem& fs); - void export_unique_triplets(const fs::path &raw_exported_dir_path, std::set unique_triplets, Files::Filesystem& fs); - void export_integration(const fs::path &raw_exported_dir_path, Files::Filesystem& fs); - void export_config(const fs::path &raw_exported_dir_path, const std::string ifw_repository_url, Files::Filesystem& fs); + struct Options + { + Optional maybe_repository_url; + Optional maybe_packages_dir_path; + Optional maybe_config_file_path; + }; + + void do_export(const std::vector &export_plan, const std::string &export_id, const Options &ifw_options, const VcpkgPaths& paths); } -- cgit v1.2.3 From c6149fae2f9f33d9ed363650aee6aea642574b0a Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Wed, 27 Sep 2017 02:57:51 +0300 Subject: [vcpkg-export-ifw] Usage QtIFW tools Download and use tools to make repository and installer --- toolsrc/include/VcpkgPaths.h | 6 ++++++ toolsrc/include/vcpkg_Commands_Export_IFW.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h index d55c95fe1..e7893ba15 100644 --- a/toolsrc/include/VcpkgPaths.h +++ b/toolsrc/include/VcpkgPaths.h @@ -57,6 +57,9 @@ namespace vcpkg const fs::path& get_cmake_exe() const; const fs::path& get_git_exe() const; const fs::path& get_nuget_exe() const; + const fs::path& get_ifw_installerbase_exe() const; + const fs::path& get_ifw_binarycreator_exe() const; + const fs::path& get_ifw_repogen_exe() const; /// Retrieve a toolset matching a VS version /// @@ -70,6 +73,9 @@ namespace vcpkg Lazy cmake_exe; Lazy git_exe; Lazy nuget_exe; + Lazy ifw_installerbase_exe; + Lazy ifw_binarycreator_exe; + Lazy ifw_repogen_exe; Lazy> toolsets; }; } diff --git a/toolsrc/include/vcpkg_Commands_Export_IFW.h b/toolsrc/include/vcpkg_Commands_Export_IFW.h index 881bbaf63..c066ca021 100644 --- a/toolsrc/include/vcpkg_Commands_Export_IFW.h +++ b/toolsrc/include/vcpkg_Commands_Export_IFW.h @@ -9,7 +9,9 @@ namespace vcpkg::Commands::Export::IFW { Optional maybe_repository_url; Optional maybe_packages_dir_path; + Optional maybe_repository_dir_path; Optional maybe_config_file_path; + Optional maybe_installer_file_path; }; void do_export(const std::vector &export_plan, const std::string &export_id, const Options &ifw_options, const VcpkgPaths& paths); -- cgit v1.2.3 From b3e06443eab560d5de848f2a066e1baa477fa57b Mon Sep 17 00:00:00 2001 From: Maria Tavlaki Date: Sun, 1 Oct 2017 22:17:33 +0300 Subject: Create stub autocomplete function --- toolsrc/include/vcpkg_Commands.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index 590f0208c..7cfa2760e 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/include/vcpkg_Commands.h @@ -194,6 +194,11 @@ namespace vcpkg::Commands void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } + namespace Autocomplete + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + namespace Help { void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); -- cgit v1.2.3 From ddbd57f5058b78e7df27497af844a41a1c79b986 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 4 Oct 2017 15:58:05 -0700 Subject: [vcpkg] Reformat and fix headers. --- toolsrc/include/vcpkg_Commands_Export.h | 8 +------- toolsrc/include/vcpkg_Commands_Export_IFW.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Commands_Export.h b/toolsrc/include/vcpkg_Commands_Export.h index 31003422d..6e698c1b4 100644 --- a/toolsrc/include/vcpkg_Commands_Export.h +++ b/toolsrc/include/vcpkg_Commands_Export.h @@ -1,14 +1,8 @@ #pragma once -#include "StatusParagraphs.h" -#include "VcpkgCmdArguments.h" #include "VcpkgPaths.h" -#include "VersionT.h" -#include "vcpkg_Build.h" -#include "vcpkg_Dependencies.h" -#include namespace vcpkg::Commands::Export { - void export_integration_files(const fs::path &raw_exported_dir_path, const VcpkgPaths& paths); + void export_integration_files(const fs::path& raw_exported_dir_path, const VcpkgPaths& paths); } diff --git a/toolsrc/include/vcpkg_Commands_Export_IFW.h b/toolsrc/include/vcpkg_Commands_Export_IFW.h index c066ca021..7bee45eaf 100644 --- a/toolsrc/include/vcpkg_Commands_Export_IFW.h +++ b/toolsrc/include/vcpkg_Commands_Export_IFW.h @@ -1,7 +1,11 @@ #pragma once -#include "vcpkg_Files.h" +#include "VcpkgPaths.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Files.h" + +#include +#include namespace vcpkg::Commands::Export::IFW { @@ -14,5 +18,8 @@ namespace vcpkg::Commands::Export::IFW Optional maybe_installer_file_path; }; - void do_export(const std::vector &export_plan, const std::string &export_id, const Options &ifw_options, const VcpkgPaths& paths); + void do_export(const std::vector& export_plan, + const std::string& export_id, + const Options& ifw_options, + const VcpkgPaths& paths); } -- cgit v1.2.3 From c98db7541594eadccf6823d4fdde2ff8c53c5fe9 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 4 Oct 2017 16:24:03 -0700 Subject: [vcpkg] Refactor out implication in option parsing for export --- toolsrc/include/Span.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/Span.h b/toolsrc/include/Span.h index b2c9acdbc..a43e8f992 100644 --- a/toolsrc/include/Span.h +++ b/toolsrc/include/Span.h @@ -2,6 +2,7 @@ #include #include +#include #include template @@ -17,6 +18,7 @@ public: constexpr Span(std::nullptr_t) noexcept : Span() {} constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {} constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {} + constexpr Span(std::initializer_list l) noexcept : m_ptr(l.begin()), m_count(l.size()) {} template constexpr Span(T (&arr)[N]) noexcept : Span(arr, N) -- cgit v1.2.3 From 7f68aa6630f96f474e85cd332dbbdc1ce6226d50 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 4 Oct 2017 15:50:48 -0700 Subject: Introduce Util::stable_keep_if() --- toolsrc/include/vcpkg_Util.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index c76ca01ac..e5ead6d3a 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -37,6 +37,12 @@ namespace vcpkg::Util return ret; } + template + void stable_keep_if(Container& cont, Pred pred) + { + cont.erase(std::stable_partition(cont.begin(), cont.end(), pred), cont.end()); + } + template void unstable_keep_if(Container& cont, Pred pred) { -- cgit v1.2.3 From 9a963f7eff1981d4e894ea8b297d092cda60b764 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Oct 2017 13:51:28 -0700 Subject: Overhaul VS selection. Add triplet option to specify VS instance --- toolsrc/include/VcpkgPaths.h | 5 +++-- toolsrc/include/vcpkg_Build.h | 3 ++- toolsrc/include/vcpkg_Util.h | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h index 4b4527434..d4640fba2 100644 --- a/toolsrc/include/VcpkgPaths.h +++ b/toolsrc/include/VcpkgPaths.h @@ -17,6 +17,7 @@ namespace vcpkg struct Toolset { + fs::path visual_studio_root_path; fs::path dumpbin; fs::path vcvarsall; std::vector vcvarsall_options; @@ -66,7 +67,8 @@ namespace vcpkg /// /// Valid version strings are "v140", "v141", and "". Empty string gets the latest. /// - const Toolset& get_toolset(const std::string& toolset_version) const; + const Toolset& VcpkgPaths::get_toolset(const Optional& toolset_version, + const Optional& visual_studio_path) const; Files::Filesystem& get_filesystem() const; @@ -78,6 +80,5 @@ namespace vcpkg Lazy ifw_binarycreator_exe; Lazy ifw_repogen_exe; Lazy> toolsets; - Lazy> toolsets_vs2017_v140; }; } diff --git a/toolsrc/include/vcpkg_Build.h b/toolsrc/include/vcpkg_Build.h index 78e89d4de..5ba675757 100644 --- a/toolsrc/include/vcpkg_Build.h +++ b/toolsrc/include/vcpkg_Build.h @@ -79,7 +79,8 @@ namespace vcpkg::Build std::string target_architecture; std::string cmake_system_name; std::string cmake_system_version; - std::string platform_toolset; + Optional platform_toolset; + Optional visual_studio_path; }; std::wstring make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index e5ead6d3a..a87045d73 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -67,6 +67,21 @@ namespace vcpkg::Util return std::find_if(cont.cbegin(), cont.cend(), pred); } + template + using ToVectorOfConstPointersT = std::decay_t()))>; + + template> + std::vector to_vector_of_const_pointers(const Container& cont) + { + std::vector output; + for (auto i = cont.cbegin(), cend = cont.end(); i != cend; ++i) + { + output.push_back(&(*i)); + } + + return output; + } + template auto find_if_not(const Container& cont, Pred pred) { -- cgit v1.2.3 From f0c23aeb6b238ee0ba2dc272ee4c193f2f777460 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Oct 2017 18:25:34 -0700 Subject: Completely rework Visual Studio detection - Now using vswhere.exe to detect all VS instance (2015 + 2017) - Default version preference order is now: stable, prerelease, legacy - Within each preference weight, the latest one is chosen - findVisualStudioInstallationInstances.ps1 now has a parameter to choose VS instance --- toolsrc/include/vcpkg_Util.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index a87045d73..facb7dd26 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -68,18 +68,12 @@ namespace vcpkg::Util } template - using ToVectorOfConstPointersT = std::decay_t()))>; + using ElementT = std::remove_reference_t()))>; - template> - std::vector to_vector_of_const_pointers(const Container& cont) + template> + std::vector element_pointers(Container&& cont) { - std::vector output; - for (auto i = cont.cbegin(), cend = cont.end(); i != cend; ++i) - { - output.push_back(&(*i)); - } - - return output; + return fmap(cont, [](auto&& x) { return &x; }); } template -- cgit v1.2.3 From 3efcc3d377750b753d516fd21b9009bfcd6e3877 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Oct 2017 11:45:08 -0700 Subject: Fix #1963 (permissive- issue) --- toolsrc/include/VcpkgPaths.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h index d4640fba2..a38865a3f 100644 --- a/toolsrc/include/VcpkgPaths.h +++ b/toolsrc/include/VcpkgPaths.h @@ -67,8 +67,8 @@ namespace vcpkg /// /// Valid version strings are "v140", "v141", and "". Empty string gets the latest. /// - const Toolset& VcpkgPaths::get_toolset(const Optional& toolset_version, - const Optional& visual_studio_path) const; + const Toolset& get_toolset(const Optional& toolset_version, + const Optional& visual_studio_path) const; Files::Filesystem& get_filesystem() const; -- cgit v1.2.3 From f6a0d78c82789af482eb3c885cbbb73aba7dfb38 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 13 Oct 2017 14:54:31 -0700 Subject: `autocomplete` Rework command, fixing a lot of corner cases in the process --- toolsrc/include/vcpkg_Commands.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index 7cfa2760e..c9a33a8f4 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/include/vcpkg_Commands.h @@ -194,10 +194,10 @@ namespace vcpkg::Commands void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } - namespace Autocomplete - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } + namespace Autocomplete + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } namespace Help { -- cgit v1.2.3 From e17de99599a2f114faab1bb4821fbaad4d266c95 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 13 Oct 2017 18:37:41 -0700 Subject: [vcpkg] Re-layout all files using new organization scheme. All filenames and directories are lowercase. Use dots for namespace separation. --- toolsrc/include/BinaryParagraph.h | 41 ---- toolsrc/include/CStringView.h | 96 --------- toolsrc/include/LineInfo.h | 19 -- toolsrc/include/MachineType.h | 36 ---- toolsrc/include/PackageSpec.h | 95 --------- toolsrc/include/PackageSpecParseResult.h | 32 --- toolsrc/include/ParagraphParseResult.h | 32 --- toolsrc/include/Paragraphs.h | 38 ---- toolsrc/include/PostBuildLint.h | 12 -- toolsrc/include/PostBuildLint_BuildType.h | 66 ------ toolsrc/include/SortedVector.h | 50 ----- toolsrc/include/SourceParagraph.h | 96 --------- toolsrc/include/Span.h | 52 ----- toolsrc/include/StatusParagraph.h | 44 ---- toolsrc/include/StatusParagraphs.h | 46 ----- toolsrc/include/VcpkgCmdArguments.h | 49 ----- toolsrc/include/VcpkgPaths.h | 84 -------- toolsrc/include/VersionT.h | 29 --- toolsrc/include/coff_file_reader.h | 21 -- toolsrc/include/filesystem_fs.h | 16 -- toolsrc/include/lazy.h | 26 --- toolsrc/include/metrics.h | 28 --- toolsrc/include/pch.h | 8 +- toolsrc/include/triplet.h | 43 ---- toolsrc/include/vcpkg/base/checks.h | 55 +++++ toolsrc/include/vcpkg/base/chrono.h | 28 +++ toolsrc/include/vcpkg/base/cofffilereader.h | 23 +++ toolsrc/include/vcpkg/base/cstringview.h | 97 +++++++++ toolsrc/include/vcpkg/base/enums.h | 12 ++ toolsrc/include/vcpkg/base/expected.h | 115 +++++++++++ toolsrc/include/vcpkg/base/files.h | 57 ++++++ toolsrc/include/vcpkg/base/graphs.h | 161 +++++++++++++++ toolsrc/include/vcpkg/base/lazy.h | 26 +++ toolsrc/include/vcpkg/base/lineinfo.h | 19 ++ toolsrc/include/vcpkg/base/machinetype.h | 37 ++++ toolsrc/include/vcpkg/base/optional.h | 99 +++++++++ toolsrc/include/vcpkg/base/sortedvector.h | 50 +++++ toolsrc/include/vcpkg/base/span.h | 60 ++++++ toolsrc/include/vcpkg/base/strings.h | 114 +++++++++++ toolsrc/include/vcpkg/base/system.h | 108 ++++++++++ toolsrc/include/vcpkg/base/util.h | 156 ++++++++++++++ toolsrc/include/vcpkg/binaryparagraph.h | 42 ++++ toolsrc/include/vcpkg/build.h | 205 +++++++++++++++++++ toolsrc/include/vcpkg/commands.h | 134 ++++++++++++ toolsrc/include/vcpkg/dependencies.h | 149 ++++++++++++++ toolsrc/include/vcpkg/export.h | 10 + toolsrc/include/vcpkg/export.ifw.h | 26 +++ toolsrc/include/vcpkg/globalstate.h | 19 ++ toolsrc/include/vcpkg/help.h | 19 ++ toolsrc/include/vcpkg/input.h | 15 ++ toolsrc/include/vcpkg/install.h | 69 +++++++ toolsrc/include/vcpkg/metrics.h | 28 +++ toolsrc/include/vcpkg/packagespec.h | 95 +++++++++ toolsrc/include/vcpkg/packagespecparseresult.h | 33 +++ toolsrc/include/vcpkg/paragraphparseresult.h | 33 +++ toolsrc/include/vcpkg/paragraphs.h | 38 ++++ toolsrc/include/vcpkg/parse.h | 38 ++++ toolsrc/include/vcpkg/postbuildlint.buildtype.h | 68 +++++++ toolsrc/include/vcpkg/postbuildlint.h | 13 ++ toolsrc/include/vcpkg/remove.h | 24 +++ toolsrc/include/vcpkg/sourceparagraph.h | 97 +++++++++ toolsrc/include/vcpkg/statusparagraph.h | 45 +++++ toolsrc/include/vcpkg/statusparagraphs.h | 47 +++++ toolsrc/include/vcpkg/triplet.h | 43 ++++ toolsrc/include/vcpkg/update.h | 21 ++ toolsrc/include/vcpkg/vcpkgcmdarguments.h | 50 +++++ toolsrc/include/vcpkg/vcpkglib.h | 38 ++++ toolsrc/include/vcpkg/vcpkgpaths.h | 85 ++++++++ toolsrc/include/vcpkg/versiont.h | 29 +++ toolsrc/include/vcpkg_Build.h | 192 ------------------ toolsrc/include/vcpkg_Checks.h | 54 ----- toolsrc/include/vcpkg_Chrono.h | 28 --- toolsrc/include/vcpkg_Commands.h | 258 ------------------------ toolsrc/include/vcpkg_Commands_Export.h | 8 - toolsrc/include/vcpkg_Commands_Export_IFW.h | 25 --- toolsrc/include/vcpkg_Dependencies.h | 147 -------------- toolsrc/include/vcpkg_Enums.h | 10 - toolsrc/include/vcpkg_Files.h | 43 ---- toolsrc/include/vcpkg_GlobalState.h | 19 -- toolsrc/include/vcpkg_Graphs.h | 159 --------------- toolsrc/include/vcpkg_Input.h | 14 -- toolsrc/include/vcpkg_Maps.h | 30 --- toolsrc/include/vcpkg_Parse.h | 38 ---- toolsrc/include/vcpkg_Strings.h | 113 ----------- toolsrc/include/vcpkg_System.h | 107 ---------- toolsrc/include/vcpkg_Util.h | 144 ------------- toolsrc/include/vcpkg_expected.h | 114 ----------- toolsrc/include/vcpkg_optional.h | 98 --------- toolsrc/include/vcpkglib.h | 38 ---- 89 files changed, 2734 insertions(+), 2694 deletions(-) delete mode 100644 toolsrc/include/BinaryParagraph.h delete mode 100644 toolsrc/include/CStringView.h delete mode 100644 toolsrc/include/LineInfo.h delete mode 100644 toolsrc/include/MachineType.h delete mode 100644 toolsrc/include/PackageSpec.h delete mode 100644 toolsrc/include/PackageSpecParseResult.h delete mode 100644 toolsrc/include/ParagraphParseResult.h delete mode 100644 toolsrc/include/Paragraphs.h delete mode 100644 toolsrc/include/PostBuildLint.h delete mode 100644 toolsrc/include/PostBuildLint_BuildType.h delete mode 100644 toolsrc/include/SortedVector.h delete mode 100644 toolsrc/include/SourceParagraph.h delete mode 100644 toolsrc/include/Span.h delete mode 100644 toolsrc/include/StatusParagraph.h delete mode 100644 toolsrc/include/StatusParagraphs.h delete mode 100644 toolsrc/include/VcpkgCmdArguments.h delete mode 100644 toolsrc/include/VcpkgPaths.h delete mode 100644 toolsrc/include/VersionT.h delete mode 100644 toolsrc/include/coff_file_reader.h delete mode 100644 toolsrc/include/filesystem_fs.h delete mode 100644 toolsrc/include/lazy.h delete mode 100644 toolsrc/include/metrics.h delete mode 100644 toolsrc/include/triplet.h create mode 100644 toolsrc/include/vcpkg/base/checks.h create mode 100644 toolsrc/include/vcpkg/base/chrono.h create mode 100644 toolsrc/include/vcpkg/base/cofffilereader.h create mode 100644 toolsrc/include/vcpkg/base/cstringview.h create mode 100644 toolsrc/include/vcpkg/base/enums.h create mode 100644 toolsrc/include/vcpkg/base/expected.h create mode 100644 toolsrc/include/vcpkg/base/files.h create mode 100644 toolsrc/include/vcpkg/base/graphs.h create mode 100644 toolsrc/include/vcpkg/base/lazy.h create mode 100644 toolsrc/include/vcpkg/base/lineinfo.h create mode 100644 toolsrc/include/vcpkg/base/machinetype.h create mode 100644 toolsrc/include/vcpkg/base/optional.h create mode 100644 toolsrc/include/vcpkg/base/sortedvector.h create mode 100644 toolsrc/include/vcpkg/base/span.h create mode 100644 toolsrc/include/vcpkg/base/strings.h create mode 100644 toolsrc/include/vcpkg/base/system.h create mode 100644 toolsrc/include/vcpkg/base/util.h create mode 100644 toolsrc/include/vcpkg/binaryparagraph.h create mode 100644 toolsrc/include/vcpkg/build.h create mode 100644 toolsrc/include/vcpkg/commands.h create mode 100644 toolsrc/include/vcpkg/dependencies.h create mode 100644 toolsrc/include/vcpkg/export.h create mode 100644 toolsrc/include/vcpkg/export.ifw.h create mode 100644 toolsrc/include/vcpkg/globalstate.h create mode 100644 toolsrc/include/vcpkg/help.h create mode 100644 toolsrc/include/vcpkg/input.h create mode 100644 toolsrc/include/vcpkg/install.h create mode 100644 toolsrc/include/vcpkg/metrics.h create mode 100644 toolsrc/include/vcpkg/packagespec.h create mode 100644 toolsrc/include/vcpkg/packagespecparseresult.h create mode 100644 toolsrc/include/vcpkg/paragraphparseresult.h create mode 100644 toolsrc/include/vcpkg/paragraphs.h create mode 100644 toolsrc/include/vcpkg/parse.h create mode 100644 toolsrc/include/vcpkg/postbuildlint.buildtype.h create mode 100644 toolsrc/include/vcpkg/postbuildlint.h create mode 100644 toolsrc/include/vcpkg/remove.h create mode 100644 toolsrc/include/vcpkg/sourceparagraph.h create mode 100644 toolsrc/include/vcpkg/statusparagraph.h create mode 100644 toolsrc/include/vcpkg/statusparagraphs.h create mode 100644 toolsrc/include/vcpkg/triplet.h create mode 100644 toolsrc/include/vcpkg/update.h create mode 100644 toolsrc/include/vcpkg/vcpkgcmdarguments.h create mode 100644 toolsrc/include/vcpkg/vcpkglib.h create mode 100644 toolsrc/include/vcpkg/vcpkgpaths.h create mode 100644 toolsrc/include/vcpkg/versiont.h delete mode 100644 toolsrc/include/vcpkg_Build.h delete mode 100644 toolsrc/include/vcpkg_Checks.h delete mode 100644 toolsrc/include/vcpkg_Chrono.h delete mode 100644 toolsrc/include/vcpkg_Commands.h delete mode 100644 toolsrc/include/vcpkg_Commands_Export.h delete mode 100644 toolsrc/include/vcpkg_Commands_Export_IFW.h delete mode 100644 toolsrc/include/vcpkg_Dependencies.h delete mode 100644 toolsrc/include/vcpkg_Enums.h delete mode 100644 toolsrc/include/vcpkg_Files.h delete mode 100644 toolsrc/include/vcpkg_GlobalState.h delete mode 100644 toolsrc/include/vcpkg_Graphs.h delete mode 100644 toolsrc/include/vcpkg_Input.h delete mode 100644 toolsrc/include/vcpkg_Maps.h delete mode 100644 toolsrc/include/vcpkg_Parse.h delete mode 100644 toolsrc/include/vcpkg_Strings.h delete mode 100644 toolsrc/include/vcpkg_System.h delete mode 100644 toolsrc/include/vcpkg_Util.h delete mode 100644 toolsrc/include/vcpkg_expected.h delete mode 100644 toolsrc/include/vcpkg_optional.h delete mode 100644 toolsrc/include/vcpkglib.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/BinaryParagraph.h b/toolsrc/include/BinaryParagraph.h deleted file mode 100644 index 61e03343a..000000000 --- a/toolsrc/include/BinaryParagraph.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include "PackageSpec.h" -#include "SourceParagraph.h" -#include - -namespace vcpkg -{ - /// - /// Built package metadata - /// - struct BinaryParagraph - { - BinaryParagraph(); - explicit BinaryParagraph(std::unordered_map fields); - BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet); - BinaryParagraph(const SourceParagraph& spgh, const FeatureParagraph& fpgh, const Triplet& triplet); - - std::string displayname() const; - - std::string fullstem() const; - - std::string dir() const; - - PackageSpec spec; - std::string version; - std::string description; - std::string maintainer; - std::string feature; - std::vector default_features; - std::vector depends; - }; - - struct BinaryControlFile - { - BinaryParagraph core_paragraph; - std::vector features; - }; - - void serialize(const BinaryParagraph& pgh, std::string& out_str); -} \ No newline at end of file diff --git a/toolsrc/include/CStringView.h b/toolsrc/include/CStringView.h deleted file mode 100644 index c1810b4f1..000000000 --- a/toolsrc/include/CStringView.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once -#include - -namespace vcpkg -{ - template - struct BasicCStringView - { - constexpr BasicCStringView() : cstr(nullptr) {} - constexpr BasicCStringView(const CharType* cstr) : cstr(cstr) {} - constexpr BasicCStringView(const BasicCStringView&) = default; - BasicCStringView(const std::basic_string& str) : cstr(str.c_str()) {} - - constexpr const CharType* c_str() const { return cstr; } - - private: - const CharType* cstr; - }; - - namespace details - { - inline bool vcpkg_strcmp(const char* l, const char* r) { return strcmp(l, r) == 0; } - inline bool vcpkg_strcmp(const wchar_t* l, const wchar_t* r) { return wcscmp(l, r) == 0; } - } - - template - bool operator==(const BasicCStringView& l, const BasicCStringView& r) - { - return details::vcpkg_strcmp(l.c_str(), r.c_str()); - } - - template - bool operator==(const CharType* l, const BasicCStringView& r) - { - return details::vcpkg_strcmp(l, r.c_str()); - } - - template - bool operator==(const BasicCStringView& r, const CharType* l) - { - return details::vcpkg_strcmp(l, r.c_str()); - } - - template - bool operator==(const std::basic_string& l, const BasicCStringView& r) - { - return l == r.c_str(); - } - - template - bool operator==(const BasicCStringView& r, const std::basic_string& l) - { - return l == r.c_str(); - } - - // notequals - template - bool operator!=(const BasicCStringView& l, const BasicCStringView& r) - { - return !details::vcpkg_strcmp(l.c_str(), r.c_str()); - } - - template - bool operator!=(const CharType* l, const BasicCStringView& r) - { - return !details::vcpkg_strcmp(l, r.c_str()); - } - - template - bool operator!=(const BasicCStringView& r, const CharType* l) - { - return !details::vcpkg_strcmp(l, r.c_str()); - } - - template - bool operator!=(const BasicCStringView& r, const std::basic_string& l) - { - return l != r.c_str(); - } - - template - bool operator!=(const std::basic_string& l, const BasicCStringView& r) - { - return l != r.c_str(); - } - - using CStringView = BasicCStringView; - using CWStringView = BasicCStringView; - - inline const char* to_printf_arg(const CStringView string_view) { return string_view.c_str(); } - - inline const wchar_t* to_wprintf_arg(const CWStringView string_view) { return string_view.c_str(); } - - static_assert(sizeof(CStringView) == sizeof(void*), "CStringView must be a simple wrapper around char*"); - static_assert(sizeof(CWStringView) == sizeof(void*), "CWStringView must be a simple wrapper around wchar_t*"); -} diff --git a/toolsrc/include/LineInfo.h b/toolsrc/include/LineInfo.h deleted file mode 100644 index 62973462a..000000000 --- a/toolsrc/include/LineInfo.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -namespace vcpkg -{ - struct LineInfo - { - int line_number; - const char* file_name; - - constexpr LineInfo() : line_number(0), file_name(nullptr) {} - constexpr LineInfo(const int lineno, const char* filename) : line_number(lineno), file_name(filename) {} - - std::string to_string() const; - }; -} - -#define VCPKG_LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) diff --git a/toolsrc/include/MachineType.h b/toolsrc/include/MachineType.h deleted file mode 100644 index 6f61bbd53..000000000 --- a/toolsrc/include/MachineType.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include - -namespace vcpkg -{ - enum class MachineType : uint16_t - { - UNKNOWN = 0x0, // The contents of this field are assumed to be applicable to any machine type - AM33 = 0x1d3, // Matsushita AM33 - AMD64 = 0x8664, // x64 - ARM = 0x1c0, // ARM little endian - ARM64 = 0xaa64, // ARM64 little endian - ARMNT = 0x1c4, // ARM Thumb-2 little endian - EBC = 0xebc, // EFI byte code - I386 = 0x14c, // Intel 386 or later processors and compatible processors - IA64 = 0x200, // Intel Itanium processor family - M32R = 0x9041, // Mitsubishi M32R little endian - MIPS16 = 0x266, // MIPS16 - MIPSFPU = 0x366, // MIPS with FPU - MIPSFPU16 = 0x466, // MIPS16 with FPU - POWERPC = 0x1f0, // Power PC little endian - POWERPCFP = 0x1f1, // Power PC with floating point support - R4000 = 0x166, // MIPS little endian - RISCV32 = 0x5032, // RISC-V 32-bit address space - RISCV64 = 0x5064, // RISC-V 64-bit address space - RISCV128 = 0x5128, // RISC-V 128-bit address space - SH3 = 0x1a2, // Hitachi SH3 - SH3DSP = 0x1a3, // Hitachi SH3 DSP - SH4 = 0x1a6, // Hitachi SH4 - SH5 = 0x1a8, // Hitachi SH5 - THUMB = 0x1c2, // Thumb - WCEMIPSV2 = 0x169, // MIPS little-endian WCE v2 - }; - - MachineType to_machine_type(const uint16_t value); -} diff --git a/toolsrc/include/PackageSpec.h b/toolsrc/include/PackageSpec.h deleted file mode 100644 index c5ce767f9..000000000 --- a/toolsrc/include/PackageSpec.h +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once - -#include "PackageSpecParseResult.h" -#include "Triplet.h" -#include "vcpkg_expected.h" - -namespace vcpkg -{ - struct ParsedSpecifier - { - std::string name; - std::vector features; - std::string triplet; - - static ExpectedT from_string(const std::string& input); - }; - - struct PackageSpec - { - static ExpectedT from_name_and_triplet(const std::string& name, - const Triplet& triplet); - - const std::string& name() const; - - const Triplet& triplet() const; - - std::string dir() const; - - std::string to_string() const; - - private: - std::string m_name; - Triplet m_triplet; - }; - - struct FeatureSpec - { - FeatureSpec(const PackageSpec& spec, const std::string& feature) : m_spec(spec), m_feature(feature) {} - - const std::string& name() const { return m_spec.name(); } - const std::string& feature() const { return m_feature; } - const Triplet& triplet() const { return m_spec.triplet(); } - - const PackageSpec& spec() const { return m_spec; } - - std::string to_string() const; - - static std::vector from_strings_and_triplet(const std::vector& depends, - const Triplet& t); - - private: - PackageSpec m_spec; - std::string m_feature; - }; - - struct FullPackageSpec - { - PackageSpec package_spec; - std::vector features; - - static std::vector to_feature_specs(const std::vector& specs); - - static ExpectedT from_string(const std::string& spec_as_string, - const Triplet& default_triplet); - }; - - struct Features - { - std::string name; - std::vector features; - - static ExpectedT from_string(const std::string& input); - }; - - bool operator==(const PackageSpec& left, const PackageSpec& right); - bool operator!=(const PackageSpec& left, const PackageSpec& right); -} - -template<> -struct std::hash -{ - size_t operator()(const vcpkg::PackageSpec& value) const - { - size_t hash = 17; - hash = hash * 31 + std::hash()(value.name()); - hash = hash * 31 + std::hash()(value.triplet()); - return hash; - } -}; - -template<> -struct std::equal_to -{ - bool operator()(const vcpkg::PackageSpec& left, const vcpkg::PackageSpec& right) const { return left == right; } -}; diff --git a/toolsrc/include/PackageSpecParseResult.h b/toolsrc/include/PackageSpecParseResult.h deleted file mode 100644 index 1462b8073..000000000 --- a/toolsrc/include/PackageSpecParseResult.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "vcpkg_expected.h" - -namespace vcpkg -{ - enum class PackageSpecParseResult - { - SUCCESS = 0, - TOO_MANY_COLONS, - INVALID_CHARACTERS - }; - - CStringView to_string(PackageSpecParseResult ev) noexcept; - - template<> - struct ErrorHolder - { - ErrorHolder() : m_err(PackageSpecParseResult::SUCCESS) {} - ErrorHolder(PackageSpecParseResult err) : m_err(err) {} - - constexpr bool has_error() const { return m_err != PackageSpecParseResult::SUCCESS; } - - const PackageSpecParseResult& error() const { return m_err; } - PackageSpecParseResult& error() { return m_err; } - - CStringView to_string() const { return vcpkg::to_string(m_err); } - - private: - PackageSpecParseResult m_err; - }; -} diff --git a/toolsrc/include/ParagraphParseResult.h b/toolsrc/include/ParagraphParseResult.h deleted file mode 100644 index eaa7e6327..000000000 --- a/toolsrc/include/ParagraphParseResult.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include - -namespace vcpkg -{ - enum class ParagraphParseResult - { - SUCCESS = 0, - EXPECTED_ONE_PARAGRAPH - }; - - struct ParagraphParseResultCategoryImpl final : std::error_category - { - virtual const char* name() const noexcept override; - - virtual std::string message(int ev) const noexcept override; - }; - - const std::error_category& paragraph_parse_result_category(); - - std::error_code make_error_code(ParagraphParseResult e); - - ParagraphParseResult to_paragraph_parse_result(int i); - - ParagraphParseResult to_paragraph_parse_result(std::error_code ec); -} - -// Enable implicit conversion to std::error_code -template<> -struct std::is_error_code_enum : ::std::true_type -{ -}; diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h deleted file mode 100644 index aae46f7da..000000000 --- a/toolsrc/include/Paragraphs.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include - -#include "BinaryParagraph.h" -#include "VcpkgPaths.h" -#include "VersionT.h" -#include "filesystem_fs.h" -#include "vcpkg_Parse.h" -#include "vcpkg_expected.h" - -namespace vcpkg::Paragraphs -{ - using RawParagraph = Parse::RawParagraph; - - Expected get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path); - Expected> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path); - Expected parse_single_paragraph(const std::string& str); - Expected> parse_paragraphs(const std::string& str); - - Parse::ParseExpected try_load_port(const Files::Filesystem& fs, const fs::path& control_path); - - Expected try_load_cached_control_package(const VcpkgPaths& paths, const PackageSpec& spec); - - struct LoadResults - { - std::vector> paragraphs; - std::vector> errors; - }; - - LoadResults try_load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir); - - std::vector> load_all_ports(const Files::Filesystem& fs, - const fs::path& ports_dir); - - std::map load_all_port_names_and_versions(const Files::Filesystem& fs, - const fs::path& ports_dir); -} diff --git a/toolsrc/include/PostBuildLint.h b/toolsrc/include/PostBuildLint.h deleted file mode 100644 index 69fafc9f7..000000000 --- a/toolsrc/include/PostBuildLint.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "PackageSpec.h" -#include "VcpkgPaths.h" -#include "vcpkg_Build.h" - -namespace vcpkg::PostBuildLint -{ - size_t perform_all_checks(const PackageSpec& spec, - const VcpkgPaths& paths, - const Build::PreBuildInfo& pre_build_info, - const Build::BuildInfo& build_info); -} diff --git a/toolsrc/include/PostBuildLint_BuildType.h b/toolsrc/include/PostBuildLint_BuildType.h deleted file mode 100644 index 38ad3084e..000000000 --- a/toolsrc/include/PostBuildLint_BuildType.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once -#include "CStringView.h" -#include "vcpkg_Build.h" -#include -#include - -namespace vcpkg::PostBuildLint -{ - enum class ConfigurationType - { - DEBUG, - RELEASE, - }; - - struct BuildType - { - enum class BackingEnum - { - DEBUG_STATIC = 1, - DEBUG_DYNAMIC, - RELEASE_STATIC, - RELEASE_DYNAMIC - }; - - static BuildType value_of(const ConfigurationType& config, const Build::LinkageType& linkage); - - BuildType() = delete; - - constexpr BuildType(const BackingEnum backing_enum, - const ConfigurationType config, - const Build::LinkageType linkage) - : backing_enum(backing_enum), m_config(config), m_linkage(linkage) - { - } - - constexpr operator BackingEnum() const { return backing_enum; } - - const ConfigurationType& config() const; - const Build::LinkageType& linkage() const; - const std::regex& crt_regex() const; - const std::string& to_string() const; - - private: - BackingEnum backing_enum; - ConfigurationType m_config; - Build::LinkageType m_linkage; - }; - - namespace BuildTypeC - { - using Build::LinkageType; - using BE = BuildType::BackingEnum; - - static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::BuildType"; - - static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageType::STATIC}; - static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageType::DYNAMIC}; - static constexpr BuildType RELEASE_STATIC = { - BE::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageType::STATIC}; - static constexpr BuildType RELEASE_DYNAMIC = { - BE::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageType::DYNAMIC}; - - static constexpr std::array VALUES = { - DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC}; - } -} diff --git a/toolsrc/include/SortedVector.h b/toolsrc/include/SortedVector.h deleted file mode 100644 index 62808cc2f..000000000 --- a/toolsrc/include/SortedVector.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include -#include - -// Add more forwarding functions to the m_data std::vector as needed. -namespace vcpkg -{ - template - class SortedVector - { - public: - using size_type = typename std::vector::size_type; - using iterator = typename std::vector::const_iterator; - - SortedVector() : m_data() {} - - explicit SortedVector(std::vector v) : m_data(std::move(v)) - { - if (!std::is_sorted(m_data.begin(), m_data.end())) - { - std::sort(m_data.begin(), m_data.end()); - } - } - - template - SortedVector(std::vector v, Compare comp) : m_data(std::move(v)) - { - if (!std::is_sorted(m_data.cbegin(), m_data.cend(), comp)) - { - std::sort(m_data.begin(), m_data.end(), comp); - } - } - - iterator begin() const { return this->m_data.cbegin(); } - - iterator end() const { return this->m_data.cend(); } - - iterator cbegin() const { return this->m_data.cbegin(); } - - iterator cend() const { return this->m_data.cend(); } - - bool empty() const { return this->m_data.empty(); } - - size_type size() const { return this->m_data.size(); } - - private: - std::vector m_data; - }; -} diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h deleted file mode 100644 index ccf9faf4f..000000000 --- a/toolsrc/include/SourceParagraph.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "PackageSpec.h" -#include "Span.h" -#include "vcpkg_Parse.h" -#include "vcpkg_System.h" -#include "vcpkg_expected.h" - -#include -#include - -namespace vcpkg -{ - struct Dependency - { - Features depend; - std::string qualifier; - - std::string name() const; - static Dependency parse_dependency(std::string name, std::string qualifier); - }; - - std::vector filter_dependencies(const std::vector& deps, const Triplet& t); - std::vector filter_dependencies_to_specs(const std::vector& deps, const Triplet& t); - - // zlib[uwp] becomes Dependency{"zlib", "uwp"} - std::vector expand_qualified_dependencies(const std::vector& depends); - - std::string to_string(const Dependency& dep); - - struct FeatureParagraph - { - std::string name; - std::string description; - std::vector depends; - }; - - /// - /// Port metadata (CONTROL file) - /// - struct SourceParagraph - { - std::string name; - std::string version; - std::string description; - std::string maintainer; - std::vector supports; - std::vector depends; - std::vector default_features; - }; - struct SourceControlFile - { - static Parse::ParseExpected parse_control_file( - std::vector&& control_paragraphs); - - std::unique_ptr core_paragraph; - std::vector> feature_paragraphs; - }; - - void print_error_message(Span> error_info_list); - inline void print_error_message(const std::unique_ptr& error_info_list) - { - return print_error_message({&error_info_list, 1}); - } - - struct Supports - { - static ExpectedT> parse(const std::vector& strs); - - using Architecture = System::CPUArchitecture; - - enum class Platform - { - WINDOWS, - UWP, - }; - enum class Linkage - { - DYNAMIC, - STATIC, - }; - enum class ToolsetVersion - { - V140, - V141, - }; - - bool is_supported(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools); - - private: - std::vector architectures; - std::vector platforms; - std::vector crt_linkages; - std::vector toolsets; - }; -} diff --git a/toolsrc/include/Span.h b/toolsrc/include/Span.h deleted file mode 100644 index a43e8f992..000000000 --- a/toolsrc/include/Span.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -template -struct Span -{ -public: - using element_type = T; - using pointer = T*; - using reference = T&; - using iterator = T*; - - constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {} - constexpr Span(std::nullptr_t) noexcept : Span() {} - constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {} - constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {} - constexpr Span(std::initializer_list l) noexcept : m_ptr(l.begin()), m_count(l.size()) {} - - template - constexpr Span(T (&arr)[N]) noexcept : Span(arr, N) - { - } - - Span(std::vector& v) noexcept : Span(v.data(), v.size()) {} - Span(const std::vector>& v) noexcept : Span(v.data(), v.size()) {} - - constexpr iterator begin() const { return m_ptr; } - constexpr iterator end() const { return m_ptr + m_count; } - - constexpr reference operator[](size_t i) const { return m_ptr[i]; } - constexpr size_t size() const { return m_count; } - -private: - pointer m_ptr; - size_t m_count; -}; - -template -Span make_span(std::vector& v) -{ - return {v.data(), v.size()}; -} - -template -Span make_span(const std::vector& v) -{ - return {v.data(), v.size()}; -} diff --git a/toolsrc/include/StatusParagraph.h b/toolsrc/include/StatusParagraph.h deleted file mode 100644 index b56533d65..000000000 --- a/toolsrc/include/StatusParagraph.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "BinaryParagraph.h" -#include - -namespace vcpkg -{ - enum class InstallState - { - ERROR_STATE, - NOT_INSTALLED, - HALF_INSTALLED, - INSTALLED, - }; - - enum class Want - { - ERROR_STATE, - UNKNOWN, - INSTALL, - HOLD, - DEINSTALL, - PURGE - }; - - /// - /// Installed package metadata - /// - struct StatusParagraph - { - StatusParagraph(); - explicit StatusParagraph(std::unordered_map&& fields); - - BinaryParagraph package; - Want want; - InstallState state; - }; - - void serialize(const StatusParagraph& pgh, std::string& out_str); - - std::string to_string(InstallState f); - - std::string to_string(Want f); -} diff --git a/toolsrc/include/StatusParagraphs.h b/toolsrc/include/StatusParagraphs.h deleted file mode 100644 index 1a9ee6a03..000000000 --- a/toolsrc/include/StatusParagraphs.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include "StatusParagraph.h" -#include -#include - -namespace vcpkg -{ - struct StatusParagraphs - { - StatusParagraphs(); - explicit StatusParagraphs(std::vector>&& ps); - - using container = std::vector>; - using iterator = container::reverse_iterator; - using const_iterator = container::const_reverse_iterator; - - const_iterator find(const PackageSpec& spec) const { return find(spec.name(), spec.triplet()); } - const_iterator find(const std::string& name, const Triplet& triplet) const; - iterator find(const std::string& name, const Triplet& triplet); - std::vector*> find_all(const std::string& name, const Triplet& triplet); - iterator find(const std::string& name, const Triplet& triplet, const std::string& feature); - - const_iterator find_installed(const PackageSpec& spec) const - { - return find_installed(spec.name(), spec.triplet()); - } - const_iterator find_installed(const std::string& name, const Triplet& triplet) const; - - iterator insert(std::unique_ptr); - - friend void serialize(const StatusParagraphs& pgh, std::string& out_str); - - iterator end() { return paragraphs.rend(); } - - const_iterator end() const { return paragraphs.rend(); } - - iterator begin() { return paragraphs.rbegin(); } - - const_iterator begin() const { return paragraphs.rbegin(); } - - private: - std::vector> paragraphs; - }; - - void serialize(const StatusParagraphs& pgh, std::string& out_str); -} diff --git a/toolsrc/include/VcpkgCmdArguments.h b/toolsrc/include/VcpkgCmdArguments.h deleted file mode 100644 index 0de5747b1..000000000 --- a/toolsrc/include/VcpkgCmdArguments.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "vcpkg_optional.h" -#include -#include -#include -#include - -namespace vcpkg -{ - struct ParsedArguments - { - std::unordered_set switches; - std::unordered_map settings; - }; - - struct VcpkgCmdArguments - { - static VcpkgCmdArguments create_from_command_line(const int argc, const wchar_t* const* const argv); - static VcpkgCmdArguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end); - - std::unique_ptr vcpkg_root_dir; - std::unique_ptr triplet; - Optional debug = nullopt; - Optional sendmetrics = nullopt; - Optional printmetrics = nullopt; - - std::string command; - std::vector command_arguments; - std::unordered_set check_and_get_optional_command_arguments( - const std::vector& valid_options) const - { - return std::move(check_and_get_optional_command_arguments(valid_options, {}).switches); - } - - ParsedArguments check_and_get_optional_command_arguments(const std::vector& valid_switches, - const std::vector& valid_settings) 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 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 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 std::string& example_text) const; - - private: - std::unordered_map> optional_command_arguments; - }; -} diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h deleted file mode 100644 index d4640fba2..000000000 --- a/toolsrc/include/VcpkgPaths.h +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once -#include "BinaryParagraph.h" -#include "Lazy.h" -#include "PackageSpec.h" -#include "filesystem_fs.h" -#include "vcpkg_Files.h" -#include "vcpkg_expected.h" - -namespace vcpkg -{ - struct ToolsetArchOption - { - CWStringView name; - System::CPUArchitecture host_arch; - System::CPUArchitecture target_arch; - }; - - struct Toolset - { - fs::path visual_studio_root_path; - fs::path dumpbin; - fs::path vcvarsall; - std::vector vcvarsall_options; - CWStringView version; - std::vector supported_architectures; - }; - - struct VcpkgPaths - { - static Expected create(const fs::path& vcpkg_root_dir); - - fs::path package_dir(const PackageSpec& spec) const; - fs::path port_dir(const PackageSpec& spec) const; - fs::path port_dir(const std::string& name) const; - fs::path build_info_file_path(const PackageSpec& spec) const; - fs::path listfile_path(const BinaryParagraph& pgh) const; - - bool is_valid_triplet(const Triplet& t) const; - - fs::path root; - fs::path packages; - fs::path buildtrees; - fs::path downloads; - fs::path ports; - fs::path installed; - fs::path triplets; - fs::path scripts; - - fs::path buildsystems; - fs::path buildsystems_msbuild_targets; - - fs::path vcpkg_dir; - fs::path vcpkg_dir_status_file; - fs::path vcpkg_dir_info; - fs::path vcpkg_dir_updates; - - fs::path ports_cmake; - - const fs::path& get_cmake_exe() const; - const fs::path& get_git_exe() const; - const fs::path& get_nuget_exe() const; - const fs::path& get_ifw_installerbase_exe() const; - const fs::path& get_ifw_binarycreator_exe() const; - const fs::path& get_ifw_repogen_exe() const; - - /// Retrieve a toolset matching a VS version - /// - /// Valid version strings are "v140", "v141", and "". Empty string gets the latest. - /// - const Toolset& VcpkgPaths::get_toolset(const Optional& toolset_version, - const Optional& visual_studio_path) const; - - Files::Filesystem& get_filesystem() const; - - private: - Lazy cmake_exe; - Lazy git_exe; - Lazy nuget_exe; - Lazy ifw_installerbase_exe; - Lazy ifw_binarycreator_exe; - Lazy ifw_repogen_exe; - Lazy> toolsets; - }; -} diff --git a/toolsrc/include/VersionT.h b/toolsrc/include/VersionT.h deleted file mode 100644 index 67efd8da3..000000000 --- a/toolsrc/include/VersionT.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include - -namespace vcpkg -{ - struct VersionT - { - VersionT(); - VersionT(const std::string& value); - - std::string to_string() const; - - std::string value; - }; - - bool operator==(const VersionT& left, const VersionT& right); - bool operator!=(const VersionT& left, const VersionT& right); - - struct VersionDiff - { - VersionT left; - VersionT right; - - VersionDiff(); - VersionDiff(const VersionT& left, const VersionT& right); - - std::string to_string() const; - }; -} diff --git a/toolsrc/include/coff_file_reader.h b/toolsrc/include/coff_file_reader.h deleted file mode 100644 index 7287211a1..000000000 --- a/toolsrc/include/coff_file_reader.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "MachineType.h" -#include "filesystem_fs.h" -#include - -namespace vcpkg::CoffFileReader -{ - struct DllInfo - { - MachineType machine_type; - }; - - struct LibInfo - { - std::vector machine_types; - }; - - DllInfo read_dll(const fs::path& path); - - LibInfo read_lib(const fs::path& path); -} diff --git a/toolsrc/include/filesystem_fs.h b/toolsrc/include/filesystem_fs.h deleted file mode 100644 index 0651ebf25..000000000 --- a/toolsrc/include/filesystem_fs.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -namespace fs -{ - namespace stdfs = std::experimental::filesystem; - - using stdfs::path; - using stdfs::copy_options; - using stdfs::file_status; - - inline bool is_regular_file(file_status s) { return stdfs::is_regular_file(s); } - inline bool is_directory(file_status s) { return stdfs::is_directory(s); } - inline bool status_known(file_status s) { return stdfs::status_known(s); } -} \ No newline at end of file diff --git a/toolsrc/include/lazy.h b/toolsrc/include/lazy.h deleted file mode 100644 index 58c11c002..000000000 --- a/toolsrc/include/lazy.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -namespace vcpkg -{ - template - class Lazy - { - public: - Lazy() : value(T()), initialized(false) {} - - template - T const& get_lazy(const F& f) const - { - if (!initialized) - { - value = f(); - initialized = true; - } - return value; - } - - private: - mutable T value; - mutable bool initialized; - }; -} diff --git a/toolsrc/include/metrics.h b/toolsrc/include/metrics.h deleted file mode 100644 index 8eae426de..000000000 --- a/toolsrc/include/metrics.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#include "vcpkg_Util.h" - -namespace vcpkg::Metrics -{ - struct Metrics : Util::ResourceBase - { - void set_send_metrics(bool should_send_metrics); - void set_print_metrics(bool should_print_metrics); - void set_user_information(const std::string& user_id, const std::string& first_use_time); - void init_user_information(std::string& user_id, std::string& first_use_time); - - void track_metric(const std::string& name, double value); - void track_property(const std::string& name, const std::string& value); - void track_property(const std::string& name, const std::wstring& value); - - void upload(const std::string& payload); - void flush(); - }; - - extern Util::LockGuarded g_metrics; - - std::wstring get_SQM_user(); - bool get_compiled_metrics_enabled(); -} diff --git a/toolsrc/include/pch.h b/toolsrc/include/pch.h index 0f34063f8..8333eb927 100644 --- a/toolsrc/include/pch.h +++ b/toolsrc/include/pch.h @@ -2,9 +2,13 @@ #define NOMINMAX #define WIN32_LEAN_AND_MEAN + #pragma warning(suppress : 4768) #include +#pragma warning(suppress : 4768) +#include + #include #include #include @@ -28,10 +32,6 @@ #include #include #include -#pragma warning(push) -#pragma warning(disable : 4768) -#include -#pragma warning(pop) #include #include #include diff --git a/toolsrc/include/triplet.h b/toolsrc/include/triplet.h deleted file mode 100644 index 46a52f8e6..000000000 --- a/toolsrc/include/triplet.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -namespace vcpkg -{ - struct TripletInstance; - - struct Triplet - { - public: - constexpr Triplet() : m_instance(&DEFAULT_INSTANCE) {} - - static Triplet from_canonical_name(const std::string& triplet_as_string); - - 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; - - const std::string& canonical_name() const; - const std::string& to_string() const; - size_t hash_code() const; - - bool operator==(const Triplet& other) const; - - private: - static const TripletInstance DEFAULT_INSTANCE; - - constexpr Triplet(const TripletInstance* ptr) : m_instance(ptr) {} - - const TripletInstance* m_instance; - }; - - bool operator!=(const Triplet& left, const Triplet& right); -} - -template<> -struct std::hash -{ - size_t operator()(const vcpkg::Triplet& t) const { return t.hash_code(); } -}; diff --git a/toolsrc/include/vcpkg/base/checks.h b/toolsrc/include/vcpkg/base/checks.h new file mode 100644 index 000000000..fb162c897 --- /dev/null +++ b/toolsrc/include/vcpkg/base/checks.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include + +namespace vcpkg::Checks +{ + void register_console_ctrl_handler(); + + // Indicate that an internal error has occurred and exit the tool. This should be used when invariants have been + // broken. + [[noreturn]] void unreachable(const LineInfo& line_info); + + [[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code); + + // Exit the tool without an error message. + [[noreturn]] inline void exit_fail(const LineInfo& line_info) { exit_with_code(line_info, EXIT_FAILURE); } + + // Exit the tool successfully. + [[noreturn]] inline void exit_success(const LineInfo& line_info) { exit_with_code(line_info, EXIT_SUCCESS); } + + // Display an error message to the user and exit the tool. + [[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView error_message); + + template + // Display an error message to the user and exit the tool. + [[noreturn]] void exit_with_message(const LineInfo& line_info, + const char* error_message_template, + const Arg1 error_message_arg1, + const Args&... error_message_args) + { + exit_with_message(line_info, + Strings::format(error_message_template, error_message_arg1, error_message_args...)); + } + + void check_exit(const LineInfo& line_info, bool expression); + + void check_exit(const LineInfo& line_info, bool expression, const CStringView error_message); + + template + void check_exit(const LineInfo& line_info, + Conditional&& expression, + const char* error_message_template, + const Arg1 error_message_arg1, + const Args&... error_message_args) + { + if (!expression) + { + // Only create the string if the expression is false + exit_with_message(line_info, + Strings::format(error_message_template, error_message_arg1, error_message_args...)); + } + } +} diff --git a/toolsrc/include/vcpkg/base/chrono.h b/toolsrc/include/vcpkg/base/chrono.h new file mode 100644 index 000000000..b525852f2 --- /dev/null +++ b/toolsrc/include/vcpkg/base/chrono.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +namespace vcpkg::Chrono +{ + class ElapsedTime + { + public: + static ElapsedTime create_started(); + + constexpr ElapsedTime() : m_start_tick() {} + + template + TimeUnit elapsed() const + { + return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - this->m_start_tick); + } + + double microseconds() const { return elapsed>().count(); } + + std::string to_string() const; + + private: + std::chrono::high_resolution_clock::time_point m_start_tick; + }; +} diff --git a/toolsrc/include/vcpkg/base/cofffilereader.h b/toolsrc/include/vcpkg/base/cofffilereader.h new file mode 100644 index 000000000..ad2cc7b12 --- /dev/null +++ b/toolsrc/include/vcpkg/base/cofffilereader.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg::CoffFileReader +{ + struct DllInfo + { + MachineType machine_type; + }; + + struct LibInfo + { + std::vector machine_types; + }; + + DllInfo read_dll(const fs::path& path); + + LibInfo read_lib(const fs::path& path); +} diff --git a/toolsrc/include/vcpkg/base/cstringview.h b/toolsrc/include/vcpkg/base/cstringview.h new file mode 100644 index 000000000..341830f05 --- /dev/null +++ b/toolsrc/include/vcpkg/base/cstringview.h @@ -0,0 +1,97 @@ +#pragma once + +#include + +namespace vcpkg +{ + template + struct BasicCStringView + { + constexpr BasicCStringView() : cstr(nullptr) {} + constexpr BasicCStringView(const CharType* cstr) : cstr(cstr) {} + constexpr BasicCStringView(const BasicCStringView&) = default; + BasicCStringView(const std::basic_string& str) : cstr(str.c_str()) {} + + constexpr const CharType* c_str() const { return cstr; } + + private: + const CharType* cstr; + }; + + namespace details + { + inline bool vcpkg_strcmp(const char* l, const char* r) { return strcmp(l, r) == 0; } + inline bool vcpkg_strcmp(const wchar_t* l, const wchar_t* r) { return wcscmp(l, r) == 0; } + } + + template + bool operator==(const BasicCStringView& l, const BasicCStringView& r) + { + return details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template + bool operator==(const CharType* l, const BasicCStringView& r) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator==(const BasicCStringView& r, const CharType* l) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator==(const std::basic_string& l, const BasicCStringView& r) + { + return l == r.c_str(); + } + + template + bool operator==(const BasicCStringView& r, const std::basic_string& l) + { + return l == r.c_str(); + } + + // notequals + template + bool operator!=(const BasicCStringView& l, const BasicCStringView& r) + { + return !details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template + bool operator!=(const CharType* l, const BasicCStringView& r) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator!=(const BasicCStringView& r, const CharType* l) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator!=(const BasicCStringView& r, const std::basic_string& l) + { + return l != r.c_str(); + } + + template + bool operator!=(const std::basic_string& l, const BasicCStringView& r) + { + return l != r.c_str(); + } + + using CStringView = BasicCStringView; + using CWStringView = BasicCStringView; + + inline const char* to_printf_arg(const CStringView string_view) { return string_view.c_str(); } + + inline const wchar_t* to_wprintf_arg(const CWStringView string_view) { return string_view.c_str(); } + + static_assert(sizeof(CStringView) == sizeof(void*), "CStringView must be a simple wrapper around char*"); + static_assert(sizeof(CWStringView) == sizeof(void*), "CWStringView must be a simple wrapper around wchar_t*"); +} diff --git a/toolsrc/include/vcpkg/base/enums.h b/toolsrc/include/vcpkg/base/enums.h new file mode 100644 index 000000000..6eca2cfe1 --- /dev/null +++ b/toolsrc/include/vcpkg/base/enums.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +#include + +namespace vcpkg::Enums +{ + std::string nullvalue_to_string(const CStringView enum_name); + + [[noreturn]] void nullvalue_used(const LineInfo& line_info, const CStringView enum_name); +} diff --git a/toolsrc/include/vcpkg/base/expected.h b/toolsrc/include/vcpkg/base/expected.h new file mode 100644 index 000000000..a946c442e --- /dev/null +++ b/toolsrc/include/vcpkg/base/expected.h @@ -0,0 +1,115 @@ +#pragma once + +#include + +#include + +namespace vcpkg +{ + template + struct ErrorHolder + { + ErrorHolder() : m_is_error(false) {} + template + ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward(err)) + { + } + + constexpr bool has_error() const { return m_is_error; } + + const Err& error() const { return m_err; } + Err& error() { return m_err; } + + CStringView to_string() const { return "value was error"; } + + private: + bool m_is_error; + Err m_err; + }; + + template<> + struct ErrorHolder + { + ErrorHolder() = default; + ErrorHolder(const std::error_code& err) : m_err(err) {} + + constexpr bool has_error() const { return bool(m_err); } + + const std::error_code& error() const { return m_err; } + std::error_code& error() { return m_err; } + + CStringView to_string() const { return "value was error"; } + + private: + std::error_code m_err; + }; + + template + class ExpectedT + { + public: + constexpr ExpectedT() = default; + + // Constructors are intentionally implicit + + ExpectedT(const S& s) : m_s(s) {} + ExpectedT(S&& s) : m_s(std::move(s)) {} + + ExpectedT(const T& t) : m_t(t) {} + ExpectedT(T&& t) : m_t(std::move(t)) {} + + ExpectedT(const ExpectedT&) = default; + ExpectedT(ExpectedT&&) = default; + ExpectedT& operator=(const ExpectedT&) = default; + ExpectedT& operator=(ExpectedT&&) = default; + + explicit constexpr operator bool() const noexcept { return !m_s.has_error(); } + constexpr bool has_value() const noexcept { return !m_s.has_error(); } + + T&& value_or_exit(const LineInfo& line_info) && + { + exit_if_error(line_info); + return std::move(this->m_t); + } + + const T& value_or_exit(const LineInfo& line_info) const& + { + exit_if_error(line_info); + return this->m_t; + } + + const S& error() const& { return this->m_s.error(); } + + S&& error() && { return std::move(this->m_s.error()); } + + const T* get() const + { + if (!this->has_value()) + { + return nullptr; + } + return &this->m_t; + } + + T* get() + { + if (!this->has_value()) + { + return nullptr; + } + return &this->m_t; + } + + private: + void exit_if_error(const LineInfo& line_info) const + { + Checks::check_exit(line_info, !m_s.has_error(), m_s.to_string()); + } + + ErrorHolder m_s; + T m_t; + }; + + template + using Expected = ExpectedT; +} diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h new file mode 100644 index 000000000..f4bcf742c --- /dev/null +++ b/toolsrc/include/vcpkg/base/files.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include + +namespace fs +{ + namespace stdfs = std::experimental::filesystem; + + using stdfs::copy_options; + using stdfs::file_status; + using stdfs::path; + + inline bool is_regular_file(file_status s) { return stdfs::is_regular_file(s); } + inline bool is_directory(file_status s) { return stdfs::is_directory(s); } + inline bool status_known(file_status s) { return stdfs::status_known(s); } +} + +namespace vcpkg::Files +{ + __interface Filesystem + { + virtual Expected read_contents(const fs::path& file_path) const = 0; + virtual Expected> read_lines(const fs::path& file_path) const = 0; + virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0; + virtual std::vector get_files_recursive(const fs::path& dir) const = 0; + virtual std::vector get_files_non_recursive(const fs::path& dir) const = 0; + + virtual void write_lines(const fs::path& file_path, const std::vector& lines) = 0; + virtual void write_contents(const fs::path& file_path, const std::string& data) = 0; + virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0; + virtual bool remove(const fs::path& path) = 0; + virtual bool remove(const fs::path& path, std::error_code& ec) = 0; + virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0; + virtual bool exists(const fs::path& path) const = 0; + virtual bool is_directory(const fs::path& path) const = 0; + virtual bool is_regular_file(const fs::path& path) const = 0; + virtual bool is_empty(const fs::path& path) const = 0; + virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0; + virtual bool create_directories(const fs::path& path, std::error_code& ec) = 0; + virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0; + virtual bool copy_file( + const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0; + virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0; + }; + + Filesystem& get_real_filesystem(); + + static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; + + bool has_invalid_chars_for_filesystem(const std::string& s); + + void print_paths(const std::vector& paths); + + std::vector find_from_PATH(const std::wstring& name); +} diff --git a/toolsrc/include/vcpkg/base/graphs.h b/toolsrc/include/vcpkg/base/graphs.h new file mode 100644 index 000000000..ff56cb298 --- /dev/null +++ b/toolsrc/include/vcpkg/base/graphs.h @@ -0,0 +1,161 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg::Graphs +{ + enum class ExplorationStatus + { + // We have not visited this vertex + NOT_EXPLORED, + + // We have visited this vertex but haven't visited all vertices in its subtree + PARTIALLY_EXPLORED, + + // We have visited this vertex and all vertices in its subtree + FULLY_EXPLORED + }; + + template + __interface AdjacencyProvider + { + std::vector adjacency_list(const U& vertex) const; + + U load_vertex_data(const V& vertex) const; + }; + + template + static void topological_sort_internal(const V& vertex, + const AdjacencyProvider& f, + std::unordered_map& exploration_status, + std::vector& sorted) + { + ExplorationStatus& status = exploration_status[vertex]; + switch (status) + { + case ExplorationStatus::FULLY_EXPLORED: return; + case ExplorationStatus::PARTIALLY_EXPLORED: Checks::exit_with_message(VCPKG_LINE_INFO, "cycle in graph"); + case ExplorationStatus::NOT_EXPLORED: + { + status = ExplorationStatus::PARTIALLY_EXPLORED; + U vertex_data = f.load_vertex_data(vertex); + for (const V& neighbour : f.adjacency_list(vertex_data)) + topological_sort_internal(neighbour, f, exploration_status, sorted); + + sorted.push_back(std::move(vertex_data)); + status = ExplorationStatus::FULLY_EXPLORED; + return; + } + default: Checks::unreachable(VCPKG_LINE_INFO); + } + } + + template + std::vector topological_sort(const std::vector& starting_vertices, const AdjacencyProvider& f) + { + std::vector sorted; + std::unordered_map exploration_status; + + for (auto& vertex : starting_vertices) + { + topological_sort_internal(vertex, f, exploration_status, sorted); + } + + return sorted; + } + + template + struct GraphAdjacencyProvider final : AdjacencyProvider + { + const std::unordered_map>& vertices; + + GraphAdjacencyProvider(const std::unordered_map>& vertices) : vertices(vertices) {} + + std::vector adjacency_list(const V& vertex) const override + { + const std::unordered_set& as_set = this->vertices.at(vertex); + return std::vector(as_set.cbegin(), as_set.cend()); // TODO: Avoid redundant copy + } + + V load_vertex_data(const V& vertex) const override { return vertex; } + }; + + template + struct Graph + { + public: + void add_vertex(V v) { this->vertices[v]; } + + // TODO: Change with iterators + void add_vertices(const std::vector& vs) + { + for (const V& v : vs) + { + this->vertices[v]; + } + } + + void add_edge(V u, V v) + { + this->vertices[v]; + this->vertices[u].insert(v); + } + + std::vector topological_sort() const + { + GraphAdjacencyProvider adjacency_provider{this->vertices}; + std::unordered_map indegrees = count_indegrees(); + + std::vector sorted; + sorted.reserve(indegrees.size()); + + std::unordered_map exploration_status; + exploration_status.reserve(indegrees.size()); + + for (auto& pair : indegrees) + { + if (pair.second == 0) // Starting from vertices with indegree == 0. Not required. + { + V vertex = pair.first; + topological_sort_internal(vertex, adjacency_provider, exploration_status, sorted); + } + } + + return sorted; + } + + std::unordered_map count_indegrees() const + { + std::unordered_map indegrees; + + for (auto& pair : this->vertices) + { + indegrees[pair.first]; + for (V neighbour : pair.second) + { + ++indegrees[neighbour]; + } + } + + return indegrees; + } + + const std::unordered_map>& adjacency_list() const { return this->vertices; } + std::vector vertex_list() const + { + // why no &? it returns 0 + std::vector vertex_list; + for (const auto& vertex : this->vertices) + { + vertex_list.emplace_back(vertex.first); + } + return vertex_list; + } + + private: + std::unordered_map> vertices; + }; +} diff --git a/toolsrc/include/vcpkg/base/lazy.h b/toolsrc/include/vcpkg/base/lazy.h new file mode 100644 index 000000000..58c11c002 --- /dev/null +++ b/toolsrc/include/vcpkg/base/lazy.h @@ -0,0 +1,26 @@ +#pragma once + +namespace vcpkg +{ + template + class Lazy + { + public: + Lazy() : value(T()), initialized(false) {} + + template + T const& get_lazy(const F& f) const + { + if (!initialized) + { + value = f(); + initialized = true; + } + return value; + } + + private: + mutable T value; + mutable bool initialized; + }; +} diff --git a/toolsrc/include/vcpkg/base/lineinfo.h b/toolsrc/include/vcpkg/base/lineinfo.h new file mode 100644 index 000000000..62973462a --- /dev/null +++ b/toolsrc/include/vcpkg/base/lineinfo.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace vcpkg +{ + struct LineInfo + { + int line_number; + const char* file_name; + + constexpr LineInfo() : line_number(0), file_name(nullptr) {} + constexpr LineInfo(const int lineno, const char* filename) : line_number(lineno), file_name(filename) {} + + std::string to_string() const; + }; +} + +#define VCPKG_LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) diff --git a/toolsrc/include/vcpkg/base/machinetype.h b/toolsrc/include/vcpkg/base/machinetype.h new file mode 100644 index 000000000..b85cdbb0b --- /dev/null +++ b/toolsrc/include/vcpkg/base/machinetype.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +namespace vcpkg +{ + enum class MachineType : uint16_t + { + UNKNOWN = 0x0, // The contents of this field are assumed to be applicable to any machine type + AM33 = 0x1d3, // Matsushita AM33 + AMD64 = 0x8664, // x64 + ARM = 0x1c0, // ARM little endian + ARM64 = 0xaa64, // ARM64 little endian + ARMNT = 0x1c4, // ARM Thumb-2 little endian + EBC = 0xebc, // EFI byte code + I386 = 0x14c, // Intel 386 or later processors and compatible processors + IA64 = 0x200, // Intel Itanium processor family + M32R = 0x9041, // Mitsubishi M32R little endian + MIPS16 = 0x266, // MIPS16 + MIPSFPU = 0x366, // MIPS with FPU + MIPSFPU16 = 0x466, // MIPS16 with FPU + POWERPC = 0x1f0, // Power PC little endian + POWERPCFP = 0x1f1, // Power PC with floating point support + R4000 = 0x166, // MIPS little endian + RISCV32 = 0x5032, // RISC-V 32-bit address space + RISCV64 = 0x5064, // RISC-V 64-bit address space + RISCV128 = 0x5128, // RISC-V 128-bit address space + SH3 = 0x1a2, // Hitachi SH3 + SH3DSP = 0x1a3, // Hitachi SH3 DSP + SH4 = 0x1a6, // Hitachi SH4 + SH5 = 0x1a8, // Hitachi SH5 + THUMB = 0x1c2, // Thumb + WCEMIPSV2 = 0x169, // MIPS little-endian WCE v2 + }; + + MachineType to_machine_type(const uint16_t value); +} diff --git a/toolsrc/include/vcpkg/base/optional.h b/toolsrc/include/vcpkg/base/optional.h new file mode 100644 index 000000000..ff7a210c7 --- /dev/null +++ b/toolsrc/include/vcpkg/base/optional.h @@ -0,0 +1,99 @@ +#pragma once + +#include + +namespace vcpkg +{ + struct NullOpt + { + explicit constexpr NullOpt(int) {} + }; + + const static constexpr NullOpt nullopt{0}; + + template + class Optional + { + public: + constexpr Optional() : m_is_present(false), m_t() {} + + // Constructors are intentionally implicit + constexpr Optional(NullOpt) : m_is_present(false), m_t() {} + + Optional(const T& t) : m_is_present(true), m_t(t) {} + + Optional(T&& t) : m_is_present(true), m_t(std::move(t)) {} + + T&& value_or_exit(const LineInfo& line_info) && + { + this->exit_if_null(line_info); + return std::move(this->m_t); + } + + const T& value_or_exit(const LineInfo& line_info) const& + { + this->exit_if_null(line_info); + return this->m_t; + } + + constexpr explicit operator bool() const { return this->m_is_present; } + + constexpr bool has_value() const { return m_is_present; } + + template + T value_or(U&& default_value) const& + { + return bool(*this) ? this->m_t : static_cast(std::forward(default_value)); + } + + template + T value_or(U&& default_value) && + { + return bool(*this) ? std::move(this->m_t) : static_cast(std::forward(default_value)); + } + + const T* get() const { return bool(*this) ? &this->m_t : nullptr; } + + T* get() { return bool(*this) ? &this->m_t : nullptr; } + + private: + void exit_if_null(const LineInfo& line_info) const + { + Checks::check_exit(line_info, this->m_is_present, "Value was null"); + } + + bool m_is_present; + T m_t; + }; + + template + Optional> make_optional(U&& u) + { + return Optional>(std::forward(u)); + } + + template + bool operator==(const Optional& o, const T& t) + { + if (auto p = o.get()) return *p == t; + return false; + } + template + bool operator==(const T& t, const Optional& o) + { + if (auto p = o.get()) return t == *p; + return false; + } + template + bool operator!=(const Optional& o, const T& t) + { + if (auto p = o.get()) return *p != t; + return true; + } + template + bool operator!=(const T& t, const Optional& o) + { + if (auto p = o.get()) return t != *p; + return true; + } +} diff --git a/toolsrc/include/vcpkg/base/sortedvector.h b/toolsrc/include/vcpkg/base/sortedvector.h new file mode 100644 index 000000000..62808cc2f --- /dev/null +++ b/toolsrc/include/vcpkg/base/sortedvector.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +// Add more forwarding functions to the m_data std::vector as needed. +namespace vcpkg +{ + template + class SortedVector + { + public: + using size_type = typename std::vector::size_type; + using iterator = typename std::vector::const_iterator; + + SortedVector() : m_data() {} + + explicit SortedVector(std::vector v) : m_data(std::move(v)) + { + if (!std::is_sorted(m_data.begin(), m_data.end())) + { + std::sort(m_data.begin(), m_data.end()); + } + } + + template + SortedVector(std::vector v, Compare comp) : m_data(std::move(v)) + { + if (!std::is_sorted(m_data.cbegin(), m_data.cend(), comp)) + { + std::sort(m_data.begin(), m_data.end(), comp); + } + } + + iterator begin() const { return this->m_data.cbegin(); } + + iterator end() const { return this->m_data.cend(); } + + iterator cbegin() const { return this->m_data.cbegin(); } + + iterator cend() const { return this->m_data.cend(); } + + bool empty() const { return this->m_data.empty(); } + + size_type size() const { return this->m_data.size(); } + + private: + std::vector m_data; + }; +} diff --git a/toolsrc/include/vcpkg/base/span.h b/toolsrc/include/vcpkg/base/span.h new file mode 100644 index 000000000..6be546351 --- /dev/null +++ b/toolsrc/include/vcpkg/base/span.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include + +namespace vcpkg +{ + template + struct Span + { + public: + using element_type = T; + using pointer = T*; + using reference = T&; + using iterator = T*; + + constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {} + constexpr Span(std::nullptr_t) noexcept : Span() {} + constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {} + constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {} + constexpr Span(std::initializer_list l) noexcept : m_ptr(l.begin()), m_count(l.size()) {} + + template + constexpr Span(T (&arr)[N]) noexcept : Span(arr, N) + { + } + + template + constexpr Span(const std::array, N>& arr) noexcept : Span(arr.data(), arr.size()) + { + } + + Span(std::vector& v) noexcept : Span(v.data(), v.size()) {} + Span(const std::vector>& v) noexcept : Span(v.data(), v.size()) {} + + constexpr iterator begin() const { return m_ptr; } + constexpr iterator end() const { return m_ptr + m_count; } + + constexpr reference operator[](size_t i) const { return m_ptr[i]; } + constexpr size_t size() const { return m_count; } + + private: + pointer m_ptr; + size_t m_count; + }; + + template + Span make_span(std::vector& v) + { + return {v.data(), v.size()}; + } + + template + Span make_span(const std::vector& v) + { + return {v.data(), v.size()}; + } +} \ No newline at end of file diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h new file mode 100644 index 000000000..59823deb8 --- /dev/null +++ b/toolsrc/include/vcpkg/base/strings.h @@ -0,0 +1,114 @@ +#pragma once + +#include + +#include + +namespace vcpkg::Strings::details +{ + template + auto to_printf_arg(const T& t) -> decltype(t.to_string()) + { + return t.to_string(); + } + + inline const char* to_printf_arg(const std::string& s) { return s.c_str(); } + + inline const char* to_printf_arg(const char* s) { return s; } + + inline int to_printf_arg(const int s) { return s; } + + inline long long to_printf_arg(const long long s) { return s; } + + inline unsigned long to_printf_arg(const unsigned long s) { return s; } + + inline size_t to_printf_arg(const size_t s) { return s; } + + inline double to_printf_arg(const double s) { return s; } + + std::string format_internal(const char* fmtstr, ...); + + inline const wchar_t* to_wprintf_arg(const std::wstring& s) { return s.c_str(); } + + inline const wchar_t* to_wprintf_arg(const wchar_t* s) { return s; } + + std::wstring wformat_internal(const wchar_t* fmtstr, ...); +} + +namespace vcpkg::Strings +{ + static constexpr const char* EMPTY = ""; + static constexpr const wchar_t* WEMPTY = L""; + + template + std::string format(const char* fmtstr, const Args&... args) + { + using vcpkg::Strings::details::to_printf_arg; + return details::format_internal(fmtstr, to_printf_arg(to_printf_arg(args))...); + } + + template + std::wstring wformat(const wchar_t* fmtstr, const Args&... args) + { + using vcpkg::Strings::details::to_wprintf_arg; + return details::wformat_internal(fmtstr, to_wprintf_arg(to_wprintf_arg(args))...); + } + + std::wstring to_utf16(const CStringView s); + + std::string to_utf8(const CWStringView w); + + std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern); + + bool case_insensitive_ascii_contains(const std::string& s, const std::string& pattern); + + bool case_insensitive_ascii_compare(const CStringView left, const CStringView right); + + std::string ascii_to_lowercase(const std::string& input); + + bool case_insensitive_ascii_starts_with(const std::string& s, const std::string& pattern); + + template + std::basic_string join(const CharType* delimiter, const Container& v, Transformer transformer) + { + const auto begin = v.begin(); + const auto end = v.end(); + + if (begin == end) + { + return std::basic_string(); + } + + std::basic_string output; + output.append(transformer(*begin)); + for (auto it = std::next(begin); it != end; ++it) + { + output.append(delimiter); + output.append(transformer(*it)); + } + + return output; + } + template + std::basic_string join(const CharType* delimiter, const Container& v) + { + using Element = decltype(*v.begin()); + return join(delimiter, v, [](const Element& x) -> const Element& { return x; }); + } + + void trim(std::string* s); + + std::string trimmed(const std::string& s); + + void trim_all_and_remove_whitespace_strings(std::vector* strings); + + std::vector split(const std::string& s, const std::string& delimiter); + + template + std::string serialize(const T& t) + { + std::string ret; + serialize(t, ret); + return ret; + } +} diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h new file mode 100644 index 000000000..a2e8f3f45 --- /dev/null +++ b/toolsrc/include/vcpkg/base/system.h @@ -0,0 +1,108 @@ +#pragma once + +#include +#include +#include + +#include + +namespace vcpkg::System +{ + tm get_current_date_time(); + + fs::path get_exe_path_of_current_process(); + + struct ExitCodeAndOutput + { + int exit_code; + std::string output; + }; + + int cmd_execute_clean(const CWStringView cmd_line); + + int cmd_execute(const CWStringView cmd_line); + + ExitCodeAndOutput cmd_execute_and_capture_output(const CWStringView cmd_line); + + std::wstring create_powershell_script_cmd(const fs::path& script_path, const CWStringView args = Strings::WEMPTY); + + enum class Color + { + success = 10, + error = 12, + warning = 14, + }; + + void println(); + void print(const CStringView message); + void println(const CStringView message); + void print(const Color c, const CStringView message); + void println(const Color c, const CStringView message); + + template + void print(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) + { + return System::print(Strings::format(messageTemplate, messageArg1, messageArgs...)); + } + + template + void print(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) + { + return System::print(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); + } + + template + void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) + { + return System::println(Strings::format(messageTemplate, messageArg1, messageArgs...)); + } + + template + void println(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) + { + return System::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); + } + + Optional get_environment_variable(const CWStringView varname) noexcept; + + Optional get_registry_string(HKEY base, const CWStringView subkey, const CWStringView valuename); + + enum class CPUArchitecture + { + X86, + X64, + ARM, + ARM64, + }; + + Optional to_cpu_architecture(CStringView arch); + + CPUArchitecture get_host_processor(); + + std::vector get_supported_host_architectures(); + + const fs::path& get_program_files_32_bit(); + + const fs::path& get_program_files_platform_bitness(); +} + +namespace vcpkg::Debug +{ + void println(const CStringView message); + void println(const System::Color c, const CStringView message); + + template + void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) + { + return Debug::println(Strings::format(messageTemplate, messageArg1, messageArgs...)); + } + + template + void println(const System::Color c, + const char* messageTemplate, + const Arg1& messageArg1, + const Args&... messageArgs) + { + return Debug::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); + } +} diff --git a/toolsrc/include/vcpkg/base/util.h b/toolsrc/include/vcpkg/base/util.h new file mode 100644 index 000000000..3834580b6 --- /dev/null +++ b/toolsrc/include/vcpkg/base/util.h @@ -0,0 +1,156 @@ +#pragma once + +#include +#include +#include +#include + +namespace vcpkg::Util +{ + template + using FmapOut = decltype(std::declval()(*begin(std::declval()))); + + template> + std::vector fmap(Cont&& xs, Func&& f) + { + std::vector ret; + ret.reserve(xs.size()); + + for (auto&& x : xs) + ret.push_back(f(x)); + + return ret; + } + + template + using FmapFlattenOut = std::decay_t()(*begin(std::declval()))))>; + + template> + std::vector fmap_flatten(Cont&& xs, Func&& f) + { + std::vector ret; + + for (auto&& x : xs) + for (auto&& y : f(x)) + ret.push_back(std::move(y)); + + return ret; + } + + template + void stable_keep_if(Container& cont, Pred pred) + { + cont.erase(std::stable_partition(cont.begin(), cont.end(), pred), cont.end()); + } + + template + void unstable_keep_if(Container& cont, Pred pred) + { + cont.erase(std::partition(cont.begin(), cont.end(), pred), cont.end()); + } + + template + void erase_remove_if(Container& cont, Pred pred) + { + cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); + } + + template + auto find(Container&& cont, V&& v) + { + using std::begin; + using std::end; + return std::find(begin(cont), end(cont), v); + } + + template + auto find_if(Container&& cont, Pred pred) + { + using std::begin; + using std::end; + return std::find_if(begin(cont), end(cont), pred); + } + + template + using ElementT = std::remove_reference_t()))>; + + template> + std::vector element_pointers(Container&& cont) + { + return fmap(cont, [](auto&& x) { return &x; }); + } + + template + auto find_if_not(Container&& cont, Pred pred) + { + using std::begin; + using std::end; + return std::find_if_not(begin(cont), end(cont), pred); + } + + template + void group_by(const Container& cont, _Inout_ std::map>* output, Func&& f) + { + for (const V& element : cont) + { + K key = f(element); + (*output)[key].push_back(&element); + } + } + + template())->first)>> + std::vector extract_keys(AssocContainer&& input_map) + { + return fmap(input_map, [](auto&& p) { return p.first; }); + } + + struct MoveOnlyBase + { + MoveOnlyBase() = default; + MoveOnlyBase(const MoveOnlyBase&) = delete; + MoveOnlyBase(MoveOnlyBase&&) = default; + + MoveOnlyBase& operator=(const MoveOnlyBase&) = delete; + MoveOnlyBase& operator=(MoveOnlyBase&&) = default; + }; + + struct ResourceBase + { + ResourceBase() = default; + ResourceBase(const ResourceBase&) = delete; + ResourceBase(ResourceBase&&) = delete; + + ResourceBase& operator=(const ResourceBase&) = delete; + ResourceBase& operator=(ResourceBase&&) = delete; + }; + + template + struct LockGuardPtr; + + template + struct LockGuarded + { + friend struct LockGuardPtr; + + LockGuardPtr lock() { return *this; } + + private: + std::mutex m_mutex; + T m_t; + }; + + template + struct LockGuardPtr + { + T& operator*() { return m_ptr; } + T* operator->() { return &m_ptr; } + + T* get() { return &m_ptr; } + + LockGuardPtr(LockGuarded& sync) : m_lock(sync.m_mutex), m_ptr(sync.m_t) {} + + private: + std::unique_lock m_lock; + T& m_ptr; + }; +} \ No newline at end of file diff --git a/toolsrc/include/vcpkg/binaryparagraph.h b/toolsrc/include/vcpkg/binaryparagraph.h new file mode 100644 index 000000000..7eb50a6d7 --- /dev/null +++ b/toolsrc/include/vcpkg/binaryparagraph.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg +{ + /// + /// Built package metadata + /// + struct BinaryParagraph + { + BinaryParagraph(); + explicit BinaryParagraph(std::unordered_map fields); + BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet); + BinaryParagraph(const SourceParagraph& spgh, const FeatureParagraph& fpgh, const Triplet& triplet); + + std::string displayname() const; + + std::string fullstem() const; + + std::string dir() const; + + PackageSpec spec; + std::string version; + std::string description; + std::string maintainer; + std::string feature; + std::vector default_features; + std::vector depends; + }; + + struct BinaryControlFile + { + BinaryParagraph core_paragraph; + std::vector features; + }; + + void serialize(const BinaryParagraph& pgh, std::string& out_str); +} \ No newline at end of file diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h new file mode 100644 index 000000000..f146e9951 --- /dev/null +++ b/toolsrc/include/vcpkg/build.h @@ -0,0 +1,205 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace vcpkg::Build +{ + namespace Command + { + void perform_and_exit(const FullPackageSpec& full_spec, + const fs::path& port_dir, + const std::unordered_set& options, + const VcpkgPaths& paths); + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + } + + enum class UseHeadVersion + { + NO = 0, + YES + }; + + inline UseHeadVersion to_use_head_version(const bool value) + { + return value ? UseHeadVersion::YES : UseHeadVersion::NO; + } + + inline bool to_bool(const UseHeadVersion value) { return value == UseHeadVersion::YES; } + + enum class AllowDownloads + { + NO = 0, + YES + }; + + inline AllowDownloads to_allow_downloads(const bool value) + { + return value ? AllowDownloads::YES : AllowDownloads::NO; + } + + inline bool to_bool(const AllowDownloads value) { return value == AllowDownloads::YES; } + + struct BuildPackageOptions + { + UseHeadVersion use_head_version; + AllowDownloads allow_downloads; + }; + + enum class BuildResult + { + NULLVALUE = 0, + SUCCEEDED, + BUILD_FAILED, + POST_BUILD_CHECKS_FAILED, + FILE_CONFLICTS, + CASCADED_DUE_TO_MISSING_DEPENDENCIES + }; + + static constexpr std::array BUILD_RESULT_VALUES = { + BuildResult::SUCCEEDED, + BuildResult::BUILD_FAILED, + BuildResult::POST_BUILD_CHECKS_FAILED, + BuildResult::FILE_CONFLICTS, + BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES}; + + const std::string& to_string(const BuildResult build_result); + std::string create_error_message(const BuildResult build_result, const PackageSpec& spec); + std::string create_user_troubleshooting_message(const PackageSpec& spec); + + /// + /// Settings from the triplet file which impact the build environment and post-build checks + /// + struct PreBuildInfo + { + /// + /// Runs the triplet file in a "capture" mode to create a PreBuildInfo + /// + static PreBuildInfo from_triplet_file(const VcpkgPaths& paths, const Triplet& triplet); + + std::string target_architecture; + std::string cmake_system_name; + std::string cmake_system_version; + Optional platform_toolset; + Optional visual_studio_path; + }; + + std::wstring make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); + + struct ExtendedBuildResult + { + BuildResult code; + std::vector unmet_dependencies; + }; + + struct BuildPackageConfig + { + BuildPackageConfig(const SourceParagraph& src, + const Triplet& triplet, + fs::path&& port_dir, + const BuildPackageOptions& build_package_options) + : src(src) + , scf(nullptr) + , triplet(triplet) + , port_dir(std::move(port_dir)) + , build_package_options(build_package_options) + , feature_list(nullptr) + { + } + + BuildPackageConfig(const SourceControlFile& src, + const Triplet& triplet, + fs::path&& port_dir, + const BuildPackageOptions& build_package_options, + const std::unordered_set& feature_list) + : src(*src.core_paragraph) + , scf(&src) + , triplet(triplet) + , port_dir(std::move(port_dir)) + , build_package_options(build_package_options) + , feature_list(&feature_list) + { + } + + const SourceParagraph& src; + const SourceControlFile* scf; + const Triplet& triplet; + fs::path port_dir; + const BuildPackageOptions& build_package_options; + const std::unordered_set* feature_list; + }; + + ExtendedBuildResult build_package(const VcpkgPaths& paths, + const BuildPackageConfig& config, + const StatusParagraphs& status_db); + + enum class BuildPolicy + { + EMPTY_PACKAGE, + DLLS_WITHOUT_LIBS, + ONLY_RELEASE_CRT, + EMPTY_INCLUDE_FOLDER, + ALLOW_OBSOLETE_MSVCRT, + // Must be last + COUNT, + }; + + constexpr std::array G_ALL_POLICIES = { + BuildPolicy::EMPTY_PACKAGE, + BuildPolicy::DLLS_WITHOUT_LIBS, + BuildPolicy::ONLY_RELEASE_CRT, + BuildPolicy::EMPTY_INCLUDE_FOLDER, + BuildPolicy::ALLOW_OBSOLETE_MSVCRT, + }; + + const std::string& to_string(BuildPolicy policy); + CStringView to_cmake_variable(BuildPolicy policy); + + struct BuildPolicies + { + BuildPolicies() = default; + BuildPolicies(std::map&& map) : m_policies(std::move(map)) {} + + bool is_enabled(BuildPolicy policy) const + { + const auto it = m_policies.find(policy); + if (it != m_policies.cend()) return it->second; + return false; + } + + private: + std::map m_policies; + }; + + enum class LinkageType : char + { + DYNAMIC, + STATIC, + }; + + Optional to_linkage_type(const std::string& str); + + struct BuildInfo + { + LinkageType crt_linkage; + LinkageType library_linkage; + + Optional version; + + BuildPolicies policies; + }; + + BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath); +} diff --git a/toolsrc/include/vcpkg/commands.h b/toolsrc/include/vcpkg/commands.h new file mode 100644 index 000000000..64b2118ce --- /dev/null +++ b/toolsrc/include/vcpkg/commands.h @@ -0,0 +1,134 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace vcpkg::Commands +{ + using CommandTypeA = void (*)(const VcpkgCmdArguments& args, + const VcpkgPaths& paths, + const Triplet& default_triplet); + using CommandTypeB = void (*)(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + using CommandTypeC = void (*)(const VcpkgCmdArguments& args); + + namespace BuildExternal + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + } + + namespace CI + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + } + + namespace Env + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + } + + namespace Create + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Edit + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace DependInfo + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Search + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace List + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Owns + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Cache + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Import + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Integrate + { + extern const char* const INTEGRATE_COMMAND_HELPSTRING; + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace PortsDiff + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Autocomplete + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + + namespace Version + { + const std::string& version(); + void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths); + void perform_and_exit(const VcpkgCmdArguments& args); + } + + namespace Contact + { + const std::string& email(); + void perform_and_exit(const VcpkgCmdArguments& args); + } + + namespace Hash + { + void perform_and_exit(const VcpkgCmdArguments& args); + } + + template + struct PackageNameAndFunction + { + std::string name; + T function; + }; + + Span> get_available_commands_type_a(); + Span> get_available_commands_type_b(); + Span> get_available_commands_type_c(); + + template + T find(const std::string& command_name, const std::vector> available_commands) + { + for (const PackageNameAndFunction& cmd : available_commands) + { + if (cmd.name == command_name) + { + return cmd.function; + } + } + + // not found + return nullptr; + } +} diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h new file mode 100644 index 000000000..2301dbc36 --- /dev/null +++ b/toolsrc/include/vcpkg/dependencies.h @@ -0,0 +1,149 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +namespace vcpkg::Dependencies +{ + enum class RequestType + { + UNKNOWN, + USER_REQUESTED, + AUTO_SELECTED + }; + + std::string to_output_string(RequestType request_type, const CStringView s); + + struct AnyParagraph + { + std::vector dependencies(const Triplet& triplet) const; + + Optional status_paragraph; + Optional binary_control_file; + Optional source_paragraph; + Optional source_control_file; + }; +} + +namespace vcpkg::Dependencies +{ + enum class InstallPlanType + { + UNKNOWN, + BUILD_AND_INSTALL, + INSTALL, + ALREADY_INSTALLED + }; + + struct InstallPlanAction : Util::MoveOnlyBase + { + static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right); + + InstallPlanAction(); + + InstallPlanAction(const PackageSpec& spec, + const std::unordered_set& features, + const RequestType& request_type); + InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type); + InstallPlanAction(const PackageSpec& spec, + const SourceControlFile& any_paragraph, + const std::unordered_set& features, + const RequestType& request_type); + + std::string displayname() const; + + PackageSpec spec; + AnyParagraph any_paragraph; + InstallPlanType plan_type; + RequestType request_type; + std::unordered_set feature_list; + }; + + enum class RemovePlanType + { + UNKNOWN, + NOT_INSTALLED, + REMOVE + }; + + struct RemovePlanAction : Util::MoveOnlyBase + { + static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right); + + RemovePlanAction(); + RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type); + + PackageSpec spec; + RemovePlanType plan_type; + RequestType request_type; + }; + + struct AnyAction + { + AnyAction(InstallPlanAction&& iplan) : install_plan(std::move(iplan)) {} + AnyAction(RemovePlanAction&& rplan) : remove_plan(std::move(rplan)) {} + + Optional install_plan; + Optional remove_plan; + + const PackageSpec& spec() const; + }; + + enum class ExportPlanType + { + UNKNOWN, + PORT_AVAILABLE_BUT_NOT_BUILT, + ALREADY_BUILT + }; + + struct ExportPlanAction : Util::MoveOnlyBase + { + static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right); + + ExportPlanAction(); + ExportPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type); + + PackageSpec spec; + AnyParagraph any_paragraph; + ExportPlanType plan_type; + RequestType request_type; + }; + + __interface PortFileProvider { virtual const SourceControlFile& get_control_file(const std::string& spec) const; }; + + struct MapPortFile : Util::ResourceBase, PortFileProvider + { + const std::unordered_map& ports; + explicit MapPortFile(const std::unordered_map& map); + const SourceControlFile& get_control_file(const std::string& spec) const override; + }; + + struct PathsPortFile : Util::ResourceBase, PortFileProvider + { + const VcpkgPaths& ports; + mutable std::unordered_map cache; + explicit PathsPortFile(const VcpkgPaths& paths); + const SourceControlFile& get_control_file(const std::string& spec) const override; + }; + + std::vector create_install_plan(const PortFileProvider& port_file_provider, + const std::vector& specs, + const StatusParagraphs& status_db); + + std::vector create_remove_plan(const std::vector& specs, + const StatusParagraphs& status_db); + + std::vector create_export_plan(const VcpkgPaths& paths, + const std::vector& specs, + const StatusParagraphs& status_db); + + std::vector create_feature_install_plan(const std::unordered_map& map, + const std::vector& specs, + const StatusParagraphs& status_db); +} diff --git a/toolsrc/include/vcpkg/export.h b/toolsrc/include/vcpkg/export.h new file mode 100644 index 000000000..f3285e187 --- /dev/null +++ b/toolsrc/include/vcpkg/export.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace vcpkg::Export +{ + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + + void export_integration_files(const fs::path& raw_exported_dir_path, const VcpkgPaths& paths); +} diff --git a/toolsrc/include/vcpkg/export.ifw.h b/toolsrc/include/vcpkg/export.ifw.h new file mode 100644 index 000000000..d28a4436d --- /dev/null +++ b/toolsrc/include/vcpkg/export.ifw.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include + +#include +#include + +namespace vcpkg::Export::IFW +{ + struct Options + { + Optional maybe_repository_url; + Optional maybe_packages_dir_path; + Optional maybe_repository_dir_path; + Optional maybe_config_file_path; + Optional maybe_installer_file_path; + }; + + void do_export(const std::vector& export_plan, + const std::string& export_id, + const Options& ifw_options, + const VcpkgPaths& paths); +} diff --git a/toolsrc/include/vcpkg/globalstate.h b/toolsrc/include/vcpkg/globalstate.h new file mode 100644 index 000000000..7cea361cf --- /dev/null +++ b/toolsrc/include/vcpkg/globalstate.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg +{ + struct GlobalState + { + static Util::LockGuarded timer; + static std::atomic debugging; + static std::atomic feature_packages; + + static std::atomic g_init_console_cp; + static std::atomic g_init_console_output_cp; + }; +} \ No newline at end of file diff --git a/toolsrc/include/vcpkg/help.h b/toolsrc/include/vcpkg/help.h new file mode 100644 index 000000000..39ad6912d --- /dev/null +++ b/toolsrc/include/vcpkg/help.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#include + +namespace vcpkg::Help +{ + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + + void help_topic_valid_triplet(const VcpkgPaths& paths); + + void print_usage(); + + void print_example(const std::string& command_and_arguments); + + std::string create_example_string(const std::string& command_and_arguments); +} diff --git a/toolsrc/include/vcpkg/input.h b/toolsrc/include/vcpkg/input.h new file mode 100644 index 000000000..621139427 --- /dev/null +++ b/toolsrc/include/vcpkg/input.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace vcpkg::Input +{ + PackageSpec check_and_get_package_spec(const std::string& package_spec_as_string, + const Triplet& default_triplet, + CStringView example_text); + FullPackageSpec check_and_get_full_package_spec(const std::string& full_package_spec_as_string, + const Triplet& default_triplet, + CStringView example_text); + + void check_triplet(const Triplet& t, const VcpkgPaths& paths); +} diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h new file mode 100644 index 000000000..02600b7f5 --- /dev/null +++ b/toolsrc/include/vcpkg/install.h @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include +#include + +#include + +namespace vcpkg::Install +{ + enum class KeepGoing + { + NO = 0, + YES + }; + + inline KeepGoing to_keep_going(const bool value) { return value ? KeepGoing::YES : KeepGoing::NO; } + + enum class PrintSummary + { + NO = 0, + YES + }; + + inline PrintSummary to_print_summary(const bool value) { return value ? PrintSummary::YES : PrintSummary::NO; } + + struct InstallDir + { + static InstallDir from_destination_root(const fs::path& destination_root, + const std::string& destination_subdirectory, + const fs::path& listfile); + + private: + fs::path m_destination; + std::string m_destination_subdirectory; + fs::path m_listfile; + + public: + const fs::path& destination() const; + const std::string& destination_subdirectory() const; + const fs::path& listfile() const; + }; + + Build::BuildResult perform_install_plan_action(const VcpkgPaths& paths, + const Dependencies::InstallPlanAction& action, + const Build::BuildPackageOptions& install_plan_options, + StatusParagraphs& status_db); + + enum class InstallResult + { + FILE_CONFLICTS, + SUCCESS, + }; + + void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& dirs); + InstallResult install_package(const VcpkgPaths& paths, + const BinaryControlFile& binary_paragraph, + StatusParagraphs* status_db); + + void perform_and_exit_ex(const std::vector& action_plan, + const Build::BuildPackageOptions& install_plan_options, + const KeepGoing keep_going, + const PrintSummary print_summary, + const VcpkgPaths& paths, + StatusParagraphs& status_db); + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); +} diff --git a/toolsrc/include/vcpkg/metrics.h b/toolsrc/include/vcpkg/metrics.h new file mode 100644 index 000000000..41be5002d --- /dev/null +++ b/toolsrc/include/vcpkg/metrics.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +namespace vcpkg::Metrics +{ + struct Metrics : Util::ResourceBase + { + void set_send_metrics(bool should_send_metrics); + void set_print_metrics(bool should_print_metrics); + void set_user_information(const std::string& user_id, const std::string& first_use_time); + void init_user_information(std::string& user_id, std::string& first_use_time); + + void track_metric(const std::string& name, double value); + void track_property(const std::string& name, const std::string& value); + void track_property(const std::string& name, const std::wstring& value); + + void upload(const std::string& payload); + void flush(); + }; + + extern Util::LockGuarded g_metrics; + + std::wstring get_SQM_user(); + bool get_compiled_metrics_enabled(); +} diff --git a/toolsrc/include/vcpkg/packagespec.h b/toolsrc/include/vcpkg/packagespec.h new file mode 100644 index 000000000..ee34f14a3 --- /dev/null +++ b/toolsrc/include/vcpkg/packagespec.h @@ -0,0 +1,95 @@ +#pragma once + +#include +#include +#include + +namespace vcpkg +{ + struct ParsedSpecifier + { + std::string name; + std::vector features; + std::string triplet; + + static ExpectedT from_string(const std::string& input); + }; + + struct PackageSpec + { + static ExpectedT from_name_and_triplet(const std::string& name, + const Triplet& triplet); + + const std::string& name() const; + + const Triplet& triplet() const; + + std::string dir() const; + + std::string to_string() const; + + private: + std::string m_name; + Triplet m_triplet; + }; + + struct FeatureSpec + { + FeatureSpec(const PackageSpec& spec, const std::string& feature) : m_spec(spec), m_feature(feature) {} + + const std::string& name() const { return m_spec.name(); } + const std::string& feature() const { return m_feature; } + const Triplet& triplet() const { return m_spec.triplet(); } + + const PackageSpec& spec() const { return m_spec; } + + std::string to_string() const; + + static std::vector from_strings_and_triplet(const std::vector& depends, + const Triplet& t); + + private: + PackageSpec m_spec; + std::string m_feature; + }; + + struct FullPackageSpec + { + PackageSpec package_spec; + std::vector features; + + static std::vector to_feature_specs(const std::vector& specs); + + static ExpectedT from_string(const std::string& spec_as_string, + const Triplet& default_triplet); + }; + + struct Features + { + std::string name; + std::vector features; + + static ExpectedT from_string(const std::string& input); + }; + + bool operator==(const PackageSpec& left, const PackageSpec& right); + bool operator!=(const PackageSpec& left, const PackageSpec& right); +} + +template<> +struct std::hash +{ + size_t operator()(const vcpkg::PackageSpec& value) const + { + size_t hash = 17; + hash = hash * 31 + std::hash()(value.name()); + hash = hash * 31 + std::hash()(value.triplet()); + return hash; + } +}; + +template<> +struct std::equal_to +{ + bool operator()(const vcpkg::PackageSpec& left, const vcpkg::PackageSpec& right) const { return left == right; } +}; diff --git a/toolsrc/include/vcpkg/packagespecparseresult.h b/toolsrc/include/vcpkg/packagespecparseresult.h new file mode 100644 index 000000000..8a56574fd --- /dev/null +++ b/toolsrc/include/vcpkg/packagespecparseresult.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +namespace vcpkg +{ + enum class PackageSpecParseResult + { + SUCCESS = 0, + TOO_MANY_COLONS, + INVALID_CHARACTERS + }; + + CStringView to_string(PackageSpecParseResult ev) noexcept; + + template<> + struct ErrorHolder + { + ErrorHolder() : m_err(PackageSpecParseResult::SUCCESS) {} + ErrorHolder(PackageSpecParseResult err) : m_err(err) {} + + constexpr bool has_error() const { return m_err != PackageSpecParseResult::SUCCESS; } + + const PackageSpecParseResult& error() const { return m_err; } + PackageSpecParseResult& error() { return m_err; } + + CStringView to_string() const { return vcpkg::to_string(m_err); } + + private: + PackageSpecParseResult m_err; + }; +} diff --git a/toolsrc/include/vcpkg/paragraphparseresult.h b/toolsrc/include/vcpkg/paragraphparseresult.h new file mode 100644 index 000000000..abdd9eecd --- /dev/null +++ b/toolsrc/include/vcpkg/paragraphparseresult.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +namespace vcpkg +{ + enum class ParagraphParseResult + { + SUCCESS = 0, + EXPECTED_ONE_PARAGRAPH + }; + + struct ParagraphParseResultCategoryImpl final : std::error_category + { + virtual const char* name() const noexcept override; + + virtual std::string message(int ev) const noexcept override; + }; + + const std::error_category& paragraph_parse_result_category(); + + std::error_code make_error_code(ParagraphParseResult e); + + ParagraphParseResult to_paragraph_parse_result(int i); + + ParagraphParseResult to_paragraph_parse_result(std::error_code ec); +} + +// Enable implicit conversion to std::error_code +template<> +struct std::is_error_code_enum : ::std::true_type +{ +}; diff --git a/toolsrc/include/vcpkg/paragraphs.h b/toolsrc/include/vcpkg/paragraphs.h new file mode 100644 index 000000000..c8dbea646 --- /dev/null +++ b/toolsrc/include/vcpkg/paragraphs.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include + +#include + +#include + +namespace vcpkg::Paragraphs +{ + using RawParagraph = Parse::RawParagraph; + + Expected get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path); + Expected> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path); + Expected parse_single_paragraph(const std::string& str); + Expected> parse_paragraphs(const std::string& str); + + Parse::ParseExpected try_load_port(const Files::Filesystem& fs, const fs::path& control_path); + + Expected try_load_cached_control_package(const VcpkgPaths& paths, const PackageSpec& spec); + + struct LoadResults + { + std::vector> paragraphs; + std::vector> errors; + }; + + LoadResults try_load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir); + + std::vector> load_all_ports(const Files::Filesystem& fs, + const fs::path& ports_dir); + + std::map load_all_port_names_and_versions(const Files::Filesystem& fs, + const fs::path& ports_dir); +} diff --git a/toolsrc/include/vcpkg/parse.h b/toolsrc/include/vcpkg/parse.h new file mode 100644 index 000000000..4b33e302e --- /dev/null +++ b/toolsrc/include/vcpkg/parse.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include +#include + +namespace vcpkg::Parse +{ + struct ParseControlErrorInfo + { + std::string name; + std::vector missing_fields; + std::vector extra_fields; + std::error_code error; + }; + + template + using ParseExpected = ExpectedT, std::unique_ptr>; + + using RawParagraph = std::unordered_map; + + struct ParagraphParser + { + ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {} + + void required_field(const std::string& fieldname, std::string& out); + std::string optional_field(const std::string& fieldname) const; + std::unique_ptr error_info(const std::string& name) const; + + private: + RawParagraph&& fields; + std::vector missing_fields; + }; + + std::vector parse_comma_list(const std::string& str); +} diff --git a/toolsrc/include/vcpkg/postbuildlint.buildtype.h b/toolsrc/include/vcpkg/postbuildlint.buildtype.h new file mode 100644 index 000000000..ff651fd7a --- /dev/null +++ b/toolsrc/include/vcpkg/postbuildlint.buildtype.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include + +#include +#include + +namespace vcpkg::PostBuildLint +{ + enum class ConfigurationType + { + DEBUG, + RELEASE, + }; + + struct BuildType + { + enum class BackingEnum + { + DEBUG_STATIC = 1, + DEBUG_DYNAMIC, + RELEASE_STATIC, + RELEASE_DYNAMIC + }; + + static BuildType value_of(const ConfigurationType& config, const Build::LinkageType& linkage); + + BuildType() = delete; + + constexpr BuildType(const BackingEnum backing_enum, + const ConfigurationType config, + const Build::LinkageType linkage) + : backing_enum(backing_enum), m_config(config), m_linkage(linkage) + { + } + + constexpr operator BackingEnum() const { return backing_enum; } + + const ConfigurationType& config() const; + const Build::LinkageType& linkage() const; + const std::regex& crt_regex() const; + const std::string& to_string() const; + + private: + BackingEnum backing_enum; + ConfigurationType m_config; + Build::LinkageType m_linkage; + }; + + namespace BuildTypeC + { + using Build::LinkageType; + using BE = BuildType::BackingEnum; + + static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::BuildType"; + + static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageType::STATIC}; + static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageType::DYNAMIC}; + static constexpr BuildType RELEASE_STATIC = { + BE::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageType::STATIC}; + static constexpr BuildType RELEASE_DYNAMIC = { + BE::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageType::DYNAMIC}; + + static constexpr std::array VALUES = { + DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC}; + } +} diff --git a/toolsrc/include/vcpkg/postbuildlint.h b/toolsrc/include/vcpkg/postbuildlint.h new file mode 100644 index 000000000..5dcfeb8df --- /dev/null +++ b/toolsrc/include/vcpkg/postbuildlint.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +namespace vcpkg::PostBuildLint +{ + size_t perform_all_checks(const PackageSpec& spec, + const VcpkgPaths& paths, + const Build::PreBuildInfo& pre_build_info, + const Build::BuildInfo& build_info); +} diff --git a/toolsrc/include/vcpkg/remove.h b/toolsrc/include/vcpkg/remove.h new file mode 100644 index 000000000..f4d381ca3 --- /dev/null +++ b/toolsrc/include/vcpkg/remove.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +namespace vcpkg::Remove +{ + enum class Purge + { + NO = 0, + YES + }; + + inline Purge to_purge(const bool value) { return value ? Purge::YES : Purge::NO; } + + void perform_remove_plan_action(const VcpkgPaths& paths, + const Dependencies::RemovePlanAction& action, + const Purge purge, + StatusParagraphs& status_db); + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); + void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db); +} diff --git a/toolsrc/include/vcpkg/sourceparagraph.h b/toolsrc/include/vcpkg/sourceparagraph.h new file mode 100644 index 000000000..0a02e4cda --- /dev/null +++ b/toolsrc/include/vcpkg/sourceparagraph.h @@ -0,0 +1,97 @@ +#pragma once + +#include +#include + +#include +#include +#include + +#include +#include + +namespace vcpkg +{ + struct Dependency + { + Features depend; + std::string qualifier; + + std::string name() const; + static Dependency parse_dependency(std::string name, std::string qualifier); + }; + + std::vector filter_dependencies(const std::vector& deps, const Triplet& t); + std::vector filter_dependencies_to_specs(const std::vector& deps, const Triplet& t); + + // zlib[uwp] becomes Dependency{"zlib", "uwp"} + std::vector expand_qualified_dependencies(const std::vector& depends); + + std::string to_string(const Dependency& dep); + + struct FeatureParagraph + { + std::string name; + std::string description; + std::vector depends; + }; + + /// + /// Port metadata (CONTROL file) + /// + struct SourceParagraph + { + std::string name; + std::string version; + std::string description; + std::string maintainer; + std::vector supports; + std::vector depends; + std::vector default_features; + }; + struct SourceControlFile + { + static Parse::ParseExpected parse_control_file( + std::vector&& control_paragraphs); + + std::unique_ptr core_paragraph; + std::vector> feature_paragraphs; + }; + + void print_error_message(Span> error_info_list); + inline void print_error_message(const std::unique_ptr& error_info_list) + { + return print_error_message({&error_info_list, 1}); + } + + struct Supports + { + static ExpectedT> parse(const std::vector& strs); + + using Architecture = System::CPUArchitecture; + + enum class Platform + { + WINDOWS, + UWP, + }; + enum class Linkage + { + DYNAMIC, + STATIC, + }; + enum class ToolsetVersion + { + V140, + V141, + }; + + bool is_supported(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools); + + private: + std::vector architectures; + std::vector platforms; + std::vector crt_linkages; + std::vector toolsets; + }; +} diff --git a/toolsrc/include/vcpkg/statusparagraph.h b/toolsrc/include/vcpkg/statusparagraph.h new file mode 100644 index 000000000..ca84b1bb7 --- /dev/null +++ b/toolsrc/include/vcpkg/statusparagraph.h @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include + +namespace vcpkg +{ + enum class InstallState + { + ERROR_STATE, + NOT_INSTALLED, + HALF_INSTALLED, + INSTALLED, + }; + + enum class Want + { + ERROR_STATE, + UNKNOWN, + INSTALL, + HOLD, + DEINSTALL, + PURGE + }; + + /// + /// Installed package metadata + /// + struct StatusParagraph + { + StatusParagraph(); + explicit StatusParagraph(std::unordered_map&& fields); + + BinaryParagraph package; + Want want; + InstallState state; + }; + + void serialize(const StatusParagraph& pgh, std::string& out_str); + + std::string to_string(InstallState f); + + std::string to_string(Want f); +} diff --git a/toolsrc/include/vcpkg/statusparagraphs.h b/toolsrc/include/vcpkg/statusparagraphs.h new file mode 100644 index 000000000..c2f3b7b8e --- /dev/null +++ b/toolsrc/include/vcpkg/statusparagraphs.h @@ -0,0 +1,47 @@ +#pragma once +#include + +#include +#include + +namespace vcpkg +{ + struct StatusParagraphs + { + StatusParagraphs(); + explicit StatusParagraphs(std::vector>&& ps); + + using container = std::vector>; + using iterator = container::reverse_iterator; + using const_iterator = container::const_reverse_iterator; + + const_iterator find(const PackageSpec& spec) const { return find(spec.name(), spec.triplet()); } + const_iterator find(const std::string& name, const Triplet& triplet) const; + iterator find(const std::string& name, const Triplet& triplet); + std::vector*> find_all(const std::string& name, const Triplet& triplet); + iterator find(const std::string& name, const Triplet& triplet, const std::string& feature); + + const_iterator find_installed(const PackageSpec& spec) const + { + return find_installed(spec.name(), spec.triplet()); + } + const_iterator find_installed(const std::string& name, const Triplet& triplet) const; + + iterator insert(std::unique_ptr); + + friend void serialize(const StatusParagraphs& pgh, std::string& out_str); + + iterator end() { return paragraphs.rend(); } + + const_iterator end() const { return paragraphs.rend(); } + + iterator begin() { return paragraphs.rbegin(); } + + const_iterator begin() const { return paragraphs.rbegin(); } + + private: + std::vector> paragraphs; + }; + + void serialize(const StatusParagraphs& pgh, std::string& out_str); +} diff --git a/toolsrc/include/vcpkg/triplet.h b/toolsrc/include/vcpkg/triplet.h new file mode 100644 index 000000000..46a52f8e6 --- /dev/null +++ b/toolsrc/include/vcpkg/triplet.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +namespace vcpkg +{ + struct TripletInstance; + + struct Triplet + { + public: + constexpr Triplet() : m_instance(&DEFAULT_INSTANCE) {} + + static Triplet from_canonical_name(const std::string& triplet_as_string); + + 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; + + const std::string& canonical_name() const; + const std::string& to_string() const; + size_t hash_code() const; + + bool operator==(const Triplet& other) const; + + private: + static const TripletInstance DEFAULT_INSTANCE; + + constexpr Triplet(const TripletInstance* ptr) : m_instance(ptr) {} + + const TripletInstance* m_instance; + }; + + bool operator!=(const Triplet& left, const Triplet& right); +} + +template<> +struct std::hash +{ + size_t operator()(const vcpkg::Triplet& t) const { return t.hash_code(); } +}; diff --git a/toolsrc/include/vcpkg/update.h b/toolsrc/include/vcpkg/update.h new file mode 100644 index 000000000..e7303d1b0 --- /dev/null +++ b/toolsrc/include/vcpkg/update.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace vcpkg::Update +{ + struct OutdatedPackage + { + static bool compare_by_name(const OutdatedPackage& left, const OutdatedPackage& right); + + PackageSpec spec; + VersionDiff version_diff; + }; + + std::vector find_outdated_packages(const VcpkgPaths& paths, const StatusParagraphs& status_db); + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); +} \ No newline at end of file diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h new file mode 100644 index 000000000..6c47b98f6 --- /dev/null +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -0,0 +1,50 @@ +#pragma once + +#include + +#include +#include +#include +#include + +namespace vcpkg +{ + struct ParsedArguments + { + std::unordered_set switches; + std::unordered_map settings; + }; + + struct VcpkgCmdArguments + { + static VcpkgCmdArguments create_from_command_line(const int argc, const wchar_t* const* const argv); + static VcpkgCmdArguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end); + + std::unique_ptr vcpkg_root_dir; + std::unique_ptr triplet; + Optional debug = nullopt; + Optional sendmetrics = nullopt; + Optional printmetrics = nullopt; + + std::string command; + std::vector command_arguments; + std::unordered_set check_and_get_optional_command_arguments( + const std::vector& valid_options) const + { + return std::move(check_and_get_optional_command_arguments(valid_options, {}).switches); + } + + ParsedArguments check_and_get_optional_command_arguments(const std::vector& valid_switches, + const std::vector& valid_settings) 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 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 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 std::string& example_text) const; + + private: + std::unordered_map> optional_command_arguments; + }; +} diff --git a/toolsrc/include/vcpkg/vcpkglib.h b/toolsrc/include/vcpkg/vcpkglib.h new file mode 100644 index 000000000..b2aad8d7b --- /dev/null +++ b/toolsrc/include/vcpkg/vcpkglib.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace vcpkg +{ + StatusParagraphs database_load_check(const VcpkgPaths& paths); + + void write_update(const VcpkgPaths& paths, const StatusParagraph& p); + + struct StatusParagraphAndAssociatedFiles + { + StatusParagraph pgh; + SortedVector files; + }; + + std::vector get_installed_ports(const StatusParagraphs& status_db); + std::vector get_installed_files(const VcpkgPaths& paths, + const StatusParagraphs& status_db); + + struct CMakeVariable + { + CMakeVariable(const CWStringView varname, const wchar_t* varvalue); + CMakeVariable(const CWStringView varname, const std::string& varvalue); + CMakeVariable(const CWStringView varname, const std::wstring& varvalue); + CMakeVariable(const CWStringView varname, const fs::path& path); + + std::wstring s; + }; + + std::wstring make_cmake_cmd(const fs::path& cmake_exe, + const fs::path& cmake_script, + const std::vector& pass_variables); + + std::string shorten_text(const std::string& desc, size_t length); +} // namespace vcpkg diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h new file mode 100644 index 000000000..df4adfd83 --- /dev/null +++ b/toolsrc/include/vcpkg/vcpkgpaths.h @@ -0,0 +1,85 @@ +#pragma once + +#include +#include + +#include +#include +#include + +namespace vcpkg +{ + struct ToolsetArchOption + { + CWStringView name; + System::CPUArchitecture host_arch; + System::CPUArchitecture target_arch; + }; + + struct Toolset + { + fs::path visual_studio_root_path; + fs::path dumpbin; + fs::path vcvarsall; + std::vector vcvarsall_options; + CWStringView version; + std::vector supported_architectures; + }; + + struct VcpkgPaths + { + static Expected create(const fs::path& vcpkg_root_dir); + + fs::path package_dir(const PackageSpec& spec) const; + fs::path port_dir(const PackageSpec& spec) const; + fs::path port_dir(const std::string& name) const; + fs::path build_info_file_path(const PackageSpec& spec) const; + fs::path listfile_path(const BinaryParagraph& pgh) const; + + bool is_valid_triplet(const Triplet& t) const; + + fs::path root; + fs::path packages; + fs::path buildtrees; + fs::path downloads; + fs::path ports; + fs::path installed; + fs::path triplets; + fs::path scripts; + + fs::path buildsystems; + fs::path buildsystems_msbuild_targets; + + fs::path vcpkg_dir; + fs::path vcpkg_dir_status_file; + fs::path vcpkg_dir_info; + fs::path vcpkg_dir_updates; + + fs::path ports_cmake; + + const fs::path& get_cmake_exe() const; + const fs::path& get_git_exe() const; + const fs::path& get_nuget_exe() const; + const fs::path& get_ifw_installerbase_exe() const; + const fs::path& get_ifw_binarycreator_exe() const; + const fs::path& get_ifw_repogen_exe() const; + + /// Retrieve a toolset matching a VS version + /// + /// Valid version strings are "v140", "v141", and "". Empty string gets the latest. + /// + const Toolset& VcpkgPaths::get_toolset(const Optional& toolset_version, + const Optional& visual_studio_path) const; + + Files::Filesystem& get_filesystem() const; + + private: + Lazy cmake_exe; + Lazy git_exe; + Lazy nuget_exe; + Lazy ifw_installerbase_exe; + Lazy ifw_binarycreator_exe; + Lazy ifw_repogen_exe; + Lazy> toolsets; + }; +} diff --git a/toolsrc/include/vcpkg/versiont.h b/toolsrc/include/vcpkg/versiont.h new file mode 100644 index 000000000..67efd8da3 --- /dev/null +++ b/toolsrc/include/vcpkg/versiont.h @@ -0,0 +1,29 @@ +#pragma once +#include + +namespace vcpkg +{ + struct VersionT + { + VersionT(); + VersionT(const std::string& value); + + std::string to_string() const; + + std::string value; + }; + + bool operator==(const VersionT& left, const VersionT& right); + bool operator!=(const VersionT& left, const VersionT& right); + + struct VersionDiff + { + VersionT left; + VersionT right; + + VersionDiff(); + VersionDiff(const VersionT& left, const VersionT& right); + + std::string to_string() const; + }; +} diff --git a/toolsrc/include/vcpkg_Build.h b/toolsrc/include/vcpkg_Build.h deleted file mode 100644 index 5ba675757..000000000 --- a/toolsrc/include/vcpkg_Build.h +++ /dev/null @@ -1,192 +0,0 @@ -#pragma once - -#include "CStringView.h" -#include "PackageSpec.h" -#include "StatusParagraphs.h" -#include "VcpkgPaths.h" -#include "vcpkg_Files.h" -#include "vcpkg_optional.h" - -#include -#include -#include - -namespace vcpkg::Build -{ - enum class UseHeadVersion - { - NO = 0, - YES - }; - - inline UseHeadVersion to_use_head_version(const bool value) - { - return value ? UseHeadVersion::YES : UseHeadVersion::NO; - } - - inline bool to_bool(const UseHeadVersion value) { return value == UseHeadVersion::YES; } - - enum class AllowDownloads - { - NO = 0, - YES - }; - - inline AllowDownloads to_allow_downloads(const bool value) - { - return value ? AllowDownloads::YES : AllowDownloads::NO; - } - - inline bool to_bool(const AllowDownloads value) { return value == AllowDownloads::YES; } - - struct BuildPackageOptions - { - UseHeadVersion use_head_version; - AllowDownloads allow_downloads; - }; - - enum class BuildResult - { - NULLVALUE = 0, - SUCCEEDED, - BUILD_FAILED, - POST_BUILD_CHECKS_FAILED, - FILE_CONFLICTS, - CASCADED_DUE_TO_MISSING_DEPENDENCIES - }; - - static constexpr std::array BUILD_RESULT_VALUES = { - BuildResult::SUCCEEDED, - BuildResult::BUILD_FAILED, - BuildResult::POST_BUILD_CHECKS_FAILED, - BuildResult::FILE_CONFLICTS, - BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES}; - - const std::string& to_string(const BuildResult build_result); - std::string create_error_message(const BuildResult build_result, const PackageSpec& spec); - std::string create_user_troubleshooting_message(const PackageSpec& spec); - - /// - /// Settings from the triplet file which impact the build environment and post-build checks - /// - struct PreBuildInfo - { - /// - /// Runs the triplet file in a "capture" mode to create a PreBuildInfo - /// - static PreBuildInfo from_triplet_file(const VcpkgPaths& paths, const Triplet& triplet); - - std::string target_architecture; - std::string cmake_system_name; - std::string cmake_system_version; - Optional platform_toolset; - Optional visual_studio_path; - }; - - std::wstring make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); - - struct ExtendedBuildResult - { - BuildResult code; - std::vector unmet_dependencies; - }; - - struct BuildPackageConfig - { - BuildPackageConfig(const SourceParagraph& src, - const Triplet& triplet, - fs::path&& port_dir, - const BuildPackageOptions& build_package_options) - : src(src) - , scf(nullptr) - , triplet(triplet) - , port_dir(std::move(port_dir)) - , build_package_options(build_package_options) - , feature_list(nullptr) - { - } - - BuildPackageConfig(const SourceControlFile& src, - const Triplet& triplet, - fs::path&& port_dir, - const BuildPackageOptions& build_package_options, - const std::unordered_set& feature_list) - : src(*src.core_paragraph) - , scf(&src) - , triplet(triplet) - , port_dir(std::move(port_dir)) - , build_package_options(build_package_options) - , feature_list(&feature_list) - { - } - - const SourceParagraph& src; - const SourceControlFile* scf; - const Triplet& triplet; - fs::path port_dir; - const BuildPackageOptions& build_package_options; - const std::unordered_set* feature_list; - }; - - ExtendedBuildResult build_package(const VcpkgPaths& paths, - const BuildPackageConfig& config, - const StatusParagraphs& status_db); - - enum class BuildPolicy - { - EMPTY_PACKAGE, - DLLS_WITHOUT_LIBS, - ONLY_RELEASE_CRT, - EMPTY_INCLUDE_FOLDER, - ALLOW_OBSOLETE_MSVCRT, - // Must be last - COUNT, - }; - - constexpr std::array G_ALL_POLICIES = { - BuildPolicy::EMPTY_PACKAGE, - BuildPolicy::DLLS_WITHOUT_LIBS, - BuildPolicy::ONLY_RELEASE_CRT, - BuildPolicy::EMPTY_INCLUDE_FOLDER, - BuildPolicy::ALLOW_OBSOLETE_MSVCRT, - }; - - const std::string& to_string(BuildPolicy policy); - CStringView to_cmake_variable(BuildPolicy policy); - - struct BuildPolicies - { - BuildPolicies() = default; - BuildPolicies(std::map&& map) : m_policies(std::move(map)) {} - - bool is_enabled(BuildPolicy policy) const - { - const auto it = m_policies.find(policy); - if (it != m_policies.cend()) return it->second; - return false; - } - - private: - std::map m_policies; - }; - - enum class LinkageType : char - { - DYNAMIC, - STATIC, - }; - - Optional to_linkage_type(const std::string& str); - - struct BuildInfo - { - LinkageType crt_linkage; - LinkageType library_linkage; - - Optional version; - - BuildPolicies policies; - }; - - BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath); -} diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h deleted file mode 100644 index ce486ac19..000000000 --- a/toolsrc/include/vcpkg_Checks.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "LineInfo.h" -#include "vcpkg_Strings.h" - -namespace vcpkg::Checks -{ - void register_console_ctrl_handler(); - - // Indicate that an internal error has occurred and exit the tool. This should be used when invariants have been - // broken. - [[noreturn]] void unreachable(const LineInfo& line_info); - - [[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code); - - // Exit the tool without an error message. - [[noreturn]] inline void exit_fail(const LineInfo& line_info) { exit_with_code(line_info, EXIT_FAILURE); } - - // Exit the tool successfully. - [[noreturn]] inline void exit_success(const LineInfo& line_info) { exit_with_code(line_info, EXIT_SUCCESS); } - - // Display an error message to the user and exit the tool. - [[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView error_message); - - template - // Display an error message to the user and exit the tool. - [[noreturn]] void exit_with_message(const LineInfo& line_info, - const char* error_message_template, - const Arg1 error_message_arg1, - const Args&... error_message_args) - { - exit_with_message(line_info, - Strings::format(error_message_template, error_message_arg1, error_message_args...)); - } - - void check_exit(const LineInfo& line_info, bool expression); - - void check_exit(const LineInfo& line_info, bool expression, const CStringView error_message); - - template - void check_exit(const LineInfo& line_info, - Conditional&& expression, - const char* error_message_template, - const Arg1 error_message_arg1, - const Args&... error_message_args) - { - if (!expression) - { - // Only create the string if the expression is false - exit_with_message(line_info, - Strings::format(error_message_template, error_message_arg1, error_message_args...)); - } - } -} diff --git a/toolsrc/include/vcpkg_Chrono.h b/toolsrc/include/vcpkg_Chrono.h deleted file mode 100644 index c14019ff9..000000000 --- a/toolsrc/include/vcpkg_Chrono.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -namespace vcpkg -{ - class ElapsedTime - { - public: - static ElapsedTime create_started(); - - constexpr ElapsedTime() : m_start_tick() {} - - template - TimeUnit elapsed() const - { - return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - this->m_start_tick); - } - - double microseconds() const { return elapsed>().count(); } - - std::string to_string() const; - - private: - std::chrono::high_resolution_clock::time_point m_start_tick; - }; -} diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h deleted file mode 100644 index 7cfa2760e..000000000 --- a/toolsrc/include/vcpkg_Commands.h +++ /dev/null @@ -1,258 +0,0 @@ -#pragma once - -#include "StatusParagraphs.h" -#include "VcpkgCmdArguments.h" -#include "VcpkgPaths.h" -#include "VersionT.h" -#include "vcpkg_Build.h" -#include "vcpkg_Dependencies.h" -#include - -namespace vcpkg::Commands -{ - using CommandTypeA = void (*)(const VcpkgCmdArguments& args, - const VcpkgPaths& paths, - const Triplet& default_triplet); - using CommandTypeB = void (*)(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - using CommandTypeC = void (*)(const VcpkgCmdArguments& args); - - namespace BuildCommand - { - void perform_and_exit(const FullPackageSpec& full_spec, - const fs::path& port_dir, - const std::unordered_set& options, - const VcpkgPaths& paths); - - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace BuildExternal - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace Install - { - enum class KeepGoing - { - NO = 0, - YES - }; - - inline KeepGoing to_keep_going(const bool value) { return value ? KeepGoing::YES : KeepGoing::NO; } - - enum class PrintSummary - { - NO = 0, - YES - }; - - inline PrintSummary to_print_summary(const bool value) { return value ? PrintSummary::YES : PrintSummary::NO; } - - struct InstallDir - { - static InstallDir from_destination_root(const fs::path& destination_root, - const std::string& destination_subdirectory, - const fs::path& listfile); - - private: - fs::path m_destination; - std::string m_destination_subdirectory; - fs::path m_listfile; - - public: - const fs::path& destination() const; - const std::string& destination_subdirectory() const; - const fs::path& listfile() const; - }; - - Build::BuildResult perform_install_plan_action(const VcpkgPaths& paths, - const Dependencies::InstallPlanAction& action, - const Build::BuildPackageOptions& install_plan_options, - StatusParagraphs& status_db); - - enum class InstallResult - { - FILE_CONFLICTS, - SUCCESS, - }; - - void install_files_and_write_listfile(Files::Filesystem& fs, - const fs::path& source_dir, - const InstallDir& dirs); - InstallResult install_package(const VcpkgPaths& paths, - const BinaryControlFile& binary_paragraph, - StatusParagraphs* status_db); - - void perform_and_exit(const std::vector& action_plan, - const Build::BuildPackageOptions& install_plan_options, - const KeepGoing keep_going, - const PrintSummary print_summary, - const VcpkgPaths& paths, - StatusParagraphs& status_db); - - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace Export - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace CI - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace Remove - { - enum class Purge - { - NO = 0, - YES - }; - - inline Purge to_purge(const bool value) { return value ? Purge::YES : Purge::NO; } - - void perform_remove_plan_action(const VcpkgPaths& paths, - const Dependencies::RemovePlanAction& action, - const Purge purge, - StatusParagraphs& status_db); - - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db); - } - - namespace Update - { - struct OutdatedPackage - { - static bool compare_by_name(const OutdatedPackage& left, const OutdatedPackage& right); - - PackageSpec spec; - VersionDiff version_diff; - }; - - std::vector find_outdated_packages(const VcpkgPaths& paths, const StatusParagraphs& status_db); - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Env - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); - } - - namespace Create - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Edit - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace DependInfo - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Search - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace List - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Owns - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Cache - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Import - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Integrate - { - extern const char* const INTEGRATE_COMMAND_HELPSTRING; - - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace PortsDiff - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Autocomplete - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - } - - namespace Help - { - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - - void help_topic_valid_triplet(const VcpkgPaths& 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 - { - const std::string& version(); - void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths); - void perform_and_exit(const VcpkgCmdArguments& args); - } - - namespace Contact - { - const std::string& email(); - void perform_and_exit(const VcpkgCmdArguments& args); - } - - namespace Hash - { - void perform_and_exit(const VcpkgCmdArguments& args); - } - - template - struct PackageNameAndFunction - { - std::string name; - T function; - }; - - const std::vector>& get_available_commands_type_a(); - const std::vector>& get_available_commands_type_b(); - const std::vector>& get_available_commands_type_c(); - - template - T find(const std::string& command_name, const std::vector> available_commands) - { - for (const PackageNameAndFunction& cmd : available_commands) - { - if (cmd.name == command_name) - { - return cmd.function; - } - } - - // not found - return nullptr; - } -} diff --git a/toolsrc/include/vcpkg_Commands_Export.h b/toolsrc/include/vcpkg_Commands_Export.h deleted file mode 100644 index 6e698c1b4..000000000 --- a/toolsrc/include/vcpkg_Commands_Export.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "VcpkgPaths.h" - -namespace vcpkg::Commands::Export -{ - void export_integration_files(const fs::path& raw_exported_dir_path, const VcpkgPaths& paths); -} diff --git a/toolsrc/include/vcpkg_Commands_Export_IFW.h b/toolsrc/include/vcpkg_Commands_Export_IFW.h deleted file mode 100644 index 7bee45eaf..000000000 --- a/toolsrc/include/vcpkg_Commands_Export_IFW.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "VcpkgPaths.h" -#include "vcpkg_Dependencies.h" -#include "vcpkg_Files.h" - -#include -#include - -namespace vcpkg::Commands::Export::IFW -{ - struct Options - { - Optional maybe_repository_url; - Optional maybe_packages_dir_path; - Optional maybe_repository_dir_path; - Optional maybe_config_file_path; - Optional maybe_installer_file_path; - }; - - void do_export(const std::vector& export_plan, - const std::string& export_id, - const Options& ifw_options, - const VcpkgPaths& paths); -} diff --git a/toolsrc/include/vcpkg_Dependencies.h b/toolsrc/include/vcpkg_Dependencies.h deleted file mode 100644 index d67122e48..000000000 --- a/toolsrc/include/vcpkg_Dependencies.h +++ /dev/null @@ -1,147 +0,0 @@ -#pragma once -#include "PackageSpec.h" -#include "StatusParagraphs.h" -#include "VcpkgPaths.h" -#include "vcpkg_Graphs.h" -#include "vcpkg_Util.h" -#include "vcpkg_optional.h" -#include - -namespace vcpkg::Dependencies -{ - enum class RequestType - { - UNKNOWN, - USER_REQUESTED, - AUTO_SELECTED - }; - - std::string to_output_string(RequestType request_type, const CStringView s); - - struct AnyParagraph - { - std::vector dependencies(const Triplet& triplet) const; - - Optional status_paragraph; - Optional binary_control_file; - Optional source_paragraph; - Optional source_control_file; - }; -} - -namespace vcpkg::Dependencies -{ - enum class InstallPlanType - { - UNKNOWN, - BUILD_AND_INSTALL, - INSTALL, - ALREADY_INSTALLED - }; - - struct InstallPlanAction : Util::MoveOnlyBase - { - static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right); - - InstallPlanAction(); - - InstallPlanAction(const PackageSpec& spec, - const std::unordered_set& features, - const RequestType& request_type); - InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type); - InstallPlanAction(const PackageSpec& spec, - const SourceControlFile& any_paragraph, - const std::unordered_set& features, - const RequestType& request_type); - - std::string displayname() const; - - PackageSpec spec; - AnyParagraph any_paragraph; - InstallPlanType plan_type; - RequestType request_type; - std::unordered_set feature_list; - }; - - enum class RemovePlanType - { - UNKNOWN, - NOT_INSTALLED, - REMOVE - }; - - struct RemovePlanAction : Util::MoveOnlyBase - { - static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right); - - RemovePlanAction(); - RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type); - - PackageSpec spec; - RemovePlanType plan_type; - RequestType request_type; - }; - - struct AnyAction - { - AnyAction(InstallPlanAction&& iplan) : install_plan(std::move(iplan)) {} - AnyAction(RemovePlanAction&& rplan) : remove_plan(std::move(rplan)) {} - - Optional install_plan; - Optional remove_plan; - - const PackageSpec& spec() const; - }; - - enum class ExportPlanType - { - UNKNOWN, - PORT_AVAILABLE_BUT_NOT_BUILT, - ALREADY_BUILT - }; - - struct ExportPlanAction : Util::MoveOnlyBase - { - static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right); - - ExportPlanAction(); - ExportPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type); - - PackageSpec spec; - AnyParagraph any_paragraph; - ExportPlanType plan_type; - RequestType request_type; - }; - - __interface PortFileProvider { virtual const SourceControlFile& get_control_file(const std::string& spec) const; }; - - struct MapPortFile : Util::ResourceBase, PortFileProvider - { - const std::unordered_map& ports; - explicit MapPortFile(const std::unordered_map& map); - const SourceControlFile& get_control_file(const std::string& spec) const override; - }; - - struct PathsPortFile : Util::ResourceBase, PortFileProvider - { - const VcpkgPaths& ports; - mutable std::unordered_map cache; - explicit PathsPortFile(const VcpkgPaths& paths); - const SourceControlFile& get_control_file(const std::string& spec) const override; - }; - - std::vector create_install_plan(const PortFileProvider& port_file_provider, - const std::vector& specs, - const StatusParagraphs& status_db); - - std::vector create_remove_plan(const std::vector& specs, - const StatusParagraphs& status_db); - - std::vector create_export_plan(const VcpkgPaths& paths, - const std::vector& specs, - const StatusParagraphs& status_db); - - std::vector create_feature_install_plan(const std::unordered_map& map, - const std::vector& specs, - const StatusParagraphs& status_db); -} diff --git a/toolsrc/include/vcpkg_Enums.h b/toolsrc/include/vcpkg_Enums.h deleted file mode 100644 index c75feaa1f..000000000 --- a/toolsrc/include/vcpkg_Enums.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include "LineInfo.h" -#include - -namespace vcpkg::Enums -{ - std::string nullvalue_to_string(const CStringView enum_name); - - [[noreturn]] void nullvalue_used(const LineInfo& line_info, const CStringView enum_name); -} diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h deleted file mode 100644 index 855e8ea45..000000000 --- a/toolsrc/include/vcpkg_Files.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "filesystem_fs.h" -#include "vcpkg_expected.h" - -namespace vcpkg::Files -{ - __interface Filesystem - { - virtual Expected read_contents(const fs::path& file_path) const = 0; - virtual Expected> read_lines(const fs::path& file_path) const = 0; - virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0; - virtual std::vector get_files_recursive(const fs::path& dir) const = 0; - virtual std::vector get_files_non_recursive(const fs::path& dir) const = 0; - - virtual void write_lines(const fs::path& file_path, const std::vector& lines) = 0; - virtual void write_contents(const fs::path& file_path, const std::string& data) = 0; - virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0; - virtual bool remove(const fs::path& path) = 0; - virtual bool remove(const fs::path& path, std::error_code& ec) = 0; - virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0; - virtual bool exists(const fs::path& path) const = 0; - virtual bool is_directory(const fs::path& path) const = 0; - virtual bool is_regular_file(const fs::path& path) const = 0; - virtual bool is_empty(const fs::path& path) const = 0; - virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0; - virtual bool create_directories(const fs::path& path, std::error_code& ec) = 0; - virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0; - virtual bool copy_file( - const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0; - virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0; - }; - - Filesystem& get_real_filesystem(); - - static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; - - bool has_invalid_chars_for_filesystem(const std::string& s); - - void print_paths(const std::vector& paths); - - std::vector find_from_PATH(const std::wstring& name); -} diff --git a/toolsrc/include/vcpkg_GlobalState.h b/toolsrc/include/vcpkg_GlobalState.h deleted file mode 100644 index 6522a25bf..000000000 --- a/toolsrc/include/vcpkg_GlobalState.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -#include "vcpkg_Chrono.h" -#include "vcpkg_Util.h" - -namespace vcpkg -{ - struct GlobalState - { - static Util::LockGuarded timer; - static std::atomic debugging; - static std::atomic feature_packages; - - static std::atomic g_init_console_cp; - static std::atomic g_init_console_output_cp; - }; -} \ No newline at end of file diff --git a/toolsrc/include/vcpkg_Graphs.h b/toolsrc/include/vcpkg_Graphs.h deleted file mode 100644 index 13c0a7136..000000000 --- a/toolsrc/include/vcpkg_Graphs.h +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once - -#include -#include - -namespace vcpkg::Graphs -{ - enum class ExplorationStatus - { - // We have not visited this vertex - NOT_EXPLORED, - - // We have visited this vertex but haven't visited all vertices in its subtree - PARTIALLY_EXPLORED, - - // We have visited this vertex and all vertices in its subtree - FULLY_EXPLORED - }; - - template - __interface AdjacencyProvider - { - std::vector adjacency_list(const U& vertex) const; - - U load_vertex_data(const V& vertex) const; - }; - - template - static void topological_sort_internal(const V& vertex, - const AdjacencyProvider& f, - std::unordered_map& exploration_status, - std::vector& sorted) - { - ExplorationStatus& status = exploration_status[vertex]; - switch (status) - { - case ExplorationStatus::FULLY_EXPLORED: return; - case ExplorationStatus::PARTIALLY_EXPLORED: Checks::exit_with_message(VCPKG_LINE_INFO, "cycle in graph"); - case ExplorationStatus::NOT_EXPLORED: - { - status = ExplorationStatus::PARTIALLY_EXPLORED; - U vertex_data = f.load_vertex_data(vertex); - for (const V& neighbour : f.adjacency_list(vertex_data)) - topological_sort_internal(neighbour, f, exploration_status, sorted); - - sorted.push_back(std::move(vertex_data)); - status = ExplorationStatus::FULLY_EXPLORED; - return; - } - default: Checks::unreachable(VCPKG_LINE_INFO); - } - } - - template - std::vector topological_sort(const std::vector& starting_vertices, const AdjacencyProvider& f) - { - std::vector sorted; - std::unordered_map exploration_status; - - for (auto& vertex : starting_vertices) - { - topological_sort_internal(vertex, f, exploration_status, sorted); - } - - return sorted; - } - - template - struct GraphAdjacencyProvider final : AdjacencyProvider - { - const std::unordered_map>& vertices; - - GraphAdjacencyProvider(const std::unordered_map>& vertices) : vertices(vertices) {} - - std::vector adjacency_list(const V& vertex) const override - { - const std::unordered_set& as_set = this->vertices.at(vertex); - return std::vector(as_set.cbegin(), as_set.cend()); // TODO: Avoid redundant copy - } - - V load_vertex_data(const V& vertex) const override { return vertex; } - }; - - template - struct Graph - { - public: - void add_vertex(V v) { this->vertices[v]; } - - // TODO: Change with iterators - void add_vertices(const std::vector& vs) - { - for (const V& v : vs) - { - this->vertices[v]; - } - } - - void add_edge(V u, V v) - { - this->vertices[v]; - this->vertices[u].insert(v); - } - - std::vector topological_sort() const - { - GraphAdjacencyProvider adjacency_provider{this->vertices}; - std::unordered_map indegrees = count_indegrees(); - - std::vector sorted; - sorted.reserve(indegrees.size()); - - std::unordered_map exploration_status; - exploration_status.reserve(indegrees.size()); - - for (auto& pair : indegrees) - { - if (pair.second == 0) // Starting from vertices with indegree == 0. Not required. - { - V vertex = pair.first; - topological_sort_internal(vertex, adjacency_provider, exploration_status, sorted); - } - } - - return sorted; - } - - std::unordered_map count_indegrees() const - { - std::unordered_map indegrees; - - for (auto& pair : this->vertices) - { - indegrees[pair.first]; - for (V neighbour : pair.second) - { - ++indegrees[neighbour]; - } - } - - return indegrees; - } - - const std::unordered_map>& adjacency_list() const { return this->vertices; } - std::vector vertex_list() const - { - // why no &? it returns 0 - std::vector vertex_list; - for (const auto& vertex : this->vertices) - { - vertex_list.emplace_back(vertex.first); - } - return vertex_list; - } - - private: - std::unordered_map> vertices; - }; -} diff --git a/toolsrc/include/vcpkg_Input.h b/toolsrc/include/vcpkg_Input.h deleted file mode 100644 index fa568207a..000000000 --- a/toolsrc/include/vcpkg_Input.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "PackageSpec.h" - -namespace vcpkg::Input -{ - PackageSpec check_and_get_package_spec(const std::string& package_spec_as_string, - const Triplet& default_triplet, - CStringView example_text); - FullPackageSpec check_and_get_full_package_spec(const std::string& full_package_spec_as_string, - const Triplet& default_triplet, - CStringView example_text); - - void check_triplet(const Triplet& t, const VcpkgPaths& paths); -} diff --git a/toolsrc/include/vcpkg_Maps.h b/toolsrc/include/vcpkg_Maps.h deleted file mode 100644 index aadd81c2b..000000000 --- a/toolsrc/include/vcpkg_Maps.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace vcpkg::Maps -{ - template - std::vector extract_keys(const std::unordered_map& input_map) - { - std::vector key_set; - for (auto const& element : input_map) - { - key_set.push_back(element.first); - } - return key_set; - } - - template - std::vector extract_keys(const std::map& input_map) - { - std::vector key_set; - for (auto const& element : input_map) - { - key_set.push_back(element.first); - } - return key_set; - } -} diff --git a/toolsrc/include/vcpkg_Parse.h b/toolsrc/include/vcpkg_Parse.h deleted file mode 100644 index 2dda033b3..000000000 --- a/toolsrc/include/vcpkg_Parse.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "vcpkg_expected.h" -#include "vcpkg_optional.h" - -namespace vcpkg::Parse -{ - struct ParseControlErrorInfo - { - std::string name; - std::vector missing_fields; - std::vector extra_fields; - std::error_code error; - }; - - template - using ParseExpected = ExpectedT, std::unique_ptr>; - - using RawParagraph = std::unordered_map; - - struct ParagraphParser - { - ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {} - - void required_field(const std::string& fieldname, std::string& out); - std::string optional_field(const std::string& fieldname) const; - std::unique_ptr error_info(const std::string& name) const; - - private: - RawParagraph&& fields; - std::vector missing_fields; - }; - - std::vector parse_comma_list(const std::string& str); -} diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h deleted file mode 100644 index c44ce2b99..000000000 --- a/toolsrc/include/vcpkg_Strings.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include "CStringView.h" -#include - -namespace vcpkg::Strings::details -{ - template - auto to_printf_arg(const T& t) -> decltype(t.to_string()) - { - return t.to_string(); - } - - inline const char* to_printf_arg(const std::string& s) { return s.c_str(); } - - inline const char* to_printf_arg(const char* s) { return s; } - - inline int to_printf_arg(const int s) { return s; } - - inline long long to_printf_arg(const long long s) { return s; } - - inline unsigned long to_printf_arg(const unsigned long s) { return s; } - - inline size_t to_printf_arg(const size_t s) { return s; } - - inline double to_printf_arg(const double s) { return s; } - - std::string format_internal(const char* fmtstr, ...); - - inline const wchar_t* to_wprintf_arg(const std::wstring& s) { return s.c_str(); } - - inline const wchar_t* to_wprintf_arg(const wchar_t* s) { return s; } - - std::wstring wformat_internal(const wchar_t* fmtstr, ...); -} - -namespace vcpkg::Strings -{ - static constexpr const char* EMPTY = ""; - static constexpr const wchar_t* WEMPTY = L""; - - template - std::string format(const char* fmtstr, const Args&... args) - { - using vcpkg::Strings::details::to_printf_arg; - return details::format_internal(fmtstr, to_printf_arg(to_printf_arg(args))...); - } - - template - std::wstring wformat(const wchar_t* fmtstr, const Args&... args) - { - using vcpkg::Strings::details::to_wprintf_arg; - return details::wformat_internal(fmtstr, to_wprintf_arg(to_wprintf_arg(args))...); - } - - std::wstring to_utf16(const CStringView s); - - std::string to_utf8(const CWStringView w); - - std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern); - - bool case_insensitive_ascii_contains(const std::string& s, const std::string& pattern); - - int case_insensitive_ascii_compare(const CStringView left, const CStringView right); - - std::string ascii_to_lowercase(const std::string& input); - - bool case_insensitive_ascii_starts_with(const std::string& s, const std::string& pattern); - - template - std::basic_string join(const CharType* delimiter, const Container& v, Transformer transformer) - { - const auto begin = v.begin(); - const auto end = v.end(); - - if (begin == end) - { - return std::basic_string(); - } - - std::basic_string output; - output.append(transformer(*begin)); - for (auto it = std::next(begin); it != end; ++it) - { - output.append(delimiter); - output.append(transformer(*it)); - } - - return output; - } - template - std::basic_string join(const CharType* delimiter, const Container& v) - { - using Element = decltype(*v.begin()); - return join(delimiter, v, [](const Element& x) -> const Element& { return x; }); - } - - void trim(std::string* s); - - std::string trimmed(const std::string& s); - - void trim_all_and_remove_whitespace_strings(std::vector* strings); - - std::vector split(const std::string& s, const std::string& delimiter); - - template - std::string serialize(const T& t) - { - std::string ret; - serialize(t, ret); - return ret; - } -} diff --git a/toolsrc/include/vcpkg_System.h b/toolsrc/include/vcpkg_System.h deleted file mode 100644 index 65f80ae6d..000000000 --- a/toolsrc/include/vcpkg_System.h +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -#include "filesystem_fs.h" -#include "vcpkg_Strings.h" -#include "vcpkg_optional.h" -#include - -namespace vcpkg::System -{ - tm get_current_date_time(); - - fs::path get_exe_path_of_current_process(); - - struct ExitCodeAndOutput - { - int exit_code; - std::string output; - }; - - int cmd_execute_clean(const CWStringView cmd_line); - - int cmd_execute(const CWStringView cmd_line); - - ExitCodeAndOutput cmd_execute_and_capture_output(const CWStringView cmd_line); - - std::wstring create_powershell_script_cmd(const fs::path& script_path, const CWStringView args = Strings::WEMPTY); - - enum class Color - { - success = 10, - error = 12, - warning = 14, - }; - - void println(); - void print(const CStringView message); - void println(const CStringView message); - void print(const Color c, const CStringView message); - void println(const Color c, const CStringView message); - - template - void print(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) - { - return System::print(Strings::format(messageTemplate, messageArg1, messageArgs...)); - } - - template - void print(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) - { - return System::print(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); - } - - template - void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) - { - return System::println(Strings::format(messageTemplate, messageArg1, messageArgs...)); - } - - template - void println(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) - { - return System::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); - } - - Optional get_environment_variable(const CWStringView varname) noexcept; - - Optional get_registry_string(HKEY base, const CWStringView subkey, const CWStringView valuename); - - enum class CPUArchitecture - { - X86, - X64, - ARM, - ARM64, - }; - - Optional to_cpu_architecture(CStringView arch); - - CPUArchitecture get_host_processor(); - - std::vector get_supported_host_architectures(); - - const fs::path& get_program_files_32_bit(); - - const fs::path& get_program_files_platform_bitness(); -} - -namespace vcpkg::Debug -{ - void println(const CStringView message); - void println(const System::Color c, const CStringView message); - - template - void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) - { - return Debug::println(Strings::format(messageTemplate, messageArg1, messageArgs...)); - } - - template - void println(const System::Color c, - const char* messageTemplate, - const Arg1& messageArg1, - const Args&... messageArgs) - { - return Debug::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); - } -} diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h deleted file mode 100644 index facb7dd26..000000000 --- a/toolsrc/include/vcpkg_Util.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace vcpkg::Util -{ - template - using FmapOut = decltype(std::declval()(*begin(std::declval()))); - - template> - std::vector fmap(Cont&& xs, Func&& f) - { - std::vector ret; - ret.reserve(xs.size()); - - for (auto&& x : xs) - ret.push_back(f(x)); - - return ret; - } - - template - using FmapFlattenOut = std::decay_t()(*begin(std::declval()))))>; - - template> - std::vector fmap_flatten(Cont&& xs, Func&& f) - { - std::vector ret; - - for (auto&& x : xs) - for (auto&& y : f(x)) - ret.push_back(std::move(y)); - - return ret; - } - - template - void stable_keep_if(Container& cont, Pred pred) - { - cont.erase(std::stable_partition(cont.begin(), cont.end(), pred), cont.end()); - } - - template - void unstable_keep_if(Container& cont, Pred pred) - { - cont.erase(std::partition(cont.begin(), cont.end(), pred), cont.end()); - } - - template - void erase_remove_if(Container& cont, Pred pred) - { - cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); - } - - template - auto find(const Container& cont, V&& v) - { - return std::find(cont.cbegin(), cont.cend(), v); - } - - template - auto find_if(const Container& cont, Pred pred) - { - return std::find_if(cont.cbegin(), cont.cend(), pred); - } - - template - using ElementT = std::remove_reference_t()))>; - - template> - std::vector element_pointers(Container&& cont) - { - return fmap(cont, [](auto&& x) { return &x; }); - } - - template - auto find_if_not(const Container& cont, Pred pred) - { - return std::find_if_not(cont.cbegin(), cont.cend(), pred); - } - - template - void group_by(const Container& cont, std::map>* output, Func f) - { - for (const V& element : cont) - { - K key = f(element); - (*output)[key].push_back(&element); - } - } - - struct MoveOnlyBase - { - MoveOnlyBase() = default; - MoveOnlyBase(const MoveOnlyBase&) = delete; - MoveOnlyBase(MoveOnlyBase&&) = default; - - MoveOnlyBase& operator=(const MoveOnlyBase&) = delete; - MoveOnlyBase& operator=(MoveOnlyBase&&) = default; - }; - - struct ResourceBase - { - ResourceBase() = default; - ResourceBase(const ResourceBase&) = delete; - ResourceBase(ResourceBase&&) = delete; - - ResourceBase& operator=(const ResourceBase&) = delete; - ResourceBase& operator=(ResourceBase&&) = delete; - }; - - template - struct LockGuardPtr; - - template - struct LockGuarded - { - friend struct LockGuardPtr; - - LockGuardPtr lock() { return *this; } - - private: - std::mutex m_mutex; - T m_t; - }; - - template - struct LockGuardPtr - { - T& operator*() { return m_ptr; } - T* operator->() { return &m_ptr; } - - T* get() { return &m_ptr; } - - LockGuardPtr(LockGuarded& sync) : m_lock(sync.m_mutex), m_ptr(sync.m_t) {} - - private: - std::unique_lock m_lock; - T& m_ptr; - }; -} \ No newline at end of file diff --git a/toolsrc/include/vcpkg_expected.h b/toolsrc/include/vcpkg_expected.h deleted file mode 100644 index 9637ec087..000000000 --- a/toolsrc/include/vcpkg_expected.h +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once - -#include "vcpkg_Checks.h" -#include - -namespace vcpkg -{ - template - struct ErrorHolder - { - ErrorHolder() : m_is_error(false) {} - template - ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward(err)) - { - } - - constexpr bool has_error() const { return m_is_error; } - - const Err& error() const { return m_err; } - Err& error() { return m_err; } - - CStringView to_string() const { return "value was error"; } - - private: - bool m_is_error; - Err m_err; - }; - - template<> - struct ErrorHolder - { - ErrorHolder() = default; - ErrorHolder(const std::error_code& err) : m_err(err) {} - - constexpr bool has_error() const { return bool(m_err); } - - const std::error_code& error() const { return m_err; } - std::error_code& error() { return m_err; } - - CStringView to_string() const { return "value was error"; } - - private: - std::error_code m_err; - }; - - template - class ExpectedT - { - public: - constexpr ExpectedT() = default; - - // Constructors are intentionally implicit - - ExpectedT(const S& s) : m_s(s) {} - ExpectedT(S&& s) : m_s(std::move(s)) {} - - ExpectedT(const T& t) : m_t(t) {} - ExpectedT(T&& t) : m_t(std::move(t)) {} - - ExpectedT(const ExpectedT&) = default; - ExpectedT(ExpectedT&&) = default; - ExpectedT& operator=(const ExpectedT&) = default; - ExpectedT& operator=(ExpectedT&&) = default; - - explicit constexpr operator bool() const noexcept { return !m_s.has_error(); } - constexpr bool has_value() const noexcept { return !m_s.has_error(); } - - T&& value_or_exit(const LineInfo& line_info) && - { - exit_if_error(line_info); - return std::move(this->m_t); - } - - const T& value_or_exit(const LineInfo& line_info) const & - { - exit_if_error(line_info); - return this->m_t; - } - - const S& error() const & { return this->m_s.error(); } - - S&& error() && { return std::move(this->m_s.error()); } - - const T* get() const - { - if (!this->has_value()) - { - return nullptr; - } - return &this->m_t; - } - - T* get() - { - if (!this->has_value()) - { - return nullptr; - } - return &this->m_t; - } - - private: - void exit_if_error(const LineInfo& line_info) const - { - Checks::check_exit(line_info, !m_s.has_error(), m_s.to_string()); - } - - ErrorHolder m_s; - T m_t; - }; - - template - using Expected = ExpectedT; -} diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h deleted file mode 100644 index 31a2d3e88..000000000 --- a/toolsrc/include/vcpkg_optional.h +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once -#include "vcpkg_Checks.h" - -namespace vcpkg -{ - struct NullOpt - { - explicit constexpr NullOpt(int) {} - }; - - const static constexpr NullOpt nullopt{0}; - - template - class Optional - { - public: - constexpr Optional() : m_is_present(false), m_t() {} - - // Constructors are intentionally implicit - constexpr Optional(NullOpt) : m_is_present(false), m_t() {} - - Optional(const T& t) : m_is_present(true), m_t(t) {} - - Optional(T&& t) : m_is_present(true), m_t(std::move(t)) {} - - T&& value_or_exit(const LineInfo& line_info) && - { - this->exit_if_null(line_info); - return std::move(this->m_t); - } - - const T& value_or_exit(const LineInfo& line_info) const & - { - this->exit_if_null(line_info); - return this->m_t; - } - - constexpr explicit operator bool() const { return this->m_is_present; } - - constexpr bool has_value() const { return m_is_present; } - - template - T value_or(U&& default_value) const & - { - return bool(*this) ? this->m_t : static_cast(std::forward(default_value)); - } - - template - T value_or(U&& default_value) && - { - return bool(*this) ? std::move(this->m_t) : static_cast(std::forward(default_value)); - } - - const T* get() const { return bool(*this) ? &this->m_t : nullptr; } - - T* get() { return bool(*this) ? &this->m_t : nullptr; } - - private: - void exit_if_null(const LineInfo& line_info) const - { - Checks::check_exit(line_info, this->m_is_present, "Value was null"); - } - - bool m_is_present; - T m_t; - }; - - template - Optional> make_optional(U&& u) - { - return Optional>(std::forward(u)); - } - - template - bool operator==(const Optional& o, const T& t) - { - if (auto p = o.get()) return *p == t; - return false; - } - template - bool operator==(const T& t, const Optional& o) - { - if (auto p = o.get()) return t == *p; - return false; - } - template - bool operator!=(const Optional& o, const T& t) - { - if (auto p = o.get()) return *p != t; - return true; - } - template - bool operator!=(const T& t, const Optional& o) - { - if (auto p = o.get()) return t != *p; - return true; - } -} diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h deleted file mode 100644 index 0bb75f9b5..000000000 --- a/toolsrc/include/vcpkglib.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "SortedVector.h" -#include "StatusParagraphs.h" -#include "VcpkgPaths.h" - -namespace vcpkg -{ - StatusParagraphs database_load_check(const VcpkgPaths& paths); - - void write_update(const VcpkgPaths& paths, const StatusParagraph& p); - - struct StatusParagraphAndAssociatedFiles - { - StatusParagraph pgh; - SortedVector files; - }; - - std::vector get_installed_ports(const StatusParagraphs& status_db); - std::vector get_installed_files(const VcpkgPaths& paths, - const StatusParagraphs& status_db); - - struct CMakeVariable - { - CMakeVariable(const CWStringView varname, const wchar_t* varvalue); - CMakeVariable(const CWStringView varname, const std::string& varvalue); - CMakeVariable(const CWStringView varname, const std::wstring& varvalue); - CMakeVariable(const CWStringView varname, const fs::path& path); - - std::wstring s; - }; - - std::wstring make_cmake_cmd(const fs::path& cmake_exe, - const fs::path& cmake_script, - const std::vector& pass_variables); - - std::string shorten_text(const std::string& desc, size_t length); -} // namespace vcpkg -- cgit v1.2.3 From bea4c2ff4936f22b4024c2afef5e403533c7b291 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 13 Oct 2017 20:58:00 -0700 Subject: [vcpkg] Begin refactor to use CommandStructure to represent command parsing --- toolsrc/include/vcpkg/install.h | 2 ++ toolsrc/include/vcpkg/remove.h | 2 ++ toolsrc/include/vcpkg/vcpkgcmdarguments.h | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index 02600b7f5..72643ff37 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -65,5 +65,7 @@ namespace vcpkg::Install const VcpkgPaths& paths, StatusParagraphs& status_db); + extern const CommandStructure INSTALL_COMMAND_STRUCTURE; + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); } diff --git a/toolsrc/include/vcpkg/remove.h b/toolsrc/include/vcpkg/remove.h index f4d381ca3..04f2461be 100644 --- a/toolsrc/include/vcpkg/remove.h +++ b/toolsrc/include/vcpkg/remove.h @@ -19,6 +19,8 @@ namespace vcpkg::Remove const Purge purge, StatusParagraphs& status_db); + extern const CommandStructure REMOVE_COMMAND_STRUCTURE; + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db); } diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h index 6c47b98f6..8b1d766b6 100644 --- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -1,6 +1,8 @@ #pragma once +#include #include +#include #include #include @@ -47,4 +49,19 @@ namespace vcpkg private: std::unordered_map> optional_command_arguments; }; + + struct VcpkgPaths; + + struct CommandStructure + { + CStringView example_text; + + size_t minimum_arity; + size_t maximum_arity; + + Span switches; + Span settings; + + std::vector (*valid_arguments)(const VcpkgPaths& paths); + }; } -- cgit v1.2.3 From 58fd38c8200ce4c96ebe1aae3f85b324456b0ff7 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sat, 14 Oct 2017 02:16:55 -0700 Subject: [vcpkg-autocomplete] Add edit completion --- toolsrc/include/vcpkg/commands.h | 1 + toolsrc/include/vcpkg/install.h | 2 +- toolsrc/include/vcpkg/remove.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/commands.h b/toolsrc/include/vcpkg/commands.h index 64b2118ce..e00812c98 100644 --- a/toolsrc/include/vcpkg/commands.h +++ b/toolsrc/include/vcpkg/commands.h @@ -38,6 +38,7 @@ namespace vcpkg::Commands namespace Edit { + extern const CommandStructure COMMAND_STRUCTURE; void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index 72643ff37..db6055f4f 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -65,7 +65,7 @@ namespace vcpkg::Install const VcpkgPaths& paths, StatusParagraphs& status_db); - extern const CommandStructure INSTALL_COMMAND_STRUCTURE; + extern const CommandStructure COMMAND_STRUCTURE; void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); } diff --git a/toolsrc/include/vcpkg/remove.h b/toolsrc/include/vcpkg/remove.h index 04f2461be..6d8a3ebe9 100644 --- a/toolsrc/include/vcpkg/remove.h +++ b/toolsrc/include/vcpkg/remove.h @@ -19,7 +19,7 @@ namespace vcpkg::Remove const Purge purge, StatusParagraphs& status_db); - extern const CommandStructure REMOVE_COMMAND_STRUCTURE; + extern const CommandStructure COMMAND_STRUCTURE; void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet); void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db); -- cgit v1.2.3