-
Notifications
You must be signed in to change notification settings - Fork 520
/
Queries.fs
95 lines (83 loc) · 4.09 KB
/
Queries.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module Paket.Queries // mostly logic which was in PublicAPI.fs but is useful to other places (like script generation)
open Domain
open System.IO
open System
let getLockFileFromDependenciesFile dependenciesFileName =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName
LockFile.LoadFrom lockFileName.FullName
let listPackages (packages: System.Collections.Generic.KeyValuePair<GroupName*PackageName, PackageResolver.PackageInfo> seq) =
packages
|> Seq.map (fun kv ->
let groupName,packageName = kv.Key
groupName.ToString(),packageName.ToString(),kv.Value.Version.ToString())
|> Seq.toList
let getAllInstalledPackagesFromLockFile (lockFile: LockFile) =
lockFile.GetGroupedResolution() |> listPackages
let getInstalledPackageModel (lockFile: LockFile) (QualifiedPackageName(groupName, packageName)) =
match lockFile.Groups |> Map.tryFind groupName with
| None -> failwithf "Group %O can't be found in paket.lock." groupName
| Some group ->
match group.TryFind(packageName) with
| None -> failwithf "Package %O is not installed in group %O." packageName groupName
| Some resolvedPackage ->
let packageName = resolvedPackage.Name
let storage = defaultArg resolvedPackage.Settings.StorageConfig PackagesFolderGroupConfig.Default
let includeVersion = defaultArg resolvedPackage.Settings.IncludeVersionInPath false
let resolvedConfig = storage.Resolve lockFile.RootPath groupName packageName resolvedPackage.Version includeVersion
let folder =
match resolvedConfig.Path with
| Some f -> f
| None -> NuGetCache.GetTargetUserFolder packageName resolvedPackage.Version
InstallModel.CreateFromContent(
packageName,
resolvedPackage.Version,
Paket.Requirements.FrameworkRestriction.NoRestriction,
NuGet.GetContent(folder).Force())
let getRuntimeGraph (lockFile: LockFile) (groupName:GroupName) =
lockFile.Groups
|> Map.tryFind groupName
|> Option.toList
|> Seq.collect (fun group -> group.Resolution |> Map.toSeq)
|> Seq.map snd
|> Seq.choose (fun p ->
let groupFolder = if groupName = Constants.MainDependencyGroup then "" else "/" + groupName.ToString()
let runtimeJson = sprintf "%s/packages%s/%O/runtime.json" lockFile.RootPath groupFolder p.Name
if File.Exists runtimeJson then Some runtimeJson
else None)
|> Seq.map File.ReadAllText
|> Seq.map RuntimeGraphParser.readRuntimeGraph
|> RuntimeGraph.mergeSeq
let getRuntimePackages (rid) (lockFile:LockFile) (groupName:GroupName) =
let g = getRuntimeGraph lockFile groupName
lockFile.Groups
|> Map.tryFind groupName
|> Option.toList
|> Seq.collect (fun group -> group.Resolution |> Map.toSeq)
|> Seq.map snd
|> Seq.collect (fun p -> RuntimeGraph.findRuntimeDependencies rid p.Name g)
|> Seq.toList
let resolveFrameworkForScriptGeneration (dependencies: DependenciesFile) = lazy (
dependencies.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.concat
)
let resolveEnvironmentFrameworkForScriptGeneration = lazy (
// HACK: resolve .net version based on environment
// list of match is incomplete / inaccurate
#if DOTNETCORE
// Environment.Version is not supported
//dunno what is used for, using a default
DotNetFramework (FrameworkVersion.V4_5)
#else
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.V4_5) // paket.exe is compiled for framework 4.5
#endif
)