Skip to content

Commit 9f9ddf7

Browse files
authored
Merge pull request #812 from vasily-kirichenko/cracker-returns-fsi-files-in-sourcefiles-array
ProjectCracker returns *.fsi files in FSharpProjectOptions.SourceFiles array
2 parents 9392303 + 03765d0 commit 9f9ddf7

File tree

7 files changed

+108
-15
lines changed

7 files changed

+108
-15
lines changed

fcs/FSharp.Compiler.Service.ProjectCracker/ProjectCracker.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ type ProjectCracker =
1616
let enableLogging = defaultArg enableLogging true
1717
let logMap = ref Map.empty
1818

19-
let rec convert (opts: Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.ProjectOptions) : FSharpProjectOptions =
19+
let rec convert (opts: ProjectCrackerTool.ProjectOptions) : FSharpProjectOptions =
20+
if not (isNull opts.Error) then failwith opts.Error
21+
2022
let referencedProjects = Array.map (fun (a, b) -> a, convert b) opts.ReferencedProjectOptions
2123

2224
let sourceFiles, otherOptions =
23-
opts.Options |> Array.partition (fun x -> x.IndexOfAny(Path.GetInvalidPathChars()) = -1 && Path.GetExtension(x).ToLower() = ".fs")
25+
opts.Options
26+
|> Array.partition (fun x ->
27+
let extension = Path.GetExtension(x).ToLower()
28+
x.IndexOfAny(Path.GetInvalidPathChars()) = -1
29+
&& (extension = ".fs" || extension = ".fsi"))
2430

2531
let sepChar = Path.DirectorySeparatorChar
2632

@@ -73,8 +79,8 @@ type ProjectCracker =
7379
p.StartInfo.RedirectStandardOutput <- true
7480
ignore <| p.Start()
7581

76-
let ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof<Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.ProjectOptions>)
77-
let opts = ser.ReadObject(p.StandardOutput.BaseStream) :?> Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.ProjectOptions
82+
let ser = new DataContractJsonSerializer(typeof<ProjectCrackerTool.ProjectOptions>)
83+
let opts = ser.ReadObject(p.StandardOutput.BaseStream) :?> ProjectCrackerTool.ProjectOptions
7884
#endif
7985

8086
convert opts, !logMap

fcs/FSharp.Compiler.Service.ProjectCrackerTool/ProjectCrackerOptions.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ type ProjectOptions =
77
Options: string[]
88
ReferencedProjectOptions: (string * ProjectOptions)[]
99
LogOutput: string
10+
Error: string
1011
}

fcs/FSharp.Compiler.Service.ProjectCrackerTool/ProjectCrackerTool.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ module internal ProjectCrackerTool =
420420
let options = { ProjectFile = file
421421
Options = Array.ofSeq (parsedProject.Options @ referencedProjectOutputs)
422422
ReferencedProjectOptions = referencedProjectOptions
423-
LogOutput = parsedProject.LogOutput }
423+
LogOutput = parsedProject.LogOutput
424+
Error = null }
424425

425426
parsedProject.OutputFile, options
426427

@@ -465,9 +466,11 @@ module internal ProjectCrackerTool =
465466
2, { ProjectFile = projectFile;
466467
Options = [||];
467468
ReferencedProjectOptions = [||];
468-
LogOutput = e.ToString() }
469+
LogOutput = e.ToString()
470+
Error = e.Message }
469471
else
470472
1, { ProjectFile = "";
471473
Options = [||];
472474
ReferencedProjectOptions = [||];
473-
LogOutput = "At least two arguments required." }
475+
LogOutput = "At least two arguments required."
476+
Error = null }

fcs/FSharp.Compiler.Service.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26730.8
3+
VisualStudioVersion = 15.0.26730.16
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{B6B68AE6-E7A4-4D43-9B34-FFA74BFE192B}"
66
ProjectSection(SolutionItems) = preProject
77
build.cmd = build.cmd
88
build.fsx = build.fsx
99
build.sh = build.sh
10+
nuget\FSharp.Compiler.Service.MSBuild.v12.nuspec = nuget\FSharp.Compiler.Service.MSBuild.v12.nuspec
1011
nuget\FSharp.Compiler.Service.nuspec = nuget\FSharp.Compiler.Service.nuspec
12+
nuget\FSharp.Compiler.Service.ProjectCracker.nuspec = nuget\FSharp.Compiler.Service.ProjectCracker.nuspec
1113
paket.dependencies = paket.dependencies
1214
README.md = README.md
1315
RELEASE_NOTES.md = RELEASE_NOTES.md

