Skip to content

Commit

Permalink
Properly resolve paket.dependencies, fixes #2025
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Jul 29, 2018
1 parent 5dcfb06 commit 024fbc4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
6 changes: 6 additions & 0 deletions integrationtests/i002025/before/paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// [ FAKE GROUP ]
group Build
source https://api.nuget.org/v3/index.json
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem
nuget Fake.Core.Target
24 changes: 24 additions & 0 deletions integrationtests/i002025/before/script/build.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#r "paket: groupref build //"
#load ".fake/build.fsx/intellisense.fsx"

open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators

Target.create "Clean" (fun _ ->
printfn ".. CLEAN .."
)

Target.create "Build" (fun _ ->
printfn ".. Build .."
)

Target.create "All" ignore

"Clean"
==> "Build"
==> "All"
13 changes: 10 additions & 3 deletions src/app/Fake.Runtime/FakeRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ let tryReadPaketDependenciesFromScript (tokenized:Fake.Runtime.FSharpParser.Toke
|> writeFixedPaketDependencies cacheDir
|> Some
else
let file = dependenciesFileName
match paketGroupReferences with
| [] ->
None
| group :: _ ->
let fullpath = Path.GetFullPath file
PaketDependencies (Dependencies fullpath, (lazy DependenciesFile.ReadFromFile fullpath), Some group)
let scriptDir = Path.GetDirectoryName scriptPath
let dependencies =
match Paket.Dependencies.TryLocate(scriptDir) with
| Some deps -> deps
| None ->
failwithf "Could not find '%s'. To use Fake with an external file, please run 'paket init' first.%sAlternatively you can use inline-dependencies. See https://fake.build/fake-fake5-modules.html"
Constants.DependenciesFileName Environment.NewLine

let fullpath = Path.GetFullPath dependencies.DependenciesFile
PaketDependencies (dependencies, (lazy DependenciesFile.ReadFromFile fullpath), Some group)
|> Some


Expand Down
5 changes: 5 additions & 0 deletions src/test/Fake.Core.IntegrationTests/SimpleHelloWorldTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ let tests =
stdOut.Contains expected
|> Expect.isTrue (sprintf "stdout should contain '%s', but was: '%s'" expected stdOut)
stdErr.Trim() |> Expect.equal "empty exected" ""

testCase "issue #2025" <| fun _ ->
handleAndFormat <| fun () ->
fakeRunAndCheckInPath "build.fsx" "build.fsx" "i002025" "script" |> ignore

]
39 changes: 28 additions & 11 deletions src/test/Fake.Core.IntegrationTests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ let integrationTestPath = Path.getFullName(__SOURCE_DIRECTORY__ + "../../../../i
let scenarioTempPath scenario = integrationTestPath @@ scenario @@ "temp"
let originalScenarioPath scenario = integrationTestPath @@ scenario @@ "before"

let resolvePath scenario (path:string) =
if Path.IsPathRooted path then path
else scenarioTempPath scenario @@ path

let prepare scenario =
let originalScenarioPath = originalScenarioPath scenario
let scenarioPath = scenarioTempPath scenario
Expand All @@ -35,12 +39,12 @@ let prepare scenario =
Directory.ensure scenarioPath
Shell.copyDir scenarioPath originalScenarioPath (fun _ -> true)

let directFakeInPath command scenarioPath target =
let directFakeInPath command workingDir target =
let result =
Process.execWithResult (fun (info:ProcStartInfo) ->
{ info with
FileName = fakeToolPath
WorkingDirectory = scenarioPath
WorkingDirectory = workingDir
Arguments = command }
|> Process.setEnvironmentVariable "target" target
|> Process.setEnvironmentVariable "FAKE_DETAILED_ERRORS" "true") (System.TimeSpan.FromMinutes 15.)
Expand All @@ -59,19 +63,25 @@ let handleAndFormat f =
let directFake command scenario =
directFakeInPath command (scenarioTempPath scenario) null

let fake command scenario =
let fakeInPath command scenario path =
prepare scenario

directFake command scenario
directFakeInPath command (resolvePath scenario path) null

let fake command scenario =
fakeInPath command scenario (scenarioTempPath scenario)

//let fakeFlags = "--verbose"
let fakeFlags = "--silent"

let fakeRunInPath runArgs scenario path =
fakeInPath (sprintf "%s run %s" fakeFlags runArgs) scenario path

let fakeRun runArgs scenario =
fake (sprintf "%s run %s" fakeFlags runArgs) scenario
fakeRunInPath runArgs scenario (scenarioTempPath scenario)

let checkIntellisense scriptName scenario =
let scenarioPath = scenarioTempPath scenario
let cachePath = scenarioPath </> ".fake" </> scriptName
let checkIntellisenseInPath scriptName path =
let cachePath = path </> ".fake" </> scriptName
File.Exists (cachePath </> "intellisense.fsx")
|> Expect.isTrue "Expect intellisense.fsx to exist"
File.Exists (cachePath </> "intellisense_lazy.fsx")
Expand All @@ -85,7 +95,14 @@ let checkIntellisense scriptName scenario =
"#endif" ]
Expect.equal "intellisense.fsx should be forwarding" expected lines

let fakeRunAndCheck scriptName runArgs scenario =
let result = fakeRun runArgs scenario
checkIntellisense scriptName scenario
let checkIntellisense scriptName scenario =
let scenarioPath = scenarioTempPath scenario
checkIntellisenseInPath scriptName scenarioPath

let fakeRunAndCheckInPath scriptName runArgs scenario path =
let result = fakeRunInPath runArgs scenario path
checkIntellisenseInPath scriptName (resolvePath scenario path)
result

let fakeRunAndCheck scriptName runArgs scenario =
fakeRunAndCheckInPath scriptName runArgs scenario (scenarioTempPath scenario)

0 comments on commit 024fbc4

Please sign in to comment.