Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load scripts should only work on lock file - fixes #2372 #2834

Merged
merged 3 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Paket.Core/Installation/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ let createProjectReferencesFiles (lockFile:LockFile) (projectFile:ProjectFile) (
// it can happen that the references file doesn't exist if paket doesn't find one in that case we update the cache by deleting it.
if paketCachedReferencesFileName.Exists then paketCachedReferencesFileName.Delete()

let CreateScriptsForGroups dependenciesFile lockFile (groups:Map<GroupName,LockFileGroup>) =
let CreateScriptsForGroups dependenciesFileName (lockFile:LockFile) (groups:Map<GroupName,LockFileGroup>) =
let groupsToGenerate =
groups
|> Seq.map (fun kvp -> kvp.Value)
Expand All @@ -365,12 +365,12 @@ let CreateScriptsForGroups dependenciesFile lockFile (groups:Map<GroupName,LockF
|> Seq.toList

if not (List.isEmpty groupsToGenerate) then
let depsCache = DependencyCache(dependenciesFile,lockFile)
let dir = DirectoryInfo dependenciesFile.Directory
let depsCache = DependencyCache(dependenciesFileName,lockFile)
let rootPath = DirectoryInfo lockFile.RootPath

let scripts = LoadingScripts.ScriptGeneration.constructScriptsFromData depsCache groupsToGenerate [] []
for sd in scripts do
sd.Save dir
sd.Save rootPath

let FindOrCreateReferencesFile (projectFile:ProjectFile) =
match projectFile.FindReferencesFile() with
Expand Down Expand Up @@ -428,7 +428,6 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign
if not (hasLocalFile || force) && isEarlyExit () then
tracefn "Last restore is still up to date."
else
let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)
if projectFile = None then
extractRestoreTargets root |> ignore

Expand All @@ -438,10 +437,12 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign
s.Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
|> Array.map (fun s -> s.Trim())
|> Array.choose FrameworkDetection.Extract)


let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do we actually need a depsfile when this fails? Or should we warn and continue?


if not hasLocalFile && not ignoreChecks then
let hasAnyChanges,nugetChanges,remoteFilechanges,hasChanges = DependencyChangeDetection.GetChanges(dependenciesFile,lockFile,false)

let checkResponse = if failOnChecks then failwithf else traceWarnfn
if hasAnyChanges then
checkResponse "paket.dependencies and paket.lock are out of sync in %s.%sPlease run 'paket install' or 'paket update' to recompute the paket.lock file." lockFileName.Directory.FullName Environment.NewLine
Expand Down Expand Up @@ -532,6 +533,6 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign
|> Async.RunSynchronously
|> ignore

CreateScriptsForGroups dependenciesFile lockFile groups
CreateScriptsForGroups dependenciesFileName lockFile groups
if isFullRestore then
File.WriteAllText(restoreCacheFile, newContents)))
21 changes: 10 additions & 11 deletions src/Paket.Core/Installation/ScriptGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ module ScriptGeneration =
self.Input |> Seq.map refString |> Seq.distinct |> String.concat "\n"

/// Save the script in '<directory>/.paket/load/<script>'
member self.Save (directory:DirectoryInfo) =
directory.Create()
let scriptFile = FileInfo (directory.FullName </> self.PartialPath)
member self.Save (rootPath:DirectoryInfo) =
rootPath.Create()
let scriptFile = FileInfo (rootPath.FullName </> self.PartialPath)
if verbose then
verbosefn "generating script - %s" scriptFile.FullName
scriptFile.Directory.Create()
let text = self.Render directory
let text = self.Render rootPath
File.WriteAllText (scriptFile.FullName, text)


Expand Down Expand Up @@ -249,21 +249,20 @@ module ScriptGeneration =


let constructScriptsFromData (depCache:DependencyCache) (groups:GroupName list) providedFrameworks providedScriptTypes =
let dependenciesFile = depCache.DependenciesFile
let frameworksForDependencyGroups = dependenciesFile.ResolveFrameworksForScriptGeneration()
let environmentFramework = FrameworkDetection.resolveEnvironmentFramework
let lockFile = depCache.LockFile

let frameworksForDependencyGroups = lockFile.ResolveFrameworksForScriptGeneration()
let environmentFramework = FrameworkDetection.resolveEnvironmentFramework

let groups =
if List.isEmpty groups then
dependenciesFile.Groups |> Seq.map (fun kvp -> kvp.Key) |> Seq.toList
lockFile.Groups |> Seq.map (fun kvp -> kvp.Key) |> Seq.toList
else
groups

