Skip to content

Commit

Permalink
Handle fsx file with dotnet core 3
Browse files Browse the repository at this point in the history
#1886
Added a new test project for Fable.Cli
  • Loading branch information
rfrerebe-stx authored and alfonsogarciacaro committed Sep 4, 2019
1 parent d4e2b72 commit 028a0b5
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 36 deletions.
23 changes: 20 additions & 3 deletions Fable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Tests.External", "tes
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ASTViewer", "src\tools\ASTViewer\ASTViewer.fsproj", "{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Cli.Test", "tests\Fable.Cli.Test\Fable.Cli.Test.fsproj", "{03BD8489-294B-4872-AB04-D9EB07E16E53}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,9 +32,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{661A1972-0D06-46E8-958C-55325E5D520C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{661A1972-0D06-46E8-958C-55325E5D520C}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -142,5 +141,23 @@ Global
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x64.Build.0 = Release|Any CPU
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x86.ActiveCfg = Release|Any CPU
{D8C8FBCB-54AF-49C3-93B1-5460668E32EC}.Release|x86.Build.0 = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|x64.ActiveCfg = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|x64.Build.0 = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|x86.ActiveCfg = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Debug|x86.Build.0 = Debug|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|Any CPU.Build.0 = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|x64.ActiveCfg = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|x64.Build.0 = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|x86.ActiveCfg = Release|Any CPU
{03BD8489-294B-4872-AB04-D9EB07E16E53}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {204581E6-42C5-4EE2-A4A9-713C32A17CF2}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ let test() =
buildSplitter "tests"
run "npx mocha build/tests --reporter dot -t 10000"
runInDir "tests/Main" "dotnet run"
runInDir "tests/Fable.Cli.Test" "dotnet run"

if envVarOrNone "APPVEYOR" |> Option.isSome then
buildStandalone()
Expand Down
92 changes: 59 additions & 33 deletions src/Fable.Cli/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,45 +256,71 @@ module Process =

exitCode

let getNetCore2AssembliesDir nugetCache netAppCoreVersion (hostVersion :string) =
Path.Combine(nugetCache, "microsoft.netcore.app", hostVersion, "ref", "netcoreapp" + netAppCoreVersion)

let getNetCore3AssembliesDir sdkBasePath netAppCoreVersion (hostVersion :string)=
Path.Combine(sdkBasePath, "packs", "microsoft.netcore.app.ref", hostVersion, "ref", "netcoreapp" + netAppCoreVersion)

let restoreNetcore2InAssembliesDir netAppCoreVersion (hostVersion :string) =
let proj = sprintf """<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp%s</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="%s" />
</ItemGroup>
</Project>
""" netAppCoreVersion hostVersion

let tempFolder = Path.GetTempPath()
let tempProj = System.IO.Path.Combine(tempFolder, (sprintf "%s.proj" (System.Guid.NewGuid().ToString("N"))))

System.IO.File.WriteAllText(tempProj, proj)
runProcess tempFolder "dotnet" (sprintf "restore \"%s\"" tempProj) |> ignore
System.IO.File.Delete(tempProj)

let getHostVersionRegex text =
Regex.Match(text , @"Host[\s\S]*?Version\s*:\s*([\d.]+[-\w]*)")

let getBasePathRegex text =
Regex.Match(text , @"Base Path\s*:\s*(.+)(\/sdk|\\sdk)")

let getNugetPathRegex text =
Regex.Match(text , @"info\s*:\s*global-packages\s*:\s*(.+)")

let getNetcoreAssembliesDir() =
let matchProcessOutput exe args regexPattern =
let matchProcessOutput exe args (execRegexPattern : string -> Match) =
let _, logOut, _ =
runProcess "." exe args
Regex.Match(String.concat " " logOut, regexPattern)
let nugetCache =
matchProcessOutput "dotnet" "nuget locals global-packages --list"
@"info\s*:\s*global-packages\s*:\s*(.+)"
|> fun m -> m.Groups.[1].Value.Trim()
logOut
|> String.concat "\n"
|> execRegexPattern

let hostVersion =
matchProcessOutput "dotnet" "--info"
@"Host[\s\S]*?Version\s*:\s*([\d.]+)"
matchProcessOutput "dotnet" "--info" getHostVersionRegex
|> fun m -> m.Groups.[1].Value
let v = hostVersion.Split('.')
let netCoreAssembliesDir = Path.Combine(nugetCache, "microsoft.netcore.app", hostVersion, "ref", "netcoreapp" + v.[0] + "." + v.[1])

if not(Directory.Exists(netCoreAssembliesDir)) then
// Create a temp proj file that has the current Microsoft.NETCore.App as dependency.
// Restore the proj file which will add the nuget package in the global cache.
// We do this because using the System dll listed in C:\Program Files\dotnet\sdk\2.1.503
// lead to weird behavior in the checkedProject.AssemblyContents.ImplementationFiles in Agent.fs.
let netappCore = sprintf "%s.%s" v.[0] v.[1]
let proj = sprintf """<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp%s</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="%s" />
</ItemGroup>
</Project>
""" netappCore hostVersion

let tempFolder = Path.GetTempPath()
let tempProj = System.IO.Path.Combine(tempFolder, (sprintf "%s.proj" (System.Guid.NewGuid().ToString("N"))))

System.IO.File.WriteAllText(tempProj, proj)
let restoreCode = runProcess tempFolder "dotnet" (sprintf "restore \"%s\"" tempProj)
System.IO.File.Delete(tempProj)

let netappCoreVersion = sprintf "%s.%s" v.[0] v.[1]

let netCoreAssembliesDir =
match v.[0] with
| "3" ->
let sdkInstallDir =
matchProcessOutput "dotnet" "--info" getBasePathRegex
|> fun m -> m.Groups.[1].Value
getNetCore3AssembliesDir sdkInstallDir netappCoreVersion hostVersion
| "2"
| _ ->
let nugetCache =
matchProcessOutput "dotnet" "nuget locals global-packages --list" getNugetPathRegex
|> fun m -> m.Groups.[1].Value.Trim()
let netCore2AssembliesDir = getNetCore2AssembliesDir nugetCache netappCoreVersion hostVersion
if not(Directory.Exists(netCore2AssembliesDir)) then
restoreNetcore2InAssembliesDir netappCoreVersion hostVersion
netCore2AssembliesDir

netCoreAssembliesDir

Expand Down
18 changes: 18 additions & 0 deletions tests/Fable.Cli.Test/Fable.Cli.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
</PropertyGroup>
<ItemGroup>
<Compile Include="RegexTest.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Expecto" Version="5.1.2" />
<PackageReference Include="FSharp.Core" Version="4.6.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Fable.Cli\Fable.Cli.fsproj" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions tests/Fable.Cli.Test/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Expecto

open RegexTest

let allTests = [ linuxTests; windowsTests]

[<EntryPoint>]
let main args =
allTests
|> testList "All"
|> runTestsWithArgs defaultConfig args
Loading

0 comments on commit 028a0b5

Please sign in to comment.