Skip to content

Commit cf19605

Browse files
author
dotnet-automerge-bot
authored
Merge pull request #7323 from dotnet/merges/master-to-release/dev16.3
Merge master to release/dev16.3
2 parents bde3682 + b62bb71 commit cf19605

File tree

6 files changed

+188
-4
lines changed

6 files changed

+188
-4
lines changed

eng/Build.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,25 @@ function Prepare-TempDir() {
278278
Copy-Item (Join-Path $RepoRoot "tests\Resources\Directory.Build.targets") $TempDir
279279
}
280280

281+
function EnablePreviewSdks() {
282+
if (Test-Path variable:global:_MSBuildExe) {
283+
return
284+
}
285+
$vsInfo = LocateVisualStudio
286+
if ($vsInfo -eq $null) {
287+
# Preview SDKs are allowed when no Visual Studio instance is installed
288+
return
289+
}
290+
291+
$vsId = $vsInfo.instanceId
292+
$vsMajorVersion = $vsInfo.installationVersion.Split('.')[0]
293+
294+
$instanceDir = Join-Path ${env:USERPROFILE} "AppData\Local\Microsoft\VisualStudio\$vsMajorVersion.0_$vsId"
295+
Create-Directory $instanceDir
296+
$sdkFile = Join-Path $instanceDir "sdk.txt"
297+
'UsePreviews=True' | Set-Content $sdkFile
298+
}
299+
281300
try {
282301
Process-Arguments
283302

@@ -289,6 +308,7 @@ try {
289308

290309
if ($ci) {
291310
Prepare-TempDir
311+
EnablePreviewSdks
292312

293313
# enable us to build netcoreapp2.1 binaries
294314
$global:_DotNetInstallDir = Join-Path $RepoRoot ".dotnet"

eng/Versions.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
<MicrosoftCodeAnalysisEditorFeaturesWpfVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesWpfVersion>
100100
<MicrosoftCodeAnalysisExternalAccessFSharpVersion>$(RoslynVersion)</MicrosoftCodeAnalysisExternalAccessFSharpVersion>
101101
<MicrosoftCodeAnalysisWorkspacesCommonVersion>$(RoslynVersion)</MicrosoftCodeAnalysisWorkspacesCommonVersion>
102+
<MicrosoftCodeAnalysisCSharpVersion>$(RoslynVersion)</MicrosoftCodeAnalysisCSharpVersion>
103+
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.17</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
102104
<MicrosoftVisualStudioLanguageServicesVersion>$(RoslynVersion)</MicrosoftVisualStudioLanguageServicesVersion>
103105
<!-- Microsoft Build packages -->
104106
<MicrosoftBuildOverallPackagesVersion>16.0.461</MicrosoftBuildOverallPackagesVersion>
@@ -165,7 +167,8 @@
165167
<MicrosoftCompositionVersion>1.0.30</MicrosoftCompositionVersion>
166168
<MicrosoftMSXMLVersion>8.0.0-alpha</MicrosoftMSXMLVersion>
167169
<MicrosoftNetCompilersVersion>2.7.0</MicrosoftNetCompilersVersion>
168-
<MicrosoftNETCoreILDAsmVersion>2.0.3</MicrosoftNETCoreILDAsmVersion>
170+
<MicrosoftNETCoreILDAsmVersion>3.0.0-preview-27318-01</MicrosoftNETCoreILDAsmVersion>
171+
<MicrosoftNETCoreILAsmVersion>3.0.0-preview-27318-01</MicrosoftNETCoreILAsmVersion>
169172
<MicrosoftNETTestSdkVersion>15.8.0</MicrosoftNETTestSdkVersion>
170173
<MicrosoftVisualFSharpTypeProvidersRedistVersion>1.0.0</MicrosoftVisualFSharpTypeProvidersRedistVersion>
171174
<MicrosoftWin32RegistryVersion>4.3.0</MicrosoftWin32RegistryVersion>

tests/fsharp/Compiler/ILChecker.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,8 @@ module ILChecker =
9595

9696
let checkIL dllFilePath expectedIL =
9797
checkILAux [] dllFilePath expectedIL
98+
99+
let reassembleIL ilFilePath dllFilePath =
100+
let ilasmPath = config.ILASM
101+
let errors, _ = exec ilasmPath ([ sprintf "%s /output=%s /dll" ilFilePath dllFilePath ])
102+
errors

tests/fsharp/Compiler/Utilities.fs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
module FSharp.Compiler.UnitTests.Utilities
4+
5+
open System
6+
open System.IO
7+
open System.Collections.Immutable
8+
open Microsoft.CodeAnalysis
9+
open Microsoft.CodeAnalysis.CSharp
10+
11+
// This file mimics how Roslyn handles their compilation references for compilation testing
12+
13+
[<RequireQualifiedAccess>]
14+
type TargetFramework =
15+
| NetStandard20
16+
| NetCoreApp30
17+
18+
module private TestReferences =
19+
20+
[<RequireQualifiedAccess>]
21+
module NetStandard20 =
22+
23+
let netStandard = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.netstandard).GetReference(display = "netstandard.dll (netstandard 2.0 ref)")
24+
25+
let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.mscorlib).GetReference(display = "mscorlib.dll (netstandard 2.0 ref)")
26+
27+
let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Runtime).GetReference(display = "System.Runtime.dll (netstandard 2.0 ref)")
28+
29+
let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Core).GetReference(display = "System.Core.dll (netstandard 2.0 ref)")
30+
31+
let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Dynamic_Runtime).GetReference(display = "System.Dynamic.Runtime.dll (netstandard 2.0 ref)")
32+
33+
[<RequireQualifiedAccess>]
34+
module NetCoreApp30 =
35+
36+
let netStandard = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.netstandard).GetReference(display = "netstandard.dll (netcoreapp 3.0 ref)")
37+
38+
let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.mscorlib).GetReference(display = "mscorlib.dll (netcoreapp 3.0 ref)")
39+
40+
let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.System_Runtime).GetReference(display = "System.Runtime.dll (netcoreapp 3.0 ref)")
41+
42+
let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.System_Core).GetReference(display = "System.Core.dll (netcoreapp 3.0 ref)")
43+
44+
let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.System_Dynamic_Runtime).GetReference(display = "System.Dynamic.Runtime.dll (netcoreapp 3.0 ref)")
45+
46+
let systemConsoleRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netcoreapp30.System_Console).GetReference(display = "System.Console.dll (netcoreapp 3.0 ref)")
47+
48+
49+
[<RequireQualifiedAccess>]
50+
module private TargetFrameworkUtil =
51+
52+
open TestReferences
53+
54+
let private netStandard20References =
55+
lazy ImmutableArray.Create(NetStandard20.netStandard.Value, NetStandard20.mscorlibRef.Value, NetStandard20.systemRuntimeRef.Value, NetStandard20.systemCoreRef.Value, NetStandard20.systemDynamicRuntimeRef.Value)
56+
57+
let private netCoreApp30References =
58+
lazy ImmutableArray.Create(NetCoreApp30.netStandard.Value, NetCoreApp30.mscorlibRef.Value, NetCoreApp30.systemRuntimeRef.Value, NetCoreApp30.systemCoreRef.Value, NetCoreApp30.systemDynamicRuntimeRef.Value, NetCoreApp30.systemConsoleRef.Value)
59+
60+
let getReferences tf =
61+
match tf with
62+
| TargetFramework.NetStandard20 -> netStandard20References.Value
63+
| TargetFramework.NetCoreApp30 -> netCoreApp30References.Value
64+
65+
type RoslynLanguageVersion = LanguageVersion
66+
67+
[<Flags>]
68+
type CSharpCompilationFlags =
69+
| None = 0x0
70+
| InternalsVisibleTo = 0x1
71+
72+
[<RequireQualifiedAccess>]
73+
type TestCompilation =
74+
| CSharp of CSharpCompilation * CSharpCompilationFlags
75+
| IL of ilSource: string * result: Lazy<string * byte []>
76+
77+
member this.AssertNoErrorsOrWarnings () =
78+
match this with
79+
| TestCompilation.CSharp (c, _) ->
80+
let diagnostics = c.GetDiagnostics ()
81+
82+
if not diagnostics.IsEmpty then
83+
NUnit.Framework.Assert.Fail ("CSharp source diagnostics:\n" + (diagnostics |> Seq.map (fun x -> x.GetMessage () + "\n") |> Seq.reduce (+)))
84+
85+
| TestCompilation.IL (_, result) ->
86+
let errors, _ = result.Value
87+
if errors.Length > 0 then
88+
NUnit.Framework.Assert.Fail ("IL source errors: " + errors)
89+
90+
member this.EmitAsFile (outputPath: string) =
91+
match this with
92+
| TestCompilation.CSharp (c, _) ->
93+
let emitResult = c.Emit outputPath
94+
if not emitResult.Success then
95+
failwithf "Unable to emit C# compilation.\n%A" emitResult.Diagnostics
96+
97+
| TestCompilation.IL (_, result) ->
98+
let (_, data) = result.Value
99+
File.WriteAllBytes (outputPath, data)
100+
101+
type CSharpLanguageVersion =
102+
| CSharp8 = 0
103+
104+
[<AbstractClass; Sealed>]
105+
type CompilationUtil private () =
106+
107+
static member CreateCSharpCompilation (source: string, lv: CSharpLanguageVersion, ?tf, ?additionalReferences, ?flags) =
108+
let lv =
109+
match lv with
110+
| CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8
111+
| _ -> LanguageVersion.Default
112+
113+
let tf = defaultArg tf TargetFramework.NetStandard20
114+
let additionalReferences = defaultArg additionalReferences ImmutableArray.Empty
115+
let flags = defaultArg flags CSharpCompilationFlags.None
116+
let references = TargetFrameworkUtil.getReferences tf
117+
let c =
118+
CSharpCompilation.Create(
119+
Guid.NewGuid().ToString (),
120+
[ CSharpSyntaxTree.ParseText (source, CSharpParseOptions lv) ],
121+
references.As<MetadataReference>().AddRange additionalReferences,
122+
CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary))
123+
Some (TestCompilation.CSharp (c, flags))
124+
125+
static member CreateILCompilation (source: string) =
126+
let compute =
127+
lazy
128+
let ilFilePath = Path.GetTempFileName ()
129+
let tmp = Path.GetTempFileName()
130+
let dllFilePath = Path.ChangeExtension (tmp, ".dll")
131+
try
132+
File.WriteAllText (ilFilePath, source)
133+
let errors = ILChecker.reassembleIL ilFilePath dllFilePath
134+
try
135+
(errors, File.ReadAllBytes dllFilePath)
136+
with
137+
| _ -> (errors, [||])
138+
finally
139+
try File.Delete ilFilePath with | _ -> ()
140+
try File.Delete tmp with | _ -> ()
141+
try File.Delete dllFilePath with | _ -> ()
142+
Some (TestCompilation.IL (source, compute))

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<Compile Include="TypeProviderTests.fs" />
3333
<Compile Include="tests.fs" />
3434
<Compile Include="Compiler\ILChecker.fs" />
35+
<Compile Include="Compiler\Utilities.fs" />
3536
<Compile Include="Compiler\CompilerAssert.fs" />
3637
<Compile Include="Compiler\Conformance\BasicGrammarElements\BasicConstants.fs" />
3738
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
@@ -73,10 +74,14 @@
7374
<ItemGroup>
7475
<PackageReference Include="Microsoft.Net.Compilers" Version="$(MicrosoftNetCompilersVersion)" />
7576
<PackageReference Include="Microsoft.NETCore.ILDAsm" Version="$(MicrosoftNETCoreILDAsmVersion)" />
77+
<PackageReference Include="Microsoft.NETCore.ILAsm" Version="$(MicrosoftNETCoreILAsmVersion)" />
7678
<PackageReference Include="StrawberryPerl64" Version="$(StrawberryPerl64Version)" PrivateAssets="all" />
7779
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
7880
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
7981
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
82+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonVersion)" />
83+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />
84+
<PackageReference Include="Microsoft.CodeAnalysis.Test.Resources.Proprietary" Version="$(MicrosoftCodeAnalysisTestResourcesProprietaryVersion)" />
8085
</ItemGroup>
8186

