Skip to content

Commit 22c8300

Browse files
authored
7-zip: Consider copies on the system. (#1571)
1 parent e8fa571 commit 22c8300

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

azure-pipelines/end-to-end-tests-dir/fetch.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$VcpkgToolsJsonSchemaFile = (Get-Item "$PSScriptRoot/../../docs/vcpkg-tools.schema.json").FullName
44
if (-not (Test-Json -ea:0 -LiteralPath "$VcpkgRoot/scripts/vcpkg-tools.json" -SchemaFile $VcpkgToolsJsonSchemaFile)) {
5-
throw "real vcpkg-tools.json doesn't conform to schema"
5+
throw "real vcpkg-tools.json doesn't conform to schema"
66
}
77

88
if (-not $IsMacOS -and -not $IsLinux) {
@@ -20,7 +20,7 @@ if (-not $IsMacOS -and -not $IsLinux) {
2020
{
2121
"schema-version": 1,
2222
"tools": [{
23-
"name": "7zip",
23+
"name": "7zip_msi",
2424
"os": "windows",
2525
"version": "19.00",
2626
"executable": "Files\\7-Zip\\7z.exe",
@@ -86,13 +86,13 @@ if (-not $IsMacOS -and -not $IsLinux) {
8686
'@ | % { $_ -replace "`r","" } | Out-File -enc ascii $VcpkgToolsJson
8787

8888
if (-not (Test-Json -ea:0 -LiteralPath $VcpkgToolsJson -SchemaFile $VcpkgToolsJsonSchemaFile)) {
89-
throw "testing vcpkg-tools.json doesn't conform to schema"
89+
throw "testing vcpkg-tools.json doesn't conform to schema"
9090
}
9191

9292
$env:VCPKG_DOWNLOADS = Join-Path $TestingRoot 'down loads'
93-
Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip", "--vcpkg-root=$TestingRoot"))
93+
Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip_msi", "--vcpkg-root=$TestingRoot"))
9494
Throw-IfFailed
95-
Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip-19.00-windows/Files/7-Zip/7z.exe"
95+
Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip_msi-19.00-windows/Files/7-Zip/7z.exe"
9696

9797
Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "ninja-testing", "--vcpkg-root=$TestingRoot"))
9898
Throw-IfFailed

src/vcpkg/tools.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,40 @@ namespace vcpkg
739739
}
740740
};
741741

742+
struct SevenZipProvider : ToolProvider
743+
{
744+
virtual bool is_abi_sensitive() const override { return false; }
745+
virtual StringView tool_data_name() const override { return Tools::SEVEN_ZIP; }
746+
virtual std::vector<StringView> system_exe_stems() const override { return {"7z"}; }
747+
virtual std::array<int, 3> default_min_version() const override { return {24, 9}; }
748+
749+
#if defined(_WIN32)
750+
virtual void add_system_paths(const ReadOnlyFilesystem&, std::vector<Path>& out_candidate_paths) const override
751+
{
752+
const auto& program_files = get_program_files_platform_bitness();
753+
if (const auto pf = program_files.get())
754+
{
755+
out_candidate_paths.push_back(*pf / "7-Zip" / "7z.exe");
756+
}
757+
758+
const auto& program_files_32_bit = get_program_files_32_bit();
759+
if (const auto pf = program_files_32_bit.get())
760+
{
761+
out_candidate_paths.push_back(*pf / "7-Zip" / "7z.exe");
762+
}
763+
}
764+
#endif
765+
766+
virtual ExpectedL<std::string> get_version(const ToolCache&, MessageSink&, const Path& exe_path) const override
767+
{
768+
return run_to_extract_version(Tools::SEVEN_ZIP, exe_path, Command(exe_path))
769+
.then([&](std::string&& output) {
770+
// Sample output: 7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29
771+
return extract_prefixed_nonwhitespace("7-Zip ", Tools::SEVEN_ZIP, std::move(output), exe_path);
772+
});
773+
}
774+
};
775+
742776
struct ToolCacheImpl final : ToolCache
743777
{
744778
const Filesystem& fs;
@@ -1024,6 +1058,10 @@ namespace vcpkg
10241058
if (tool == Tools::COSCLI) return get_path(CosCliProvider(), status_sink);
10251059
if (tool == Tools::PYTHON3) return get_path(Python3Provider(), status_sink);
10261060
if (tool == Tools::PYTHON3_WITH_VENV) return get_path(Python3WithVEnvProvider(), status_sink);
1061+
if (tool == Tools::SEVEN_ZIP || tool == Tools::SEVEN_ZIP_ALT)
1062+
{
1063+
return get_path(SevenZipProvider(), status_sink);
1064+
}
10271065
if (tool == Tools::TAR)
10281066
{
10291067
return {find_system_tar(fs).value_or_exit(VCPKG_LINE_INFO), {}};

0 commit comments

Comments
 (0)