diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index 94580743..8411390d 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -315,8 +315,8 @@ proc inferInstallRules(pkgInfo: var PackageInfo, options: Options) = if fileExists(pkgInfo.getRealDir() / pkgInfo.name.addFileExt("nim")): pkgInfo.installFiles.add(pkgInfo.name.addFileExt("nim")) -proc readPackageInfo(nf: NimbleFile, options: Options, - onlyMinimalInfo=false): PackageInfo = +proc readPackageInfo(result: var PackageInfo, nf: NimbleFile, options: Options, + onlyMinimalInfo=false) = ## Reads package info from the specified Nimble file. ## ## Attempts to read it using the "old" Nimble ini format first, if that @@ -335,7 +335,8 @@ proc readPackageInfo(nf: NimbleFile, options: Options, # Check the cache. if options.pkgInfoCache.hasKey(nf): - return options.pkgInfoCache[nf] + result = options.pkgInfoCache[nf] + return result = initPackageInfo(nf) let minimalInfo = getNameVersion(nf) @@ -403,7 +404,7 @@ proc readPackageInfo(nf: NimbleFile, options: Options, proc validate*(file: NimbleFile, options: Options, error: var ValidationError, pkgInfo: var PackageInfo): bool = try: - pkgInfo = readPackageInfo(file, options) + pkgInfo.readPackageInfo(file, options) except ValidationError as exc: error = exc[] return false @@ -413,8 +414,9 @@ proc validate*(file: NimbleFile, options: Options, proc getPkgInfoFromFile*(file: NimbleFile, options: Options): PackageInfo = ## Reads the specified .nimble file and returns its data as a PackageInfo ## object. Any validation errors are handled and displayed as warnings. + var info: PackageInfo try: - result = readPackageInfo(file, options) + info.readPackageInfo(file, options) except ValidationError: let exc = (ref ValidationError)(getCurrentException()) if exc.warnAll: @@ -422,6 +424,8 @@ proc getPkgInfoFromFile*(file: NimbleFile, options: Options): PackageInfo = display("Hint:", exc.hint, Warning, HighPriority) else: raise + finally: + result = info proc getPkgInfo*(dir: string, options: Options): PackageInfo = ## Find the .nimble file in ``dir`` and parses it, returning a PackageInfo. @@ -453,7 +457,7 @@ proc getInstalledPkgs*(libsDir: string, options: Options): let meta = readMetaData(path) var pkg: PackageInfo try: - pkg = readPackageInfo(nimbleFile, options, onlyMinimalInfo=false) + pkg.readPackageInfo(nimbleFile, options, onlyMinimalInfo=false) except ValidationError: let exc = (ref ValidationError)(getCurrentException()) exc.msg = createErrorMsg(validationErrorMsg, path, exc.msg) @@ -477,7 +481,9 @@ proc getInstalledPkgs*(libsDir: string, options: Options): result.add((pkg, meta)) proc isNimScript*(nf: string, options: Options): bool = - result = readPackageInfo(nf, options).isNimScript + var p: PackageInfo + p.readPackageInfo(nf, options) + result = p.isNimScript proc toFullInfo*(pkg: PackageInfo, options: Options): PackageInfo = if pkg.isMinimal: