Skip to content

Commit 49347bc

Browse files
vzarytovskiibaronfel
authored andcommitted
Fixed CompilerAssert for non-windows; Updated README
1 parent b0bd54d commit 49347bc

File tree

4 files changed

+81
-43
lines changed

4 files changed

+81
-43
lines changed

tests/FSharp.Test.Utilities/CompilerAssert.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ let main argv = 0"""
125125
File.WriteAllText(programFsFileName, programFs)
126126

127127
let pInfo = ProcessStartInfo ()
128-
129128
pInfo.FileName <- config.DotNetExe
130129
pInfo.Arguments <- "build"
131130
pInfo.WorkingDirectory <- projectDirectory
@@ -147,7 +146,7 @@ let main argv = 0"""
147146
cleanUp <- false
148147
printfn "%s" output
149148
printfn "%s" errors
150-
raise (new Exception (sprintf "An error occured getting netcoreapp references: %A" e))
149+
raise (new Exception (sprintf "An error occurred getting netcoreapp references: %A" e))
151150
finally
152151
if cleanUp then
153152
try Directory.Delete(projectDirectory) with | _ -> ()

tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net472;netcoreapp3.0</TargetFrameworks>
55
<TargetFrameworks Condition="'$(OS)' == 'Unix'">netcoreapp3.0</TargetFrameworks>
6-
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
6+
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
77
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81</AssetTargetFallback>
88
<ReferenceVsAssemblies>true</ReferenceVsAssemblies>
99
<OutputType>Library</OutputType>

tests/FSharp.Test.Utilities/TestFramework.fs

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,41 +142,72 @@ type TestConfig =
142142
DotNetExe: string
143143
DefaultPlatform: string}
144144

145+
#if NETCOREAPP
146+
open System.Runtime.InteropServices
147+
#endif
145148

146-
module WindowsPlatform =
147-
let Is64BitOperatingSystem envVars =
148-
// On Windows PROCESSOR_ARCHITECTURE has the value AMD64 on 64 bit Intel Machines
149-
let value =
150-
let find s = envVars |> Map.tryFind s
151-
[| "PROCESSOR_ARCHITECTURE" |] |> Seq.tryPick (fun s -> find s) |> function None -> "" | Some x -> x
152-
value = "AMD64"
149+
let getOperatingSystem () =
150+
#if NETCOREAPP
151+
let isPlatform p = RuntimeInformation.IsOSPlatform(p)
152+
if isPlatform OSPlatform.Windows then "win"
153+
elif isPlatform OSPlatform.Linux then "linux"
154+
elif isPlatform OSPlatform.OSX then "osx"
155+
else "unknown"
156+
#else
157+
"win"
158+
#endif
153159

154-
type FSLibPaths =
160+
module DotnetPlatform =
161+
let Is64BitOperatingSystem envVars =
162+
match getOperatingSystem () with
163+
| "win" ->
164+
// On Windows PROCESSOR_ARCHITECTURE has the value AMD64 on 64 bit Intel Machines
165+
let value =
166+
let find s = envVars |> Map.tryFind s
167+
[| "PROCESSOR_ARCHITECTURE" |] |> Seq.tryPick (fun s -> find s) |> function None -> "" | Some x -> x
168+
value = "AMD64"
169+
| _ -> System.Environment.Is64BitOperatingSystem // As an alternative for netstandard1.4+: System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture
170+
171+
type FSLibPaths =
155172
{ FSCOREDLLPATH : string }
156173

157-
let requireFile nm =
158-
if Commands.fileExists __SOURCE_DIRECTORY__ nm |> Option.isSome then nm else failwith (sprintf "couldn't find %s. Running 'build test' once might solve this issue" nm)
159-
160-
let packagesDir =
161-
match Environment.GetEnvironmentVariable("NUGET_PACKAGES") with
162-
| null -> Environment.GetEnvironmentVariable("USERPROFILE") ++ ".nuget" ++ "packages"
163-
| path -> path
174+
let getPackagesDir () =
175+
let p = match Environment.GetEnvironmentVariable("NUGET_PACKAGES") with
176+
| null ->
177+
match Environment.GetEnvironmentVariable("USERPROFILE") with
178+
| null -> Environment.GetEnvironmentVariable("HOME")
179+
| p -> p
180+
| path -> path
181+
p ++ ".nuget" ++ "packages"
182+
183+
let requireFile dir path =
184+
// Linux filesystems are (in most cases) case-sensitive.
185+
// However when nuget packages are installed to $HOME/.nuget/packages, it seems they are lowercased
186+
let fullPath = (dir ++ path)
187+
match Commands.fileExists __SOURCE_DIRECTORY__ fullPath with
188+
| Some p -> p
189+
| None ->
190+
let fullPathLower = (dir ++ path.ToLower())
191+
match Commands.fileExists __SOURCE_DIRECTORY__ fullPathLower with
192+
| Some p -> p
193+
| None -> failwith (sprintf "Couldn't find \"%s\" on the following paths: \"%s\", \"%s\". Running 'build test' once might solve this issue" path fullPath fullPathLower)
164194

