Skip to content

Commit 3ee822b

Browse files
committed
fix(): add script to install from chocolatey
Add the `Install-FromChoco.ps1` script to install packages from Chocolatey.
1 parent 9ffe96b commit 3ee822b

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (c) 2025, the WebKit for Windows project authors. Please see the
2+
# AUTHORS file for details. All rights reserved. Use of this source code is
3+
# governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
<#
6+
.Synopsis
7+
Installs a Windows package through choco.
8+
9+
.Description
10+
Installs a package from chocolatey onto the system.
11+
12+
.Parameter Name
13+
The name of the package.
14+
15+
.Parameter Version
16+
The version of the package to install.
17+
18+
.Parameter Options
19+
A list of options to pass in.
20+
21+
.Parameter InstallerOptions
22+
A list of options to pass to the installer.
23+
24+
.Parameter PackageParameters
25+
A list of parameters to pass to the package.
26+
27+
.Parameter NoVerify
28+
If set the installation is not verified by attempting to call an executable
29+
with the given name.
30+
31+
.Parameter VerifyExe
32+
The executable to use to verify the installation. If not provided defaults to
33+
the name.
34+
35+
.Parameter VersionOptions
36+
The options to pass to the executable to get the version.
37+
#>
38+
function Install-FromChoco {
39+
param(
40+
[Parameter(Mandatory)]
41+
[string]$name,
42+
[Parameter()]
43+
[string]$version,
44+
[Parameter()]
45+
[string[]]$options = @(),
46+
[Parameter()]
47+
[string[]]$installerOptions = @(),
48+
[Parameter()]
49+
[string[]]$packageParameters = @(),
50+
[Parameter()]
51+
[switch]$noVerify = $false,
52+
[Parameter()]
53+
[string]$verifyExe,
54+
[Parameter()]
55+
[string[]]$versionOptions = @('--version')
56+
)
57+
58+
$chocoArgs = @('install',$name,'--confirm');
59+
$chocoArgs += $options;
60+
61+
if ($version) {
62+
$chocoArgs += @('--version',$version);
63+
}
64+
65+
if ($installerOptions) {
66+
$chocoArgs += @('--install-arguments',("'{0}'" -f ($installerOptions -join ' ')));
67+
}
68+
69+
if ($packageParameters) {
70+
$chocoArgs += @('--package-parameters',("'{0}'" -f ($packageParameters -join ' ')));
71+
}
72+
73+
Write-Host ('choco {0}' -f ($chocoArgs -join ' '));
74+
$process = Start-Process choco -Passthru -NoNewWindow -ArgumentList $chocoArgs;
75+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments','',Scope = 'Function')]
76+
$handle = $process.Handle;
77+
$process.WaitForExit();
78+
79+
if ($process.ExitCode -ne 0) {
80+
Write-Error ('{0} installer failed with exit code {1}' -f $name,$process.ExitCode) -ErrorAction Stop;
81+
return;
82+
}
83+
84+
# Update path
85+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1;
86+
refreshenv;
87+
88+
if (!$noVerify) {
89+
if (!$verifyExe) {
90+
$verifyExe = $name;
91+
}
92+
93+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
94+
$verifyCommand = (' {0} {1}' -f $verifyExe,($versionOptions -join ' '));
95+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
96+
Invoke-Expression $verifyCommand;
97+
}
98+
}

WebKitDev/WebKitDev.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,17 @@
9393
'Functions/Install-Flex.ps1',
9494
'Functions/Install-Font.ps1',
9595
'Functions/Install-FromArchive.ps1',
96+
'Functions/Install-FromChoco.ps1',
9697
'Functions/Install-FromExe.ps1',
9798
'Functions/Install-FromExeDownload.ps1',
9899
'Functions/Install-FromMsi.ps1',
99100
'Functions/Install-FromPacman.ps1',
100101
'Functions/Install-Git.ps1',
101102
'Functions/Install-Gperf.ps1',
102103
'Functions/Install-LLVM.ps1',
104+
'Functions/Install-MSYS2.ps1',
103105
'Functions/Install-Make.ps1',
104106
'Functions/Install-MinioClient.ps1',
105-
'Functions/Install-MSYS2.ps1',
106107
'Functions/Install-Nasm.ps1',
107108
'Functions/Install-Ninja.ps1',
108109
'Functions/Install-NuGet.ps1',
@@ -111,12 +112,12 @@
111112
'Functions/Install-Python.ps1',
112113
'Functions/Install-Ruby.ps1',
113114
'Functions/Install-SVN.ps1',
114-
'Functions/Install-Xampp.ps1',
115115
'Functions/Install-VSBuildTools2015.ps1',
116116
'Functions/Install-VSBuildTools2017.ps1',
117117
'Functions/Install-VSBuildTools2019.ps1',
118118
'Functions/Install-VSBuildTools2022.ps1',
119119
'Functions/Install-Windows10SDK.ps1',
120+
'Functions/Install-Xampp.ps1',
120121
'Functions/Invoke-CMakeBuild.ps1',
121122
'Functions/Invoke-WebFileRequest.ps1',
122123
'Functions/Register-SystemPath.ps1',

0 commit comments

Comments
 (0)