aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-11-09 11:15:31 -0800
committerGitHub <noreply@github.com>2020-11-09 11:15:31 -0800
commita94f261320398b859e5afb2b4d4c5a574f5d205a (patch)
treed8ae8ad5f740275f2c75e4981c5bd27a9b15a9ed /toolsrc/include
parent179bdd1697e03663869c2c3341343396c3ac6dfb (diff)
downloadvcpkg-a94f261320398b859e5afb2b4d4c5a574f5d205a.tar.gz
vcpkg-a94f261320398b859e5afb2b4d4c5a574f5d205a.zip
[vcpkg] Initial Registries: Part 2 MVP (#14153)
* [vcpkg wip] start implementation of registries pt. 2 * Remove the `ports` field of `VcpkgPaths` This is an implementation detail, and so we want to make sure that it's obvious that this is an internal detail; thus, we add a new function `builtin_ports_directory()`, which returns the directory where the builtin ports backing store is. * continue WIP * wip * It works! * format * fix some issues * switch from function static to DelayedInit * fix lexically_normal for experimental::filesystem * format * fix missing include * add STL notice * whee error handling * moar error handling! * ignore extra files in registries * formatting * Billy CRs * Update toolsrc/include/vcpkg/versiont.h * fix add_filename test * fix tests * remove unused function add_filename
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/delayed_init.h29
-rw-r--r--toolsrc/include/vcpkg/base/files.h7
-rw-r--r--toolsrc/include/vcpkg/base/jsonreader.h24
-rw-r--r--toolsrc/include/vcpkg/base/optional.h4
-rw-r--r--toolsrc/include/vcpkg/base/pragmas.h1
-rw-r--r--toolsrc/include/vcpkg/configurationdeserializer.h2
-rw-r--r--toolsrc/include/vcpkg/dependencies.h4
-rw-r--r--toolsrc/include/vcpkg/registries.h17
-rw-r--r--toolsrc/include/vcpkg/vcpkgpaths.h5
-rw-r--r--toolsrc/include/vcpkg/versiont.h8
10 files changed, 87 insertions, 14 deletions
diff --git a/toolsrc/include/vcpkg/base/delayed_init.h b/toolsrc/include/vcpkg/base/delayed_init.h
new file mode 100644
index 000000000..a3257f54e
--- /dev/null
+++ b/toolsrc/include/vcpkg/base/delayed_init.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <vcpkg/base/optional.h>
+
+#include <memory>
+#include <mutex>
+
+namespace vcpkg
+{
+ // implements the equivalent of function static initialization for an object
+ template<class T>
+ struct DelayedInit
+ {
+ template<class F>
+ const T& get(F&& f) const
+ {
+ std::call_once(underlying_->flag_, [&f, this]() { underlying_->storage_ = std::forward<F>(f)(); });
+ return *underlying_->storage_.get();
+ }
+
+ private:
+ struct Storage
+ {
+ std::once_flag flag_;
+ Optional<T> storage_;
+ };
+ std::unique_ptr<Storage> underlying_ = std::make_unique<Storage>();
+ };
+}
diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h
index 1c5e8393f..3e56101c9 100644
--- a/toolsrc/include/vcpkg/base/files.h
+++ b/toolsrc/include/vcpkg/base/files.h
@@ -38,6 +38,7 @@ namespace fs
path u8path(vcpkg::StringView s);
inline path u8path(const char* first, const char* last) { return u8path(vcpkg::StringView{first, last}); }
+ inline path u8path(std::initializer_list<char> il) { return u8path(vcpkg::StringView{il.begin(), il.end()}); }
inline path u8path(const char* s) { return u8path(vcpkg::StringView{s, s + ::strlen(s)}); }
#if defined(_MSC_VER)
@@ -58,6 +59,9 @@ namespace fs
std::string u8string(const path& p);
std::string generic_u8string(const path& p);
+ // equivalent to p.lexically_normal()
+ path lexically_normal(const path& p);
+
#if defined(_WIN32)
enum class file_type
{
@@ -251,9 +255,6 @@ namespace vcpkg::Files
constexpr char preferred_separator = '/';
#endif // _WIN32
- // Adds file as a new path element to the end of base, with an additional slash if necessary
- std::string add_filename(StringView base, StringView file);
-
#if defined(_WIN32)
fs::path win32_fix_path_case(const fs::path& source);
#endif // _WIN32
diff --git a/toolsrc/include/vcpkg/base/jsonreader.h b/toolsrc/include/vcpkg/base/jsonreader.h
index 6518501a2..cdd0299d2 100644
--- a/toolsrc/include/vcpkg/base/jsonreader.h
+++ b/toolsrc/include/vcpkg/base/jsonreader.h
@@ -112,6 +112,24 @@ namespace vcpkg::Json
m_path.pop_back();
}
+ // value should be the value at key of the currently visited object
+ template<class Type>
+ void visit_at_index(const Value& value, int64_t index, Type& place, IDeserializer<Type>& visitor)
+ {
+ m_path.push_back(index);
+ auto opt = visitor.visit(*this, value);
+
+ if (auto p_opt = opt.get())
+ {
+ place = std::move(*p_opt);
+ }
+ else
+ {
+ add_expected_type_error(visitor.type_name());
+ }
+ m_path.pop_back();
+ }
+
// returns whether key \in obj
template<class Type>
bool optional_object_field(const Object& obj, StringView key, Type& place, IDeserializer<Type>& visitor)
@@ -167,8 +185,8 @@ namespace vcpkg::Json
}
};
- VCPKG_MSVC_WARNING(push);
- VCPKG_MSVC_WARNING(disable : 4505);
+ VCPKG_MSVC_WARNING(push)
+ VCPKG_MSVC_WARNING(disable : 4505)
template<class Type>
Optional<Type> IDeserializer<Type>::visit(Reader& r, const Value& value)
@@ -235,7 +253,7 @@ namespace vcpkg::Json
return nullopt;
}
- VCPKG_MSVC_WARNING(pop);
+ VCPKG_MSVC_WARNING(pop)
struct StringDeserializer final : IDeserializer<std::string>
{
diff --git a/toolsrc/include/vcpkg/base/optional.h b/toolsrc/include/vcpkg/base/optional.h
index 606d60ce5..c46c2e6f8 100644
--- a/toolsrc/include/vcpkg/base/optional.h
+++ b/toolsrc/include/vcpkg/base/optional.h
@@ -30,7 +30,7 @@ namespace vcpkg
constexpr OptionalStorage(const T& t) : m_is_present(true), m_t(t) { }
constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) { }
template<class U, class = std::enable_if_t<!std::is_reference<U>::value>>
- constexpr explicit OptionalStorage(Optional<U>&& t) : m_is_present(false), m_inactive()
+ explicit OptionalStorage(Optional<U>&& t) : m_is_present(false), m_inactive()
{
if (auto p = t.get())
{
@@ -39,7 +39,7 @@ namespace vcpkg
}
}
template<class U>
- constexpr explicit OptionalStorage(const Optional<U>& t) : m_is_present(false), m_inactive()
+ explicit OptionalStorage(const Optional<U>& t) : m_is_present(false), m_inactive()
{
if (auto p = t.get())
{
diff --git a/toolsrc/include/vcpkg/base/pragmas.h b/toolsrc/include/vcpkg/base/pragmas.h
index 73f14c4b2..06efd5105 100644
--- a/toolsrc/include/vcpkg/base/pragmas.h
+++ b/toolsrc/include/vcpkg/base/pragmas.h
@@ -25,6 +25,7 @@
#define ASSUME(expr)
#endif
+// the static_assert(true, "")s are to avoid the extra ';' warning
#ifdef _MSC_VER
#define VCPKG_MSVC_WARNING(...) __pragma(warning(__VA_ARGS__))
#define GCC_DIAGNOSTIC(...)
diff --git a/toolsrc/include/vcpkg/configurationdeserializer.h b/toolsrc/include/vcpkg/configurationdeserializer.h
index 83d3d0869..d6b239356 100644
--- a/toolsrc/include/vcpkg/configurationdeserializer.h
+++ b/toolsrc/include/vcpkg/configurationdeserializer.h
@@ -21,7 +21,7 @@ namespace vcpkg
constexpr static StringLiteral PATH = "path";
constexpr static StringLiteral KIND_BUILTIN = "builtin";
- constexpr static StringLiteral KIND_DIRECTORY = "directory";
+ constexpr static StringLiteral KIND_FILESYSTEM = "filesystem";
virtual StringView type_name() const override;
virtual View<StringView> valid_fields() const override;
diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h
index db135aa28..5e46a6194 100644
--- a/toolsrc/include/vcpkg/dependencies.h
+++ b/toolsrc/include/vcpkg/dependencies.h
@@ -172,7 +172,5 @@ namespace vcpkg::Dependencies
std::vector<std::string> features,
CMakeVars::CMakeVarProvider& var_provider);
- void print_plan(const ActionPlan& action_plan,
- const bool is_recursive = true,
- const fs::path& default_ports_dir = {});
+ void print_plan(const ActionPlan& action_plan, const bool is_recursive = true, const fs::path& vcpkg_root_dir = {});
}
diff --git a/toolsrc/include/vcpkg/registries.h b/toolsrc/include/vcpkg/registries.h
index 812bce86b..1f8c0f393 100644
--- a/toolsrc/include/vcpkg/registries.h
+++ b/toolsrc/include/vcpkg/registries.h
@@ -6,6 +6,8 @@
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/view.h>
+#include <vcpkg/versiont.h>
+
#include <memory>
#include <string>
#include <system_error>
@@ -13,9 +15,22 @@
namespace vcpkg
{
+ struct RegistryEntry
+ {
+ // returns fs::path() if version doesn't exist
+ virtual fs::path get_port_directory(const VcpkgPaths& paths, const VersionT& version) const = 0;
+
+ virtual ~RegistryEntry() = default;
+ };
+
struct RegistryImpl
{
- virtual fs::path get_registry_root(const VcpkgPaths& paths) const = 0;
+ // returns nullptr if the port doesn't exist
+ virtual std::unique_ptr<RegistryEntry> get_port_entry(const VcpkgPaths& paths, StringView port_name) const = 0;
+ // appends the names of the ports to the out parameter
+ virtual void get_all_port_names(std::vector<std::string>& port_names, const VcpkgPaths& paths) const = 0;
+
+ virtual Optional<VersionT> get_baseline_version(const VcpkgPaths& paths, StringView port_name) const = 0;
virtual ~RegistryImpl() = default;
};
diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h
index aa1ba92d7..def874e7c 100644
--- a/toolsrc/include/vcpkg/vcpkgpaths.h
+++ b/toolsrc/include/vcpkg/vcpkgpaths.h
@@ -86,7 +86,6 @@ namespace vcpkg
fs::path buildtrees;
fs::path downloads;
fs::path packages;
- fs::path ports;
fs::path installed;
fs::path triplets;
fs::path community_triplets;
@@ -128,6 +127,10 @@ namespace vcpkg
const FeatureFlagSettings& get_feature_flags() const;
void track_feature_flag_metrics() const;
+ // the directory of the builtin ports
+ // this should be used only for helper commands, not core commands like `install`.
+ fs::path builtin_ports_directory() const { return root / fs::u8path("ports"); }
+
private:
std::unique_ptr<details::VcpkgPathsImpl> m_pimpl;
};
diff --git a/toolsrc/include/vcpkg/versiont.h b/toolsrc/include/vcpkg/versiont.h
index 768ca0c47..506d7090a 100644
--- a/toolsrc/include/vcpkg/versiont.h
+++ b/toolsrc/include/vcpkg/versiont.h
@@ -1,4 +1,5 @@
#pragma once
+
#include <string>
namespace vcpkg
@@ -14,6 +15,8 @@ namespace vcpkg
friend bool operator==(const VersionT& left, const VersionT& right);
friend bool operator!=(const VersionT& left, const VersionT& right);
+ friend struct VersionTMapLess;
+
private:
std::string value;
int port_version;
@@ -29,4 +32,9 @@ namespace vcpkg
std::string to_string() const;
};
+
+ struct VersionTMapLess
+ {
+ bool operator()(const VersionT& left, const VersionT& right) const;
+ };
}