fcs/build.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ Target "Test.NetFx" (fun _ ->
9999
// --------------------------------------------------------------------------------------
100100
// Build a NuGet package
101101
Target "NuGet.NetFx" (fun _ ->
102-
runCmdIn __SOURCE_DIRECTORY__ @"..\.nuget\NuGet.exe" @"pack nuget\FSharp.Compiler.Service.nuspec -OutputDirectory %s" releaseDir
103-
runCmdIn __SOURCE_DIRECTORY__ @"..\.nuget\NuGet.exe" @"pack nuget\FSharp.Compiler.Service.MSBuild.v12.nuspec -OutputDirectory %s" releaseDir
104-
runCmdIn __SOURCE_DIRECTORY__ @"..\.nuget\NuGet.exe" @"pack nuget\FSharp.Compiler.Service.ProjectCracker.nuspec -OutputDirectory %s" releaseDir
102+
runCmdIn __SOURCE_DIRECTORY__ "../.nuget/NuGet.exe" @"pack nuget/FSharp.Compiler.Service.nuspec -OutputDirectory %s" releaseDir
103+
runCmdIn __SOURCE_DIRECTORY__ "../.nuget/NuGet.exe" @"pack nuget/FSharp.Compiler.Service.MSBuild.v12.nuspec -OutputDirectory %s" releaseDir
104+
runCmdIn __SOURCE_DIRECTORY__ "../.nuget/NuGet.exe" @"pack nuget/FSharp.Compiler.Service.ProjectCracker.nuspec -OutputDirectory %s" releaseDir
105105
)
106106

107107

tests/service/ProjectOptionsTests.fs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,19 @@ let ``Project file parsing -- compile files 2``() =
137137
[<Test>]
138138
let ``Project file parsing -- bad project file``() =
139139
let f = normalizePath (__SOURCE_DIRECTORY__ + @"/data/Malformed.fsproj")
140-
let log = snd (ProjectCracker.GetProjectOptionsFromProjectFileLogged(f))
141-
log.[f] |> should contain "Microsoft.Build.Exceptions.InvalidProjectFileException"
140+
try
141+
ProjectCracker.GetProjectOptionsFromProjectFileLogged(f) |> ignore
142+
failwith "Expected exception"
143+
with e ->
144+
Assert.That(e.Message, Contains.Substring "The project file could not be loaded.")
142145

143146
[<Test>]
144147
let ``Project file parsing -- non-existent project file``() =
145148
let f = normalizePath (__SOURCE_DIRECTORY__ + @"/data/DoesNotExist.fsproj")
146-
let log = snd (ProjectCracker.GetProjectOptionsFromProjectFileLogged(f, enableLogging=true))
147-
log.[f] |> should contain "System.IO.FileNotFoundException"
149+
try
150+
ProjectCracker.GetProjectOptionsFromProjectFileLogged(f, enableLogging=true) |> ignore
151+
with e ->
152+
Assert.That(e.Message, Contains.Substring "Could not find file")
148153

149154
[<Test>]
150155
let ``Project file parsing -- output file``() =
@@ -217,6 +222,19 @@ let ``Project file parsing -- Logging``() =
217222
else
218223
Assert.That(log, Is.StringContaining("""Using "ResolveAssemblyReference" task from assembly "Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"."""))
219224

225+
[<Test>]
226+
let ``Project file parsing -- FSharpProjectOptions.SourceFiles contains both fs and fsi files``() =
227+
let projectFileName = normalizePath (__SOURCE_DIRECTORY__ + @"/data/FsAndFsiFiles.fsproj")
228+
let options, log = ProjectCracker.GetProjectOptionsFromProjectFileLogged(projectFileName, enableLogging=true)
229+
printfn "%A" log
230+
let expectedSourceFiles =
231+
[| "Test1File2.fsi"
232+
"Test1File2.fs"
233+
"Test1File1.fs"
234+
"Test1File0.fsi"
235+
"Test1File0.fs" |]
236+
Assert.That(options.SourceFiles |> Array.map Path.GetFileName, Is.EqualTo expectedSourceFiles, "source files")
237+
220238
[<Test>]
221239
let ``Project file parsing -- Full path``() =
222240
let f = normalizePath (__SOURCE_DIRECTORY__ + @"/data/ToolsVersion12.fsproj")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{116cc2f9-f987-4b3d-915a-34cac04a73da}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Test1</RootNamespace>
11+
<AssemblyName>Test1</AssemblyName>
12+
<OutputPath>bin\$(Configuration)\</OutputPath>
13+
<UsePartialTypes>False</UsePartialTypes>
14+
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
17+
<DebugSymbols>True</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>False</Optimize>
20+
<Tailcalls>False</Tailcalls>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<WarningLevel>3</WarningLevel>
23+
<PlatformTarget>x86</PlatformTarget>
24+
<DocumentationFile>bin\Debug\Test1.xml</DocumentationFile>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>True</Optimize>
29+
<Tailcalls>True</Tailcalls>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<WarningLevel>3</WarningLevel>
32+
<PlatformTarget>x86</PlatformTarget>
33+
<DocumentationFile>bin\Release\Test1.xml</DocumentationFile>
34+
<DebugSymbols>False</DebugSymbols>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="FSharp.Core">
38+
<HintPath>..\..\..\packages\Microsoft.Portable.FSharp.Core.4.1.20\lib\profiles\net40\FSharp.Core.dll</HintPath>
39+
</Reference>
40+
<Reference Include="mscorlib" />
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Test1File2.fsi" />
46+
<Compile Include="Test1File2.fs" />
47+
<Compile Include="Test1File1.fs" />
48+
<Compile Include="Test1File0.fsi" />
49+
<Compile Include="Test1File0.fs" />
50+
</ItemGroup>
51+
<Import Project="..\..\..\packages\FSharp.Compiler.Tools.4.1.23\tools\Microsoft.FSharp.Targets" />
52+
<Choose>
53+
<When Condition="($(TargetFrameworkIdentifier) == '.NETStandard' And $(TargetFrameworkVersion) == 'v1.6') Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And $(TargetFrameworkVersion) == 'v1.0') Or ($(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5')">
54+
<ItemGroup>
55+
<Reference Include="nunit.framework">
56+
<HintPath>..\..\..\packages\NUnit\lib\nunit.framework.dll</HintPath>
57+
<Private>True</Private>
58+
<Paket>True</Paket>
59+
</Reference>
60+
</ItemGroup>
61+
</When>
62+
</Choose>
63+
</Project>

0 commit comments

Comments
 (0)