Skip to content

Commit f8bb9ef

Browse files
authored
Update dev-environment-setup.ps1
This PR fixes the parameters passed to the `choco` command. Because of the way powershell sends parameters to a command when it is external (MicrosoftDocs/PowerShell-Docs#2361), the `params` parameters passed where not being correctly interpreted by `choco` and would therefore not being taken into account. Now, we use `Start-Process` with `-ArgumentList` which correctly parses and sends the parameters to `choco.exe` which allow us a couple of things: 1. `msys2` will be installed to the `InstallDir´ (it just so happens that we use the default folder for installation) 2. We can not add workloads to the VS 2022 Community installation, which has a couple of benefits: 2.1. We can add `Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended` and `Microsoft.VisualStudio.Workload.ManagedDesktop` which are necessary for compiling Selenium in Visual Studio 2.2. Now the installation of VS is completely automatic and does not need feedback from the user
1 parent ed794f7 commit f8bb9ef

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

scripts/dev-environment-setup.ps1

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,26 @@ Function Install-ChocoPackage {
77
param (
88
[string]$PackageName,
99
[string]$ExecutableName,
10-
[string]$AdditionalParams = ""
10+
[string]$AdditionalParams = $null
1111
)
1212

13+
$params = @(
14+
"install",
15+
$PackageName,
16+
"-y"
17+
)
18+
19+
# Add AdditionalParams only if it has a value
20+
if (-not [string]::IsNullOrWhiteSpace($AdditionalParams)) {
21+
$params += $AdditionalParams
22+
}
23+
1324
Write-Host "Checking installation of $PackageName"
1425
if (-Not (Get-Command $ExecutableName -ErrorAction SilentlyContinue)) {
1526
Write-Host "Installing $PackageName..."
16-
choco install $PackageName -y $AdditionalParams
27+
#choco install $PackageName -y $AdditionalParams
28+
#Start-Process choco -ArgumentList 'install', 'visualstudio2022community', '--params "--add Microsoft.VisualStudio.Workload.NativeDesktop" --passive', '-y'
29+
Start-Process choco -ArgumentList $params -Verbose -NoNewWindow -Wait
1730
refreshenv -Path ...
1831
} else {
1932
Write-Host "$PackageName is already installed."
@@ -25,7 +38,7 @@ Function Install-JDK17 {
2538
$javaVersion = if ($javacInstalled) { & javac -version 2>&1 | Select-String -Pattern '"(\d+)' | ForEach-Object { $_.Matches.Groups[1].Value } }
2639

2740
if (-Not $javacInstalled -or [int]$javaVersion -ne 17) {
28-
Install-ChocoPackage -PackageName "openjdk17" -ExecutableName "javac"
41+
Install-ChocoPackage -PackageName "openjdk17" -ExecutableName "javac" -AdditionalParams ""
2942
} else {
3043
Write-Host "JDK 17 is already installed."
3144
}
@@ -71,7 +84,7 @@ Function Clone-Repository {
7184
}
7285

7386
Function Install-IntelliJ {
74-
Install-ChocoPackage -PackageName "intellijidea-community" -ExecutableName "idea64"
87+
Install-ChocoPackage -PackageName "intellijidea-community" -ExecutableName "idea64" -AdditionalParams ""
7588

7689
$ideaPath = Get-ChildItem -Path "C:\Program Files\JetBrains" -Filter idea64.exe -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 -ExpandProperty FullName
7790
& $ideaPath installPlugins "com.google.idea.bazel.ijwb"
@@ -118,15 +131,15 @@ if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) {
118131

119132
Install-JDK17
120133
Set-JavaEnvironmentVariable
121-
Install-ChocoPackage -PackageName "git" -ExecutableName "git"
122-
Install-ChocoPackage -PackageName "bazelisk" -ExecutableName "bazel"
123-
Install-ChocoPackage -PackageName "msys2" -ExecutableName "C:\tools\msys64\usr\bin\bash.exe" -AdditionalParams "--params '/InstallDir=C:\tools\msys64'"
134+
Install-ChocoPackage -PackageName "git" -ExecutableName "git" -AdditionalParams ""
135+
Install-ChocoPackage -PackageName "bazelisk" -ExecutableName "bazel" -AdditionalParams ""
136+
Install-ChocoPackage -PackageName "msys2" -ExecutableName "C:\tools\msys64\usr\bin\bash.exe" -AdditionalParams '--params="/InstallDir=C:\tools\msys64"'
124137
Update-EnvironmentVariables -VariableName "PATH" -Value "C:\tools\msys64\usr\bin"
125138
Update-EnvironmentVariables -VariableName "BAZEL_SH" -Value "C:\tools\msys64\usr\bin\bash.exe"
126-
Install-ChocoPackage -PackageName "visualstudio2022community" -ExecutableName "devenv"
139+
Install-ChocoPackage -PackageName "visualstudio2022community" -ExecutableName "devenv" -AdditionalParams '--params="--add Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended --add Microsoft.VisualStudio.Workload.ManagedDesktop --passive"'
127140

128-
Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe"
129-
Read-Host -Prompt "Install C++ in Visual Studio then Press Enter to continue"
141+
# Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe"
142+
# Read-Host -Prompt "Install C++ in Visual Studio then Press Enter to continue"
130143

131144
$bazelVcPath = "C:\Program Files\Microsoft Visual Studio\2022\Community\VC"
132145
Update-EnvironmentVariables -VariableName "BAZEL_VC" -Value $bazelVcPath

0 commit comments

Comments
 (0)