Skip to content

Commit

Permalink
add coreclr compatible mono.cecil (jbevain/cecil#269), make fake core…
Browse files Browse the repository at this point in the history
… run with net46 and compile for netcoreapp1.0
  • Loading branch information
matthid committed Jul 22, 2016
1 parent 573a4dc commit 8cac788
Show file tree
Hide file tree
Showing 22 changed files with 15,279 additions and 40 deletions.
Binary file not shown.
Binary file not shown.
Binary file added lib/nupgks/Mono.Cecil.0.9.6.0.nupkg
Binary file not shown.
Binary file added lib/nupgks/Mono.Cecil.0.9.6.0.symbols.nupkg
Binary file not shown.
Expand Up @@ -6,7 +6,11 @@ module internal Env =
let inline isNull o = obj.ReferenceEquals(null, o)
let isMono = try System.Type.GetType("Mono.Runtime") |> isNull |> not with _ -> false
let (++) a b = System.IO.Path.Combine(a,b)
#if NETSTANDARD1_5
let (=?) s1 s2 = System.String.Equals(s1, s2, System.StringComparison.OrdinalIgnoreCase)
#else
let (=?) s1 s2 = System.String.Equals(s1, s2, System.StringComparison.InvariantCultureIgnoreCase)
#endif
let (<>?) s1 s2 = not (s1 =? s2)

#if NET40
Expand All @@ -20,11 +24,13 @@ open System.Diagnostics
module Log =
let source = new TraceSource("Yaaf.FSharp.Scriping")

#if !NETSTANDARD1_5
let LogConsole levels =
let consoleListener = new ConsoleTraceListener();
consoleListener.TraceOutputOptions <- TraceOptions.DateTime
consoleListener.Filter <- new EventTypeFilter(levels)
source.Listeners.Add consoleListener |> ignore
#endif

let traceEventf t f =
Printf.kprintf (fun s -> source.TraceEvent(t, 0, s)) f
Expand Down Expand Up @@ -64,6 +70,9 @@ module internal CompilerServiceExtensions =
let defaultFrameworkVersion = "4.5"
#endif

let getLib dir nm =
dir ++ nm + ".dll"
#if !NETSTANDARD1_5
let referenceAssemblyDirectory frameworkVersion =
let isWindows = System.Environment.OSVersion.Platform = System.PlatformID.Win32NT
let baseDir =
Expand All @@ -79,8 +88,6 @@ module internal CompilerServiceExtensions =
if Directory.Exists refDir then refDir
else System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()

let getLib dir nm =
dir ++ nm + ".dll"
let referenceAssembly frameworkVersion = getLib (referenceAssemblyDirectory frameworkVersion)
let fsCore frameworkVersion fsharpVersion =
let isWindows = System.Environment.OSVersion.Platform = System.PlatformID.Win32NT
Expand All @@ -100,12 +107,16 @@ module internal CompilerServiceExtensions =
let ass = typedefof<option<_>>.Assembly
let name = ass.GetName()
name.Version.ToString()

#endif
let fscoreResolveDirs libDirs =
[ yield System.AppDomain.CurrentDomain.BaseDirectory
[
#if !NETSTANDARD1_5
yield System.AppDomain.CurrentDomain.BaseDirectory
yield referenceAssemblyDirectory defaultFrameworkVersion
yield System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
#endif
yield! libDirs
#if !NETSTANDARD1_5
yield Environment.CurrentDirectory
// Prefer the currently loaded version
yield fsCore "4.0" loadedFsCoreVersion
Expand All @@ -123,6 +134,7 @@ module internal CompilerServiceExtensions =
if isMono then
// See https://github.com/fsharp/FSharp.Compiler.Service/issues/317
yield referenceAssemblyDirectory "4.0"
#endif
]

let tryCheckFsCore fscorePath =
Expand Down Expand Up @@ -150,14 +162,17 @@ module internal CompilerServiceExtensions =
[ "FSharp.Core"
"System.EnterpriseServices.Thunk" // See #4
"System.EnterpriseServices.Wrapper" ] // See #4
#if !NETSTANDARD1_5
let getDefaultSystemReferences frameworkVersion =
Directory.EnumerateFiles(referenceAssemblyDirectory frameworkVersion)
|> Seq.filter (fun file -> Path.GetExtension file =? ".dll")
|> Seq.map Path.GetFileNameWithoutExtension
|> Seq.filter (fun f ->
sysLibBlackList |> Seq.forall (fun backListed -> f <>? backListed))

#endif
let getCheckerArguments frameworkVersion defaultReferences (fsCoreLib: _ option) dllFiles libDirs otherFlags =
ignore frameworkVersion
ignore defaultReferences
let base1 = Path.GetTempFileName()
let dllName = Path.ChangeExtension(base1, ".dll")
let xmlName = Path.ChangeExtension(base1, ".xml")
Expand All @@ -171,9 +186,11 @@ module internal CompilerServiceExtensions =
//yield "--optimize-"
yield "--nooptimizationdata"
yield "--noframework"
#if !NETSTANDARD1_5
yield sprintf "-I:%s" (referenceAssemblyDirectory frameworkVersion)
for ref in defaultReferences do
yield sprintf "-r:%s" (referenceAssembly frameworkVersion ref)
#endif
if fsCoreLib.IsSome then
yield sprintf "-r:%s" fsCoreLib.Value
yield "--out:" + dllName
Expand All @@ -193,6 +210,7 @@ module internal CompilerServiceExtensions =
projFileName, args

let findAssemblyVersion (assembly:Assembly) =
#if !NETSTANDARD1_5
let customAttributes = assembly.GetCustomAttributesData()
let targetFramework =
customAttributes
Expand All @@ -216,6 +234,10 @@ module internal CompilerServiceExtensions =
let version = versionString.Substring ("Version=v".Length)
Some (framework, version)
| None -> None
#else
ignore assembly
None
#endif

let getProjectReferences frameworkVersion otherFlags libDirs dllFiles =
let otherFlags = defaultArg otherFlags Seq.empty
Expand All @@ -237,12 +259,16 @@ module internal CompilerServiceExtensions =
if not hasFsCoreLib then
Some (findFSCore dllFiles libDirs)
else None


#if !NETSTANDARD1_5
let defaultReferences =
getDefaultSystemReferences frameworkVersion
|> Seq.filter (not << hasAssembly)

let projFileName, args = getCheckerArguments frameworkVersion defaultReferences (fsCoreLib: _ option) dllFiles libDirs otherFlags
#else
let projFileName, args = getCheckerArguments frameworkVersion ignore (fsCoreLib: _ option) dllFiles libDirs otherFlags
#endif
Log.verbf "Checker Arguments: %O" (Log.formatArgs args)

let options = checker.GetProjectOptionsFromCommandLineArgs(projFileName, args)
Expand Down Expand Up @@ -353,7 +379,11 @@ module internal CompilerServiceExtensions =
t.Name
and getFSharpTypeName (t:System.Type) =
let optFsharpName =
#if !NETSTANDARD1_5
match FSharpAssembly.FromAssembly t.Assembly with
#else
match FSharpAssembly.FromAssembly (t.GetTypeInfo().Assembly) with
#endif
| Some fsAssembly ->
match fsAssembly.FindType t with
| Some entity -> Some entity.DisplayName
Expand All @@ -370,7 +400,12 @@ module internal CompilerServiceExtensions =
member x.FSharpFullName = x.Namespace + "." + x.FSharpName

module internal TypeParamHelper =
#if !NETSTANDARD1_5
let rec getFSharpTypeParameterList (t:System.Type) =
#else
let rec getFSharpTypeParameterList (tk:System.Type) =
let t = tk.GetTypeInfo()
#endif
let builder = new System.Text.StringBuilder()
if t.IsGenericType then
let args = t.GetGenericArguments()
Expand Down Expand Up @@ -400,7 +435,9 @@ type internal InteractionResult =
{ Output : OutputData; Error : OutputData }

/// This exception indicates that an exception happened while compiling or executing given F# code.
#if !NETSTANDARD1_5
[<System.Serializable>]
#endif
#if YAAF_FSHARP_SCRIPTING_PUBLIC
type FsiEvaluationException =
#else
Expand All @@ -413,6 +450,7 @@ type internal FsiEvaluationException =
inherit System.Exception(msg, inner)
input = input
result = result }
#if !NETSTANDARD1_5
new (info:System.Runtime.Serialization.SerializationInfo, context:System.Runtime.Serialization.StreamingContext) = {
inherit System.Exception(info, context)
input = info.GetString("Input")
Expand All @@ -434,6 +472,7 @@ type internal FsiEvaluationException =
info.AddValue("Result_Error_FsiOutput", x.result.Error.FsiOutput)
info.AddValue("Result_Error_ScriptOutput", x.result.Error.ScriptOutput)
info.AddValue("Result_Error_Merged", x.result.Error.Merged)
#endif
member x.Result with get () = x.result
member x.Input with get () = x.input
override x.ToString () =
Expand All @@ -443,7 +482,9 @@ type internal FsiEvaluationException =
(nl x.Result.Error.Merged) (nl x.Result.Output.Merged) (nl x.Input) (base.ToString())

/// Exception for invalid expression types
#if !NETSTANDARD1_5
[<System.Serializable>]
#endif
#if YAAF_FSHARP_SCRIPTING_PUBLIC
type FsiExpressionTypeException =
#else
Expand All @@ -456,11 +497,13 @@ type internal FsiExpressionTypeException =
inherit FsiEvaluationException(msg, input, result, null)
expected = expect
value = value }
#if !NETSTANDARD1_5
new (info:System.Runtime.Serialization.SerializationInfo, context:System.Runtime.Serialization.StreamingContext) = {
inherit FsiEvaluationException(info, context)
expected = null
value = None
}
#endif
member x.Value with get () = x.value
member x.ExpectedType with get () = x.expected

Expand Down Expand Up @@ -714,6 +757,7 @@ type internal FsiOptions =
WarnAsErrorList = []
ScriptArgs = [] }
static member Default =
#if !NETSTANDARD1_5
// find a FSharp.Core.dll with optdata and sigdata
let runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
let includes =
Expand All @@ -724,6 +768,9 @@ type internal FsiOptions =
// See also https://github.com/fsharp/fsharp/pull/389, https://github.com/fsharp/fsharp/pull/388
[ runtimeDir; System.IO.Path.Combine (monoDir, "4.0") ]
else [ runtimeDir ]
#else
let includes = []
#endif
let fsCore = FSharpAssemblyHelper.findFSCore [] includes
Log.verbf "Using FSharp.Core: %s" fsCore
{ FsiOptions.Empty with
Expand Down
22 changes: 22 additions & 0 deletions src/app/Fake.netcore/Cli.fs
@@ -0,0 +1,22 @@
/// New Command line interface for FAKE that utilises Argu.
[<RequireQualifiedAccessAttribute>]
module Cli

open System
open CommandLine

[<Verb("run", HelpText = "Run the given FAKE script.")>]
type RunOptions = {
[<Option(Separator=',', Required = false, HelpText = "Overwrite some environment variables. Use env1:val1,env2:val2")>] environmentVariables : seq<string>;
[<Option(HelpText = "Be more verbose in the output (legacy 'PrintDetails' or -pd).")>] verbose : bool;
[<Option(HelpText = "Use the given string as arguments for FSI. Make sure to escape properly.")>] fsiArgs : string;
[<Option(HelpText = "Pauses FAKE with a Debugger.Break() near the start (legacy 'Break' or -br).")>] debugScript : bool;
[<Option(HelpText = "Runs only the specified target and not the dependencies.")>] singleTarget : bool;
[<Option(HelpText = "Disables caching of compiled script")>] noCache : bool;
[<Value(0, Required = false, MetaName="script", HelpText = "The build script to run, defaults to build.fsx.")>] script : string option;
[<Value(1, Required = false, MetaName="target", HelpText = "The the target to run, defaults to the target defined in the build script.")>] target : string option;
}
[<Verb("version", HelpText = "print the current version.")>]
type VersionOptions = {
[<Option(HelpText = "Be more verbose in the output (legacy 'PrintDetails' or -pd).")>] verbose : bool;
}
19 changes: 19 additions & 0 deletions src/app/Fake.netcore/Fake.netcore.xproj
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>9a05cdd6-654c-4df1-91ca-6da9fdf7e7a7</ProjectGuid>
<RootNamespace>Fake.netcore</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
14 changes: 14 additions & 0 deletions src/app/Fake.netcore/NuGet.Config
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-cli" value="https://dotnet.myget.org/F/dotnet-cli/api/v3/index.json" />
<!--<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />-->
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="fsharp-daily" value="https://www.myget.org/F/fsharp-daily/api/v3/index.json" />
<add key="my_local" value="../../../lib/nupgks" />
<add key="fakelib.netcore" value="../FakeLib.netcore/bin/Debug" />
<add key="commandline.netcore" value="https://www.myget.org/F/ebyte-dotnetcore/api/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit 8cac788

Please sign in to comment.