Skip to content

Commit 062d354

Browse files
authored
Fix: 6546 (#6550)
1 parent 5cf2d97 commit 062d354

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

tests/fsharp/single-test.fs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,28 @@ let generateOverrides =
9090
</Project>"
9191
template
9292

93-
let generateProjectArtifacts (pc:ProjectConfiguration) targetFramework configuration =
93+
// Arguments:
94+
// pc = ProjectConfiguration
95+
// outputType = OutputType.Exe, OutputType.Library or OutputType.Script
96+
// targetFramework optimize = "net472" OR NETCOREAPP2.1 etc ...
97+
// optimize = true or false
98+
// configuration = "Release" or "Debug"
99+
//
100+
let generateProjectArtifacts (pc:ProjectConfiguration) outputType (targetFramework:string) configuration =
101+
let fsharpCoreLocation =
102+
let compiler =
103+
if outputType = OutputType.Script then
104+
"fsi"
105+
else
106+
"FSharp.Core"
107+
let targetCore =
108+
if targetFramework.StartsWith("netstandard", StringComparison.InvariantCultureIgnoreCase) || targetFramework.StartsWith("netcoreapp", StringComparison.InvariantCultureIgnoreCase) then
109+
"netstandard1.6"
110+
else
111+
"net45"
112+
(Path.GetFullPath(__SOURCE_DIRECTORY__) + "/../../artifacts/bin/" + compiler + "/" + configuration + "/" + targetCore + "/FSharp.Core.dll")
113+
114+
94115
let computeSourceItems addDirectory addCondition (compileItem:CompileItem) sources =
95116
let computeInclude src =
96117
let fileName = if addDirectory then Path.Combine(pc.SourceDirectory, src) else src
@@ -119,10 +140,11 @@ let generateProjectArtifacts (pc:ProjectConfiguration) targetFramework configura
119140
let debug = if pc.Optimize then "True" else "False"
120141
let generateProjBody =
121142
let template = @"<Project Sdk='Microsoft.NET.Sdk'>
122-
143+
123144
<PropertyGroup>
124145
<OutputType>$(OUTPUTTYPE)</OutputType>
125146
<TargetFramework>$(TARGETFRAMEWORK)</TargetFramework>
147+
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
126148
<IsPackable>false</IsPackable>
127149
<DebugSymbols>$(DEBUG)</DebugSymbols>
128150
<DebugType>portable</DebugType>
@@ -135,7 +157,13 @@ let generateProjectArtifacts (pc:ProjectConfiguration) targetFramework configura
135157
<RestoreAdditionalProjectSources Condition = "" '$(RestoreAdditionalProjectSources)' != ''"">$(RestoreAdditionalProjectSources);$(RestoreFromArtifactsPath)</RestoreAdditionalProjectSources>
136158
</PropertyGroup>
137159
138-
<!-- Utility sources -->
160+
<!-- FSharp.Core reference -->
161+
<ItemGroup>
162+
<Reference Include='FSharp.Core'>
163+
<HintPath>$(FSHARPCORELOCATION)</HintPath>
164+
</Reference>
165+
</ItemGroup>
166+
139167
<ItemGroup>$(UTILITYSOURCEITEMS)
140168
</ItemGroup>
141169
@@ -168,6 +196,7 @@ let generateProjectArtifacts (pc:ProjectConfiguration) targetFramework configura
168196
|> replace "$(REFERENCEITEMS)" pc.ReferenceItems true true CompileItem.Reference
169197
|> replace "$(LOADSOURCEITEMS)" pc.LoadSources true true CompileItem.LoadSource
170198
|> replace "$(USESOURCEITEMS)" pc.UseSources true true CompileItem.UseSource
199+
|> replaceTokens "$(FSHARPCORELOCATION)" fsharpCoreLocation
171200
|> replaceTokens "$(DIRECTORYBUILDLOCATION)" (Path.GetFullPath(__SOURCE_DIRECTORY__))
172201
|> replaceTokens "$(OUTPUTTYPE)" outputType
173202
|> replaceTokens "$(OPTIMIZE)" optimize
@@ -186,6 +215,11 @@ let singleTestBuildAndRunCore cfg copyFiles p =
186215
let referenceItems = if String.IsNullOrEmpty(copyFiles) then [] else [copyFiles]
187216
let framework = "netcoreapp2.0"
188217

218+
// Arguments:
219+
// outputType = OutputType.Exe, OutputType.Library or OutputType.Script
220+
// compilerType = "coreclr" or "net40"
221+
// targetFramework optimize = "net472" OR NETCOREAPP2.1 etc ...
222+
// optimize = true or false
189223
let executeSingleTestBuildAndRun outputType compilerType targetFramework optimize =
190224
let mutable result = false
191225
let directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() )
@@ -219,7 +253,7 @@ let singleTestBuildAndRunCore cfg copyFiles p =
219253
let executeFsc testCompilerVersion targetFramework =
220254
let propsBody = generateProps testCompilerVersion cfg.BUILD_CONFIG
221255
emitFile propsFileName propsBody
222-
let projectBody = generateProjectArtifacts pc targetFramework cfg.BUILD_CONFIG
256+
let projectBody = generateProjectArtifacts pc outputType targetFramework cfg.BUILD_CONFIG
223257
emitFile projectFileName projectBody
224258
use testOkFile = new FileGuard(Path.Combine(directory, "test.ok"))
225259
exec { cfg with Directory = directory } cfg.DotNetExe (sprintf "run -f %s" targetFramework)
@@ -229,7 +263,7 @@ let singleTestBuildAndRunCore cfg copyFiles p =
229263
let executeFsi testCompilerVersion targetFramework =
230264
let propsBody = generateProps testCompilerVersion cfg.BUILD_CONFIG
231265
emitFile propsFileName propsBody
232-
let projectBody = generateProjectArtifacts pc targetFramework cfg.BUILD_CONFIG
266+
let projectBody = generateProjectArtifacts pc outputType targetFramework cfg.BUILD_CONFIG
233267
emitFile projectFileName projectBody
234268
use testOkFile = new FileGuard(Path.Combine(directory, "test.ok"))
235269
exec { cfg with Directory = directory } cfg.DotNetExe "build /t:RunFSharpScript"

0 commit comments

Comments
 (0)