165195
let config configurationName envVars =
166-
167196
let SCRIPT_ROOT = __SOURCE_DIRECTORY__
168197
#if NET472
169198
let fscArchitecture = "net472"
170199
let fsiArchitecture = "net472"
171200
let fsharpCoreArchitecture = "net45"
172201
let fsharpBuildArchitecture = "net472"
173202
let fsharpCompilerInteractiveSettingsArchitecture = "net472"
203+
let peverifyArchitecture = "net472"
174204
#else
175205
let fscArchitecture = "netcoreapp3.0"
176206
let fsiArchitecture = "netcoreapp3.0"
177207
let fsharpCoreArchitecture = "netstandard2.0"
178208
let fsharpBuildArchitecture = "netcoreapp3.0"
179209
let fsharpCompilerInteractiveSettingsArchitecture = "netstandard2.0"
210+
let peverifyArchitecture = "netcoreapp3.0"
180211
#endif
181212
let repoRoot = SCRIPT_ROOT ++ ".." ++ ".."
182213
let artifactsPath = repoRoot ++ "artifacts"
@@ -185,31 +216,42 @@ let config configurationName envVars =
185216
let csc_flags = "/nologo"
186217
let fsc_flags = "-r:System.Core.dll --nowarn:20 --define:COMPILED"
187218
let fsi_flags = "-r:System.Core.dll --nowarn:20 --define:INTERACTIVE --maxerrors:1 --abortonerror"
188-
let Is64BitOperatingSystem = WindowsPlatform.Is64BitOperatingSystem envVars
219+
let operatingSystem = getOperatingSystem ()
220+
let Is64BitOperatingSystem = DotnetPlatform.Is64BitOperatingSystem envVars
189221
let architectureMoniker = if Is64BitOperatingSystem then "x64" else "x86"
190-
let CSC = requireFile (packagesDir ++ "Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
191-
let ILDASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ildasm.exe")
192-
let ILASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ilasm.exe")
193-
let coreclrdll = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "coreclr.dll")
194-
let PEVERIFY = requireFile (artifactsBinPath ++ "PEVerify" ++ configurationName ++ "net472" ++ "PEVerify.exe")
195-
let FSI_FOR_SCRIPTS = artifactsBinPath ++ "fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe"
196-
let FSharpBuild = requireFile (artifactsBinPath ++ "FSharp.Build" ++ configurationName ++ fsharpBuildArchitecture ++ "FSharp.Build.dll")
197-
let FSharpCompilerInteractiveSettings = requireFile (artifactsBinPath ++ "FSharp.Compiler.Interactive.Settings" ++ configurationName ++ fsharpCompilerInteractiveSettingsArchitecture ++ "FSharp.Compiler.Interactive.Settings.dll")
222+
let packagesDir = getPackagesDir ()
223+
let requirePackage = requireFile packagesDir
224+
let requireArtifact = requireFile artifactsBinPath
225+
let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
226+
let ILDASM_EXE = if operatingSystem = "windows" then "ildasm.exe" else "ildasm"
227+
let ILDASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILDASM_EXE)
228+
let ILASM_EXE = if operatingSystem = "windows" then "ilasm.exe" else "ilasm"
229+
let ILASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILASM_EXE)
230+
let CORECLR_DLL = if operatingSystem = "windows" then "coreclr.dll" elif operatingSystem = "osx" then "libcoreclr.dylib" else "libcoreclr.so"
231+
let coreclrdll = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ CORECLR_DLL)
232+
let PEVERIFY_EXE = if operatingSystem = "windows" then "PEVerify.exe" else "PEVerify"
233+
let PEVERIFY = requireArtifact ("PEVerify" ++ configurationName ++ peverifyArchitecture ++ PEVERIFY_EXE)
234+
let FSharpBuild = requireArtifact ("FSharp.Build" ++ configurationName ++ fsharpBuildArchitecture ++ "FSharp.Build.dll")
235+
let FSharpCompilerInteractiveSettings = requireArtifact ("FSharp.Compiler.Interactive.Settings" ++ configurationName ++ fsharpCompilerInteractiveSettingsArchitecture ++ "FSharp.Compiler.Interactive.Settings.dll")
236+
198237
let dotNetExe =
199238
// first look for {repoRoot}\.dotnet\dotnet.exe, otherwise fallback to %PATH%
200-
let repoLocalDotnetPath = repoRoot ++ ".dotnet" ++ "dotnet.exe"
239+
let DOTNET_EXE = if operatingSystem = "windows" then "dotnet.exe" else "dotnet"
240+
let repoLocalDotnetPath = repoRoot ++ ".dotnet" ++ DOTNET_EXE
201241
if File.Exists(repoLocalDotnetPath) then repoLocalDotnetPath
202-
else "dotnet.exe"
242+
else DOTNET_EXE
243+
203244
// ildasm + ilasm requires coreclr.dll to run which has already been restored to the packages directory
204-
File.Copy(coreclrdll, Path.GetDirectoryName(ILDASM) ++ "coreclr.dll", overwrite=true)
205-
File.Copy(coreclrdll, Path.GetDirectoryName(ILASM) ++ "coreclr.dll", overwrite=true)
245+
File.Copy(coreclrdll, Path.GetDirectoryName(ILDASM) ++ CORECLR_DLL, overwrite=true)
246+
File.Copy(coreclrdll, Path.GetDirectoryName(ILASM) ++ CORECLR_DLL, overwrite=true)
206247

