Skip to content
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
98 changes: 98 additions & 0 deletions WebKitDev/Functions/Install-FromChoco.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright (c) 2025, the WebKit for Windows project authors. Please see the
# AUTHORS file for details. All rights reserved. Use of this source code is
# governed by a BSD-style license that can be found in the LICENSE file.

<#
.Synopsis
Installs a Windows package through choco.

.Description
Installs a package from chocolatey onto the system.

.Parameter Name
The name of the package.

.Parameter Version
The version of the package to install.

.Parameter Options
A list of options to pass in.

.Parameter InstallerOptions
A list of options to pass to the installer.

.Parameter PackageParameters
A list of parameters to pass to the package.

.Parameter NoVerify
If set the installation is not verified by attempting to call an executable
with the given name.

.Parameter VerifyExe
The executable to use to verify the installation. If not provided defaults to
the name.

.Parameter VersionOptions
The options to pass to the executable to get the version.
#>
function Install-FromChoco {
param(
[Parameter(Mandatory)]
[string]$name,
[Parameter()]
[string]$version,
[Parameter()]
[string[]]$options = @(),
[Parameter()]
[string[]]$installerOptions = @(),
[Parameter()]
[string[]]$packageParameters = @(),
[Parameter()]
[switch]$noVerify = $false,
[Parameter()]
[string]$verifyExe,
[Parameter()]
[string[]]$versionOptions = @('--version')
)

$chocoArgs = @('install',$name,'--confirm');
$chocoArgs += $options;

if ($version) {
$chocoArgs += @('--version',$version);
}

if ($installerOptions) {
$chocoArgs += @('--install-arguments',("'{0}'" -f ($installerOptions -join ' ')));
}

if ($packageParameters) {
$chocoArgs += @('--package-parameters',("'{0}'" -f ($packageParameters -join ' ')));
}

Write-Information ('choco {0}' -f ($chocoArgs -join ' '));
$process = Start-Process choco -Passthru -NoNewWindow -ArgumentList $chocoArgs;
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments','',Scope = 'Function')]
$handle = $process.Handle;
$process.WaitForExit();

if ($process.ExitCode -ne 0) {
Write-Error ('{0} installer failed with exit code {1}' -f $name,$process.ExitCode) -ErrorAction Stop;
return;
}

# Update path
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1;
refreshenv;

if (!$noVerify) {
if (!$verifyExe) {
$verifyExe = $name;
}

Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
$verifyCommand = (' {0} {1}' -f $verifyExe,($versionOptions -join ' '));
Write-Information -MessageData $verifyCommand -InformationAction Continue;
Invoke-Expression $verifyCommand;
}
}
5 changes: 3 additions & 2 deletions WebKitDev/WebKitDev.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@
'Functions/Install-Flex.ps1',
'Functions/Install-Font.ps1',
'Functions/Install-FromArchive.ps1',
'Functions/Install-FromChoco.ps1',
'Functions/Install-FromExe.ps1',
'Functions/Install-FromExeDownload.ps1',
'Functions/Install-FromMsi.ps1',
'Functions/Install-FromPacman.ps1',
'Functions/Install-Git.ps1',
'Functions/Install-Gperf.ps1',
'Functions/Install-LLVM.ps1',
'Functions/Install-MSYS2.ps1',
'Functions/Install-Make.ps1',
'Functions/Install-MinioClient.ps1',
'Functions/Install-MSYS2.ps1',
'Functions/Install-Nasm.ps1',
'Functions/Install-Ninja.ps1',
'Functions/Install-NuGet.ps1',
Expand All @@ -111,12 +112,12 @@
'Functions/Install-Python.ps1',
'Functions/Install-Ruby.ps1',
'Functions/Install-SVN.ps1',
'Functions/Install-Xampp.ps1',
'Functions/Install-VSBuildTools2015.ps1',
'Functions/Install-VSBuildTools2017.ps1',
'Functions/Install-VSBuildTools2019.ps1',
'Functions/Install-VSBuildTools2022.ps1',
'Functions/Install-Windows10SDK.ps1',
'Functions/Install-Xampp.ps1',
'Functions/Invoke-CMakeBuild.ps1',
'Functions/Invoke-WebFileRequest.ps1',
'Functions/Register-SystemPath.ps1',
Expand Down