Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x-update-baseline] Initial implementation #341

Merged
merged 14 commits into from
Apr 19, 2022
11 changes: 8 additions & 3 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ namespace vcpkg
return lhs.data() >= rhs.data();
}

bool empty() { return m_data.empty(); }
void clear() { m_data.clear(); }

private:
std::string m_data;

Expand Down Expand Up @@ -244,6 +247,8 @@ namespace vcpkg::msg
DECLARE_MSG_ARG(expected, "");
DECLARE_MSG_ARG(actual, "");
DECLARE_MSG_ARG(list, "");
DECLARE_MSG_ARG(old_value, "");
DECLARE_MSG_ARG(new_value, "");

DECLARE_MSG_ARG(actual_version, "1.3.8");
DECLARE_MSG_ARG(arch, "x64");
Expand Down Expand Up @@ -314,10 +319,10 @@ namespace vcpkg::msg

inline void print_warning(const LocalizedString& s)
{
print(Color::warning, format(msgErrorMessage).append(s).appendnl());
print(Color::warning, format(msgWarningMessage).append(s).appendnl());
}
template<class Message, class... Ts>
void print_warning(Message m, Ts... args)
typename Message::is_message_type print_warning(Message m, Ts... args)
{
print(Color::warning, format(msgWarningMessage).append(format(m, args...).appendnl()));
}
Expand All @@ -327,7 +332,7 @@ namespace vcpkg::msg
print(Color::error, format(msgErrorMessage).append(s).appendnl());
}
template<class Message, class... Ts>
void print_error(Message m, Ts... args)
typename Message::is_message_type print_error(Message m, Ts... args)
{
print(Color::error, format(msgErrorMessage).append(format(m, args...).appendnl()));
}
Expand Down
80 changes: 55 additions & 25 deletions include/vcpkg/base/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ namespace vcpkg
const T& value() const { return this->m_t; }
T& value() { return this->m_t; }

const T* get() const& { return m_is_present ? &m_t : nullptr; }
T* get() & { return m_is_present ? &m_t : nullptr; }
const T* get() const&& = delete;
T* get() && = delete;

void destroy()
{
m_is_present = false;
Expand Down Expand Up @@ -180,6 +185,11 @@ namespace vcpkg
const T& value() const { return this->m_t; }
T& value() { return this->m_t; }

const T* get() const& { return m_is_present ? &m_t : nullptr; }
T* get() & { return m_is_present ? &m_t : nullptr; }
const T* get() const&& = delete;
T* get() && = delete;

template<class... Args>
T& emplace(Args&&... args)
{
Expand Down Expand Up @@ -228,6 +238,8 @@ namespace vcpkg
return *m_t;
}

T* get() const { return m_t; }

private:
T* m_t;
};
Expand All @@ -246,6 +258,8 @@ namespace vcpkg

const T& value() const { return *this->m_t; }

const T* get() const { return m_t; }

const T& emplace(const T& t)
{
m_t = &t;
Expand All @@ -260,6 +274,10 @@ namespace vcpkg
template<class T>
struct Optional
{
private:
details::OptionalStorage<T> m_base;

public:
constexpr Optional() noexcept { }

// Constructors are intentionally implicit
Expand Down Expand Up @@ -320,12 +338,11 @@ namespace vcpkg
return this->m_base.has_value() ? std::move(this->m_base.value()) : static_cast<T&&>(default_value);
}

typename std::add_pointer<const T>::type get() const
{
return this->m_base.has_value() ? &this->m_base.value() : nullptr;
}

typename std::add_pointer<T>::type get() { return this->m_base.has_value() ? &this->m_base.value() : nullptr; }
// this allows us to error out when `.get()` would return a pointer to a temporary
decltype(auto) get() const& { return this->m_base.get(); }
decltype(auto) get() & { return this->m_base.get(); }
decltype(auto) get() const&& { return std::move(this->m_base).get(); }
decltype(auto) get() && { return std::move(this->m_base).get(); }

template<class F>
using map_t = decltype(std::declval<F&>()(std::declval<const T&>()));
Expand Down Expand Up @@ -396,9 +413,6 @@ namespace vcpkg
return !rhs.m_base.has_value();
}
friend bool operator!=(const Optional& lhs, const Optional& rhs) noexcept { return !(lhs == rhs); }

private:
details::OptionalStorage<T> m_base;
};

