Skip to content

Commit

Permalink
generate-include-script should not #r FSharp.Core.dll
Browse files Browse the repository at this point in the history
Add test case and fix implementation
  • Loading branch information
smoothdeveloper committed Oct 7, 2016
1 parent 9b4fff8 commit 34701eb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
Expand Up @@ -170,4 +170,24 @@ let ``mscorlib excluded from f# script`` () =
|> String.containsIgnoreCase "mscorlib"
)

Assert.False hasFilesWithMsCorlib
Assert.False hasFilesWithMsCorlib


[<Test; Category("scriptgen")>]
let ``fsharp.core excluded from f# script`` () =
let scenario = "fsharpcore"
paket "install" scenario |> ignore

directPaket "generate-include-scripts framework net46" scenario |> ignore

let scriptRootDir = scriptRoot scenario
let hasFilesWithFsharpCore =
scriptRootDir.GetFiles("*.fsx", SearchOption.AllDirectories)
|> Seq.exists (fun f ->
f.FullName
|> File.ReadAllText
|> String.containsIgnoreCase "fsharp.core.dll"
)

Assert.False hasFilesWithFsharpCore

@@ -0,0 +1,3 @@
source http://nuget.org/api/v2

nuget Suave = 1.1.3
27 changes: 17 additions & 10 deletions src/Paket.Core/ScriptGeneration.fs
Expand Up @@ -90,6 +90,11 @@ module ScriptGeneration =

let private makeRelativePath (scriptFile: FileInfo) (libFile: FileInfo) =
(Uri scriptFile.FullName).MakeRelativeUri(Uri libFile.FullName).ToString()

let shouldExcludeNugetForFSharpScript nuget =
match nuget with
| "FSharp.Core" -> true
| _ -> false

let filterFSharpFrameworkReferences assemblies =
assemblies
Expand Down Expand Up @@ -228,15 +233,17 @@ module ScriptGeneration =
(getScriptFile : GroupName -> FileInfo)
(writeScript : FileInfo -> ScriptPiece seq -> unit)
(filterFrameworkAssemblies : string seq -> string seq)
(filterNuget : string -> bool)
(framework : FrameworkIdentifier)
=
let all =
seq {
for group, nuget, _ in deps.GetInstalledPackages() do
let model = deps.GetInstalledPackageModel(Some group, nuget)
let libs = model.GetLibReferences(framework) |> Seq.map (fun f -> FileInfo f)
let syslibs = model.GetFrameworkAssembliesLazy.Value
yield group, (libs, syslibs |> Set.toSeq)
if not (filterNuget nuget) then
let model = deps.GetInstalledPackageModel(Some group, nuget)
let libs = model.GetLibReferences(framework) |> Seq.map (fun f -> FileInfo f)
let syslibs = model.GetFrameworkAssembliesLazy.Value
yield group, (libs, syslibs |> Set.toSeq)
}
|> Seq.groupBy fst
|> Seq.map (fun (group, items) -> group, items |> Seq.map snd)
Expand Down Expand Up @@ -315,7 +322,7 @@ module ScriptGeneration =

/// Generate a include scripts for all packages defined in paket.dependencies,
/// if a package is ordered before its dependencies this function will throw.
let generateScriptsForRootFolderGeneric extension scriptGenerator scriptWriter filterFrameworkLibs (framework: FrameworkIdentifier) (rootFolder: DirectoryInfo) =
let generateScriptsForRootFolderGeneric extension scriptGenerator scriptWriter filterFrameworkLibs filterNuget (framework: FrameworkIdentifier) (rootFolder: DirectoryInfo) =
let dependenciesFile, lockFile =
let deps = Paket.Dependencies.Locate(rootFolder.FullName)
let lock =
Expand Down Expand Up @@ -351,7 +358,7 @@ module ScriptGeneration =
let folder = getScriptFolder includeScriptsRootFolder framework group
FileInfo(Path.Combine(folder.FullName, sprintf "include.%s.group.%s" (group.GetCompareString()) extension).ToLowerInvariant())

generateGroupScript dependenciesFile getGroupFile scriptWriter filterFrameworkLibs framework
generateGroupScript dependenciesFile getGroupFile scriptWriter filterFrameworkLibs filterNuget framework

type ScriptType =
| CSharp
Expand All @@ -368,9 +375,9 @@ module ScriptGeneration =
| _ -> None

let generateScriptsForRootFolder scriptType =
let scriptGenerator, scriptWriter, filterFrameworkLibs =
let scriptGenerator, scriptWriter, filterFrameworkLibs, shouldExcludeNuget =
match scriptType with
| CSharp -> generateCSharpScript, writeCSharpScript, id
| FSharp -> generateFSharpScript, writeFSharpScript, filterFSharpFrameworkReferences
| CSharp -> generateCSharpScript, writeCSharpScript, id, (fun _ -> false)
| FSharp -> generateFSharpScript, writeFSharpScript, filterFSharpFrameworkReferences, shouldExcludeNugetForFSharpScript

generateScriptsForRootFolderGeneric scriptType.Extension scriptGenerator scriptWriter filterFrameworkLibs
generateScriptsForRootFolderGeneric scriptType.Extension scriptGenerator scriptWriter filterFrameworkLibs shouldExcludeNuget

0 comments on commit 34701eb

Please sign in to comment.