-
Notifications
You must be signed in to change notification settings - Fork 287
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
Change tool metadata file format to JSON #1553
base: main
Are you sure you want to change the base?
Conversation
…ting trivial destruction.
…the search loop, and get rid of magic numbers that is the length of the table.
Make the table be static data, deduplicate part of the expression in the search loop, and get rid of magic numbers that is the length of the table.
5fe30dc
to
3747fae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feature!
if (Util::contains(KNOWN_ARCHITECTURES, sv)) | ||
{ | ||
return sv.to_string(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Util::contains(KNOWN_ARCHITECTURES, sv)) | |
{ | |
return sv.to_string(); | |
} | |
if (to_cpu_architecture(sv).has_value()) { return sv.to_string(); } |
?
Alternately, can this just be made to return CPUArchitecture
directly instead? This also avoids the need to have a duplicate KNOWN_ARCHITECTURES
table.
(If you still want the table to generate the error message, can it at least be combined with the bits powering to_cpu_architecture
so that we don't introduce a bug any time any of those are edited? For example:
struct KnownCPUArchitecture {
StringLiteral name;
CPUArchitecture architecture;
};
inline constexpr KnownCPUArchitecture KnownArchitectures[] = {
{"x86", CPUArchitecture::X86},
{"x64", CPUArchitecture::X64},
{"amd64", CPUArchitecture::X64},
{"arm", CPUArchitecture::ARM},
{"arm64", CPUArchitecture::ARM64},
{"arm64ec", CPUArchitecture::ARM64EC},
{"s390x", CPUArchitecture::S390X},
{"ppc64le", CPUArchitecture::PPC64LE},
{"riscv32", CPUArchitecture::RISCV32},
{"riscv64", CPUArchitecture::RISCV64},
{"loongarch32", CPUArchitecture::LOONGARCH32},
{"loongarch64", CPUArchitecture::LOONGARCH64},
{"mips64", CPUArchitecture::MIPS64},
};
)
@@ -358,6 +358,7 @@ namespace vcpkg | |||
args.parser.parse_option( | |||
SwitchBuiltinRegistryVersionsDir, StabilityTag::Experimental, args.builtin_registry_versions_dir); | |||
args.parser.parse_option(SwitchRegistriesCache, StabilityTag::Experimental, args.registries_cache_dir); | |||
args.parser.parse_option(SwitchToolDataFile, StabilityTag::ImplementationDetail, args.tools_data_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget docs :)
@@ -1,6 +1,7 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really think this should just be in tools.h
given that the things in here are contractual despite trying to claim that it's used for 'test'ing. But that's a preexisting situation so no change requested if you don't want to go there.
REQUIRE(!invalid_arch.has_value()); | ||
CHECK("invalid_arch.json: error: $.tools[0].arch (a CPU architecture): Invalid architecture: notanarchitecture. " | ||
"Expected " | ||
"one of: x86,x64,arm,arm64,arm64ec,s390x,ppc64le,riscv32,riscv64,loongarch32,loongarch64,mips64\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"one of: x86,x64,arm,arm64,arm64ec,s390x,ppc64le,riscv32,riscv64,loongarch32,loongarch64,mips64\n" | |
"one of: x86, x64,arm, arm64, arm64ec, s390x, ppc64le, riscv32, riscv64, loongarch32, loongarch64,mips64\n" |
if (auto tool_data = maybe_tool_data.get()) | ||
{ | ||
return *tool_data; | ||
} | ||
|
||
return msg::format(msgErrorWhileParsingToolData, msg::path = origin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (auto tool_data = maybe_tool_data.get()) | |
{ | |
return *tool_data; | |
} | |
return msg::format(msgErrorWhileParsingToolData, msg::path = origin); | |
return maybe_tool_data.value_or_exit(VCPKG_LINE_INFO); |
Any errors in parsing should have been reported by Json::Reader
, so if we get here vcpkg has a bug and we shouldn't have separate localized messages for bugs.
auto as_json = Json::parse(contents, origin); | ||
if (!as_json) | ||
{ | ||
return as_json.error(); | ||
} | ||
auto as_value = std::move(as_json).value(VCPKG_LINE_INFO).value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have error handling like that in Json::parse_object
rather than crashing if it can't be interpreted as a value here.
std::error_code ec; | ||
auto contents = fs.read_contents(path, ec); | ||
if (ec) | ||
{ | ||
return format_filesystem_call_error(ec, __func__, {path}); | ||
} | ||
|
||
return parse_tool_data(contents, path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::error_code ec; | |
auto contents = fs.read_contents(path, ec); | |
if (ec) | |
{ | |
return format_filesystem_call_error(ec, __func__, {path}); | |
} | |
return parse_tool_data(contents, path); | |
return fs.try_read_contents(path).then([](FileContents&& fc) -> ExpectedL<std::vector<ToolDataEntry>> { | |
return parse_tool_data(fc.content, Path{fc.origin}); | |
}); |
std::string arch_str; | ||
if (r.optional_object_field(obj, "arch", arch_str, Json::ArchitectureDeserializer::instance)) | ||
{ | ||
auto it = arch_map.find(arch_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use to_cpu_architecture
instead of a second duplicate table?
Continuation of #1490
Related: #1277
This PR contains several changes:
vcpkgTools.xml
data into a JSON file and removes the XML parsing code.To do: