Skip to content

Commit

Permalink
add some logic to write relative instead of absolute paths to cache, f…
Browse files Browse the repository at this point in the history
…ixes #1924
  • Loading branch information
matthid committed May 21, 2018
1 parent 26ecd57 commit 5b96244
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/app/Fake.Runtime/CoreCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ let prepareContext (config:FakeConfig) (cache:ICachingProvider) =
|> Seq.map File.ReadAllText
|> fun texts -> File.WriteAllText(fakeCacheContentsFile, String.Join("", texts))
// write fakeCacheDepsFile
File.WriteAllLines(fakeCacheDepsFile, locations)
File.WriteAllLines(fakeCacheDepsFile, locations |> Seq.map (Path.fixPathForCache config.ScriptFilePath))

let readFromCache () =
File.ReadAllText fakeCacheFile
Expand All @@ -340,6 +340,7 @@ let prepareContext (config:FakeConfig) (cache:ICachingProvider) =
let inline dependencyCacheUpdated () =
let contents =
File.ReadLines fakeCacheDepsFile
|> Seq.map (Path.readPathFromCache config.ScriptFilePath)
|> Seq.map (fun line -> if File.Exists line then Some (File.ReadAllText line) else None)
|> Seq.toList
if contents |> Seq.exists Option.isNone then false
Expand Down
1 change: 1 addition & 0 deletions src/app/Fake.Runtime/Environment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ let environVarOrNone name =

/// Returns if the build parameter with the given name was set
let inline hasEnvironVar name = environVar name |> isNull |> not

13 changes: 7 additions & 6 deletions src/app/Fake.Runtime/FakeRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open System.IO
open Fake.Runtime
open Fake.Runtime.Runners
open Paket
open System

type FakeSection =
| PaketDependencies of Paket.Dependencies * Lazy<Paket.DependenciesFile> * group : String option
Expand Down Expand Up @@ -385,7 +386,7 @@ let paketCachingProvider (config:FakeConfig) cacheDir (paketApi:Paket.Dependenci
let splits = line.Split(';')
let isRef = bool.Parse splits.[0]
let ver = splits.[1]
let loc = splits.[2]
let loc = Path.readPathFromCache config.ScriptFilePath splits.[2]
let fullName = splits.[3]
{ IsReferenceAssembly = isRef
Info =
Expand All @@ -395,12 +396,12 @@ let paketCachingProvider (config:FakeConfig) cacheDir (paketApi:Paket.Dependenci
|> Seq.toList

let writeToCache (list:AssemblyData list) =
list
list
|> Seq.map (fun item ->
sprintf "%b;%s;%s;%s"
item.IsReferenceAssembly
item.Info.Version
item.Info.Location
(Path.fixPathForCache config.ScriptFilePath item.Info.Location)
item.Info.FullName)
|> fun lines -> File.WriteAllLines(assemblyCacheFile, lines)
File.Copy(lockFilePath.FullName, assemblyCacheHashFile, true)
Expand Down Expand Up @@ -521,7 +522,7 @@ let prepareFakeScript (config:FakeConfig) =
let writeToCache (section : FakeSection option) =
match section with
| Some (PaketDependencies(p, _, group)) ->
sprintf "paket: %s, %s" p.DependenciesFile (match group with | Some g -> g | _ -> "<null>")
sprintf "paket: %s, %s" (Path.fixPathForCache config.ScriptFilePath p.DependenciesFile) (match group with | Some g -> g | _ -> "<null>")
| None -> "none"
|> fun t -> File.WriteAllText(scriptSectionCacheFile, t)
File.Copy (script, scriptSectionHashFile, true)
Expand All @@ -531,7 +532,7 @@ let prepareFakeScript (config:FakeConfig) =
if t.StartsWith("paket:") then
let s = t.Substring("paket: ".Length)
let splits = s.Split(',')
let depsFile = splits.[0]
let depsFile = Path.readPathFromCache config.ScriptFilePath splits.[0]
let group =
let trimmed = splits.[1].Trim()
if trimmed = "<null>" then None else Some trimmed
Expand Down Expand Up @@ -626,4 +627,4 @@ let retrieveHints (config:FakeConfig) (runResult:Runners.RunResult) =
yield "To further diagnose the problem you can set the 'FAKE_DETAILED_ERRORS' environment variable to 'true'"
if not config.VerboseLevel.PrintVerbose && Environment.GetEnvironmentVariable "FAKE_DETAILED_ERRORS" <> "true" then
yield "To further diagnose the problem you can run fake in verbose mode `fake -v run ...` or set the 'FAKE_DETAILED_ERRORS' environment variable to 'true'"
]
]
27 changes: 26 additions & 1 deletion src/app/Fake.Runtime/Path.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
/// Contains basic functions for string manipulation.
module Fake.Runtime.Path
open System
open System.IO

// Normalizes path for different OS
let inline normalizePath (path : string) =
path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)

let getCurrentDirectory () =
System.IO.Directory.GetCurrentDirectory()
System.IO.Directory.GetCurrentDirectory()

let private nugetDir = Path.GetFullPath(Paket.Constants.UserNuGetPackagesFolder).TrimEnd([|'/' ;'\\'|]) + "/"
let fixPathForCache scriptPath (s:string) =
let norm = Path.GetFullPath s
if norm.StartsWith(nugetDir, if Paket.Utils.isWindows then StringComparison.OrdinalIgnoreCase else StringComparison.Ordinal) then
sprintf "nugetcache://%s" (norm.Substring (nugetDir.Length))
else
let scriptDir = Uri(Path.GetDirectoryName scriptPath + "/")
let other = Uri(s)
let rel = scriptDir.MakeRelativeUri(other)
if rel.IsAbsoluteUri then rel.AbsoluteUri
else
sprintf "scriptpath:///%s" rel.OriginalString

let readPathFromCache scriptPath (s:string) =
let uri = Uri(s)
if uri.Scheme = "nugetcache" then
let rel = uri.AbsolutePath.TrimStart [| '/'|]
Path.Combine (nugetDir, rel)
elif uri.Scheme = "scriptpath" then
let rel = uri.OriginalString.Substring("scriptpath:///".Length)
Path.Combine(Path.GetDirectoryName scriptPath, rel)
else
uri.AbsolutePath

0 comments on commit 5b96244

Please sign in to comment.