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
61 changes: 36 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,25 @@ namespace vcpkg
return Optional<std::decay_t<U>>(std::forward<U>(u));
}

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

template<class T, class U>
auto operator!=(const Optional<T>& lhs, const U& rhs) -> decltype(!(lhs == rhs))
{
if (auto p = o.get()) return *p != t;
return true;
return !(lhs == rhs);
}
template<class T>
bool operator!=(const T& t, const Optional<T>& o)
template<class T, class U>
auto operator!=(const T& lhs, const Optional<U>& rhs) -> decltype(!(lhs == rhs))
{
if (auto p = o.get()) return t != *p;
return true;
return !(lhs == rhs);
}
}
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 registry_location() const;
};

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

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

struct ConfigurationAndLocation
{
Configuration config;
Path directory;
ConfigurationLocation location = ConfigurationLocation::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 ConfigurationAndLocation;
struct RegistryConfig;
struct ManifestConfiguration;
}
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 ManifestAndLocation
{
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 ManifestAndLocation&> get_manifest() const;
const ConfigurationAndLocation& get_configuration() const;
const RegistrySet& get_registry_set() const;

// Retrieve a toolset matching the requirements in prebuildinfo
Expand Down
8 changes: 8 additions & 0 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
"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.",
"UpdateBaselineGitError": "git failed to fetch remote repository {url}",
"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}",
"UpdateBaselineUpdatedBaseline": "updated registry '{url}': baseline {old_value} -> {new_value}",
"UpdateCommandDidYouMean": "Did you mean `vcpkg x-update-baseline`?",
"UpdateCommandNoManifestMode": "Error: the update command does not support manifest mode.",
"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",
"UpdateBaselineGitError": "git failed to fetch remote repository {url}",
"_UpdateBaselineGitError.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\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",
"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",
"UpdateCommandDidYouMean": "Did you mean `vcpkg x-update-baseline`?",
"UpdateCommandNoManifestMode": "Error: the update command does not support manifest mode.",
"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
5 changes: 2 additions & 3 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ namespace vcpkg::Commands
specs.push_back(std::move(value));
}

const auto& manifest_path = paths.get_manifest_path().value_or_exit(VCPKG_LINE_INFO);
auto maybe_manifest_scf = SourceControlFile::parse_manifest_object(manifest_path, *manifest);
auto maybe_manifest_scf = SourceControlFile::parse_manifest_object(manifest->path, manifest->manifest);
if (!maybe_manifest_scf)
{
print_error_message(maybe_manifest_scf.error());
Expand Down Expand Up @@ -124,7 +123,7 @@ namespace vcpkg::Commands
}

paths.get_filesystem().write_contents(
manifest_path, Json::stringify(serialize_manifest(manifest_scf), {}), VCPKG_LINE_INFO);
manifest->path, Json::stringify(serialize_manifest(manifest_scf), {}), VCPKG_LINE_INFO);
msg::println(msgAddPortSucceded);
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
3 changes: 3 additions & 0 deletions src/vcpkg/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <vcpkg/commands.regenerate.h>
#include <vcpkg/commands.search.h>
#include <vcpkg/commands.setinstalled.h>
#include <vcpkg/commands.update-baseline.h>
#include <vcpkg/commands.upgrade.h>
#include <vcpkg/commands.upload-metrics.h>
#include <vcpkg/commands.use.h>
Expand Down Expand Up @@ -103,6 +104,7 @@ namespace vcpkg::Commands
static const RegenerateCommand regenerate{};
static const SearchCommand search{};
static const Update::UpdateCommand update{};
static const UpdateBaselineCommand update_baseline{};
static const UseCommand use{};
static const X_VSInstances::VSInstancesCommand vsinstances{};
static const ZCeCommand ce{};
Expand All @@ -126,6 +128,7 @@ namespace vcpkg::Commands
{"portsdiff", &portsdiff},
{"search", &search},
{"update", &update},
{"x-update-baseline", &update_baseline},
{"use", &use},
{"x-add-version", &add_version},
{"x-ci-clean", &ciclean},
Expand Down
Loading