8287
</Project>

tests/fsharp/test-framework.fs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ module Commands =
105105
let ildasm exec ildasmExe flags assembly =
106106
exec ildasmExe (sprintf "%s %s" flags (quotepath assembly))
107107

108+
let ilasm exec ilasmExe flags assembly =
109+
exec ilasmExe (sprintf "%s %s" flags (quotepath assembly))
110+
108111
let peverify exec peverifyExe flags path =
109112
exec peverifyExe (sprintf "%s %s" (quotepath path) flags)
110113

@@ -132,6 +135,7 @@ type TestConfig =
132135
FSharpCompilerInteractiveSettings : string
133136
fsi_flags : string
134137
ILDASM : string
138+
ILASM : string
135139
PEVERIFY : string
136140
Directory: string
137141
DotNetExe: string
@@ -173,14 +177,16 @@ let config configurationName envVars =
173177
let repoRoot = SCRIPT_ROOT ++ ".." ++ ".."
174178
let artifactsPath = repoRoot ++ "artifacts"
175179
let artifactsBinPath = artifactsPath ++ "bin"
180+
let coreClrRuntimePackageVersion = "3.0.0-preview-27318-01"
176181
let csc_flags = "/nologo"
177182
let fsc_flags = "-r:System.Core.dll --nowarn:20 --define:COMPILED"
178183
let fsi_flags = "-r:System.Core.dll --nowarn:20 --define:INTERACTIVE --maxerrors:1 --abortonerror"
179184
let Is64BitOperatingSystem = WindowsPlatform.Is64BitOperatingSystem envVars
180185
let architectureMoniker = if Is64BitOperatingSystem then "x64" else "x86"
181186
let CSC = requireFile (packagesDir ++ "Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
182-
let ILDASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ "2.0.3" ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ildasm.exe")
183-
let coreclrdll = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ "2.0.3" ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "coreclr.dll")
187+
let ILDASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ildasm.exe")
188+
let ILASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ilasm.exe")
189+
let coreclrdll = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "coreclr.dll")
184190
let PEVERIFY = requireFile (artifactsBinPath ++ "PEVerify" ++ configurationName ++ "net472" ++ "PEVerify.exe")
185191
let FSI_FOR_SCRIPTS = artifactsBinPath ++ "fsi" ++ configurationName ++ fsiArchitecture ++ "fsi.exe"
186192
let FSharpBuild = requireFile (artifactsBinPath ++ "FSharp.Build" ++ configurationName ++ fsharpBuildArchitecture ++ "FSharp.Build.dll")
@@ -190,8 +196,9 @@ let config configurationName envVars =
190196
let repoLocalDotnetPath = repoRoot ++ ".dotnet" ++ "dotnet.exe"
191197
if File.Exists(repoLocalDotnetPath) then repoLocalDotnetPath
192198
else "dotnet.exe"
193-
// ildasm requires coreclr.dll to run which has already been restored to the packages directory
199+
// ildasm + ilasm requires coreclr.dll to run which has already been restored to the packages directory
194200
File.Copy(coreclrdll, Path.GetDirectoryName(ILDASM) ++ "coreclr.dll", overwrite=true)
201+
File.Copy(coreclrdll, Path.GetDirectoryName(ILASM) ++ "coreclr.dll", overwrite=true)
195202

