Skip to content

Commit 194b5fe

Browse files
CopilotT-Gro
andcommitted
Implement proper build-time generated BuildInfo files with MSBuild targets
- Removed runtime-based BuildInfo files and replaced with MSBuild-generated ones - Added MSBuild targets that capture actual build-time values: SDK version, F# compiler paths, and local build flag - Files are generated before compilation with proper build-time information - Added BuildInfo files to .gitignore since they're generated at build time - Enhanced test assertions to validate build info consistency and catch future regressions - Tests now verify that build-time values are captured correctly and match compiler usage expectations Co-authored-by: T-Gro <[email protected]>
1 parent 9846cef commit 194b5fe

File tree

7 files changed

+90
-59
lines changed

7 files changed

+90
-59
lines changed

tests/FSharp.Compiler.ComponentTests/CompilerCompatibilityTests.fs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,44 @@ type CompilerCompatibilityTests() =
6868

6969
let (exitCode, output, _error) = runApp appDllPath
7070
Assert.Equal(0, exitCode)
71-
Assert.Contains("SUCCESS: All compiler compatibility tests passed", output)
71+
Assert.Contains("SUCCESS: All compiler compatibility tests passed", output)
72+
73+
// Parse build info from output to validate compiler usage consistency
74+
let lines = output.Split('\n') |> Array.map (fun s -> s.Trim())
75+
76+
// Extract isLocalBuild values from the output
77+
let parseIsLocalBuild (prefix: string) =
78+
lines
79+
|> Array.tryFindIndex (fun l -> l.StartsWith(prefix))
80+
|> Option.bind (fun startIdx ->
81+
lines
82+
|> Array.skip (startIdx + 1)
83+
|> Array.tryFind (fun l -> l.Contains("Is Local Build: "))
84+
|> Option.map (fun l -> l.Contains("Is Local Build: true")))
85+
|> function Some x -> x | None -> false
86+
87+
let libIsLocalBuild = parseIsLocalBuild "Library Build Info:"
88+
let appIsLocalBuild = parseIsLocalBuild "Application Build Info:"
89+
90+
// Validate that build info matches expected compiler versions
91+
let expectedLibIsLocal = libCompilerVersion = "local"
92+
let expectedAppIsLocal = appCompilerVersion = "local"
93+
94+
Assert.True((libIsLocalBuild = expectedLibIsLocal),
95+
$"Library build info mismatch: expected isLocalBuild={expectedLibIsLocal} for version '{libCompilerVersion}', but got {libIsLocalBuild}")
96+
Assert.True((appIsLocalBuild = expectedAppIsLocal),
97+
$"Application build info mismatch: expected isLocalBuild={expectedAppIsLocal} for version '{appCompilerVersion}', but got {appIsLocalBuild}")
98+
99+
// Validate consistency: same compiler versions should have same build info
100+
if libCompilerVersion = appCompilerVersion then
101+
Assert.True((libIsLocalBuild = appIsLocalBuild),
102+
$"Inconsistent build info: both lib and app use '{libCompilerVersion}' but have different isLocalBuild values (lib={libIsLocalBuild}, app={appIsLocalBuild})")
103+
else
104+
Assert.True((libIsLocalBuild <> appIsLocalBuild),
105+
$"Expected different build info for different compiler versions (lib='{libCompilerVersion}', app='{appCompilerVersion}'), but both have isLocalBuild={libIsLocalBuild}")
106+
107+
// Additional validation: check that we have actual build-time values
108+
Assert.True((lines |> Array.exists (fun l -> l.Contains("SDK Version:") && not (l.Contains("Unknown")))),
109+
"SDK Version should be captured from build-time, not show 'Unknown'")
110+
Assert.True((lines |> Array.exists (fun l -> l.Contains("F# Compiler Path:") && not (l.Contains("Unknown")))),
111+
"F# Compiler Path should be captured from build-time, not show 'Unknown'")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ignore test-generated files
22
global.json
33
commandline.txt
4+
**/*BuildInfo.fs
45
StandardOutput.txt
56
StandardError.txt
Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
namespace CompilerCompatApp
2-
3-
open System
4-
open System.Reflection
5-
open System.Diagnostics
6-
72
module AppBuildInfo =
8-
let sdkVersion =
9-
try
10-
// Try to get .NET version from runtime
11-
Environment.Version.ToString()
12-
with _ -> "Unknown"
13-
14-
let fscPath =
15-
try
16-
// Check if we're using local compiler by looking at assembly location
17-
let assembly = Assembly.GetExecutingAssembly()
18-
let location = assembly.Location
19-
if location.Contains("artifacts") then
20-
$"Local compiler (artifacts): {location}"
21-
else
22-
$"SDK compiler: {location}"
23-
with _ -> "Unknown"
24-
25-
let isLocalBuild =
26-
try
27-
// Additional check to see if we're using local build
28-
let assembly = Assembly.GetExecutingAssembly()
29-
assembly.Location.Contains("artifacts")
30-
with _ -> false
3+
let sdkVersion = "10.0.100-rc.1.25411.109"
4+
let fsharpCompilerPath = "/usr/share/dotnet/dotnet"
5+
let dotnetFscCompilerPath = "/home/runner/work/fsharp/fsharp/artifacts/Bootstrap/fsc/fsc.dll"
6+
let isLocalBuild = false

tests/projects/CompilerCompat/CompilerCompatApp/CompilerCompatApp.fsproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,22 @@
1616
<ProjectReference Include="../CompilerCompatLib/CompilerCompatLib.fsproj" />
1717
</ItemGroup>
1818

19+
<Target Name="GenerateAppBuildInfo" BeforeTargets="BeforeCompile">
20+
<PropertyGroup>
21+
<IsLocalBuildValue Condition="'$(LoadLocalFSharpBuild)' == 'True'">true</IsLocalBuildValue>
22+
<IsLocalBuildValue Condition="'$(LoadLocalFSharpBuild)' != 'True'">false</IsLocalBuildValue>
23+
<CleanDotnetFscCompilerPath Condition="'$(DotnetFscCompilerPath)' != ''">$(DotnetFscCompilerPath.Replace('&quot;', ''))</CleanDotnetFscCompilerPath>
24+
<CleanDotnetFscCompilerPath Condition="'$(DotnetFscCompilerPath)' == ''">N/A</CleanDotnetFscCompilerPath>
25+
</PropertyGroup>
26+
<WriteLinesToFile
27+
File="AppBuildInfo.fs"
28+
Overwrite="true"
29+
Lines="namespace CompilerCompatApp
30+
module AppBuildInfo =
31+
let sdkVersion = &quot;$(NETCoreSdkVersion)&quot;
32+
let fsharpCompilerPath = &quot;$(FscToolPath)\$(FscToolExe)&quot;
33+
let dotnetFscCompilerPath = &quot;$(CleanDotnetFscCompilerPath)&quot;
34+
let isLocalBuild = $(IsLocalBuildValue)" />
35+
</Target>
36+
1937
</Project>

tests/projects/CompilerCompat/CompilerCompatApp/Program.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ let main _argv =
99
printfn "=== BUILD VERIFICATION ==="
1010
printfn "Library Build Info:"
1111
printfn " SDK Version: %s" LibBuildInfo.sdkVersion
12-
printfn " FSC Path: %s" LibBuildInfo.fscPath
12+
printfn " F# Compiler Path: %s" LibBuildInfo.fsharpCompilerPath
13+
printfn " .NET FSC Compiler Path: %s" LibBuildInfo.dotnetFscCompilerPath
1314
printfn " Is Local Build: %b" LibBuildInfo.isLocalBuild
1415
printfn "Application Build Info:"
1516
printfn " SDK Version: %s" AppBuildInfo.sdkVersion
16-
printfn " FSC Path: %s" AppBuildInfo.fscPath
17+
printfn " F# Compiler Path: %s" AppBuildInfo.fsharpCompilerPath
18+
printfn " .NET FSC Compiler Path: %s" AppBuildInfo.dotnetFscCompilerPath
1719
printfn " Is Local Build: %b" AppBuildInfo.isLocalBuild
1820
printfn "=========================="
1921

tests/projects/CompilerCompat/CompilerCompatLib/CompilerCompatLib.fsproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@
1212
<Compile Include="Library.fs" />
1313
</ItemGroup>
1414

15+
<Target Name="GenerateLibBuildInfo" BeforeTargets="BeforeCompile">
16+
<PropertyGroup>
17+
<IsLocalBuildValue Condition="'$(LoadLocalFSharpBuild)' == 'True'">true</IsLocalBuildValue>
18+
<IsLocalBuildValue Condition="'$(LoadLocalFSharpBuild)' != 'True'">false</IsLocalBuildValue>
19+
<CleanDotnetFscCompilerPath Condition="'$(DotnetFscCompilerPath)' != ''">$(DotnetFscCompilerPath.Replace('&quot;', ''))</CleanDotnetFscCompilerPath>
20+
<CleanDotnetFscCompilerPath Condition="'$(DotnetFscCompilerPath)' == ''">N/A</CleanDotnetFscCompilerPath>
21+
</PropertyGroup>
22+
<WriteLinesToFile
23+
File="LibBuildInfo.fs"
24+
Overwrite="true"
25+
Lines="namespace CompilerCompatLib
26+
module LibBuildInfo =
27+
let sdkVersion = &quot;$(NETCoreSdkVersion)&quot;
28+
let fsharpCompilerPath = &quot;$(FscToolPath)\$(FscToolExe)&quot;
29+
let dotnetFscCompilerPath = &quot;$(CleanDotnetFscCompilerPath)&quot;
30+
let isLocalBuild = $(IsLocalBuildValue)" />
31+
</Target>
32+
1533
</Project>
Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
namespace CompilerCompatLib
2-
3-
open System
4-
open System.Reflection
5-
open System.Diagnostics
6-
72
module LibBuildInfo =
8-
let sdkVersion =
9-
try
10-
// Try to get .NET version from runtime
11-
Environment.Version.ToString()
12-
with _ -> "Unknown"
13-
14-
let fscPath =
15-
try
16-
// Check if we're using local compiler by looking at assembly location
17-
let assembly = Assembly.GetExecutingAssembly()
18-
let location = assembly.Location
19-
if location.Contains("artifacts") then
20-
$"Local compiler (artifacts): {location}"
21-
else
22-
$"SDK compiler: {location}"
23-
with _ -> "Unknown"
24-
25-
let isLocalBuild =
26-
try
27-
// Additional check to see if we're using local build
28-
let assembly = Assembly.GetExecutingAssembly()
29-
assembly.Location.Contains("artifacts")
30-
with _ -> false
3+
let sdkVersion = "10.0.100-rc.1.25411.109"
4+
let fsharpCompilerPath = "/usr/share/dotnet/dotnet"
5+
let dotnetFscCompilerPath = "/home/runner/work/fsharp/fsharp/artifacts/Bootstrap/fsc/fsc.dll"
6+
let isLocalBuild = false

0 commit comments

Comments
 (0)