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

7-zip: Consider copies on the system. #1571

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions azure-pipelines/end-to-end-tests-dir/fetch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/vcpkg/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringView> system_exe_stems() const override { return {"7z"}; }
virtual std::array<int, 3> default_min_version() const override { return {24, 9}; }

#if defined(_WIN32)
virtual void add_system_paths(const ReadOnlyFilesystem&, std::vector<Path>& 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<std::string> 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;
Expand Down Expand Up @@ -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), {}};
Expand Down