if verbose then
verbosefn "Generating load scripts for the following groups: %A" (groups |> List.map (fun g -> g.Name.ToString()))
verbosefn " - using Paket dependency file: %s" dependenciesFile.FileName
verbosefn " - using Packe fock file: %s" lockFile.FileName
verbosefn " - using Paket dependency file: %s" depCache.DependenciesFileName
verbosefn " - using Packe lock file: %s" lockFile.FileName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Packe"?


let tupleMap f v = (v, f v)
let failOnMismatch toParse parsed fn message =
Expand Down
15 changes: 1 addition & 14 deletions src/Paket.Core/PaketConfigFiles/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -714,20 +714,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
FileInfo(Path.Combine(FileInfo(dependenciesFileName).Directory.FullName, Constants.LocalFileName))

/// Find the matching lock file to a dependencies file
member this.FindLockfile() = DependenciesFile.FindLockfile this.FileName


member this.ResolveFrameworksForScriptGeneration () = lazy (
this.Groups
|> Seq.map (fun f -> f.Value.Options.Settings.FrameworkRestrictions)
|> Seq.map(fun restrictions ->
match restrictions with
| Paket.Requirements.AutoDetectFramework -> failwithf "couldn't detect framework"
| Paket.Requirements.ExplicitRestriction list ->
list.RepresentedFrameworks |> Seq.choose (function TargetProfile.SinglePlatform tf -> Some tf | _ -> None)
)
|> Seq.concat
)
member this.FindLockFile() = DependenciesFile.FindLockfile this.FileName


type PaketFiles =
Expand Down
9 changes: 4 additions & 5 deletions src/Paket.Core/PaketConfigFiles/DependencyCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ReferenceType =
| Framework info -> sprintf "Framework: '%s'" info
| LoadScript info -> sprintf "LoadScript: '%s'" info.FullName

type DependencyCache (dependencyFile:DependenciesFile, lockFile:LockFile) =
type DependencyCache (dependencyFileName:string, lockFile:LockFile) =
let loadedGroups = HashSet<GroupName>()
let mutable nuspecCache = ConcurrentDictionary<PackageName*SemVerInfo, Nuspec>()
let mutable installModelCache = ConcurrentDictionary<GroupName * PackageName,InstallModel>()
Expand Down Expand Up @@ -175,7 +175,7 @@ type DependencyCache (dependencyFile:DependenciesFile, lockFile:LockFile) =


member __.LockFile = lockFile
member __.DependenciesFile = dependencyFile
member __.DependenciesFileName = dependencyFileName

member __.InstallModels () =
installModelCache |> Seq.map (fun x -> x.Value) |> List.ofSeq
Expand Down Expand Up @@ -236,9 +236,8 @@ type DependencyCache (dependencyFile:DependenciesFile, lockFile:LockFile) =


new (dependencyFilePath:string) =
let depFile = DependenciesFile.ReadFromFile dependencyFilePath
let lockFile = depFile.FindLockfile() |> fun path -> path.FullName |> LockFile.LoadFrom
DependencyCache (depFile,lockFile)
let lockFile = DependenciesFile.FindLockfile dependencyFilePath |> fun path -> path.FullName |> LockFile.LoadFrom
DependencyCache (dependencyFilePath,lockFile)


member __.InstallModel groupName packageName = tryGet (groupName, packageName) installModelCache
Expand Down
13 changes: 13 additions & 0 deletions src/Paket.Core/PaketConfigFiles/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,19 @@ type LockFile (fileName:string, groups: Map<GroupName,LockFileGroup>) =
| Some v -> Some(allDependenciesOf v.Name)
| None -> None


member this.ResolveFrameworksForScriptGeneration () = lazy (
this.Groups
|> Seq.map (fun f -> f.Value.Options.Settings.FrameworkRestrictions)
|> Seq.map(fun restrictions ->
match restrictions with
| Paket.Requirements.AutoDetectFramework -> failwithf "couldn't detect framework"
| Paket.Requirements.ExplicitRestriction list ->
list.RepresentedFrameworks |> Seq.choose (function TargetProfile.SinglePlatform tf -> Some tf | _ -> None)
)
|> Seq.concat
)

/// Gets only direct dependencies of the given package in the given group.
member this.GetDirectDependenciesOfSafe(groupName:GroupName,package,context) =
let group = groups.[groupName]
Expand Down