diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2020-02-04 15:50:10 -0800 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2020-02-04 15:50:10 -0800 |
| commit | 6f66ad14fe9da11d4bf50f5b25b4da86ed971c53 (patch) | |
| tree | 0f5dbcd1719cd6a8e486c4058cfefd607d58aa6c /toolsrc/include | |
| parent | d502f061bb3ee0258d6453acbf258b9e5d93d564 (diff) | |
| parent | d808514c9df44bb97d6eccff952bfe8ec4e156f7 (diff) | |
| download | vcpkg-6f66ad14fe9da11d4bf50f5b25b4da86ed971c53.tar.gz vcpkg-6f66ad14fe9da11d4bf50f5b25b4da86ed971c53.zip | |
Merge remote-tracking branch 'origin/master' into HEAD
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/pch.h | 4 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg-test/mockcmakevarprovider.h | 38 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg-test/util.h | 23 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/files.h | 8 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/graphs.h | 47 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/span.h | 3 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/util.h | 14 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/binaryparagraph.h | 11 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/build.h | 36 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/cmakevars.h | 69 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/dependencies.h | 98 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/install.h | 14 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/logicexpression.h | 16 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/packagespec.h | 29 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/portfileprovider.h | 38 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/sourceparagraph.h | 88 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/statusparagraph.h | 1 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/update.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/vcpkgpaths.h | 14 |
19 files changed, 376 insertions, 177 deletions
diff --git a/toolsrc/include/pch.h b/toolsrc/include/pch.h index ce2a7c9c5..a6a442f0a 100644 --- a/toolsrc/include/pch.h +++ b/toolsrc/include/pch.h @@ -31,7 +31,11 @@ #include <cstdint> #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include <cstring> +#if USE_STD_FILESYSTEM +#include <filesystem> +#else #include <experimental/filesystem> +#endif #include <fstream> #include <functional> #include <iomanip> diff --git a/toolsrc/include/vcpkg-test/mockcmakevarprovider.h b/toolsrc/include/vcpkg-test/mockcmakevarprovider.h new file mode 100644 index 000000000..03defdcdd --- /dev/null +++ b/toolsrc/include/vcpkg-test/mockcmakevarprovider.h @@ -0,0 +1,38 @@ +#pragma once
+
+#include <vcpkg/cmakevars.h>
+
+namespace vcpkg::Test
+{
+ struct MockCMakeVarProvider : CMakeVars::CMakeVarProvider
+ {
+ void load_generic_triplet_vars(const Triplet& triplet) const override { generic_triplet_vars[triplet] = {}; }
+
+ void load_dep_info_vars(Span<const PackageSpec> specs) const override
+ {
+ for (auto&& spec : specs)
+ dep_info_vars[spec] = {};
+ }
+
+ void load_tag_vars(Span<const FullPackageSpec> specs,
+ const PortFileProvider::PortFileProvider& port_provider) const override
+ {
+ for (auto&& spec : specs)
+ tag_vars[spec.package_spec] = {};
+ Util::unused(port_provider);
+ }
+
+ Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars(
+ const Triplet& triplet) const override;
+
+ Optional<const std::unordered_map<std::string, std::string>&> get_dep_info_vars(
+ const PackageSpec& spec) const override;
+
+ Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars(
+ const PackageSpec& spec) const override;
+
+ mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> dep_info_vars;
+ mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> tag_vars;
+ mutable std::unordered_map<Triplet, std::unordered_map<std::string, std::string>> generic_triplet_vars;
+ };
+}
diff --git a/toolsrc/include/vcpkg-test/util.h b/toolsrc/include/vcpkg-test/util.h index 259b0ba7e..088a39b7d 100644 --- a/toolsrc/include/vcpkg-test/util.h +++ b/toolsrc/include/vcpkg-test/util.h @@ -17,6 +17,12 @@ namespace vcpkg::Test { + std::unique_ptr<SourceControlFile> make_control_file( + const char* name, + const char* depends, + const std::vector<std::pair<const char*, const char*>>& features = {}, + const std::vector<const char*>& default_features = {}); + std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name, const char* depends = "", const char* default_features = "", @@ -27,6 +33,23 @@ namespace vcpkg::Test const char* depends = "", const char* triplet = "x86-windows"); + /// <summary> + /// Map of source control files by their package name. + /// </summary> + struct PackageSpecMap + { + std::unordered_map<std::string, SourceControlFileLocation> map; + Triplet triplet; + PackageSpecMap(const Triplet& t = Triplet::X86_WINDOWS) noexcept : triplet(t) {} + + PackageSpec emplace(const char* name, + const char* depends = "", + const std::vector<std::pair<const char*, const char*>>& features = {}, + const std::vector<const char*>& default_features = {}); + + PackageSpec emplace(vcpkg::SourceControlFileLocation&& scfl); + }; + vcpkg::PackageSpec unsafe_pspec(std::string name, vcpkg::Triplet t = vcpkg::Triplet::X86_WINDOWS); template<class T, class S> diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h index e9d3d33bf..bb4a10d49 100644 --- a/toolsrc/include/vcpkg/base/files.h +++ b/toolsrc/include/vcpkg/base/files.h @@ -2,12 +2,20 @@ #include <vcpkg/base/expected.h> +#if USE_STD_FILESYSTEM +#include <filesystem> +#else #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include <experimental/filesystem> +#endif namespace fs { +#if USE_STD_FILESYSTEM + namespace stdfs = std::filesystem; +#else namespace stdfs = std::experimental::filesystem; +#endif using stdfs::copy_options; using stdfs::path; diff --git a/toolsrc/include/vcpkg/base/graphs.h b/toolsrc/include/vcpkg/base/graphs.h index 683735b1c..f368a872d 100644 --- a/toolsrc/include/vcpkg/base/graphs.h +++ b/toolsrc/include/vcpkg/base/graphs.h @@ -1,11 +1,10 @@ #pragma once +#include <string> #include <unordered_map> -#include <unordered_set> -#include <utility> +#include <vector> #include <vcpkg/base/checks.h> -#include <vcpkg/base/span.h> #include <vcpkg/base/system.print.h> namespace vcpkg::Graphs @@ -95,10 +94,8 @@ namespace vcpkg::Graphs } } - template<class VertexContainer, class V, class U> - std::vector<U> topological_sort(VertexContainer starting_vertices, - const AdjacencyProvider<V, U>& f, - Randomizer* randomizer) + template<class Range, class V, class U> + std::vector<U> topological_sort(Range starting_vertices, const AdjacencyProvider<V, U>& f, Randomizer* randomizer) { std::vector<U> sorted; std::unordered_map<V, ExplorationStatus> exploration_status; @@ -112,40 +109,4 @@ namespace vcpkg::Graphs return sorted; } - - template<class V> - struct Graph final : AdjacencyProvider<V, V> - { - public: - void add_vertex(const V& v) { this->m_edges[v]; } - - void add_edge(const V& u, const V& v) - { - this->m_edges[v]; - this->m_edges[u].insert(v); - } - - std::vector<V> vertex_list() const - { - std::vector<V> vertex_list; - for (auto&& vertex : this->m_edges) - vertex_list.emplace_back(vertex.first); - return vertex_list; - } - - std::vector<V> adjacency_list(const V& vertex) const override - { - const std::unordered_set<V>& as_set = this->m_edges.at(vertex); - return std::vector<V>(as_set.cbegin(), as_set.cend()); // TODO: Avoid redundant copy - } - - V load_vertex_data(const V& vertex) const override { return vertex; } - - // Note: this function indicates how tied this template is to the exact type it will be templated upon. - // Possible fix: This type shouldn't implement to_string() and should instead be derived from? - std::string to_string(const V& spec) const override { return spec->spec.to_string(); } - - private: - std::unordered_map<V, std::unordered_set<V>> m_edges; - }; } diff --git a/toolsrc/include/vcpkg/base/span.h b/toolsrc/include/vcpkg/base/span.h index 4c805e2b4..a5ba884af 100644 --- a/toolsrc/include/vcpkg/base/span.h +++ b/toolsrc/include/vcpkg/base/span.h @@ -23,14 +23,13 @@ namespace vcpkg constexpr Span(std::nullptr_t) noexcept : m_ptr(nullptr), m_count(0) {}
constexpr Span(pointer ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
constexpr Span(pointer ptr_begin, pointer ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
- constexpr Span(std::initializer_list<T> l) noexcept : m_ptr(l.begin()), m_count(l.size()) {}
template<size_t N>
constexpr Span(T (&arr)[N]) noexcept : m_ptr(arr), m_count(N)
{
}
- template<size_t N>
+ template<size_t N, class = std::enable_if_t<std::is_const_v<T>>>
constexpr Span(std::remove_const_t<T> (&arr)[N]) noexcept : m_ptr(arr), m_count(N)
{
}
diff --git a/toolsrc/include/vcpkg/base/util.h b/toolsrc/include/vcpkg/base/util.h index ad628e071..849781b95 100644 --- a/toolsrc/include/vcpkg/base/util.h +++ b/toolsrc/include/vcpkg/base/util.h @@ -18,7 +18,7 @@ namespace vcpkg::Util namespace Vectors { template<class Container, class T = ElementT<Container>> - void concatenate(std::vector<T>* augend, const Container& addend) + void append(std::vector<T>* augend, const Container& addend) { augend->insert(augend->end(), addend.begin(), addend.end()); } @@ -122,6 +122,12 @@ namespace vcpkg::Util std::sort(begin(cont), end(cont), comp); } + template<class Range, class Pred> + bool any_of(Range&& rng, Pred pred) + { + return std::any_of(rng.begin(), rng.end(), std::move(pred)); + } + template<class Range> Range&& sort_unique_erase(Range&& cont) { @@ -220,4 +226,10 @@ namespace vcpkg::Util void unused(const Ts&...) { } + + template<class T> + T copy(const T& t) + { + return t; + } } diff --git a/toolsrc/include/vcpkg/binaryparagraph.h b/toolsrc/include/vcpkg/binaryparagraph.h index 457205384..223a1fb86 100644 --- a/toolsrc/include/vcpkg/binaryparagraph.h +++ b/toolsrc/include/vcpkg/binaryparagraph.h @@ -13,8 +13,14 @@ namespace vcpkg { BinaryParagraph(); explicit BinaryParagraph(Parse::RawParagraph fields); - BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet, const std::string& abi_tag); - BinaryParagraph(const SourceParagraph& spgh, const FeatureParagraph& fpgh, const Triplet& triplet); + BinaryParagraph(const SourceParagraph& spgh, + const Triplet& triplet, + const std::string& abi_tag, + const std::vector<FeatureSpec>& deps); + BinaryParagraph(const SourceParagraph& spgh, + const FeatureParagraph& fpgh, + const Triplet& triplet, + const std::vector<FeatureSpec>& deps); std::string displayname() const; @@ -30,6 +36,7 @@ namespace vcpkg std::vector<std::string> default_features; std::vector<std::string> depends; std::string abi; + Type type; }; struct BinaryControlFile diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index be5424296..57663ebe5 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -1,5 +1,6 @@ #pragma once +#include <vcpkg/cmakevars.h> #include <vcpkg/packagespec.h> #include <vcpkg/statusparagraphs.h> #include <vcpkg/triplet.h> @@ -21,6 +22,7 @@ namespace vcpkg::Build { void perform_and_exit_ex(const FullPackageSpec& full_spec, const SourceControlFileLocation& scfl, + const PortFileProvider::PathsPortFileProvider& provider, const ParsedArguments& options, const VcpkgPaths& paths); @@ -88,6 +90,12 @@ namespace vcpkg::Build YES }; + enum class PurgeDecompressFailure + { + NO = 0, + YES + }; + struct BuildPackageOptions { UseHeadVersion use_head_version; @@ -99,6 +107,7 @@ namespace vcpkg::Build DownloadTool download_tool; BinaryCaching binary_caching; FailOnTombstone fail_on_tombstone; + PurgeDecompressFailure purge_decompress_failure; }; enum class BuildResult @@ -130,12 +139,9 @@ namespace vcpkg::Build /// </summary> struct PreBuildInfo { - /// <summary> - /// Runs the triplet file in a "capture" mode to create a PreBuildInfo - /// </summary> - static PreBuildInfo from_triplet_file(const VcpkgPaths& paths, - const Triplet& triplet, - Optional<const SourceControlFileLocation&> port = nullopt); + PreBuildInfo(const VcpkgPaths& paths, + const Triplet& triplet, + const std::unordered_map<std::string, std::string>& cmakevars); std::string triplet_abi_tag; std::string target_architecture; @@ -193,12 +199,18 @@ namespace vcpkg::Build BuildPackageConfig(const SourceControlFileLocation& scfl, const Triplet& triplet, const BuildPackageOptions& build_package_options, - const std::set<std::string>& feature_list) + const CMakeVars::CMakeVarProvider& var_provider, + const std::unordered_map<std::string, std::vector<FeatureSpec>>& feature_dependencies, + const std::vector<PackageSpec>& package_dependencies, + const std::vector<std::string>& feature_list) : scfl(scfl) , scf(*scfl.source_control_file) , triplet(triplet) , port_dir(scfl.source_location) , build_package_options(build_package_options) + , var_provider(var_provider) + , feature_dependencies(feature_dependencies) + , package_dependencies(package_dependencies) , feature_list(feature_list) { } @@ -206,9 +218,13 @@ namespace vcpkg::Build const SourceControlFileLocation& scfl; const SourceControlFile& scf; const Triplet& triplet; - fs::path port_dir; + const fs::path& port_dir; const BuildPackageOptions& build_package_options; - const std::set<std::string>& feature_list; + const CMakeVars::CMakeVarProvider& var_provider; + + const std::unordered_map<std::string, std::vector<FeatureSpec>>& feature_dependencies; + const std::vector<PackageSpec>& package_dependencies; + const std::vector<std::string>& feature_list; }; ExtendedBuildResult build_package(const VcpkgPaths& paths, @@ -223,6 +239,7 @@ namespace vcpkg::Build ONLY_RELEASE_CRT, EMPTY_INCLUDE_FOLDER, ALLOW_OBSOLETE_MSVCRT, + ALLOW_RESTRICTED_HEADERS, // Must be last COUNT, }; @@ -234,6 +251,7 @@ namespace vcpkg::Build BuildPolicy::ONLY_RELEASE_CRT, BuildPolicy::EMPTY_INCLUDE_FOLDER, BuildPolicy::ALLOW_OBSOLETE_MSVCRT, + BuildPolicy::ALLOW_RESTRICTED_HEADERS, }; const std::string& to_string(BuildPolicy policy); diff --git a/toolsrc/include/vcpkg/cmakevars.h b/toolsrc/include/vcpkg/cmakevars.h new file mode 100644 index 000000000..c634866d0 --- /dev/null +++ b/toolsrc/include/vcpkg/cmakevars.h @@ -0,0 +1,69 @@ +#pragma once + +#include <vcpkg/base/hash.h> +#include <vcpkg/base/system.process.h> + +#include <vcpkg/portfileprovider.h> +#include <vcpkg/vcpkgpaths.h> + +namespace vcpkg::CMakeVars +{ + struct CMakeVarProvider + { + virtual Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars( + const Triplet& triplet) const = 0; + + virtual Optional<const std::unordered_map<std::string, std::string>&> get_dep_info_vars( + const PackageSpec& spec) const = 0; + + virtual Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars( + const PackageSpec& spec) const = 0; + + virtual void load_generic_triplet_vars(const Triplet& triplet) const = 0; + + virtual void load_dep_info_vars(Span<const PackageSpec> specs) const = 0; + + virtual void load_tag_vars(Span<const FullPackageSpec> specs, + const PortFileProvider::PortFileProvider& port_provider) const = 0; + }; + + struct TripletCMakeVarProvider : Util::ResourceBase, CMakeVarProvider + { + private: + fs::path create_tag_extraction_file( + const Span<const std::pair<const FullPackageSpec*, std::string>>& spec_abi_settings) const; + + fs::path create_dep_info_extraction_file(const Span<const PackageSpec> specs) const; + + void launch_and_split(const fs::path& script_path, + std::vector<std::vector<std::pair<std::string, std::string>>>& vars) const; + + public: + explicit TripletCMakeVarProvider(const vcpkg::VcpkgPaths& paths) : paths(paths) {} + + void load_generic_triplet_vars(const Triplet& triplet) const override; + + void load_dep_info_vars(Span<const PackageSpec> specs) const override; + + void load_tag_vars(Span<const FullPackageSpec> specs, + const PortFileProvider::PortFileProvider& port_provider) const override; + + Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars( + const Triplet& triplet) const override; + + Optional<const std::unordered_map<std::string, std::string>&> get_dep_info_vars( + const PackageSpec& spec) const override; + + Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars( + const PackageSpec& spec) const override; + + private: + const VcpkgPaths& paths; + const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE); + const fs::path get_tags_path = paths.scripts / "vcpkg_get_tags.cmake"; + const fs::path get_dep_info_path = paths.scripts / "vcpkg_get_dep_info.cmake"; + mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> dep_resolution_vars; + mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> tag_vars; + mutable std::unordered_map<Triplet, std::unordered_map<std::string, std::string>> generic_triplet_vars; + }; +} diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h index e9018b1b8..eb9d42b6d 100644 --- a/toolsrc/include/vcpkg/dependencies.h +++ b/toolsrc/include/vcpkg/dependencies.h @@ -3,7 +3,9 @@ #include <vcpkg/base/optional.h> #include <vcpkg/base/util.h> #include <vcpkg/build.h> +#include <vcpkg/cmakevars.h> #include <vcpkg/packagespec.h> +#include <vcpkg/portfileprovider.h> #include <vcpkg/statusparagraphs.h> #include <vcpkg/vcpkgpaths.h> @@ -43,15 +45,12 @@ namespace vcpkg::Dependencies InstallPlanAction() noexcept; - InstallPlanAction(InstalledPackageView&& spghs, - const std::set<std::string>& features, - const RequestType& request_type); + InstallPlanAction(InstalledPackageView&& spghs, const RequestType& request_type); InstallPlanAction(const PackageSpec& spec, const SourceControlFileLocation& scfl, - const std::set<std::string>& features, const RequestType& request_type, - std::vector<PackageSpec>&& dependencies); + std::unordered_map<std::string, std::vector<FeatureSpec>>&& dependencies); std::string displayname() const; @@ -63,9 +62,11 @@ namespace vcpkg::Dependencies InstallPlanType plan_type; RequestType request_type; Build::BuildPackageOptions build_options; - std::set<std::string> feature_list; - std::vector<PackageSpec> computed_dependencies; + std::unordered_map<std::string, std::vector<FeatureSpec>> feature_dependencies; + std::vector<PackageSpec> package_dependencies; + + std::vector<std::string> feature_list; }; enum class RemovePlanType @@ -87,15 +88,14 @@ namespace vcpkg::Dependencies RequestType request_type; }; - struct AnyAction + struct ActionPlan { - AnyAction(InstallPlanAction&& iplan) : install_action(std::move(iplan)) {} - AnyAction(RemovePlanAction&& rplan) : remove_action(std::move(rplan)) {} - - Optional<InstallPlanAction> install_action; - Optional<RemovePlanAction> remove_action; + bool empty() const { return remove_actions.empty() && already_installed.empty() && install_actions.empty(); } + size_t size() const { return remove_actions.size() + already_installed.size() + install_actions.size(); } - const PackageSpec& spec() const; + std::vector<RemovePlanAction> remove_actions; + std::vector<InstallPlanAction> already_installed; + std::vector<InstallPlanAction> install_actions; }; enum class ExportPlanType @@ -127,80 +127,36 @@ namespace vcpkg::Dependencies Optional<InstalledPackageView> m_installed_package; }; - struct PortFileProvider - { - virtual Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const = 0; - virtual std::vector<const SourceControlFileLocation*> load_all_control_files() const = 0; - }; - - struct MapPortFileProvider : Util::ResourceBase, PortFileProvider - { - explicit MapPortFileProvider(const std::unordered_map<std::string, SourceControlFileLocation>& map); - Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override; - std::vector<const SourceControlFileLocation*> load_all_control_files() const override; - - private: - const std::unordered_map<std::string, SourceControlFileLocation>& ports; - }; - - struct PathsPortFileProvider : Util::ResourceBase, PortFileProvider - { - explicit PathsPortFileProvider(const vcpkg::VcpkgPaths& paths, - const std::vector<std::string>* ports_dirs_paths); - Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override; - std::vector<const SourceControlFileLocation*> load_all_control_files() const override; - - private: - Files::Filesystem& filesystem; - std::vector<fs::path> ports_dirs; - mutable std::unordered_map<std::string, SourceControlFileLocation> cache; - }; - struct ClusterGraph; - struct GraphPlan; struct CreateInstallPlanOptions { Graphs::Randomizer* randomizer = nullptr; }; - struct PackageGraph - { - PackageGraph(const PortFileProvider& provider, const StatusParagraphs& status_db); - ~PackageGraph(); - - void install(const FeatureSpec& spec, - const std::unordered_set<std::string>& prevent_default_features = {}) const; - void upgrade(const PackageSpec& spec) const; - - std::vector<AnyAction> serialize(const CreateInstallPlanOptions& options = {}) const; - - private: - std::unique_ptr<GraphPlan> m_graph_plan; - std::unique_ptr<ClusterGraph> m_graph; - }; - std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs, const StatusParagraphs& status_db); std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs, const StatusParagraphs& status_db); - std::vector<AnyAction> create_feature_install_plan( - const std::unordered_map<std::string, SourceControlFileLocation>& map, - const std::vector<FeatureSpec>& specs, - const StatusParagraphs& status_db); - /// <summary>Figure out which actions are required to install features specifications in `specs`.</summary> /// <param name="provider">Contains the ports of the current environment.</param> /// <param name="specs">Feature specifications to resolve dependencies for.</param> /// <param name="status_db">Status of installed packages in the current environment.</param> - std::vector<AnyAction> create_feature_install_plan(const PortFileProvider& provider, - const std::vector<FeatureSpec>& specs, - const StatusParagraphs& status_db, - const CreateInstallPlanOptions& options = {}); - - void print_plan(const std::vector<AnyAction>& action_plan, + ActionPlan create_feature_install_plan(const PortFileProvider::PortFileProvider& provider, + const CMakeVars::CMakeVarProvider& var_provider, + const std::vector<FullPackageSpec>& specs, + const StatusParagraphs& status_db, + const CreateInstallPlanOptions& options = {}); + + ActionPlan create_upgrade_plan(const PortFileProvider::PortFileProvider& provider, + const CMakeVars::CMakeVarProvider& var_provider, + const std::vector<PackageSpec>& specs, + const StatusParagraphs& status_db, + const CreateInstallPlanOptions& options = {}); + + void print_plan(const ActionPlan& action_plan, const bool is_recursive = true, const fs::path& default_ports_dir = ""); } diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index 2e92764dc..e020c8653 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -20,7 +20,7 @@ namespace vcpkg::Install struct SpecSummary { - SpecSummary(const PackageSpec& spec, const Dependencies::AnyAction* action); + SpecSummary(const PackageSpec& spec, const Dependencies::InstallPlanAction* action); const BinaryParagraph* get_binary_paragraph() const; @@ -28,7 +28,7 @@ namespace vcpkg::Install Build::ExtendedBuildResult build_result; vcpkg::Chrono::ElapsedTime timing; - const Dependencies::AnyAction* action; + const Dependencies::InstallPlanAction* action; }; struct InstallSummary @@ -58,8 +58,9 @@ namespace vcpkg::Install }; Build::ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths, - const Dependencies::InstallPlanAction& action, - StatusParagraphs& status_db); + Dependencies::InstallPlanAction& action, + StatusParagraphs& status_db, + const CMakeVars::CMakeVarProvider& var_provider); enum class InstallResult { @@ -74,10 +75,11 @@ namespace vcpkg::Install const BinaryControlFile& binary_paragraph, StatusParagraphs* status_db); - InstallSummary perform(const std::vector<Dependencies::AnyAction>& action_plan, + InstallSummary perform(Dependencies::ActionPlan& action_plan, const KeepGoing keep_going, const VcpkgPaths& paths, - StatusParagraphs& status_db); + StatusParagraphs& status_db, + const CMakeVars::CMakeVarProvider& var_provider); extern const CommandStructure COMMAND_STRUCTURE; diff --git a/toolsrc/include/vcpkg/logicexpression.h b/toolsrc/include/vcpkg/logicexpression.h index 8795971b9..3a3d0debe 100644 --- a/toolsrc/include/vcpkg/logicexpression.h +++ b/toolsrc/include/vcpkg/logicexpression.h @@ -1,10 +1,24 @@ #pragma once
#include <string>
+#include <unordered_map>
+#include <vcpkg/base/expected.h>
namespace vcpkg
{
+ struct ExpressionContext
+ {
+ // map of cmake variables and their values.
+ const std::unordered_map<std::string, std::string>& cmake_context;
+
+ // The legacy context is a string (typically the name of the triplet).
+ // An identifier was considered 'true' if it is a substring of this.
+ // It is now used for backwards compatability diagnostic messages and
+ // will be eventually removed.
+ const std::string& legacy_context;
+ };
+
// Evaluate simple vcpkg logic expressions. An identifier in the expression is considered 'true'
// if it is a substring of the evaluation_context (typically the name of the triplet)
- bool evaluate_expression(const std::string& expression, const std::string& evaluation_context);
+ ExpectedT<bool, std::string> evaluate_expression(const std::string& expression, const ExpressionContext& context);
}
\ No newline at end of file diff --git a/toolsrc/include/vcpkg/packagespec.h b/toolsrc/include/vcpkg/packagespec.h index c87c6a2c6..628352cdb 100644 --- a/toolsrc/include/vcpkg/packagespec.h +++ b/toolsrc/include/vcpkg/packagespec.h @@ -23,6 +23,9 @@ namespace vcpkg /// struct PackageSpec { + PackageSpec() noexcept = default; + PackageSpec(std::string name, Triplet triplet) : m_name(std::move(name)), m_triplet(triplet) {} + static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name, const Triplet& triplet); @@ -103,7 +106,14 @@ namespace vcpkg PackageSpec package_spec; std::vector<std::string> features; - static std::vector<FeatureSpec> to_feature_specs(const std::vector<FullPackageSpec>& specs); + FullPackageSpec() noexcept = default; + explicit FullPackageSpec(PackageSpec spec, std::vector<std::string> features = {}) + : package_spec(std::move(spec)), features(std::move(features)) + { + } + + std::vector<FeatureSpec> to_feature_specs(const std::vector<std::string>& default_features, + const std::vector<std::string>& all_features) const; static ExpectedT<FullPackageSpec, PackageSpecParseResult> from_string(const std::string& spec_as_string, const Triplet& default_triplet); @@ -145,4 +155,21 @@ namespace std { bool operator()(const vcpkg::PackageSpec& left, const vcpkg::PackageSpec& right) const { return left == right; } }; + + template<> + struct hash<vcpkg::FeatureSpec> + { + size_t operator()(const vcpkg::FeatureSpec& value) const + { + size_t hash = std::hash<vcpkg::PackageSpec>()(value.spec()); + hash = hash * 31 + std::hash<std::string>()(value.feature()); + return hash; + } + }; + + template<> + struct equal_to<vcpkg::FeatureSpec> + { + bool operator()(const vcpkg::FeatureSpec& left, const vcpkg::FeatureSpec& right) const { return left == right; } + }; } diff --git a/toolsrc/include/vcpkg/portfileprovider.h b/toolsrc/include/vcpkg/portfileprovider.h new file mode 100644 index 000000000..79f69d9ae --- /dev/null +++ b/toolsrc/include/vcpkg/portfileprovider.h @@ -0,0 +1,38 @@ +#pragma once + +#include <vcpkg/base/optional.h> +#include <vcpkg/base/util.h> +#include <vcpkg/sourceparagraph.h> +#include <vcpkg/vcpkgpaths.h> + +namespace vcpkg::PortFileProvider +{ + struct PortFileProvider + { + virtual Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const = 0; + virtual std::vector<const SourceControlFileLocation*> load_all_control_files() const = 0; + }; + + struct MapPortFileProvider : Util::ResourceBase, PortFileProvider + { + explicit MapPortFileProvider(const std::unordered_map<std::string, SourceControlFileLocation>& map); + Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override; + std::vector<const SourceControlFileLocation*> load_all_control_files() const override; + + private: + const std::unordered_map<std::string, SourceControlFileLocation>& ports; + }; + + struct PathsPortFileProvider : Util::ResourceBase, PortFileProvider + { + explicit PathsPortFileProvider(const vcpkg::VcpkgPaths& paths, + const std::vector<std::string>* ports_dirs_paths); + Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override; + std::vector<const SourceControlFileLocation*> load_all_control_files() const override; + + private: + Files::Filesystem& filesystem; + std::vector<fs::path> ports_dirs; + mutable std::unordered_map<std::string, SourceControlFileLocation> cache; + }; +} diff --git a/toolsrc/include/vcpkg/sourceparagraph.h b/toolsrc/include/vcpkg/sourceparagraph.h index 95347770a..0574afe74 100644 --- a/toolsrc/include/vcpkg/sourceparagraph.h +++ b/toolsrc/include/vcpkg/sourceparagraph.h @@ -7,6 +7,8 @@ #include <vcpkg/base/span.h> #include <vcpkg/base/system.h> +#include <vcpkg/base/system.print.h> + #include <string> #include <vector> @@ -21,15 +23,28 @@ namespace vcpkg static Dependency parse_dependency(std::string name, std::string qualifier); }; - std::vector<std::string> filter_dependencies(const std::vector<Dependency>& deps, const Triplet& t); - std::vector<FeatureSpec> filter_dependencies_to_specs(const std::vector<Dependency>& deps, const Triplet& t); - std::vector<Features> filter_dependencies_to_features(const std::vector<vcpkg::Dependency>& deps, const Triplet& t); + std::vector<FullPackageSpec> filter_dependencies(const std::vector<Dependency>& deps, + const Triplet& t, + const std::unordered_map<std::string, std::string>& cmake_vars); // zlib[uwp] becomes Dependency{"zlib", "uwp"} std::vector<Dependency> expand_qualified_dependencies(const std::vector<std::string>& depends); std::string to_string(const Dependency& dep); + struct Type + { + enum + { + UNKNOWN, + PORT, + ALIAS, + } type; + + static std::string to_string(const Type&); + static Type from_string(const std::string&); + }; + /// <summary> /// Port metadata of additional feature in a package (part of CONTROL file) /// </summary> @@ -50,9 +65,10 @@ namespace vcpkg std::string description; std::string maintainer; std::string homepage; - std::vector<std::string> supports; std::vector<Dependency> depends; std::vector<std::string> default_features; + Type type; + std::string supports_expression; }; /// <summary> @@ -60,21 +76,48 @@ namespace vcpkg /// </summary> struct SourceControlFile { + SourceControlFile() = default; + SourceControlFile(const SourceControlFile& scf) + : core_paragraph(std::make_unique<SourceParagraph>(*scf.core_paragraph)) + { + for (const auto& feat_ptr : scf.feature_paragraphs) + { + feature_paragraphs.emplace_back(std::make_unique<FeatureParagraph>(*feat_ptr)); + } + } + static Parse::ParseExpected<SourceControlFile> parse_control_file( - std::vector<Parse::RawParagraph>&& control_paragraphs); + const fs::path& path_to_control, std::vector<Parse::RawParagraph>&& control_paragraphs); std::unique_ptr<SourceParagraph> core_paragraph; std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs; Optional<const FeatureParagraph&> find_feature(const std::string& featurename) const; + Optional<const std::vector<Dependency>&> find_dependencies_for_feature(const std::string& featurename) const; }; /// <summary> - /// Full metadata of a package: core and other features. As well as the location the SourceControlFile was loaded - /// from. + /// Full metadata of a package: core and other features. As well as the location the SourceControlFile was + /// loaded from. /// </summary> struct SourceControlFileLocation { + SourceControlFileLocation(const SourceControlFileLocation& scfl) + : source_control_file(std::make_unique<SourceControlFile>(*scfl.source_control_file)) + , source_location(scfl.source_location) + { + } + + SourceControlFileLocation(std::unique_ptr<SourceControlFile>&& scf, fs::path&& source) + : source_control_file(std::move(scf)), source_location(std::move(source)) + { + } + + SourceControlFileLocation(std::unique_ptr<SourceControlFile>&& scf, const fs::path& source) + : source_control_file(std::move(scf)), source_location(source) + { + } + std::unique_ptr<SourceControlFile> source_control_file; fs::path source_location; }; @@ -84,35 +127,4 @@ namespace vcpkg { return print_error_message({&error_info_list, 1}); } - - struct Supports - { - static ExpectedT<Supports, std::vector<std::string>> parse(const std::vector<std::string>& 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<Architecture> architectures; - std::vector<Platform> platforms; - std::vector<Linkage> crt_linkages; - std::vector<ToolsetVersion> toolsets; - }; } diff --git a/toolsrc/include/vcpkg/statusparagraph.h b/toolsrc/include/vcpkg/statusparagraph.h index 6e832fe2f..ec850607d 100644 --- a/toolsrc/include/vcpkg/statusparagraph.h +++ b/toolsrc/include/vcpkg/statusparagraph.h @@ -56,6 +56,7 @@ namespace vcpkg const PackageSpec& spec() const { return core->package.spec; } std::vector<PackageSpec> dependencies() const; + std::unordered_map<std::string, std::vector<FeatureSpec>> feature_dependencies() const; const StatusParagraph* core; std::vector<const StatusParagraph*> features; diff --git a/toolsrc/include/vcpkg/update.h b/toolsrc/include/vcpkg/update.h index b85f7b2b3..6091da778 100644 --- a/toolsrc/include/vcpkg/update.h +++ b/toolsrc/include/vcpkg/update.h @@ -17,7 +17,7 @@ namespace vcpkg::Update VersionDiff version_diff; }; - std::vector<OutdatedPackage> find_outdated_packages(const Dependencies::PortFileProvider& provider, + std::vector<OutdatedPackage> find_outdated_packages(const PortFileProvider::PortFileProvider& provider, const StatusParagraphs& status_db); void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h index 8107b8201..52d77d283 100644 --- a/toolsrc/include/vcpkg/vcpkgpaths.h +++ b/toolsrc/include/vcpkg/vcpkgpaths.h @@ -47,6 +47,14 @@ namespace vcpkg struct VcpkgPaths { + struct TripletFile + { + std::string name; + fs::path location; + + TripletFile(const std::string& name, const fs::path& location) : name(name), location(location){} + }; + static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir, const Optional<fs::path>& vcpkg_scripts_root_dir, const std::string& default_vs_path, @@ -57,7 +65,8 @@ namespace vcpkg fs::path listfile_path(const BinaryParagraph& pgh) const; bool is_valid_triplet(const Triplet& t) const; - const std::vector<std::string>& get_available_triplets() const; + const std::vector<std::string> get_available_triplets_names() const; + const std::vector<TripletFile>& get_available_triplets() const; const fs::path get_triplet_file_path(const Triplet& triplet) const; fs::path root; @@ -67,6 +76,7 @@ namespace vcpkg fs::path ports; fs::path installed; fs::path triplets; + fs::path community_triplets; fs::path scripts; fs::path tools; @@ -92,7 +102,7 @@ namespace vcpkg Files::Filesystem& get_filesystem() const; private: - Lazy<std::vector<std::string>> available_triplets; + Lazy<std::vector<TripletFile>> available_triplets; Lazy<std::vector<Toolset>> toolsets; Lazy<std::vector<Toolset>> toolsets_vs2013; |
