Skip to content

Commit

Permalink
add messages!
Browse files Browse the repository at this point in the history
```
PS /../nimazzuc/projects/testproj> ../vcpkg-tool/build/vcpkg x-update-baseline --dry-run
registry 'https://github.com/microsoft/vcpkg' already up to date: 89295c9
registry '/a/b' not updated: default
registry 'https://foobar' not updated: default
warning: git failed to fetch remote repository https://foobar
Error: Failed to fetch ref HEAD from repository https://foobar.
fatal: unable to access 'https://foobar/': Could not resolve host: foobar
```
  • Loading branch information
strega-nil committed Apr 6, 2022
1 parent 5507daa commit 3905cc9
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 26 deletions.
2 changes: 2 additions & 0 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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
1 change: 1 addition & 0 deletions include/vcpkg/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace vcpkg
Json::Value serialize() const;

Optional<std::string> get_latest_baseline(const VcpkgPaths& paths, LocalizedString& error) const;
StringView registry_location() const;
};

struct Configuration
Expand Down
9 changes: 7 additions & 2 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,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",
"UpdateBaselineGitError": "Git failed to fetch remote repository {url}:",
"UpdateBaselineNoConfiguration": "There is no configuration file to update.",
"UpdateBaselineAddBaselineNoManifest": "the --{option} switch was passed, but there is no manifest file to add a `builtin-baseline` field to.",
"UpdateBaselineAlreadyUpToDate": "registry '{url}' already up to date: {value}",
"UpdateBaselineGitError": "git failed to fetch remote repository {url}",
"UpdateBaselineNoConfiguration": "there is no `vcpkg-configuration.json` nor manifest file 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}",
Expand Down
14 changes: 12 additions & 2 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,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",
"UpdateBaselineGitError": "Git failed to fetch remote repository {url}:",
"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",
"UpdateBaselineAlreadyUpToDate": "registry '{url}' already up to date: {value}",
"_UpdateBaselineAlreadyUpToDate.comment": "example of {value} is '5507daa796359fe8d45418e694328e878ac2b82f'\nexample of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"UpdateBaselineGitError": "git failed to fetch remote repository {url}",
"_UpdateBaselineGitError.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"UpdateBaselineNoConfiguration": "There is no configuration file to update.",
"UpdateBaselineNoConfiguration": "there is no `vcpkg-configuration.json` nor manifest file 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}",
Expand Down
83 changes: 69 additions & 14 deletions src/vcpkg/commands.update-baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@ namespace
(msg::option),
"",
"the --{option} switch was passed, but there is no manifest file to add a `builtin-baseline` field to.");

DECLARE_AND_REGISTER_MESSAGE(UpdateBaselineUpdatedBaseline,
(msg::url, msg::old_value, msg::new_value),
"example of {old_value}, {new_value} is '5507daa796359fe8d45418e694328e878ac2b82f'",
"updated registry '{url}': baseline {old_value} -> {new_value}");
DECLARE_AND_REGISTER_MESSAGE(UpdateBaselineAlreadyUpToDate,
(msg::url, msg::value),
"example of {value} is '5507daa796359fe8d45418e694328e878ac2b82f'",
"registry '{url}' already up to date: {value}");
DECLARE_AND_REGISTER_MESSAGE(UpdateBaselineNoUpdate,
(msg::url, msg::value),
"example of {value} is '5507daa796359fe8d45418e694328e878ac2b82f'",
"registry '{url}' not updated: {value}");
}

