Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #798 (relying on undefined behaviour) #802

Merged
merged 3 commits into from May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/nimblepkg/packageparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -413,15 +414,18 @@ 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:
display("Warning:", exc.msg, Warning, HighPriority)
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.
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down