template<class U>
Expand All @@ -407,28 +421,44 @@ namespace vcpkg
return Optional<std::decay_t<U>>(std::forward<U>(u));
}

template<class T>
bool operator==(const Optional<T>& o, const T& t)
// these cannot be hidden friends, unfortunately
template<class T, class U>
auto operator==(const Optional<T>& lhs, const Optional<U>& rhs) -> decltype(*lhs.get() == *rhs.get())
{
if (auto p = o.get()) return *p == t;
return false;
if (lhs.has_value() && rhs.has_value())
{
return *lhs.get() == *rhs.get();
}
return lhs.has_value() == rhs.has_value();
}
template<class T>
bool operator==(const T& t, const Optional<T>& o)
template<class T, class U>
auto operator==(const Optional<T>& lhs, const U& rhs) -> decltype(*lhs.get() == rhs)
{
if (auto p = o.get()) return t == *p;
return false;
return lhs.has_value() ? *lhs.get() == rhs : false;
}
template<class T>
bool operator!=(const Optional<T>& o, const T& t)
template<class T, class U>
auto operator==(const T& lhs, const Optional<U>& rhs) -> decltype(lhs == *rhs.get())
{
if (auto p = o.get()) return *p != t;
return true;
return rhs.has_value() ? lhs == *rhs.get() : false;
}
template<class T>
bool operator!=(const T& t, const Optional<T>& o)

template<class T, class U>
auto operator!=(const Optional<T>& lhs, const Optional<U>& rhs) -> decltype(*lhs.get() != *rhs.get())
{
if (lhs.has_value() && rhs.has_value())
{
return *lhs.get() != *rhs.get();
}
return lhs.has_value() != rhs.has_value();
}
template<class T, class U>
auto operator!=(const Optional<T>& lhs, const U& rhs) -> decltype(*lhs.get() != rhs)
{
return lhs.has_value() ? *lhs.get() != rhs : true;
}
template<class T, class U>
auto operator!=(const T& lhs, const Optional<U>& rhs) -> decltype(lhs != *rhs.get())
{
if (auto p = o.get()) return t != *p;
return true;
return rhs.has_value() ? lhs != *rhs.get() : true;
}
}
11 changes: 11 additions & 0 deletions include/vcpkg/commands.update-baseline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands
{
struct UpdateBaselineCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
22 changes: 22 additions & 0 deletions include/vcpkg/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace vcpkg
Optional<std::vector<std::string>> packages;

Json::Value serialize() const;

ExpectedL<Optional<std::string>> get_latest_baseline(const VcpkgPaths& paths) const;
StringView pretty_location() const;
};

struct Configuration
Expand All @@ -42,6 +45,25 @@ namespace vcpkg
static View<StringView> known_fields();
};

enum class ConfigurationSource
{
None,
VcpkgConfigurationFile,
ManifestFile,
};

struct ConfigurationAndSource
{
Configuration config;
Path directory;
ConfigurationSource source = ConfigurationSource::None;

std::unique_ptr<RegistrySet> instantiate_registry_set(const VcpkgPaths& paths) const
{
return config.instantiate_registry_set(paths, directory);
}
};

