forked from fsharp/fsharp-compiler-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
518 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace RunAssemblyResolveProblem.AssemblyInfo | ||
|
||
open System.Reflection | ||
open System.Runtime.CompilerServices | ||
open System.Runtime.InteropServices | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[<assembly: AssemblyTitle("RunAssemblyResolveProblem")>] | ||
[<assembly: AssemblyDescription("")>] | ||
[<assembly: AssemblyConfiguration("")>] | ||
[<assembly: AssemblyCompany("")>] | ||
[<assembly: AssemblyProduct("RunAssemblyResolveProblem")>] | ||
[<assembly: AssemblyCopyright("Copyright © 2015")>] | ||
[<assembly: AssemblyTrademark("")>] | ||
[<assembly: AssemblyCulture("")>] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[<assembly: ComVisible(false)>] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[<assembly: Guid("8990e2bf-92db-43b1-affe-9ead609fcce4")>] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [<assembly: AssemblyVersion("1.0.*")>] | ||
[<assembly: AssemblyVersion("1.0.0.0")>] | ||
[<assembly: AssemblyFileVersion("1.0.0.0")>] | ||
|
||
do | ||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
module RunAssemblyResolveProblem.Test | ||
|
||
open System | ||
open System.IO | ||
open Microsoft.FSharp.Compiler | ||
open Microsoft.FSharp.Compiler.Interactive.Shell | ||
open Microsoft.FSharp.Compiler.SourceCodeServices | ||
|
||
// Intialize output and input streams | ||
let inStream = new StringReader("") | ||
let outStream = new CompilerOutputStream() | ||
let errStream = new CompilerOutputStream() | ||
|
||
// Build command line arguments & start FSI session | ||
|
||
open System | ||
open System.Reflection | ||
let sysLib nm = | ||
if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows | ||
@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\" + nm + ".dll" | ||
else | ||
let sysDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() | ||
let (++) a b = System.IO.Path.Combine(a,b) | ||
sysDir ++ nm + ".dll" | ||
|
||
let run () = | ||
printfn "Creating Checker..." | ||
let checker = FSharpChecker.Create() | ||
let base1 = Path.GetTempFileName() | ||
let dllName = Path.ChangeExtension(base1, ".dll") | ||
let xmlName = Path.ChangeExtension(base1, ".xml") | ||
let fileName1 = Path.ChangeExtension(base1, ".fs") | ||
let projFileName = Path.ChangeExtension(base1, ".fsproj") | ||
File.WriteAllText(fileName1, "module M") | ||
let checkerArgs = | ||
[| "--simpleresolution" | ||
"--noframework" | ||
"--debug:full" | ||
"--define:DEBUG" | ||
"--optimize-" | ||
fileName1 | ||
"-r:" + sysLib "mscorlib" | ||
"-r:" + sysLib "System" | ||
"-r:" + sysLib "System.Core" | ||
"-r:" + Path.GetFullPath "TEST_BUG/FSharp.Core.dll" | ||
"-r:" + Path.GetFullPath "TEST_BUG/AssemblyResolveProblem.dll" | ||
"-r:" + Path.GetFullPath "TEST_BUG/FSharp.Configuration.dll" | ||
"-r:" + Path.GetFullPath "TEST_BUG/unresolved/SharpYaml.dll" | ||
"--out:" + dllName | ||
"--doc:" + xmlName | ||
"--warn:3" | ||
"--fullpaths" | ||
"--flaterrors" | ||
"--target:library" |] | ||
|
||
printfn "Get results... %A" checkerArgs | ||
let options = checker.GetProjectOptionsFromCommandLineArgs(projFileName, checkerArgs) | ||
printfn "Get ParseAndCheckProject..." | ||
let results = checker.ParseAndCheckProject(options) |> Async.RunSynchronously | ||
|
||
let mapError (err:FSharpErrorInfo) = | ||
sprintf "**** %s: %s" (if err.Severity = Microsoft.FSharp.Compiler.FSharpErrorSeverity.Error then "error" else "warning") err.Message | ||
if results.HasCriticalErrors then | ||
let errors = results.Errors |> Seq.map mapError | ||
let errorMsg = sprintf "Parsing and checking project failed: \n\t%s" (System.String.Join("\n\t", errors)) | ||
failwith errorMsg | ||
else | ||
if results.Errors.Length > 0 then | ||
let warnings = results.Errors |> Seq.map mapError | ||
printfn "Parsing and checking warnings: \n\t%s" (System.String.Join("\n\t", warnings)) | ||
|
||
printfn "Get referenceMap..." | ||
let referenceMap = | ||
results.ProjectContext.GetReferencedAssemblies() | ||
|> Seq.choose (fun (r:FSharpAssembly) -> r.FileName |> Option.map (fun f -> f, r)) | ||
|> dict | ||
|
||
printfn "Get map..." | ||
let map = | ||
["AssemblyResolveProblem.dll"] |> Seq.map (fun file -> file, if referenceMap.ContainsKey file then Some referenceMap.[file] else None) | ||
map | ||
|
||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let fscore = | ||
if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows | ||
@"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll" | ||
else | ||
typeof<_ option>.Assembly.Location | ||
|
||
let yamlPath = "unresolved/SharpYaml.dll" | ||
let files = | ||
[| fscore, "FSharp.Core.dll" | ||
Path.ChangeExtension (fscore, "optdata"), "FSharp.Core.optdata" | ||
Path.ChangeExtension (fscore, "sigdata"), "FSharp.Core.sigdata" | ||
"bin/v4.5/AssemblyResolveProblem.dll", "AssemblyResolveProblem.dll" | ||
"bin/v4.5/SharpYaml.dll", yamlPath | ||
"bin/v4.5/FSharp.Configuration.dll", "FSharp.Configuration.dll" | ||
|] | ||
let destDir = "TEST_BUG" | ||
for sourceFile, destFile in files do | ||
let destPath = Path.Combine(destDir, destFile) | ||
let destDir = Path.GetDirectoryName(destPath) | ||
if not (Directory.Exists destDir) then | ||
Directory.CreateDirectory destDir |> ignore | ||
if not (File.Exists destPath) then | ||
File.Copy(sourceFile, destPath) | ||
|
||
//System.Environment.CurrentDirectory <- Path.GetFullPath(destDir) | ||
|
||
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration() | ||
let argv = [| "C:\\fsi.exe" |] | ||
let allArgs = | ||
Array.append argv | ||
[| "--noninteractive"; "--noframework"; "-r:" + Path.GetFullPath "TEST_BUG/FSharp.Core.dll" |] | ||
printfn "Start Session... " | ||
let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, new StreamWriter(outStream), new StreamWriter(errStream)) | ||
|
||
printfn "Start EvalInteraction... " | ||
try | ||
fsiSession.EvalScript (Path.GetFullPath "RunAssemblyResolveProblem.fsx") | ||
finally | ||
printfn "Output: %s, Error: %s" (outStream.Read()) (errStream.Read()) | ||
0 // return an integer exit code |
89 changes: 89 additions & 0 deletions
89
RunAssemblyResolveProblem/RunAssemblyResolveProblem.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>8990e2bf-92db-43b1-affe-9ead609fcce4</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>RunAssemblyResolveProblem</RootNamespace> | ||
<AssemblyName>RunAssemblyResolveProblem</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion> | ||
<Name>RunAssemblyResolveProblem</Name> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<Tailcalls>false</Tailcalls> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<WarningLevel>3</WarningLevel> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DocumentationFile>bin\Debug\RunAssemblyResolveProblem.XML</DocumentationFile> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
<StartWorkingDirectory>C:\Users\dragon\Documents\Projects\FSharp.Compiler.Service\</StartWorkingDirectory> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<Tailcalls>true</Tailcalls> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<WarningLevel>3</WarningLevel> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DocumentationFile>bin\Release\RunAssemblyResolveProblem.XML</DocumentationFile> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
<StartWorkingDirectory>C:\Users\dragon\Documents\Projects\FSharp.Compiler.Service\</StartWorkingDirectory> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Numerics" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Program.fs" /> | ||
<None Include="App.config" /> | ||
<None Include="RunAssemblyResolveProblem.fsx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\src\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj"> | ||
<Name>FSharp.Compiler.Service</Name> | ||
<Project>{2e4d67b4-522d-4cf7-97e4-ba940f0b18f3}</Project> | ||
<Private>True</Private> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Choose> | ||
<When Condition="'$(VisualStudioVersion)' == '11.0'"> | ||
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')"> | ||
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath> | ||
</PropertyGroup> | ||
</When> | ||
<Otherwise> | ||
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')"> | ||
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath> | ||
</PropertyGroup> | ||
</Otherwise> | ||
</Choose> | ||
<Import Project="$(FSharpTargetsPath)" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
open System | ||
open System.IO | ||
open System.Reflection | ||
|
||
printfn "Adding Handler..." | ||
AppDomain.CurrentDomain.add_AssemblyResolve( | ||
new ResolveEventHandler(fun _ e -> | ||
printfn "resolving %s" e.Name | ||
if e.Name.StartsWith "SharpYaml" then | ||
Assembly.LoadFrom(Path.GetFullPath "TEST_BUG/unresolved/SharpYaml.dll") | ||
elif e.Name.StartsWith "FSharp.Core" then | ||
Assembly.LoadFrom(Path.GetFullPath "TEST_BUG/FSharp.Core.dll") | ||
else null)) | ||
|
||
#r @"FSharp.Compiler.Service.dll" | ||
#r @"RunAssemblyResolveProblem.exe" | ||
|
||
try | ||
let map = RunAssemblyResolveProblem.Test.run() | ||
ignore map | ||
with e -> printfn "Error: %O" e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.