mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 11:37:12 +01:00

==== Changes Related to manifests ==== * Add the `manifests` feature flag * This only says whether we look for a `vcpkg.json` in the cwd, not whether we support parsing manifests (for ports, for example) * Changes to the manifests RFC * `"authors"` -> `"maintainers"` * `--x-classic-mode` -> `-manifests` \in `vcpkg_feature_flags` * reserve `"core"` in addition to `"default"`, since that's already reserved for features * Add a small helper note about what identifiers must look like * `<license-string>`: SPDX v3.8 -> v3.9 * `"feature"."description"` is allowed to be an array of strings as well * `"version"` -> `"version-string"` for forward-compat with versions RFC * Add the `--feature-flags` option * Add the ability to turn off feature flags via passing `-<feature-flag>` to `VCPKG_FEATURE_FLAGS` or `--feature-flags` * Add CMake toolchain support for manifests * Requires either: * a feature flag of `manifests` in either `Env{VCPKG_FEATURE_FLAGS}` or `VCPKG_FEATURE_FLAGS` * Passing the `VCPKG_ENABLE_MANIFESTS` option * The toolchain will install your packages to `${VCPKG_MANIFEST_DIR}/vcpkg_installed`. * Add MSBuild `vcpkg integrate install` support for manifests * Requires `VcpkgEnableManifest` to be true * `vcpkg create` creates a port that has a `vcpkg.json` instead of a `CONTROL` * argparse, abseil, 3fd, and avisynthplus ports switched to manifest from CONTROL * Add support for `--x-manifest-root`, as well as code for finding it if not passed * Add support for parsing manifests! * Add a filesystem lock! ==== Important Changes which are somewhat unrelated to manifests ==== * Rename `logicexpression.{h,cpp}` to `platform-expression.{h,cpp}` * Add `PlatformExpression` type which takes the place of the old logic expression * Split the parsing of platform expressions from checking whether they're true or not * Eagerly parse PlatformExpressions as opposed to leaving them as strings * Add checking for feature flag consistency * i.e., if `-binarycaching` is passed, you shouldn't be passing `--binarysource` * Add the `Json::Reader` type which, with the help of user-defined visitors, converts JSON to your internal type * VcpkgArgParser: place the switch names into a constant as opposed to using magic constants * In general update the parsing code so that this ^ works * Add `Port-Version` fields to CONTROL files * This replaces the existing practice of `Version: <my-version>-<port-version>` ==== Smaller changes ==== * small drive-by cleanups to some CMake * `${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}` -> `${CURRENT_INSTALLED_DIR}` * Remove `-analyze` when compiling with clang-cl, since that's not a supported flag (vcpkg's build system) * Add a message about which compiler is detected by vcpkg's build system machinery * Fix `Expected::then` * Convert `""` to `{}` for `std::string` and `fs::path`, to avoid a `strlen` (additionally, `.empty()` instead of `== ""`, and `.clear()`) * Add `Strings::strto` which converts strings to numeric types * Support built-in arrays and `StringView` for `Strings::join` * Add `operator<` and friends to `StringView` * Add `substr` to `StringView` * SourceParagraphParser gets some new errors
241 lines
6.3 KiB
C++
241 lines
6.3 KiB
C++
#pragma once
|
|
|
|
#include <vcpkg/base/checks.h>
|
|
#include <vcpkg/base/stringliteral.h>
|
|
|
|
#include <system_error>
|
|
|
|
namespace vcpkg
|
|
{
|
|
template<class Err>
|
|
struct ErrorHolder
|
|
{
|
|
ErrorHolder() : m_is_error(false), m_err{} {}
|
|
template<class U>
|
|
ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward<U>(err))
|
|
{
|
|
}
|
|
|
|
constexpr bool has_error() const { return m_is_error; }
|
|
|
|
const Err& error() const { return m_err; }
|
|
Err& error() { return m_err; }
|
|
|
|
StringLiteral to_string() const { return "value was error"; }
|
|
|
|
private:
|
|
bool m_is_error;
|
|
Err m_err;
|
|
};
|
|
|
|
template<>
|
|
struct ErrorHolder<std::string>
|
|
{
|
|
ErrorHolder() : m_is_error(false) { }
|
|
template<class U>
|
|
ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward<U>(err))
|
|
{
|
|
}
|
|
|
|
bool has_error() const { return m_is_error; }
|
|
|
|
const std::string& error() const { return m_err; }
|
|
std::string& error() { return m_err; }
|
|
|
|
const std::string& to_string() const { return m_err; }
|
|
|
|
private:
|
|
bool m_is_error;
|
|
std::string m_err;
|
|
};
|
|
|
|
template<>
|
|
struct ErrorHolder<std::error_code>
|
|
{
|
|
ErrorHolder() = default;
|
|
ErrorHolder(const std::error_code& err) : m_err(err) { }
|
|
|
|
bool has_error() const { return bool(m_err); }
|
|
|
|
const std::error_code& error() const { return m_err; }
|
|
std::error_code& error() { return m_err; }
|
|
|
|
std::string to_string() const { return m_err.message(); }
|
|
|
|
private:
|
|
std::error_code m_err;
|
|
};
|
|
|
|
struct ExpectedLeftTag
|
|
{
|
|
};
|
|
struct ExpectedRightTag
|
|
{
|
|
};
|
|
constexpr ExpectedLeftTag expected_left_tag;
|
|
constexpr ExpectedRightTag expected_right_tag;
|
|
|
|
template<class T>
|
|
struct ExpectedHolder
|
|
{
|
|
ExpectedHolder() = default;
|
|
ExpectedHolder(const T& t) : t(t) { }
|
|
ExpectedHolder(T&& t) : t(std::move(t)) { }
|
|
using pointer = T*;
|
|
using const_pointer = const T*;
|
|
T* get() { return &t; }
|
|
const T* get() const { return &t; }
|
|
T t;
|
|
};
|
|
template<class T>
|
|
struct ExpectedHolder<T&>
|
|
{
|
|
ExpectedHolder(T& t) : t(&t) { }
|
|
ExpectedHolder() : t(nullptr) { }
|
|
using pointer = T*;
|
|
using const_pointer = T*;
|
|
T* get() { return t; }
|
|
T* get() const { return t; }
|
|
T* t;
|
|
};
|
|
|
|
template<class T, class S>
|
|
class ExpectedT
|
|
{
|
|
public:
|
|
constexpr ExpectedT() = default;
|
|
|
|
// Constructors are intentionally implicit
|
|
|
|
ExpectedT(const S& s, ExpectedRightTag = {}) : m_s(s) { }
|
|
ExpectedT(S&& s, ExpectedRightTag = {}) : m_s(std::move(s)) { }
|
|
|
|
ExpectedT(const T& t, ExpectedLeftTag = {}) : m_t(t) { }
|
|
template<class = std::enable_if<!std::is_reference_v<T>>>
|
|
ExpectedT(T&& t, ExpectedLeftTag = {}) : 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.get());
|
|
}
|
|
|
|
const T& value_or_exit(const LineInfo& line_info) const&
|
|
{
|
|
exit_if_error(line_info);
|
|
return *this->m_t.get();
|
|
}
|
|
|
|
const S& error() const& { return this->m_s.error(); }
|
|
|
|
S&& error() && { return std::move(this->m_s.error()); }
|
|
|
|
typename ExpectedHolder<T>::const_pointer get() const
|
|
{
|
|
if (!this->has_value())
|
|
{
|
|
return nullptr;
|
|
}
|
|
return this->m_t.get();
|
|
}
|
|
|
|
typename ExpectedHolder<T>::pointer get()
|
|
{
|
|
if (!this->has_value())
|
|
{
|
|
return nullptr;
|
|
}
|
|
return this->m_t.get();
|
|
}
|
|
|
|
template<class F>
|
|
using map_t = decltype(std::declval<F&>()(*std::declval<typename ExpectedHolder<T>::const_pointer>()));
|
|
|
|
template<class F, class U = map_t<F>>
|
|
ExpectedT<U, S> map(F f) const&
|
|
{
|
|
if (has_value())
|
|
{
|
|
return {f(*m_t.get()), expected_left_tag};
|
|
}
|
|
else
|
|
{
|
|
return {error(), expected_right_tag};
|
|
}
|
|
}
|
|
|
|
template<class F>
|
|
using move_map_t =
|
|
decltype(std::declval<F&>()(std::move(*std::declval<typename ExpectedHolder<T>::pointer>())));
|
|
|
|
template<class F, class U = move_map_t<F>>
|
|
ExpectedT<U, S> map(F f) &&
|
|
{
|
|
if (has_value())
|
|
{
|
|
return {f(std::move(*m_t.get())), expected_left_tag};
|
|
}
|
|
else
|
|
{
|
|
return {std::move(*this).error(), expected_right_tag};
|
|
}
|
|
}
|
|
|
|
template<class F, class U = map_t<F>>
|
|
U then(F f) const&
|
|
{
|
|
if (has_value())
|
|
{
|
|
return f(*m_t.get());
|
|
}
|
|
else
|
|
{
|
|
return U{error(), expected_right_tag};
|
|
}
|
|
}
|
|
|
|
template<class F, class U = move_map_t<F>>
|
|
U then(F f) &&
|
|
{
|
|
if (has_value())
|
|
{
|
|
return f(std::move(*m_t.get()));
|
|
}
|
|
else
|
|
{
|
|
return U{std::move(*this).error(), expected_right_tag};
|
|
}
|
|
}
|
|
|
|
private:
|
|
void exit_if_error(const LineInfo& line_info) const
|
|
{
|
|
// This is used for quick value_or_exit() calls, so always put line_info in the error message.
|
|
Checks::check_exit(line_info,
|
|
!m_s.has_error(),
|
|
"Failed at [%s] with message:\n%s",
|
|
line_info.to_string(),
|
|
m_s.to_string());
|
|
}
|
|
|
|
ErrorHolder<S> m_s;
|
|
ExpectedHolder<T> m_t;
|
|
};
|
|
|
|
template<class T>
|
|
using Expected = ExpectedT<T, std::error_code>;
|
|
|
|
template<class T>
|
|
using ExpectedS = ExpectedT<T, std::string>;
|
|
}
|