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

Make registries distinguish between 'baseline is broken' and 'baseline missing'. #1203

Merged
merged 7 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ DECLARE_MESSAGE(BaselineFileNoDefaultField,
(msg::commit_sha),
"",
"The baseline file at commit {commit_sha} was invalid (no \"default\" field).")
DECLARE_MESSAGE(BaselineFileNoDefaultFieldPath,
(msg::path),
"",
"baseline file at {path} was invalid (no \"default\" field)")
DECLARE_MESSAGE(BaselineGitShowFailed,
(msg::commit_sha),
"",
Expand All @@ -297,11 +293,6 @@ DECLARE_MESSAGE(BaselineMissing,
"git add versions\n"
"git commit -m \"Update version database\"\n"
"to set {version} as the baseline version.")
DECLARE_MESSAGE(BaselineMissingDefault,
(msg::commit_sha, msg::url),
"",
"The baseline.json from commit `\"{commit_sha}\"` in the repo {url} was invalid (did not "
"contain a \"default\" field).")
DECLARE_MESSAGE(BinaryCacheVendorHTTP, (), "", "HTTP servers")
DECLARE_MESSAGE(BinarySourcesArg,
(),
Expand Down Expand Up @@ -911,10 +902,6 @@ DECLARE_MESSAGE(CouldNotDeduceNugetIdAndVersion,
(msg::path),
"",
"Could not deduce nuget id and version from filename: {path}")
DECLARE_MESSAGE(CouldNotFindBaseline,
(msg::commit_sha, msg::path),
"",
"Could not find explicitly specified baseline `\"{commit_sha}\"` in baseline file {path}")
DECLARE_MESSAGE(CouldNotFindBaselineInCommit,
(msg::url, msg::commit_sha, msg::package_name),
"",
Expand Down Expand Up @@ -1223,7 +1210,6 @@ DECLARE_MESSAGE(FailedToDetermineCurrentCommit, (), "", "Failed to determine the
DECLARE_MESSAGE(FailedToDownloadFromMirrorSet, (), "", "Failed to download from mirror set")
DECLARE_MESSAGE(FailedToExtract, (msg::path), "", "Failed to extract \"{path}\":")
DECLARE_MESSAGE(FailedToFetchRepo, (msg::url), "", "Failed to fetch {url}.")
DECLARE_MESSAGE(FailedToFindBaseline, (), "", "Failed to find baseline.json")
DECLARE_MESSAGE(FailedToFindPortFeature,
(msg::feature, msg::package_name),
"",
Expand Down
12 changes: 3 additions & 9 deletions include/vcpkg/paragraphparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ namespace vcpkg
template<class P>
using ParseExpected = vcpkg::ExpectedT<std::unique_ptr<P>, std::unique_ptr<ParseControlErrorInfo>>;

template<class P>
ExpectedL<std::unique_ptr<P>> map_parse_expected_to_localized_string(ParseExpected<P>&& parse_expected)
static constexpr struct ToLocalizedString_t
{
if (auto value = parse_expected.get())
{
return std::move(*value);
}

return LocalizedString::from_raw(parse_expected.error()->to_string());
}
LocalizedString operator()(std::unique_ptr<ParseControlErrorInfo> p) const;
} ToLocalizedString;

using Paragraph = std::map<std::string, std::pair<std::string, TextRowCol>, std::less<>>;

Expand Down
7 changes: 0 additions & 7 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@
"BaselineConflict": "Specifying vcpkg-configuration.default-registry in a manifest file conflicts with built-in baseline.\nPlease remove one of these conflicting settings.",
"BaselineFileNoDefaultField": "The baseline file at commit {commit_sha} was invalid (no \"default\" field).",
"_BaselineFileNoDefaultField.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
"BaselineFileNoDefaultFieldPath": "baseline file at {path} was invalid (no \"default\" field)",
"_BaselineFileNoDefaultFieldPath.comment": "An example of {path} is /foo/bar.",
"BaselineGitShowFailed": "while checking out baseline from commit '{commit_sha}', failed to `git show` versions/baseline.json. This may be fixed by fetching commits with `git fetch`.",
"_BaselineGitShowFailed.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
"BaselineMissing": "Baseline version not found. Run:\nvcpkg x-add-version {package_name}\ngit add versions\ngit commit -m \"Update version database\"\nto set {version} as the baseline version.",
"_BaselineMissing.comment": "An example of {package_name} is zlib. An example of {version} is 1.3.8.",
"BaselineMissingDefault": "The baseline.json from commit `\"{commit_sha}\"` in the repo {url} was invalid (did not contain a \"default\" field).",
"_BaselineMissingDefault.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949. An example of {url} is https://github.com/microsoft/vcpkg.",
"BinaryCacheVendorHTTP": "HTTP servers",
"BinarySourcesArg": "Binary caching sources. See 'vcpkg help binarycaching'",
"_BinarySourcesArg.comment": "'vcpkg help binarycaching' is a command line and should not be localized",
Expand Down Expand Up @@ -534,8 +530,6 @@
"CorruptedInstallTree": "Your vcpkg 'installed' tree is corrupted.",
"CouldNotDeduceNugetIdAndVersion": "Could not deduce nuget id and version from filename: {path}",
"_CouldNotDeduceNugetIdAndVersion.comment": "An example of {path} is /foo/bar.",
"CouldNotFindBaseline": "Could not find explicitly specified baseline `\"{commit_sha}\"` in baseline file {path}",
"_CouldNotFindBaseline.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949. An example of {path} is /foo/bar.",
"CouldNotFindBaselineInCommit": "Couldn't find baseline in {url} at {commit_sha} for {package_name}.",
"_CouldNotFindBaselineInCommit.comment": "An example of {url} is https://github.com/microsoft/vcpkg. An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949. An example of {package_name} is zlib.",
"CouldNotFindGitTreeAtCommit": "could not find the git tree for `versions` in repo {package_name} at commit {commit_sha}",
Expand Down Expand Up @@ -742,7 +736,6 @@
"_FailedToExtract.comment": "An example of {path} is /foo/bar.",
"FailedToFetchRepo": "Failed to fetch {url}.",
"_FailedToFetchRepo.comment": "An example of {url} is https://github.com/microsoft/vcpkg.",
"FailedToFindBaseline": "Failed to find baseline.json",
"FailedToFindPortFeature": "{package_name} has no feature named {feature}.",
"_FailedToFindPortFeature.comment": "An example of {feature} is avisynthplus. An example of {package_name} is zlib.",
"FailedToFormatMissingFile": "No files to format.\nPlease pass either --all, or the explicit files to format or convert.",
Expand Down
62 changes: 23 additions & 39 deletions src/vcpkg/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ namespace vcpkg
return result;
}

LocalizedString ToLocalizedString_t::operator()(std::unique_ptr<ParseControlErrorInfo> p) const
{
return LocalizedString::from_raw(p->to_string());
}

std::unique_ptr<ParseControlErrorInfo> ParseControlErrorInfo::from_error(StringView name, LocalizedString&& ls)
{
auto error_info = std::make_unique<ParseControlErrorInfo>();
Expand Down Expand Up @@ -384,8 +389,9 @@ namespace vcpkg::Paragraphs
{
if (val->value.is_object())
{
return map_parse_expected_to_localized_string(SourceControlFile::parse_port_manifest_object(
origin, val->value.object(VCPKG_LINE_INFO), warning_sink));
return SourceControlFile::parse_port_manifest_object(
origin, val->value.object(VCPKG_LINE_INFO), warning_sink)
.map_error(ToLocalizedString);
}

return msg::format(msgJsonValueNotObject);
BillyONeal marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -406,11 +412,10 @@ namespace vcpkg::Paragraphs
return try_load_manifest_text(text, origin, warning_sink);
}

ExpectedL<std::vector<Paragraph>> pghs = parse_paragraphs(StringView{text}, origin);
auto pghs = parse_paragraphs(StringView{text}, origin);
if (auto vector_pghs = pghs.get())
{
return map_parse_expected_to_localized_string(
SourceControlFile::parse_control_file(origin, std::move(*vector_pghs)));
return SourceControlFile::parse_control_file(origin, std::move(*vector_pghs)).map_error(ToLocalizedString);
}

return std::move(pghs).error();
Expand Down Expand Up @@ -438,20 +443,10 @@ namespace vcpkg::Paragraphs

if (fs.exists(control_path, IgnoreErrors{}))
{
ExpectedL<std::vector<Paragraph>> pghs = get_paragraphs(fs, control_path);
if (auto vector_pghs = pghs.get())
{
auto maybe_parsed_control =
SourceControlFile::parse_control_file(control_path, std::move(*vector_pghs));
if (auto parsed_control = maybe_parsed_control.get())
{
return std::move(*parsed_control);
}

return LocalizedString::from_raw(maybe_parsed_control.error()->to_string());
}

return std::move(pghs).error();
return get_paragraphs(fs, control_path).then([&](std::vector<Paragraph>&& vector_pghs) {
return SourceControlFile::parse_control_file(control_path, std::move(vector_pghs))
.map_error(ToLocalizedString);
});
}

if (fs.exists(port_directory, IgnoreErrors{}))
Expand All @@ -468,33 +463,22 @@ namespace vcpkg::Paragraphs
return msg::format_error(msgManifestConflict, msg::path = port_directory);
}

auto maybe_parsed = try_load_manifest_text(manifest_contents, manifest_path, stdout_sink);
if (auto parsed = maybe_parsed.get())
{
return std::move(*parsed);
}

return std::move(maybe_parsed).error();
return try_load_manifest_text(manifest_contents, manifest_path, stdout_sink);
}

ExpectedL<std::unique_ptr<SourceControlFile>> try_load_port_required(const ReadOnlyFilesystem& fs,
StringView port_name,
const Path& port_directory)
{
auto maybe_maybe_res = try_load_port(fs, port_name, port_directory);
auto maybe_res = maybe_maybe_res.get();
if (!maybe_res)
{
return std::move(maybe_maybe_res).error();
}

auto res = maybe_res->get();
if (!res)
{
return msg::format_error(msgPortDoesNotExist, msg::package_name = port_name);
}
return try_load_port(fs, port_name, port_directory)
.then([&](std::unique_ptr<SourceControlFile>&& loaded) -> ExpectedL<std::unique_ptr<SourceControlFile>> {
if (!loaded)
{
return msg::format_error(msgPortDoesNotExist, msg::package_name = port_name);
}

return std::move(*maybe_res);
return std::move(loaded);
});
}

ExpectedL<BinaryControlFile> try_load_cached_package(const ReadOnlyFilesystem& fs,
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/portfileprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace vcpkg

private:
const RegistrySet& registry_set;
mutable Cache<std::string, ExpectedL<Version>> m_baseline_cache;
Cache<std::string, ExpectedL<Version>> m_baseline_cache;
};

struct VersionedPortfileProviderImpl : IFullVersionedPortfileProvider
Expand Down
Loading