Fixes small bugs introduced by nimscript.
This commit is contained in:
parent
7d5428be19
commit
20d4a59609
3 changed files with 36 additions and 13 deletions
|
|
@ -766,11 +766,13 @@ proc install(packages: seq[PkgTuple],
|
||||||
|
|
||||||
proc build(options: Options) =
|
proc build(options: Options) =
|
||||||
var pkgInfo = getPkgInfo(getCurrentDir())
|
var pkgInfo = getPkgInfo(getCurrentDir())
|
||||||
|
nimScriptHint(pkgInfo)
|
||||||
let paths = processDeps(pkginfo, options)
|
let paths = processDeps(pkginfo, options)
|
||||||
buildFromDir(pkgInfo, paths, false)
|
buildFromDir(pkgInfo, paths, false)
|
||||||
|
|
||||||
proc compile(options: Options) =
|
proc compile(options: Options) =
|
||||||
var pkgInfo = getPkgInfo(getCurrentDir())
|
var pkgInfo = getPkgInfo(getCurrentDir())
|
||||||
|
nimScriptHint(pkgInfo)
|
||||||
let paths = processDeps(pkginfo, options)
|
let paths = processDeps(pkginfo, options)
|
||||||
let realDir = pkgInfo.getRealDir()
|
let realDir = pkgInfo.getRealDir()
|
||||||
|
|
||||||
|
|
@ -1073,7 +1075,9 @@ proc doAction(options: Options) =
|
||||||
of actionUpdate:
|
of actionUpdate:
|
||||||
update(options)
|
update(options)
|
||||||
of actionInstall:
|
of actionInstall:
|
||||||
discard install(options.action.packages, options)
|
let (_, pkgInfo) = install(options.action.packages, options)
|
||||||
|
if options.action.packages.len == 0:
|
||||||
|
nimScriptHint(pkgInfo)
|
||||||
of actionUninstall:
|
of actionUninstall:
|
||||||
uninstall(options)
|
uninstall(options)
|
||||||
of actionSearch:
|
of actionSearch:
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ type
|
||||||
PackageInfo* = object
|
PackageInfo* = object
|
||||||
mypath*: string ## The path of this .nimble file
|
mypath*: string ## The path of this .nimble file
|
||||||
isNimScript*: bool ## Determines if this pkg info was read from a nims file
|
isNimScript*: bool ## Determines if this pkg info was read from a nims file
|
||||||
|
isMinimal*: bool
|
||||||
name*: string
|
name*: string
|
||||||
version*: string
|
version*: string
|
||||||
author*: string
|
author*: string
|
||||||
|
|
|
||||||
|
|
@ -93,20 +93,24 @@ proc validatePackageInfo(pkgInfo: PackageInfo, path: string) =
|
||||||
if pkgInfo.version == "":
|
if pkgInfo.version == "":
|
||||||
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
||||||
" does not contain a version field.")
|
" does not contain a version field.")
|
||||||
if pkgInfo.author == "":
|
|
||||||
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
if not pkgInfo.isMinimal:
|
||||||
" does not contain an author field.")
|
if pkgInfo.author == "":
|
||||||
if pkgInfo.description == "":
|
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
||||||
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
" does not contain an author field.")
|
||||||
" does not contain a description field.")
|
if pkgInfo.description == "":
|
||||||
if pkgInfo.license == "":
|
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
||||||
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
" does not contain a description field.")
|
||||||
" does not contain a license field.")
|
if pkgInfo.license == "":
|
||||||
if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]:
|
raise newException(NimbleError, "Incorrect .nimble file: " & path &
|
||||||
raise newException(NimbleError, "'" & pkgInfo.backend &
|
" does not contain a license field.")
|
||||||
"' is an invalid backend.")
|
if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]:
|
||||||
|
raise newException(NimbleError, "'" & pkgInfo.backend &
|
||||||
|
"' is an invalid backend.")
|
||||||
|
|
||||||
validateVersion(pkgInfo.version)
|
validateVersion(pkgInfo.version)
|
||||||
|
|
||||||
|
proc nimScriptHint*(pkgInfo: PackageInfo) =
|
||||||
if not pkgInfo.isNimScript:
|
if not pkgInfo.isNimScript:
|
||||||
# TODO: Turn this into a warning.
|
# TODO: Turn this into a warning.
|
||||||
# TODO: Add a URL explaining more.
|
# TODO: Add a URL explaining more.
|
||||||
|
|
@ -195,6 +199,13 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
|
||||||
proc getNameVersion*(pkgpath: string): tuple[name, version: string] =
|
proc getNameVersion*(pkgpath: string): tuple[name, version: string] =
|
||||||
## Splits ``pkgpath`` in the format ``/home/user/.nimble/pkgs/package-0.1``
|
## Splits ``pkgpath`` in the format ``/home/user/.nimble/pkgs/package-0.1``
|
||||||
## into ``(packagea, 0.1)``
|
## into ``(packagea, 0.1)``
|
||||||
|
##
|
||||||
|
## Also works for file paths like:
|
||||||
|
## ``/home/user/.nimble/pkgs/package-0.1/package.nimble``
|
||||||
|
|
||||||
|
if pkgPath.splitFile.ext == ".nimble":
|
||||||
|
return getNameVersion(pkgPath.splitPath.head)
|
||||||
|
|
||||||
result.name = ""
|
result.name = ""
|
||||||
result.version = ""
|
result.version = ""
|
||||||
let tail = pkgpath.splitPath.tail
|
let tail = pkgpath.splitPath.tail
|
||||||
|
|
@ -215,6 +226,9 @@ proc readPackageInfo*(nf: NimbleFile; onlyMinimalInfo=false): PackageInfo =
|
||||||
## fails attempts to evaluate it as a nimscript file.
|
## fails attempts to evaluate it as a nimscript file.
|
||||||
##
|
##
|
||||||
## If both fail then returns an error.
|
## If both fail then returns an error.
|
||||||
|
##
|
||||||
|
## When ``onlyMinimalInfo`` is true, only the `name` and `version` fields are
|
||||||
|
## populated. The isNimScript field can also be relied on.
|
||||||
result = initPackageInfo(nf)
|
result = initPackageInfo(nf)
|
||||||
|
|
||||||
var success = false
|
var success = false
|
||||||
|
|
@ -232,6 +246,8 @@ proc readPackageInfo*(nf: NimbleFile; onlyMinimalInfo=false): PackageInfo =
|
||||||
let tmp = getNameVersion(nf)
|
let tmp = getNameVersion(nf)
|
||||||
result.name = tmp.name
|
result.name = tmp.name
|
||||||
result.version = tmp.version
|
result.version = tmp.version
|
||||||
|
result.isNimScript = true
|
||||||
|
result.isMinimal = true
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
readPackageInfoFromNims(nf, result)
|
readPackageInfoFromNims(nf, result)
|
||||||
|
|
@ -429,6 +445,8 @@ when isMainModule:
|
||||||
("packagea", "0.1")
|
("packagea", "0.1")
|
||||||
doAssert getNameVersion("/home/user/.nimble/libs/package-a-0.1") ==
|
doAssert getNameVersion("/home/user/.nimble/libs/package-a-0.1") ==
|
||||||
("package-a", "0.1")
|
("package-a", "0.1")
|
||||||
|
doAssert getNameVersion("/home/user/.nimble/libs/package-a-0.1/package.nimble") ==
|
||||||
|
("package-a", "0.1")
|
||||||
|
|
||||||
validatePackageName("foo_bar")
|
validatePackageName("foo_bar")
|
||||||
validatePackageName("f_oo_b_a_r")
|
validatePackageName("f_oo_b_a_r")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue