@@ -307,7 +307,7 @@ proc mergeFollowedDevFileData(lhs: var DevelopFileData, rhs: DevelopFileData,
307307 errors.collidingNames)
308308
309309proc load (path: Path , dependentPkg: PackageInfo , options: Options ,
310- silentIfFileNotExists, raiseOnValidationErrors: bool ):
310+ silentIfFileNotExists, raiseOnValidationErrors, loadGlobalDeps : bool ):
311311 DevelopFileData
312312
313313template load (dependentPkg: PackageInfo , args: varargs [untyped ]):
@@ -318,8 +318,37 @@ template load(dependentPkg: PackageInfo, args: varargs[untyped]):
318318 dependentPkg.assertIsLoaded
319319 load (dependentPkg.getPkgDevFilePath, dependentPkg, args)
320320
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+
321350proc load (path: Path , dependentPkg: PackageInfo , options: Options ,
322- silentIfFileNotExists, raiseOnValidationErrors: bool ):
351+ silentIfFileNotExists, raiseOnValidationErrors, loadGlobalDeps : bool ):
323352 DevelopFileData =
324353 # # Loads data from a develop file at path `path`.
325354 # #
@@ -328,6 +357,10 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
328357 # #
329358 # # If `raiseOnValidationErrors` raises a `NimbleError` in the case some of the
330359 # # 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.
331364 # #
332365 # # Raises if the develop file or some of the included develop files:
333366 # # - cannot be read.
@@ -343,9 +376,6 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
343376 result .path = path
344377 result .dependentPkg = dependentPkg
345378
346- if silentIfFileNotExists and not path.fileExists:
347- return
348-
349379 var
350380 errors {.global .}: ErrorsCollection
351381 visitedFiles {.global .}: HashSet [Path ]
@@ -355,31 +385,38 @@ proc load(path: Path, dependentPkg: PackageInfo, options: Options,
355385 if dependentPkg.isLoaded:
356386 visitedPkgs.incl dependentPkg.getNimbleFileDir
357387
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
371393
372- for inclPath in result .jsonData.includes:
373- let inclPath = inclPath.normalizedPath
374- if visitedFiles.contains (inclPath):
375- continue
376- var inclDevFileData = initDevelopFileData ()
377394 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)
383420
384421 if result .dependentPkg.isLoaded and path.splitPath.tail == developFileName:
385422 # 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,
390427 continue
391428 var followedPkgDevFileData = initDevelopFileData ()
392429 try :
393- followedPkgDevFileData = load (pkg[], options, true , false )
430+ followedPkgDevFileData = load (pkg[], options, true , false , false )
394431 except :
395432 # The errors will be accumulated in `errors` global variable and
396433 # reported by the `load` call which initiated the recursive process.
@@ -580,7 +617,7 @@ proc includeDevelopFile(data: var DevelopFileData, path: Path,
580617
581618 var inclFileData = initDevelopFileData ()
582619 try :
583- inclFileData = load (path, initPackageInfo (), options, false , true )
620+ inclFileData = load (path, initPackageInfo (), options, false , true , false )
584621 except CatchableError as error:
585622 displayError (failedToLoadFileMsg ($ path))
586623 displayDetails (error)
@@ -660,7 +697,7 @@ proc updateDevelopFile*(dependentPkg: PackageInfo, options: Options): bool =
660697 var
661698 hasError = false
662699 hasSuccessfulRemoves = false
663- data = load (developFile, dependentPkg, options, true , true )
700+ data = load (developFile, dependentPkg, options, true , true , false )
664701
665702 defer :
666703 let writeEmpty = hasSuccessfulRemoves or
@@ -691,7 +728,8 @@ proc processDevelopDependencies*(dependentPkg: PackageInfo, options: Options):
691728 # # Returns a sequence with the develop mode dependencies of the `dependentPkg`
692729 # # and recursively all of their develop mode dependencies.
693730
694- let data = load (dependentPkg, options, true , true )
731+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
732+ let data = load (dependentPkg, options, true , true , loadGlobalDeps)
695733 result = newSeqOfCap [PackageInfo ](data.nameToPkg.len)
696734 for _, pkg in data.nameToPkg:
697735 result .add pkg[]
@@ -702,7 +740,8 @@ proc getDevelopDependencies*(dependentPkg: PackageInfo, options: Options):
702740 # # mode dependencies of package `dependentPkg` and recursively all of their
703741 # # develop mode dependencies.
704742
705- let data = load (dependentPkg, options, true , true )
743+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
744+ let data = load (dependentPkg, options, true , true , loadGlobalDeps)
706745 return data.nameToPkg
707746
708747type
@@ -908,6 +947,7 @@ proc validateDevelopFile*(dependentPkg: PackageInfo, options: Options) =
908947 # # The procedure is used in the Nimble's `check` command to transitively
909948 # # validate the contents of the develop files.
910949
911- discard load (dependentPkg, options, true , true )
950+ let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
951+ discard load (dependentPkg, options, true , true , loadGlobalDeps)
912952 if dependentPkg.areLockedDepsLoaded:
913953 validateDevelopFileAgainstLockFile (dependentPkg, options)
0 commit comments