@@ -6,6 +6,7 @@ open System.IO
6
6
open System.Text .RegularExpressions
7
7
open Chessie.ErrorHandling
8
8
open Paket.Domain
9
+ open Paket.Requirements
9
10
10
11
module private TemplateParser =
11
12
type private ParserState =
@@ -141,7 +142,7 @@ type OptionalPackagingInfo =
141
142
RequireLicenseAcceptance : bool
142
143
Tags : string list
143
144
DevelopmentDependency : bool
144
- Dependencies : ( PackageName * VersionRequirement ) list
145
+ Dependencies : ( PackageName * VersionRequirement * FrameworkIdentifier option ) list
145
146
ExcludedDependencies : Set < PackageName >
146
147
ExcludedGroups : Set < GroupName >
147
148
References : string list
@@ -261,45 +262,80 @@ module internal TemplateFile =
261
262
| Some m -> ok m
262
263
| None -> failP file " No description line in paket.template file."
263
264
265
+ let private (| Framework | _ |) ( line : string ) =
266
+ match line.Trim() with
267
+ | String.RemovePrefix " framework:" _ as trimmed -> Some ( FrameworkDetection.Extract( trimmed.Replace( " framework: " , " " )))
268
+ | _ -> None
269
+
270
+ let private (| Empty | _ |) ( line : string ) =
271
+ match line.Trim() with
272
+ | _ when String.IsNullOrWhiteSpace line -> Some ( Empty line)
273
+ | String.RemovePrefix " //" _ -> Some ( Empty line)
274
+ | String.RemovePrefix " #" _ -> Some ( Empty line)
275
+ | _ -> None
276
+ type TargetFrameworkGroup =
277
+ {
278
+ Framework : FrameworkIdentifier option
279
+ Dependencies : ( PackageName * VersionRequirement * FrameworkIdentifier option ) List }
280
+ static member ForNone = { Framework = None ; Dependencies = [] }
281
+ static member ForFramework framework = { Framework = framework ; Dependencies = [] }
282
+
283
+ let private getDependencyByLine ( fileName , lockFile : LockFile , currentVersion : SemVerInfo option , specificVersions : Map < string , SemVerInfo >, line : string , framework : FrameworkIdentifier option )=
284
+ let reg = Regex( @" (?<id>\S+)(?<version>.*)" ) .Match line
285
+ let name = PackageName reg.Groups.[ " id" ]. Value
286
+ let versionRequirement =
287
+ let versionString =
288
+ let s = reg.Groups.[ " version" ]. Value.Trim()
289
+ if s.Contains " CURRENTVERSION" then
290
+ match specificVersions.TryFind ( string name) with
291
+ | Some v -> s.Replace( " CURRENTVERSION" , string v)
292
+ | None ->
293
+ match currentVersion with
294
+ | Some v -> s.Replace( " CURRENTVERSION" , string v)
295
+ | None -> failwithf " The template file %s contains the placeholder CURRENTVERSION, but no version was given." fileName
296
+
297
+ elif s.Contains " LOCKEDVERSION" then
298
+ match lockFile.Groups.[ Constants.MainDependencyGroup]. Resolution |> Map.tryFind name with
299
+ | Some p -> s.Replace( " LOCKEDVERSION" , string p.Version)
300
+ | None ->
301
+ let packages =
302
+ lockFile.GetGroupedResolution()
303
+ |> Seq.filter ( fun kv -> snd kv.Key = name)
304
+ |> Seq.toList
305
+
306
+ match packages with
307
+ | [] -> failwithf " The template file %s contains the placeholder LOCKEDVERSION, but no version was given for package %O in paket.lock." fileName name
308
+ | [ kv] -> s.Replace( " LOCKEDVERSION" , string kv.Value.Version)
309
+ | _ -> failwithf " The template file %s contains the placeholder LOCKEDVERSION, but more than one group contains package %O in paket.lock." fileName name
310
+
311
+ else s
312
+
313
+ DependenciesFileParser.parseVersionRequirement versionString
314
+ name, versionRequirement, framework
315
+
316
+ let private getDependenciesByTargetFramework fileName lockFile currentVersion specificVersions ( lineNo , state : TargetFrameworkGroup list ) line =
317
+ match state with
318
+ | current:: other ->
319
+ let lineNo = lineNo + 1
320
+ match line with
321
+ | Framework framework ->
322
+ let group = TargetFrameworkGroup.ForFramework framework:: current:: other
323
+ lineNo, group
324
+ | Empty _ -> lineNo, current:: other
325
+ | _ ->
326
+ let dependency = getDependencyByLine( fileName, lockFile, currentVersion, specificVersions, line, current.Framework)
327
+ lineNo ,{ current with Dependencies = current.Dependencies @ [ dependency] }:: other
328
+ | [] -> failwithf " Error in paket.dependencies line %d " lineNo
329
+
264
330
let private getDependencies ( fileName , lockFile : LockFile , info : Map < string , string >, currentVersion : SemVerInfo option , specificVersions : Map < string , SemVerInfo >) =
265
331
match Map.tryFind " dependencies" info with
266
332
| None -> []
267
333
| Some d ->
268
- d.Split '\n'
269
- |> Array.map ( fun d ->
270
- let reg = Regex( @" (?<id>\S+)(?<version>.*)" ) .Match d
271
- let name = PackageName reg.Groups.[ " id" ]. Value
272
- let versionRequirement =
273
- let versionString =
274
- let s = reg.Groups.[ " version" ]. Value.Trim()
275
- if s.Contains " CURRENTVERSION" then
276
- match specificVersions.TryFind ( string name) with
277
- | Some v -> s.Replace( " CURRENTVERSION" , string v)
278
- | None ->
279
- match currentVersion with
280
- | Some v -> s.Replace( " CURRENTVERSION" , string v)
281
- | None -> failwithf " The template file %s contains the placeholder CURRENTVERSION, but no version was given." fileName
282
-
283
- elif s.Contains " LOCKEDVERSION" then
284
- match lockFile.Groups.[ Constants.MainDependencyGroup]. Resolution |> Map.tryFind name with
285
- | Some p -> s.Replace( " LOCKEDVERSION" , string p.Version)
286
- | None ->
287
- let packages =
288
- lockFile.GetGroupedResolution()
289
- |> Seq.filter ( fun kv -> snd kv.Key = name)
290
- |> Seq.toList
291
-
292
- match packages with
293
- | [] -> failwithf " The template file %s contains the placeholder LOCKEDVERSION, but no version was given for package %O in paket.lock." fileName name
294
- | [ kv] -> s.Replace( " LOCKEDVERSION" , string kv.Value.Version)
295
- | _ -> failwithf " The template file %s contains the placeholder LOCKEDVERSION, but more than one group contains package %O in paket.lock." fileName name
296
-
297
- else s
298
-
299
- DependenciesFileParser.parseVersionRequirement versionString
300
-
301
- name, versionRequirement)
302
- |> Array.toList
334
+ d.Split '\n'
335
+ |> Array.fold ( getDependenciesByTargetFramework fileName lockFile currentVersion specificVersions) ( 0 , [ TargetFrameworkGroup.ForNone])
336
+ |> snd
337
+ |> List.rev
338
+ |> List.collect ( fun a -> a.Dependencies)
303
339
304
340
305
341
let private getExcludedDependencies ( info : Map < string , string >) =
0 commit comments