Skip to content

Commit 0faaa86

Browse files
authored
Various updates to ILVerify (#18060)
1 parent ebdd536 commit 0faaa86

11 files changed

+38
-12
lines changed

DEVGUIDE.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fs
228228

229229
### Updating ILVerify baselines
230230

231-
These control IL for the core modules of the compiler. The baselines are located in the `eng` folder and look like:
231+
These are IL baseline tests for the core assemblies of the compiler (FSharp.Core and FSharp.Compiler.Service). The baselines are located in the `tests/ILVerify` folder and look like:
232+
232233
```
233234
ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl
234235
ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl
@@ -240,7 +241,10 @@ ilverify_FSharp.Core_Release_netstandard2.0.bsl
240241
ilverify_FSharp.Core_Release_netstandard2.1.bsl
241242
```
242243

243-
If you want to update them, run the [ilverify.ps1]([url](https://github.com/dotnet/fsharp/blob/main/eng/ilverify.ps1)) script in PowerShell. The script will create `.actual` files. If the differences make sense, replace the original baselines with the actual files.
244+
If you want to update them, either
245+
246+
1. Run the [ilverify.ps1]([url](https://github.com/dotnet/fsharp/blob/main/tests/ILVerify/ilverify.ps1)) script in PowerShell. The script will create `.actual` files. If the differences make sense, replace the original baselines with the actual files.
247+
2. Set the `TEST_UPDATE_BSL` to `1` (please refer to "Updating baselines in tests" section in this file) **and** run `ilverify.ps1` - this will automatically replace baselines. After that, please carefully review the change and push it to your branch if it makes sense.
244248

245249
## Automated Source Code Formatting
246250

azure-pipelines-PR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,6 @@ stages:
825825
installationPath: $(Agent.ToolsDirectory)/dotnet
826826
- script: dotnet tool restore
827827
displayName: Restore dotnet tools
828-
- pwsh: .\eng\ilverify.ps1
828+
- pwsh: .\tests\ILVerify\ilverify.ps1
829829
displayName: Run ILVerify
830830
workingDirectory: $(Build.SourcesDirectory)

eng/ilverify.ps1 renamed to tests/ILVerify/ilverify.ps1

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
Write-Host "Checking whether running on Windows: $IsWindows"
66

7-
[string] $repo_path = (Get-Item -Path $PSScriptRoot).Parent
7+
[string] $repo_path = (Get-Item -Path $PSScriptRoot).Parent.Parent
88

99
Write-Host "Repository path: $repo_path"
1010

1111
[string] $script = if ($IsWindows) { Join-Path $repo_path "build.cmd" } else { Join-Path $repo_path "build.sh" }
12+
[string] $additional_arguments = if ($IsWindows) { "-noVisualStudio" } else { "" }
1213

1314
# Set configurations to build
1415
[string[]] $configurations = @("Debug", "Release")
@@ -29,7 +30,7 @@ $projects = @{
2930
# Run build script for each configuration (NOTE: We don't build Proto)
3031
foreach ($configuration in $configurations) {
3132
Write-Host "Building $configuration configuration..."
32-
& $script -c $configuration
33+
& $script -c $configuration $additional_arguments
3334
if ($LASTEXITCODE -ne 0 -And $LASTEXITCODE -ne '') {
3435
Write-Host "Build failed for $configuration configuration (last exit code: $LASTEXITCODE)."
3536
exit 1
@@ -111,14 +112,20 @@ foreach ($project in $projects.Keys) {
111112
}
112113
}
113114

114-
$baseline_file = Join-Path $repo_path "eng" "ilverify_${project}_${configuration}_${tfm}.bsl"
115+
$baseline_file = Join-Path $repo_path "tests/ILVerify" "ilverify_${project}_${configuration}_${tfm}.bsl"
115116

116117
$baseline_actual_file = [System.IO.Path]::ChangeExtension($baseline_file, 'bsl.actual')
117118

118119
if (-not (Test-Path $baseline_file)) {
119120
Write-Host "Baseline file not found: $baseline_file"
120-
$ilverify_output | Set-Content $baseline_actual_file
121-
$failed = $true
121+
if ($env:TEST_UPDATE_BSL -eq "1") {
122+
Write-Host "Creating initial baseline file: $baseline_file"
123+
$ilverify_output | Set-Content $baseline_file
124+
} else {
125+
Write-Host "Creating .actual baseline file: $baseline_actual_file"
126+
$ilverify_output | Set-Content $baseline_actual_file
127+
$failed = $true
128+
}
122129
continue
123130
}
124131

@@ -127,8 +134,14 @@ foreach ($project in $projects.Keys) {
127134

128135
if ($baseline.Length -eq 0) {
129136
Write-Host "Baseline file is empty: $baseline_file"
130-
$ilverify_output | Set-Content $baseline_actual_file
131-
$failed = $true
137+
if ($env:TEST_UPDATE_BSL -eq "1") {
138+
Write-Host "Updating empty baseline file: $baseline_file"
139+
$ilverify_output | Set-Content $baseline_file
140+
} else {
141+
Write-Host "Creating initial .actual baseline file: $baseline_actual_file"
142+
$ilverify_output | Set-Content $baseline_actual_file
143+
$failed = $true
144+
}
132145
continue
133146
}
134147

@@ -142,10 +155,19 @@ foreach ($project in $projects.Keys) {
142155
Write-Host "ILverify output does not match baseline, differences:"
143156

144157
$cmp | Format-Table | Out-String | Write-Host
145-
$ilverify_output | Set-Content $baseline_actual_file
158+
159+
# Update baselines if TEST_UPDATE_BSL is set to 1
160+
if ($env:TEST_UPDATE_BSL -eq "1") {
161+
Write-Host "Updating baseline file: $baseline_file"
162+
$ilverify_output | Set-Content $baseline_file
163+
} else {
164+
$ilverify_output | Set-Content $baseline_actual_file
165+
}
146166
$failed = $true
147167
continue
148168
}
169+
170+
149171
}
150172
}
151173
}
@@ -155,4 +177,4 @@ if ($failed) {
155177
exit 1
156178
}
157179

158-
exit 0
180+
exit 0

0 commit comments

Comments
 (0)