struct ManifestConfiguration
{
Optional<std::string> builtin_baseline;
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/fwd/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace vcpkg
{
struct Configuration;
struct ConfigurationAndSource;
struct RegistryConfig;
struct ManifestConfiguration;
}
2 changes: 2 additions & 0 deletions include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace vcpkg
{
constexpr StringLiteral builtin_registry_git_url() { return "https://github.com/microsoft/vcpkg"; }

struct LockFile
{
struct EntryData
Expand Down
10 changes: 8 additions & 2 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ namespace vcpkg
struct PackageSpec;
struct Triplet;

struct ManifestAndPath
{
Json::Object manifest;
Path path;
};

struct VcpkgPaths
{
struct TripletFile
Expand Down Expand Up @@ -147,8 +153,8 @@ namespace vcpkg
const Path& relative_path_to_file) const;
ExpectedS<Path> git_checkout_object_from_remote_registry(StringView tree) const;

Optional<const Json::Object&> get_manifest() const;
Optional<const Path&> get_manifest_path() const;
Optional<const ManifestAndPath&> get_manifest() const;
const ConfigurationAndSource& get_configuration() const;
const RegistrySet& get_registry_set() const;

// Retrieve a toolset matching the requirements in prebuildinfo
Expand Down
7 changes: 7 additions & 0 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
"UnknownBaselineFileContent": "unrecognizable baseline entry; expected 'port:triplet=(fail|skip)'",
"UnsupportedSystemName": "Error: Could not map VCPKG_CMAKE_SYSTEM_NAME '{system_name}' to a vcvarsall platform. Supported system names are '', 'Windows' and 'WindowsStore'.",
"UnsupportedToolchain": "Error: in triplet {triplet}: Unable to find a valid toolchain combination.\n The requested target architecture was {arch}\n The selected Visual Studio instance is at {path}\n The available toolchain combinations are {list}\n",
"UpdateBaselineAddBaselineNoManifest": "the --{option} switch was passed, but there is no manifest file to add a `builtin-baseline` field to.",
"UpdateBaselineLocalGitError": "git failed to parse HEAD for the local vcpkg registry at '{path}'",
"UpdateBaselineNoConfiguration": "neither `vcpkg.json` nor `vcpkg-configuration.json` exist to update.",
"UpdateBaselineNoExistingBuiltinBaseline": "the manifest file currently does not contain a `builtin-baseline` field; in order to add one, pass the --{option} switch.",
"UpdateBaselineNoUpdate": "registry '{url}' not updated: '{value}'",
"UpdateBaselineRemoteGitError": "git failed to fetch remote repository '{url}'",
"UpdateBaselineUpdatedBaseline": "updated registry '{url}': baseline '{old_value}' -> '{new_value}'",
"UploadedPackagesToVendor": "Uploaded {count} package(s) to {vendor} in {elapsed}",
"UsingManifestAt": "Using manifest file at {path}.",
"Utf8DecoderDereferencedAtEof": "dereferenced Utf8Decoder at the end of a string.",
Expand Down
13 changes: 13 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
"_UnsupportedSystemName.comment": "example of {system_name} is 'Darwin'.\n",
"UnsupportedToolchain": "Error: in triplet {triplet}: Unable to find a valid toolchain combination.\n The requested target architecture was {arch}\n The selected Visual Studio instance is at {path}\n The available toolchain combinations are {list}\n",
"_UnsupportedToolchain.comment": "example for {list} is 'x86, arm64'\nexample of {triplet} is 'x64-windows'.\nexample of {arch} is 'x64'.\nexample of {path} is '/foo/bar'.\n",
"UpdateBaselineAddBaselineNoManifest": "the --{option} switch was passed, but there is no manifest file to add a `builtin-baseline` field to.",
"_UpdateBaselineAddBaselineNoManifest.comment": "example of {option} is 'editable'.\n",
"UpdateBaselineLocalGitError": "git failed to parse HEAD for the local vcpkg registry at '{path}'",
"_UpdateBaselineLocalGitError.comment": "example of {path} is '/foo/bar'.\n",
"UpdateBaselineNoConfiguration": "neither `vcpkg.json` nor `vcpkg-configuration.json` exist to update.",
"UpdateBaselineNoExistingBuiltinBaseline": "the manifest file currently does not contain a `builtin-baseline` field; in order to add one, pass the --{option} switch.",
"_UpdateBaselineNoExistingBuiltinBaseline.comment": "example of {option} is 'editable'.\n",
"UpdateBaselineNoUpdate": "registry '{url}' not updated: '{value}'",
"_UpdateBaselineNoUpdate.comment": "example of {value} is '5507daa796359fe8d45418e694328e878ac2b82f'\nexample of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"UpdateBaselineRemoteGitError": "git failed to fetch remote repository '{url}'",
"_UpdateBaselineRemoteGitError.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"UpdateBaselineUpdatedBaseline": "updated registry '{url}': baseline '{old_value}' -> '{new_value}'",
"_UpdateBaselineUpdatedBaseline.comment": "example of {old_value}, {new_value} is '5507daa796359fe8d45418e694328e878ac2b82f'\nexample of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"UploadedPackagesToVendor": "Uploaded {count} package(s) to {vendor} in {elapsed}",
"_UploadedPackagesToVendor.comment": "example of {count} is '42'.\nexample of {elapsed} is '3.532 min'.\nexample of {vendor} is 'Azure'.\n",
"UsingManifestAt": "Using manifest file at {path}.",
Expand Down
1 change: 1 addition & 0 deletions src/vcpkg-test/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ TEST_CASE ("list of commands is correct", "[commands]")
"remove",
"search",
"update",
"x-update-baseline",
"upgrade",
"use",
"version",
Expand Down
Loading