namespace vcpkg::Commands
{
static constexpr StringLiteral OPTION_ADD_INITIAL_BASELINE = "add-initial-baseline";
static constexpr StringLiteral OPTION_DRY_RUN = "dry-run";

static constexpr CommandSwitch switches[] = {
{OPTION_ADD_INITIAL_BASELINE, "add a `builtin-baseline` to a vcpkg.json that doesn't already have it"},
{OPTION_DRY_RUN, "Print out plan without execution"},
};

static const CommandStructure COMMAND_STRUCTURE{
Expand All @@ -41,23 +56,51 @@ namespace vcpkg::Commands
{switches},
};

static void print_update_message(StringView url,
Optional<StringView> p_old_baseline,
const Optional<std::string>& new_baseline)
{
auto old_baseline = p_old_baseline.value_or("none");
if (auto p = new_baseline.get())
{
if (p_old_baseline.has_value() && *p == old_baseline)
{
msg::println(msgUpdateBaselineAlreadyUpToDate, msg::url = url, msg::value = old_baseline);
}
else
{
msg::println(msgUpdateBaselineUpdatedBaseline,
msg::url = url,
msg::old_value = old_baseline,
msg::new_value = *p);
}
}
else
{
msg::println(msgUpdateBaselineNoUpdate, msg::url = url, msg::value = old_baseline);
}
}

void UpdateBaselineCommand::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const
{
auto options = args.parse_arguments(COMMAND_STRUCTURE);

const bool add_builtin_baseline = Util::Sets::contains(options.switches, OPTION_ADD_INITIAL_BASELINE);
const bool dry_run = Util::Sets::contains(options.switches, OPTION_DRY_RUN);

auto configuration = paths.get_configuration();
auto p_manifest = paths.get_manifest().get();
const bool has_manifest = paths.get_manifest().has_value();
auto manifest = has_manifest ? *paths.get_manifest().get() : ManifestAndLocation{};

if (configuration.location == ConfigurationLocation::None && !p_manifest)
if (configuration.location == ConfigurationLocation::None && !has_manifest)
{
msg::print_warning(msgUpdateBaselineNoConfiguration);
Checks::exit_success(VCPKG_LINE_INFO);
}

bool has_builtin_baseline = p_manifest && p_manifest->manifest.contains("builtin-baseline");
bool add_builtin_baseline = Util::Sets::contains(options.switches, OPTION_ADD_INITIAL_BASELINE);
bool has_builtin_baseline = manifest.manifest.contains("builtin-baseline");

if (add_builtin_baseline && !p_manifest)
if (add_builtin_baseline && !has_manifest)
{
Checks::msg_exit_with_error(
VCPKG_LINE_INFO, msgUpdateBaselineAddBaselineNoManifest, msg::option = OPTION_ADD_INITIAL_BASELINE);
Expand All @@ -68,30 +111,38 @@ namespace vcpkg::Commands
Checks::exit_success(VCPKG_LINE_INFO);
}

auto updated_configuration = configuration.config;
auto updated_manifest = p_manifest ? p_manifest->manifest : Json::Object{};
LocalizedString error;

if (has_builtin_baseline || add_builtin_baseline)
{
// remove default_reg, since that's filled in with the builtin-baseline
configuration.config.default_reg = nullopt;

auto synthesized_registry = RegistryConfig{};
synthesized_registry.kind = "builtin";

auto result = synthesized_registry.get_latest_baseline(paths, error);

auto p_builtin_baseline = manifest.manifest.get("builtin-baseline");
auto old_baseline = p_builtin_baseline ? Optional<StringView>(p_builtin_baseline->string()) : nullopt;
print_update_message(synthesized_registry.registry_location(), old_baseline, result);

if (auto p = result.get())
{
updated_manifest.insert_or_replace("builtin-baseline", *p);
manifest.manifest.insert_or_replace("builtin-baseline", std::move(*p));
}
else if (!error.empty())
{
msg::print_warning(error);
}
}

if (auto default_reg = updated_configuration.default_reg.get())
if (auto default_reg = configuration.config.default_reg.get())
{
auto new_baseline = default_reg->get_latest_baseline(paths, error);

print_update_message(default_reg->registry_location(), default_reg->baseline, new_baseline);

if (auto p = new_baseline.get())
{
default_reg->baseline = std::move(*p);
Expand All @@ -102,9 +153,12 @@ namespace vcpkg::Commands
}
}

for (auto& reg : updated_configuration.registries)
for (auto& reg : configuration.config.registries)
{
auto new_baseline = reg.get_latest_baseline(paths, error);

print_update_message(reg.registry_location(), reg.baseline, new_baseline);

if (auto p = new_baseline.get())
{
reg.baseline = std::move(*p);
Expand All @@ -117,19 +171,20 @@ namespace vcpkg::Commands

if (configuration.location == ConfigurationLocation::ManifestFile)
{
updated_manifest.insert_or_replace("vcpkg-configuration", updated_configuration.serialize());
manifest.manifest.insert_or_replace("vcpkg-configuration", configuration.config.serialize());
}
else if (configuration.location == ConfigurationLocation::VcpkgConfigurationFile)

if (!dry_run && configuration.location == ConfigurationLocation::VcpkgConfigurationFile)
{
paths.get_filesystem().write_contents(configuration.directory / "vcpkg-configuration.json",
Json::stringify(configuration.config.serialize(), {}),
VCPKG_LINE_INFO);
}

if (p_manifest)
if (!dry_run && has_manifest)
{
paths.get_filesystem().write_contents(
p_manifest->path, Json::stringify(updated_manifest, {}), VCPKG_LINE_INFO);
manifest.path, Json::stringify(manifest.manifest, {}), VCPKG_LINE_INFO);
}

Checks::exit_success(VCPKG_LINE_INFO);
Expand Down
37 changes: 29 additions & 8 deletions src/vcpkg/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ namespace
{
using namespace vcpkg;

DECLARE_AND_REGISTER_MESSAGE(UpdateBaselineGitError,
(msg::url),
"",
"Git failed to fetch remote repository {url}:");
DECLARE_AND_REGISTER_MESSAGE(UpdateBaselineGitError, (msg::url), "", "git failed to fetch remote repository {url}");

struct RegistryConfigDeserializer : Json::IDeserializer<RegistryConfig>
{
Expand Down Expand Up @@ -551,15 +548,17 @@ namespace vcpkg
}
else
{
error = msg::format(msgUpdateBaselineGitError, msg::url = url);
error = msg::format(msgUpdateBaselineGitError, msg::url = url)
.appendnl()
.append_raw(Strings::trim(res.error()));
return nullopt;
}
}

static constexpr StringLiteral BUILTIN_GIT_URL = "https://github.com/microsoft/vcpkg";

Optional<std::string> RegistryConfig::get_latest_baseline(const VcpkgPaths& paths, LocalizedString& error) const
{
static constexpr StringLiteral builtin_git_url = "https://github.com/microsoft/vcpkg";

error.clear();

if (kind == RegistryConfigDeserializer::KIND_GIT)
Expand All @@ -568,14 +567,36 @@ namespace vcpkg
}
else if (kind == RegistryConfigDeserializer::KIND_BUILTIN)
{
return get_baseline_from_git_repo(paths, builtin_git_url, error);
return get_baseline_from_git_repo(paths, BUILTIN_GIT_URL, error);
}
else
{
return nullopt;
}
}

StringView RegistryConfig::registry_location() const
{
if (kind == RegistryConfigDeserializer::KIND_BUILTIN)
{
return BUILTIN_GIT_URL;
}
if (kind == RegistryConfigDeserializer::KIND_FILESYSTEM)
{
return path.value_or_exit(VCPKG_LINE_INFO);
}
if (kind == RegistryConfigDeserializer::KIND_GIT)
{
return repo.value_or_exit(VCPKG_LINE_INFO);
}
if (kind == RegistryConfigDeserializer::KIND_ARTIFACT)
{
return location.value_or_exit(VCPKG_LINE_INFO);
}

Checks::unreachable(VCPKG_LINE_INFO);
}

View<StringView> Configuration::known_fields()
{
static constexpr StringView known_fields[]{
Expand Down

0 comments on commit 3905cc9

Please sign in to comment.