From 6774160a8fdbdfb31143e1f32f44e5b3301431ff Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 14 Jan 2025 16:35:41 -0800 Subject: [PATCH 1/2] 7-zip: Consider copies on the system. --- src/vcpkg/tools.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/vcpkg/tools.cpp b/src/vcpkg/tools.cpp index 20c19af394..8c4cef66d8 100644 --- a/src/vcpkg/tools.cpp +++ b/src/vcpkg/tools.cpp @@ -738,6 +738,40 @@ namespace vcpkg } }; + struct SevenZipProvider : ToolProvider + { + virtual bool is_abi_sensitive() const override { return false; } + virtual StringView tool_data_name() const override { return Tools::SEVEN_ZIP; } + virtual std::vector system_exe_stems() const override { return {"7z"}; } + virtual std::array default_min_version() const override { return {24, 9}; } + +#if defined(_WIN32) + virtual void add_system_paths(const ReadOnlyFilesystem&, std::vector& out_candidate_paths) const override + { + const auto& program_files = get_program_files_platform_bitness(); + if (const auto pf = program_files.get()) + { + out_candidate_paths.push_back(*pf / "7-Zip" / "7z.exe"); + } + + const auto& program_files_32_bit = get_program_files_32_bit(); + if (const auto pf = program_files_32_bit.get()) + { + out_candidate_paths.push_back(*pf / "7-Zip" / "7z.exe"); + } + } +#endif + + virtual ExpectedL get_version(const ToolCache&, MessageSink&, const Path& exe_path) const override + { + return run_to_extract_version(Tools::SEVEN_ZIP, exe_path, Command(exe_path)) + .then([&](std::string&& output) { + // Sample output: 7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29 + return extract_prefixed_nonwhitespace("7-Zip ", Tools::SEVEN_ZIP, std::move(output), exe_path); + }); + } + }; + struct ToolCacheImpl final : ToolCache { const Filesystem& fs; @@ -996,6 +1030,10 @@ namespace vcpkg if (tool == Tools::COSCLI) return get_path(CosCliProvider(), status_sink); if (tool == Tools::PYTHON3) return get_path(Python3Provider(), status_sink); if (tool == Tools::PYTHON3_WITH_VENV) return get_path(Python3WithVEnvProvider(), status_sink); + if (tool == Tools::SEVEN_ZIP || tool == Tools::SEVEN_ZIP_ALT) + { + return get_path(SevenZipProvider(), status_sink); + } if (tool == Tools::TAR) { return {find_system_tar(fs).value_or_exit(VCPKG_LINE_INFO), {}}; From ef1035f316147737ec7b462c120b8211885892cb Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 14 Jan 2025 16:52:57 -0800 Subject: [PATCH 2/2] Teach the fetch test to force downloaded copy. --- azure-pipelines/end-to-end-tests-dir/fetch.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azure-pipelines/end-to-end-tests-dir/fetch.ps1 b/azure-pipelines/end-to-end-tests-dir/fetch.ps1 index 1a0e332be6..768ab2576d 100644 --- a/azure-pipelines/end-to-end-tests-dir/fetch.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/fetch.ps1 @@ -2,7 +2,7 @@ $VcpkgToolsJsonSchemaFile = (Get-Item "$PSScriptRoot/../../docs/vcpkg-tools.schema.json").FullName if (-not (Test-Json -ea:0 -LiteralPath "$VcpkgRoot/scripts/vcpkg-tools.json" -SchemaFile $VcpkgToolsJsonSchemaFile)) { - throw "real vcpkg-tools.json doesn't conform to schema" + throw "real vcpkg-tools.json doesn't conform to schema" } if (-not $IsMacOS -and -not $IsLinux) { @@ -20,7 +20,7 @@ if (-not $IsMacOS -and -not $IsLinux) { { "schema-version": 1, "tools": [{ - "name": "7zip", + "name": "7zip_msi", "os": "windows", "version": "19.00", "executable": "Files\\7-Zip\\7z.exe", @@ -86,13 +86,13 @@ if (-not $IsMacOS -and -not $IsLinux) { '@ | % { $_ -replace "`r","" } | Out-File -enc ascii $VcpkgToolsJson if (-not (Test-Json -ea:0 -LiteralPath $VcpkgToolsJson -SchemaFile $VcpkgToolsJsonSchemaFile)) { - throw "testing vcpkg-tools.json doesn't conform to schema" + throw "testing vcpkg-tools.json doesn't conform to schema" } $env:VCPKG_DOWNLOADS = Join-Path $TestingRoot 'down loads' - Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip", "--vcpkg-root=$TestingRoot")) + Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip_msi", "--vcpkg-root=$TestingRoot")) Throw-IfFailed - Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip-19.00-windows/Files/7-Zip/7z.exe" + Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip_msi-19.00-windows/Files/7-Zip/7z.exe" Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "ninja-testing", "--vcpkg-root=$TestingRoot")) Throw-IfFailed