207-
let FSI = requireFile (FSI_FOR_SCRIPTS)
248+
let FSI_FOR_SCRIPTS = ("fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe")
249+
let FSI = requireArtifact FSI_FOR_SCRIPTS
208250
#if !NETCOREAPP
209-
let FSIANYCPU = requireFile (artifactsBinPath ++ "fsiAnyCpu" ++ configurationName ++ "net472" ++ "fsiAnyCpu.exe")
251+
let FSIANYCPU = requireArtifact ("fsiAnyCpu" ++ configurationName ++ "net472" ++ "fsiAnyCpu.exe")
210252
#endif
211-
let FSC = requireFile (artifactsBinPath ++ "fsc" ++ configurationName ++ fscArchitecture ++ "fsc.exe")
212-
let FSCOREDLLPATH = requireFile (artifactsBinPath ++ "FSharp.Core" ++ configurationName ++ fsharpCoreArchitecture ++ "FSharp.Core.dll")
253+
let FSC = requireArtifact ("fsc" ++ configurationName ++ fscArchitecture ++ "fsc.exe")
254+
let FSCOREDLLPATH = requireArtifact ("FSharp.Core" ++ configurationName ++ fsharpCoreArchitecture ++ "FSharp.Core.dll")
213255

214256
let defaultPlatform =
215257
match Is64BitOperatingSystem with
@@ -279,9 +321,9 @@ let envVars () =
279321
let initializeSuite () =
280322

281323
#if DEBUG
282-
let configurationName = "debug"
324+
let configurationName = "Debug"
283325
#else
284-
let configurationName = "release"
326+
let configurationName = "Release"
285327
#endif
286328
let env = envVars ()
287329

tests/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ Existing FSharpQA and Cambridge need to be migrated to corresponding test projec
9393

9494
## Next steps
9595

96-
* [**In Progress**] Move `FSharp.TestHelpers` to `FSharp.Test.Utilities`.
97-
* [**In Progress**] Create initial test projects structure for new tests (`FSharp.Compiler.ComponentTests`).
9896
* [**In Progress**] Migrate existing `NUnit` tests to xUnit.
99-
* [**In progress**] Change build scripts to run new suites as well as old ones.
97+
* Clean up CompilerAssert.
98+
* Make PEVerify tests work in netcore/non-windows environment.
10099
* Start migration of existing (namely, FSharpQA and Cambridge) suites to xUnit-based projects.
101100

102101
## Open questions:
@@ -108,5 +107,3 @@ Existing FSharpQA and Cambridge need to be migrated to corresponding test projec
108107
Related issues: (https://github.com/dotnet/fsharp/issues/7075)
109108

110109
You can find this document under 'tests/README.md'.
111-
112-
**I would like to hear some feedback the community, so we can quickly re-iterate over it (if needed), and start working :)**

0 commit comments

Comments
 (0)