Skip to content

Commit

Permalink
Implement #1926
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed May 12, 2018
1 parent 841784f commit 7b915d6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
6 changes: 6 additions & 0 deletions help/markdown/fake-commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ Fake Options [fake_opts]:
Fake Run Options [run_opts]:
-d, --debug Debug the script.
-n, --nocache Disable fake cache for this run.
-p, --partial-restore
Only restore the required group instead of a full restore,
can be set globally by setting the environment variable FAKE_PARTIAL_RESTORE to true.
--fsiargs <fsiargs> [*] Arguments passed to the f# interactive.
Fake Build Options [build_opts]:
-d, --debug Debug the script.
-n, --nocache Disable fake cache for this run.
-p, --partial-restore
Only restore the required group instead of a full restore,
can be set globally by setting the environment variable FAKE_PARTIAL_RESTORE to true.
--fsiargs <fsiargs> [*] Arguments passed to the f# interactive.
-f, --script <script.fsx>
The script to execute (defaults to `build.fsx`).
Expand Down
59 changes: 34 additions & 25 deletions src/app/Fake.Runtime/FakeRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System
open System.IO
open Fake.Runtime
open Fake.Runtime.Runners
open Paket

type FakeSection =
Expand Down Expand Up @@ -134,8 +135,10 @@ type AssemblyData =
{ IsReferenceAssembly : bool
Info : Runners.AssemblyInfo }

let paketCachingProvider (script:string) (logLevel:Trace.VerboseLevel) cacheDir (paketApi:Paket.Dependencies) (paketDependenciesFile:Lazy<Paket.DependenciesFile>) group =
let paketCachingProvider (config:FakeConfig) cacheDir (paketApi:Paket.Dependencies) (paketDependenciesFile:Lazy<Paket.DependenciesFile>) group =
use __ = Fake.Profile.startCategory Fake.Profile.Category.Paket
let logLevel = config.VerboseLevel
let script = config.ScriptFilePath
let groupStr = match group with Some g -> g | None -> "Main"
let groupName = Paket.Domain.GroupName (groupStr)
#if DOTNETCORE
Expand Down Expand Up @@ -359,8 +362,10 @@ let paketCachingProvider (script:string) (logLevel:Trace.VerboseLevel) cacheDir
if needLocalLock then File.Copy(lockFilePath.FullName, localLock, true)

// Restore
paketApi.Restore((*false, group, [], false, true*))
|> ignore
if config.RestoreOnlyGroup then
paketApi.Restore(false,group,[],false,false,false,None)
else
paketApi.Restore()

// https://github.com/fsharp/FAKE/issues/1908
writeIntellisenseFile cacheDir // write intellisense.fsx immediately
Expand Down Expand Up @@ -463,10 +468,10 @@ let paketCachingProvider (script:string) (logLevel:Trace.VerboseLevel) cacheDir
if writeIntellisenseTask.IsValueCreated then
writeIntellisenseTask.Value.Wait() }

let restoreDependencies script logLevel cacheDir section =
let restoreDependencies config cacheDir section =
match section with
| PaketDependencies (paketDependencies, paketDependenciesFile, group) ->
paketCachingProvider script logLevel cacheDir paketDependencies paketDependenciesFile group
paketCachingProvider config cacheDir paketDependencies paketDependenciesFile group

let tryFindGroupFromDepsFile scriptDir =
let depsFile = Path.Combine(scriptDir, "paket.dependencies")
Expand Down Expand Up @@ -498,8 +503,9 @@ let tryFindGroupFromDepsFile scriptDir =
| _ -> None
else None

