From 1cf7eeea86b0bd7ad05dd755f9100b99e0344e72 Mon Sep 17 00:00:00 2001 From: "Kevin Ransom (msft)" Date: Mon, 21 Dec 2020 07:19:15 -0800 Subject: [PATCH] Build FSI and FSC using AppHost (#10736) * move over to fsc.dll and fsi.dll --- FSharpTests.Directory.Build.props | 4 +- eng/Build.ps1 | 2 +- src/buildtools/AssemblyCheck/AssemblyCheck.fs | 71 ++++++++++++------- .../Microsoft.FSharp.NetSdk.props | 4 +- .../Microsoft.FSharp.Compiler.nuspec | 4 +- src/fsharp/fsc/fsc.fsproj | 3 +- src/fsharp/fsi/fsi.fsproj | 3 +- tests/FSharp.Test.Utilities/CompilerAssert.fs | 2 +- tests/FSharp.Test.Utilities/TestFramework.fs | 8 ++- 9 files changed, 63 insertions(+), 38 deletions(-) diff --git a/FSharpTests.Directory.Build.props b/FSharpTests.Directory.Build.props index 90d73761408..098235215c1 100644 --- a/FSharpTests.Directory.Build.props +++ b/FSharpTests.Directory.Build.props @@ -22,12 +22,12 @@ $([System.IO.Path]::GetDirectoryName('$(DOTNET_HOST_PATH)')) dotnet.exe dotnet - $(MSBuildThisFileDirectory)artifacts\bin\fsc\$(Configuration)\netcoreapp3.1\fsc.exe + $(MSBuildThisFileDirectory)artifacts\bin\fsc\$(Configuration)\netcoreapp3.1\fsc.dll $([System.IO.Path]::GetDirectoryName('$(DOTNET_HOST_PATH)')) dotnet.exe dotnet - $(MSBuildThisFileDirectory)artifacts\bin\fsi\$(Configuration)\netcoreapp3.1\fsi.exe + $(MSBuildThisFileDirectory)artifacts\bin\fsi\$(Configuration)\netcoreapp3.1\fsi.dll diff --git a/eng/Build.ps1 b/eng/Build.ps1 index 429ad1d580c..3555d70f48f 100644 --- a/eng/Build.ps1 +++ b/eng/Build.ps1 @@ -163,7 +163,7 @@ function Update-Arguments() { $script:bootstrap = $True } } else { - if (-Not (Test-Path "$ArtifactsDir\Bootstrap\fsc\fsc.exe") -or (Test-Path "$ArtifactsDir\Bootstrap\fsc\fsc.runtimeconfig.json")) { + if (-Not (Test-Path "$ArtifactsDir\Bootstrap\fsc\fsc.dll") -or (Test-Path "$ArtifactsDir\Bootstrap\fsc\fsc.runtimeconfig.json")) { $script:bootstrap = $True } } diff --git a/src/buildtools/AssemblyCheck/AssemblyCheck.fs b/src/buildtools/AssemblyCheck/AssemblyCheck.fs index 9eb04a3087d..a4f916e2f49 100644 --- a/src/buildtools/AssemblyCheck/AssemblyCheck.fs +++ b/src/buildtools/AssemblyCheck/AssemblyCheck.fs @@ -15,35 +15,52 @@ module AssemblyCheck = let private devVersionPattern = new Regex(@"-(ci|dev)", RegexOptions.Compiled) let verifyEmbeddedPdb (filename:string) = - use fileStream = File.OpenRead(filename) - let reader = new PEReader(fileStream) - let mutable hasEmbeddedPdb = false - - try - for entry in reader.ReadDebugDirectory() do - match entry.Type with - | DebugDirectoryEntryType.CodeView -> - let _ = reader.ReadCodeViewDebugDirectoryData(entry) - () - - | DebugDirectoryEntryType.EmbeddedPortablePdb -> - let _ = reader.ReadEmbeddedPortablePdbDebugDirectoryData(entry) - hasEmbeddedPdb <- true - () - - | DebugDirectoryEntryType.PdbChecksum -> - let _ = reader.ReadPdbChecksumDebugDirectoryData(entry) - () - - | _ -> () - with | e -> printfn "Error validating assembly %s\nMessage: %s" filename (e.ToString()) - hasEmbeddedPdb + let isManagedDll = + try + // Is il assembly? throws if not + let _ = AssemblyName.GetAssemblyName(filename).Version + true + with + | :? System.BadImageFormatException -> false // uninterested in embedded pdbs for native dlls + + if isManagedDll then + use fileStream = File.OpenRead(filename) + let reader = new PEReader(fileStream) + let mutable hasEmbeddedPdb = false + + try + for entry in reader.ReadDebugDirectory() do + match entry.Type with + | DebugDirectoryEntryType.CodeView -> + let _ = reader.ReadCodeViewDebugDirectoryData(entry) + () + + | DebugDirectoryEntryType.EmbeddedPortablePdb -> + let _ = reader.ReadEmbeddedPortablePdbDebugDirectoryData(entry) + hasEmbeddedPdb <- true + () + + | DebugDirectoryEntryType.PdbChecksum -> + let _ = reader.ReadPdbChecksumDebugDirectoryData(entry) + () + + | _ -> () + with + | e -> printfn "Error validating assembly %s\nMessage: %s" filename (e.ToString()) + + hasEmbeddedPdb + else + true let verifyAssemblies (binariesPath:string) = let excludedAssemblies = [ ] |> Set.ofList + let maybeNativeExe = + [ "fsi.exe" + "fsc.exe" ] |> Set.ofList + let fsharpAssemblies = [ "FSharp*.dll" "fsc.exe" @@ -63,8 +80,12 @@ module AssemblyCheck = let failedVersionCheck = fsharpAssemblies |> List.filter (fun a -> - let assemblyVersion = AssemblyName.GetAssemblyName(a).Version - assemblyVersion = versionZero || assemblyVersion = versionOne) + try + let assemblyVersion = AssemblyName.GetAssemblyName(a).Version + assemblyVersion = versionZero || assemblyVersion = versionOne + with | :? System.BadImageFormatException -> + // fsc.exe and fsi.exe are il on the desktop and native on the coreclr + Set.contains (Path.GetFileName(a)) maybeNativeExe |> not) if failedVersionCheck.Length > 0 then printfn "The following assemblies had a version of %A or %A" versionZero versionOne diff --git a/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props b/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props index 3a51d7287a5..a4b48f9cc61 100644 --- a/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props +++ b/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props @@ -59,11 +59,11 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and $([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH))) $([System.IO.Path]::GetFileName($(DOTNET_HOST_PATH))) - "$(MSBuildThisFileDirectory)fsc.exe" + "$(MSBuildThisFileDirectory)fsc.dll" $([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH))) $([System.IO.Path]::GetFileName($(DOTNET_HOST_PATH))) - "$(MSBuildThisFileDirectory)fsi.exe" + "$(MSBuildThisFileDirectory)fsi.dll" - + + diff --git a/src/fsharp/fsc/fsc.fsproj b/src/fsharp/fsc/fsc.fsproj index b773ec682d0..696b268c3b3 100644 --- a/src/fsharp/fsc/fsc.fsproj +++ b/src/fsharp/fsc/fsc.fsproj @@ -12,12 +12,11 @@ netcoreapp3.0 net472;netcoreapp3.1 netcoreapp3.1 - .exe $(NoWarn);45;55;62;75;1204 true $(OtherFlags) --maxerrors:20 --extraoptimizationloops:1 true - false + true diff --git a/src/fsharp/fsi/fsi.fsproj b/src/fsharp/fsi/fsi.fsproj index 97cf56032e6..6e1f1e0eb7c 100644 --- a/src/fsharp/fsi/fsi.fsproj +++ b/src/fsharp/fsi/fsi.fsproj @@ -12,13 +12,12 @@ netcoreapp3.0 net472;netcoreapp3.1 netcoreapp3.1 - .exe $(NoWarn);45;55;62;75;1204 true --warnon:1182 --maxerrors:20 --extraoptimizationloops:1 fsi.res true - false + true diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 943f9aa9aff..ba6395c9aa0 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -239,7 +239,7 @@ let main argv = 0""" let args = options |> Array.append defaultProjectOptions.OtherOptions - |> Array.append [| "fsc.exe"; inputFilePath; "-o:" + outputFilePath; (if isExe then "--target:exe" else "--target:library"); "--nowin32manifest" |] + |> Array.append [| "fsc.dll"; inputFilePath; "-o:" + outputFilePath; (if isExe then "--target:exe" else "--target:library"); "--nowin32manifest" |] let errors, _ = checker.Compile args |> Async.RunSynchronously errors, outputFilePath diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index 0191804c72c..18af5370bc9 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -293,13 +293,19 @@ let config configurationName envVars = if File.Exists(repoLocalDotnetPath) then repoLocalDotnetPath else DOTNET_EXE +#if !NETCOREAPP let FSI_PATH = ("fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe") +#else + let FSI_PATH = ("fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.dll") +#endif let FSI_FOR_SCRIPTS = requireArtifact FSI_PATH let FSI = requireArtifact FSI_PATH #if !NETCOREAPP let FSIANYCPU = requireArtifact ("fsiAnyCpu" ++ configurationName ++ "net472" ++ "fsiAnyCpu.exe") -#endif let FSC = requireArtifact ("fsc" ++ configurationName ++ fscArchitecture ++ "fsc.exe") +#else + let FSC = requireArtifact ("fsc" ++ configurationName ++ fscArchitecture ++ "fsc.dll") +#endif let FSCOREDLLPATH = requireArtifact ("FSharp.Core" ++ configurationName ++ fsharpCoreArchitecture ++ "FSharp.Core.dll") let defaultPlatform =