196203
let FSI = requireFile (FSI_FOR_SCRIPTS)
197204
#if !FSHARP_SUITE_DRIVES_CORECLR_TESTS
@@ -210,6 +217,7 @@ let config configurationName envVars =
210217
{ EnvironmentVariables = envVars
211218
FSCOREDLLPATH = FSCOREDLLPATH
212219
ILDASM = ILDASM
220+
ILASM = ILASM
213221
PEVERIFY = PEVERIFY
214222
CSC = CSC
215223
BUILD_CONFIG = configurationName
@@ -449,6 +457,7 @@ let fscBothToOut cfg out arg = Printf.ksprintf (Commands.fsc cfg.Directory (exec
449457
let fscAppendErrExpectFail cfg errPath arg = Printf.ksprintf (Commands.fsc cfg.Directory (execAppendErrExpectFail cfg errPath) cfg.DotNetExe cfg.FSC) arg
450458
let csc cfg arg = Printf.ksprintf (Commands.csc (exec cfg) cfg.CSC) arg
451459
let ildasm cfg arg = Printf.ksprintf (Commands.ildasm (exec cfg) cfg.ILDASM) arg
460+
let ilasm cfg arg = Printf.ksprintf (Commands.ilasm (exec cfg) cfg.ILASM) arg
452461
let peverify cfg = Commands.peverify (exec cfg) cfg.PEVERIFY "/nologo"
453462
let peverifyWithArgs cfg args = Commands.peverify (exec cfg) cfg.PEVERIFY args
454463
let fsi cfg = Printf.ksprintf (Commands.fsi (exec cfg) cfg.FSI)

0 commit comments

Comments
 (0)