@@ -307,7 +307,7 @@ proc mergeFollowedDevFileData(lhs: var DevelopFileData, rhs: DevelopFileData,
307
307
errors.collidingNames)
308
308
309
309
proc load(path: Path, dependentPkg: PackageInfo, options: Options,
310
- silentIfFileNotExists, raiseOnValidationErrors: bool ):
310
+ silentIfFileNotExists, raiseOnValidationErrors, loadGlobalDeps : bool ):
311
311
DevelopFileData
312
312
313
313
template load(dependentPkg: PackageInfo, args: varargs [untyped ]):
@@ -318,8 +318,37 @@ template load(dependentPkg: PackageInfo, args: varargs[untyped]):
318
318
dependentPkg.assertIsLoaded
319
319
load(dependentPkg.getPkgDevFilePath, dependentPkg, args)
320
320
321
+ proc loadGlobalDependencies(result : var DevelopFileData,
322
+ collidingNames: var CollidingNames,
323
+ options: Options) =
324
+ ## Loads data from the `links` subdirectory in the Nimble cache. The links
325
+ ## in the cache are treated as paths in a global develop file used when a
326
+ ## local one does not exist.
327
+
328
+ for (kind, path) in walkDir(options.getPkgsLinksDir):
329
+ if kind != pcDir:
330
+ continue
331
+ let (pkgName, _, _) = getNameVersionChecksum(path)
332
+ let linkFilePath = path / pkgName.getLinkFileName
333
+ if not linkFilePath.fileExists:
334
+ displayWarning(&"Not found link file in \"{path}\".")
335
+ continue
336
+ let lines = linkFilePath.readFile.split("\n")
337
+ if lines.len != 2:
338
+ displayWarning(&"Invalid link file \"{linkFilePath}\".")
339
+ continue
340
+ let pkgPath = lines[ 1]
341
+ let (pkgInfo, error) = validatePackage(pkgPath, options)
342
+ if error == nil :
343
+ let path = path.Path
344
+ result .addPackage(pkgInfo, path, [path].toHashSet, collidingNames)
345
+ else :
346
+ displayWarning(
347
+ & " Package \" { pkgName} \" at path \" { pkgPath} \" is invalid. Skipping it. " )
348
+ displayDetails(error.msg)
349
+
321
350
proc load(path: Path, dependentPkg: PackageInfo, options: Options,
322
- silentIfFileNotExists, raiseOnValidationErrors: bool ):
351
+ silentIfFileNotExists, raiseOnValidationErrors, loadGlobalDeps : bool ):
323
352
DevelopFileData =
324
353
# # Loads data from a develop file at path `path`.
325
354
# #
@@ -328,6 +357,10 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
328
357
# #
329
358
# # If `raiseOnValidationErrors` raises a `NimbleError` in the case some of the
330
359
# # contents of the develop file are invalid.
360
+ # #
361
+ # # If `loadGlobalDeps` then load the packages pointed by the link files in the
362
+ # # `links` directory in the Nimble cache instead of the once pointed by the
363
+ # # local develop file.
331
364
# #
332
365
# # Raises if the develop file or some of the included develop files:
333
366
# # - cannot be read.
@@ -343,9 +376,6 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
343
376
result .path = path
344
377
result .dependentPkg = dependentPkg
345
378
346
- if silentIfFileNotExists and not path.fileExists:
347
- return
348
-
349
379
var
350
380
errors {.global.}: ErrorsCollection
351
381
visitedFiles {.global.}: HashSet[Path]
@@ -355,31 +385,38 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
355
385
if dependentPkg.isLoaded:
356
386
visitedPkgs.incl dependentPkg.getNimbleFileDir
357
387
358
- try:
359
- fromJson(result .jsonData, parseFile(path), Joptions(allowExtraKeys: true))
360
- except ValueError as error:
361
- raise nimbleError(notAValidDevFileJsonMsg($path), details = error)
362
-
363
- for depPath in result .jsonData.dependencies:
364
- let depPath = if depPath.isAbsolute:
365
- depPath.normalizedPath else: (path.splitFile.dir / depPath).normalizedPath
366
- let (pkgInfo, error) = validatePackage(depPath, options)
367
- if error == nil:
368
- result .addPackage(pkgInfo, path, [path].toHashSet, errors.collidingNames)
369
- else:
370
- errors.invalidPackages[depPath] = error
388
+ if loadGlobalDeps:
389
+ loadGlobalDependencies(result , errors.collidingNames, options)
390
+ else :
391
+ if silentIfFileNotExists and not path.fileExists:
392
+ return
371
393
372
- for inclPath in result .jsonData.includes:
373
- let inclPath = inclPath.normalizedPath
374
- if visitedFiles.contains(inclPath):
375
- continue
376
- var inclDevFileData = initDevelopFileData()
377
394
try :
378
- inclDevFileData = load(inclPath, initPackageInfo(), options, false, false)
379
- except CatchableError as error:
380
- errors.invalidIncludeFiles[path] = error
381
- continue
382
- result .mergeIncludedDevFileData(inclDevFileData, errors)
395
+ fromJson(result .jsonData, parseFile(path), Joptions(allowExtraKeys: true ))
396
+ except ValueError as error:
397
+ raise nimbleError(notAValidDevFileJsonMsg($ path), details = error)
398
+
399
+ for depPath in result .jsonData.dependencies:
400
+ let depPath = if depPath.isAbsolute:
401
+ depPath.normalizedPath else : (path.splitFile.dir / depPath).normalizedPath
402
+ let (pkgInfo, error) = validatePackage(depPath, options)
403
+ if error == nil :
404
+ result .addPackage(pkgInfo, path, [path].toHashSet, errors.collidingNames)
405
+ else :
406
+ errors.invalidPackages[depPath] = error
407
+
408
+ for inclPath in result .jsonData.includes:
409
+ let inclPath = inclPath.normalizedPath
410
+ if visitedFiles.contains(inclPath):
411
+ continue
412
+ var inclDevFileData = initDevelopFileData()
413
+ try :
414
+ inclDevFileData = load(
415
+ inclPath, initPackageInfo(), options, false , false , false )
416
+ except CatchableError as error:
417
+ errors.invalidIncludeFiles[path] = error
418
+ continue
419
+ result .mergeIncludedDevFileData(inclDevFileData, errors)
383
420
384
421
if result .dependentPkg.isLoaded and path.splitPath.tail == developFileName:
385
422
# If this is a package develop file, but not a free one, for each of the
@@ -390,7 +427,7 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
390
427
continue
391
428
var followedPkgDevFileData = initDevelopFileData()
392
429
try :
393
- followedPkgDevFileData = load(pkg[], options, true, false)
430
+ followedPkgDevFileData = load(pkg[], options, true , false , false )
394
431
except :
395
432
# The errors will be accumulated in `errors` global variable and
396
433
# reported by the `load` call which initiated the recursive process.
@@ -580,7 +617,7 @@ proc includeDevelopFile(data: var DevelopFileData, path: Path,
580
617
581
618
var inclFileData = initDevelopFileData()
582
619
try:
583
- inclFileData = load(path, initPackageInfo(), options, false, true)
620
+ inclFileData = load(path, initPackageInfo(), options, false, true, false )
584
621
except CatchableError as error:
585
622
displayError(failedToLoadFileMsg($path))
586
623
displayDetails(error)
@@ -660,7 +697,7 @@ proc updateDevelopFile*(dependentPkg: PackageInfo, options: Options): bool =
660
697
var
661
698
hasError = false
662
699
hasSuccessfulRemoves = false
663
- data = load(developFile, dependentPkg, options, true, true)
700
+ data = load(developFile, dependentPkg, options, true, true, false )
664
701
665
702
defer:
666
703
let writeEmpty = hasSuccessfulRemoves or
@@ -691,7 +728,8 @@ proc processDevelopDependencies*(dependentPkg: PackageInfo, options: Options):
691
728
## Returns a sequence with the develop mode dependencies of the `dependentPkg`
692
729
## and recursively all of their develop mode dependencies.
693
730
694
- let data = load(dependentPkg, options, true, true)
731
+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
732
+ let data = load(dependentPkg, options, true, true, loadGlobalDeps)
695
733
result = newSeqOfCap[PackageInfo](data.nameToPkg.len)
696
734
for _, pkg in data.nameToPkg:
697
735
result .add pkg[]
@@ -702,7 +740,8 @@ proc getDevelopDependencies*(dependentPkg: PackageInfo, options: Options):
702
740
## mode dependencies of package `dependentPkg` and recursively all of their
703
741
## develop mode dependencies.
704
742
705
- let data = load(dependentPkg, options, true, true)
743
+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
744
+ let data = load(dependentPkg, options, true, true, loadGlobalDeps)
706
745
return data.nameToPkg
707
746
708
747
type
@@ -908,6 +947,7 @@ proc validateDevelopFile*(dependentPkg: PackageInfo, options: Options) =
908
947
## The procedure is used in the Nimble's `check` command to transitively
909
948
## validate the contents of the develop files.
910
949
911
- discard load(dependentPkg, options, true, true)
950
+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
951
+ discard load(dependentPkg, options, true, true, loadGlobalDeps)
912
952
if dependentPkg.areLockedDepsLoaded:
913
953
validateDevelopFileAgainstLockFile(dependentPkg, options)
0 commit comments