Skip to content

Commit

Permalink
add scripttype argument to generate scripts for a language only
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel authored and smoothdeveloper committed May 3, 2016
1 parent fed823d commit c6603f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/Paket.Core/ScriptGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ module ScriptGeneration =
match x with
| CSharp -> "csx"
| FSharp -> "fsx"
static member TryCreate s =
match s with
| "csx" -> Some CSharp
| "fsx" -> Some FSharp
| _ -> None

let generateScriptsForRootFolder scriptType =
let scriptGenerator =
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,13 @@ with

type GenerateIncludeScriptsArgs =
| [<CustomCommandLine("framework")>] Framework of string
| [<CustomCommandLine("type")>] ScriptType of string
with
interface IArgParserTemplate with
member this.Usage =
match this with
| Framework _ -> "Framework identifier to generate scripts for, such as net4 or netcore or xamarinios."
| ScriptType _ -> "Language to generate scripts for, must be one of 'fsx' or 'csx'. Can be provided multiple times."



Expand Down
46 changes: 23 additions & 23 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,8 @@ let push (results : ParseResults<_>) =

let generateIncludeScripts (results : ParseResults<GenerateIncludeScriptsArgs>) =

let framework = results.TryGetResult <@ GenerateIncludeScriptsArgs.Framework @>

let scriptTypes = [Paket.LoadingScripts.ScriptGeneration.CSharp; Paket.LoadingScripts.ScriptGeneration.FSharp]
let providedFramework = results.GetResults <@ GenerateIncludeScriptsArgs.Framework @>
let providedScriptTypes = results.GetResults <@ GenerateIncludeScriptsArgs.ScriptType @>

let dependencies =
Dependencies.Locate()
Expand All @@ -316,48 +315,49 @@ let generateIncludeScripts (results : ParseResults<GenerateIncludeScriptsArgs>)
dependencies.RootPath
|> DirectoryInfo

let resolveFrameworksFromPaket () =
let frameworksForDependencyGroups = lazy (
dependencies.Groups
|> Seq.map (fun f -> f.Value.Options.Settings.FrameworkRestrictions)
|> Seq.map(function
| Paket.Requirements.AutoDetectFramework -> failwithf "couldn't detect framework"
| Paket.Requirements.FrameworkRestrictionList list ->
list |> Seq.map (
list |> Seq.collect (
function
| Paket.Requirements.FrameworkRestriction.Exactly framework
| Paket.Requirements.FrameworkRestriction.AtLeast framework
| Paket.Requirements.FrameworkRestriction.Between (framework,_) -> framework
| Paket.Requirements.FrameworkRestriction.AtLeast framework -> Seq.singleton framework
| Paket.Requirements.FrameworkRestriction.Between (bottom,top) -> [bottom; top] |> Seq.ofList //TODO: do we need to cap the list of generated frameworks based on this? also see todo in Requirements.fs for potential generation of range for 'between'
| Paket.Requirements.FrameworkRestriction.Portable portable -> failwithf "unhandled portable framework %s" portable
)
)
|> Seq.concat
)

let resolveFrameworkFromEnvironment () =
let environmentFramework = lazy (
// HACK: resolve .net version based on environment
// list of match is incomplete / innacurate
let version = Environment.Version
match version.Major, version.Minor, version.Build, version.Revision with
| 4, 0, 30319, 42000 -> DotNetFramework (FrameworkVersion.V4_6)
| 4, 0, 30319, _ -> DotNetFramework (FrameworkVersion.V4_5)
| _ -> DotNetFramework (FrameworkVersion.V3_5)
)

let allFrameworks =
let maybeFramework =
match framework with
| Some framework -> FrameworkDetection.Extract framework
| None -> None
match maybeFramework with
| Some framework -> seq { yield framework }
| None ->
resolveFrameworksFromPaket ()
|> fun frameworks ->
if Seq.isEmpty frameworks then
seq { yield resolveFrameworkFromEnvironment() }
else frameworks
let frameworksToGenerate =
let targetFrameworkList = providedFramework |> List.choose FrameworkDetection.Extract |> Seq.ofList

if targetFrameworkList |> Seq.isEmpty |> not then targetFrameworkList
else if frameworksForDependencyGroups.Value |> Seq.isEmpty |> not then frameworksForDependencyGroups.Value
else Seq.singleton environmentFramework.Value

let scriptTypesToGenerate =
let parsed = providedScriptTypes |> List.choose Paket.LoadingScripts.ScriptGeneration.ScriptType.TryCreate
match parsed with
| [] -> [Paket.LoadingScripts.ScriptGeneration.CSharp; Paket.LoadingScripts.ScriptGeneration.FSharp]
| xs -> xs

for framework in allFrameworks do
for framework in frameworksToGenerate do
tracefn "generating scripts for framework %s" (framework.ToString())
for scriptType in scriptTypes do
for scriptType in scriptTypesToGenerate do
Paket.LoadingScripts.ScriptGeneration.generateScriptsForRootFolder scriptType framework rootFolder


Expand Down

0 comments on commit c6603f8

Please sign in to comment.