let prepareFakeScript (tokenized:Lazy<Fake.Runtime.FSharpParser.TokenizedScript>) logLevel script =
// read dependencies from the top
let prepareFakeScript (config:FakeConfig) =
// read dependencies from the top
let script = config.ScriptFilePath
let scriptDir = Path.GetDirectoryName (script)
let cacheDir = Path.Combine(scriptDir, ".fake", Path.GetFileName(script))
Directory.CreateDirectory (cacheDir) |> ignore
Expand All @@ -508,7 +514,7 @@ let prepareFakeScript (tokenized:Lazy<Fake.Runtime.FSharpParser.TokenizedScript>
let scriptSectionCacheFile = Path.Combine(cacheDir, "fake-section.txt")
let inline getSectionUncached () =
use __ = Fake.Profile.startCategory Fake.Profile.Category.Analyzing
let newSection = tryReadPaketDependenciesFromScript tokenized.Value cacheDir script
let newSection = tryReadPaketDependenciesFromScript config.ScriptTokens.Value cacheDir script
match newSection with
| Some s -> Some s
| None ->
Expand Down Expand Up @@ -551,7 +557,7 @@ let prepareFakeScript (tokenized:Lazy<Fake.Runtime.FSharpParser.TokenizedScript>

match section with
| Some section ->
restoreDependencies script logLevel cacheDir section
restoreDependencies config cacheDir section
| None ->
let defaultPaketCode = """
source https://api.nuget.org/v3/index.json
Expand All @@ -567,10 +573,10 @@ If you know what you are doing you can silence this warning by setting the envir
{ Header = "paket-inline"
Section = defaultPaketCode }
|> writeFixedPaketDependencies cacheDir
restoreDependencies script logLevel cacheDir section
restoreDependencies config cacheDir section

let prepareAndRunScriptRedirect (logLevel:Trace.VerboseLevel) (fsiOptions:string list) scriptPath scriptArgs onErrMsg onOutMsg useCache =

let createConfig (logLevel:Trace.VerboseLevel) (fsiOptions:string list) scriptPath scriptArgs onErrMsg onOutMsg useCache restoreOnlyGroup =
if logLevel.PrintVerbose then Trace.log (sprintf "prepareAndRunScriptRedirect(Script: %s, fsiOptions: %A)" scriptPath (System.String.Join(" ", fsiOptions)))
let fsiOptionsObj = Yaaf.FSharp.Scripting.FsiOptions.ofArgs fsiOptions
let newFsiOptions =
Expand All @@ -584,19 +590,22 @@ let prepareAndRunScriptRedirect (logLevel:Trace.VerboseLevel) (fsiOptions:string
use out = Yaaf.FSharp.Scripting.ScriptHost.CreateForwardWriter onOutMsg
use err = Yaaf.FSharp.Scripting.ScriptHost.CreateForwardWriter onErrMsg
let tokenized = lazy (File.ReadLines scriptPath |> FSharpParser.getTokenized scriptPath ("FAKE_DEPENDENCIES" :: newFsiOptions.Defines))
let config =
{ Runners.FakeConfig.VerboseLevel = logLevel
Runners.FakeConfig.ScriptFilePath = scriptPath
Runners.FakeConfig.ScriptTokens = tokenized
Runners.FakeConfig.CompileOptions =
{ FsiOptions = newFsiOptions; RuntimeDependencies = [] }
Runners.FakeConfig.UseCache = useCache
Runners.FakeConfig.Out = out
Runners.FakeConfig.Err = err
Runners.FakeConfig.ScriptArgs = scriptArgs }
let provider = prepareFakeScript tokenized logLevel scriptPath
CoreCache.runScriptWithCacheProvider config provider

let inline prepareAndRunScript logLevel fsiOptions scriptPath scriptArgs useCache =
prepareAndRunScriptRedirect logLevel fsiOptions scriptPath scriptArgs (printf "%s") (printf "%s") useCache
{ Runners.FakeConfig.VerboseLevel = logLevel
Runners.FakeConfig.ScriptFilePath = scriptPath
Runners.FakeConfig.ScriptTokens = tokenized
Runners.FakeConfig.CompileOptions =
{ FsiOptions = newFsiOptions; RuntimeDependencies = [] }
Runners.FakeConfig.UseCache = useCache
Runners.FakeConfig.RestoreOnlyGroup = restoreOnlyGroup
Runners.FakeConfig.Out = out
Runners.FakeConfig.Err = err
Runners.FakeConfig.ScriptArgs = scriptArgs }

let createConfigSimple (logLevel:Trace.VerboseLevel) (fsiOptions:string list) scriptPath scriptArgs useCache restoreOnlyGroup =
createConfig logLevel fsiOptions scriptPath scriptArgs (printf "%s") (printf "%s") useCache restoreOnlyGroup

let prepareAndRunScript (config:FakeConfig) =
let provider = prepareFakeScript config
CoreCache.runScriptWithCacheProvider config provider

1 change: 1 addition & 0 deletions src/app/Fake.Runtime/Runners.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type FakeConfig =
ScriptTokens : Lazy<Fake.Runtime.FSharpParser.TokenizedScript>
CompileOptions : CompileOptions
UseCache : bool
RestoreOnlyGroup : bool
Out: TextWriter
Err: TextWriter
ScriptArgs: string list }
Expand Down
6 changes: 6 additions & 0 deletions src/app/Fake.netcore/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ Fake Options [fake_opts]:
Fake Run Options [run_opts]:
-d, --debug Debug the script.
-n, --nocache Disable fake cache for this run.
-p, --partial-restore
Only restore the required group instead of a full restore,
can be set globally by setting the environment variable FAKE_PARTIAL_RESTORE to true.
--fsiargs <fsiargs> [*] Arguments passed to the f# interactive.
Fake Build Options [build_opts]:
-d, --debug Debug the script.
-n, --nocache Disable fake cache for this run.
-p, --partial-restore
Only restore the required group instead of a full restore,
can be set globally by setting the environment variable FAKE_PARTIAL_RESTORE to true.
--fsiargs <fsiargs> [*] Arguments passed to the f# interactive.
-f, --script <script.fsx>
The script to execute (defaults to `build.fsx`).
Expand Down
5 changes: 4 additions & 1 deletion src/app/Fake.netcore/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type RunArguments = {
Debug : bool
//SingleTarget : bool
NoCache : bool
RestoreOnlyGroup : bool
VerboseLevel : VerboseLevel
IsBuild : bool // Did the user call `fake build` or `fake run`?
}
Expand Down Expand Up @@ -149,7 +150,8 @@ let runOrBuild (args : RunArguments) =

let useCache = not args.NoCache
try
if not (FakeRuntime.prepareAndRunScript args.VerboseLevel additionalArgs scriptFile args.ScriptArguments useCache) then false
let config = FakeRuntime.createConfigSimple args.VerboseLevel additionalArgs scriptFile args.ScriptArguments useCache args.RestoreOnlyGroup
if not (FakeRuntime.prepareAndRunScript config) then false
else
if args.VerboseLevel.PrintVerbose then log "Ready."
true
Expand Down Expand Up @@ -237,6 +239,7 @@ let parseAction (results:DocoptMap) =

Debug = DocoptResult.hasFlag "--debug" results
NoCache = DocoptResult.hasFlag "--nocache" results
RestoreOnlyGroup = DocoptResult.hasFlag "--partial-restore" results || Environment.GetEnvironmentVariable ("FAKE_PARTIAL_RESTORE") = "true"
VerboseLevel = verboseLevel
IsBuild = not isRun // Did the user call `fake build` or `fake run`?
}
Expand Down

0 comments on commit 7b915d6

Please sign in to comment.