From d671cb38c8b7f250211f260b288c6de3d0265d7b Mon Sep 17 00:00:00 2001 From: Don Olmstead Date: Mon, 6 Oct 2025 16:04:36 -0700 Subject: [PATCH] fix(): add script to install from chocolatey Add the `Install-FromChoco.ps1` script to install packages from Chocolatey. --- WebKitDev/Functions/Install-FromChoco.ps1 | 98 +++++++++++++++++++++++ WebKitDev/WebKitDev.psd1 | 5 +- 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 WebKitDev/Functions/Install-FromChoco.ps1 diff --git a/WebKitDev/Functions/Install-FromChoco.ps1 b/WebKitDev/Functions/Install-FromChoco.ps1 new file mode 100644 index 0000000..c8918db --- /dev/null +++ b/WebKitDev/Functions/Install-FromChoco.ps1 @@ -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; + } +} diff --git a/WebKitDev/WebKitDev.psd1 b/WebKitDev/WebKitDev.psd1 index 4770584..f077bf5 100644 --- a/WebKitDev/WebKitDev.psd1 +++ b/WebKitDev/WebKitDev.psd1 @@ -93,6 +93,7 @@ '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', @@ -100,9 +101,9 @@ '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', @@ -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',