Implements basic support for building with .nimble-link'ed packages.
This commit is contained in:
parent
5f1de1e4ff
commit
97dc0ffb45
8 changed files with 90 additions and 31 deletions
|
|
@ -18,6 +18,7 @@ when not defined(nimscript):
|
|||
isNimScript*: bool ## Determines if this pkg info was read from a nims file
|
||||
isMinimal*: bool
|
||||
isInstalled*: bool ## Determines if the pkg this info belongs to is installed
|
||||
isLinked*: bool ## Determines if the pkg this info belongs to has been linked via `develop`
|
||||
postHooks*: HashSet[string] ## Useful to know so that Nimble doesn't execHook unnecessarily
|
||||
preHooks*: HashSet[string]
|
||||
name*: string
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ proc getNameVersion*(pkgpath: string): tuple[name, version: string] =
|
|||
##
|
||||
## Also works for file paths like:
|
||||
## ``/home/user/.nimble/pkgs/package-0.1/package.nimble``
|
||||
if pkgPath.splitFile.ext == ".nimble" or pkgPath.splitFile.ext == ".babel":
|
||||
if pkgPath.splitFile.ext in [".nimble", ".nimble-link", ".babel"]:
|
||||
return getNameVersion(pkgPath.splitPath.head)
|
||||
|
||||
result.name = ""
|
||||
|
|
@ -281,7 +281,7 @@ proc findNimbleFile*(dir: string; error: bool): string =
|
|||
if kind in {pcFile, pcLinkToFile}:
|
||||
let ext = path.splitFile.ext
|
||||
case ext
|
||||
of ".babel", ".nimble":
|
||||
of ".babel", ".nimble", ".nimble-link":
|
||||
result = path
|
||||
inc hits
|
||||
else: discard
|
||||
|
|
@ -293,8 +293,16 @@ proc findNimbleFile*(dir: string; error: bool): string =
|
|||
raise newException(NimbleError,
|
||||
"Specified directory does not contain a .nimble file.")
|
||||
else:
|
||||
display("Warning:", "No .nimble file found for " & dir, Warning,
|
||||
HighPriority)
|
||||
display("Warning:", "No .nimble or .nimble-link file found for " &
|
||||
dir, Warning, HighPriority)
|
||||
|
||||
if result.splitFile.ext == ".nimble-link":
|
||||
# Return the path of the real .nimble file.
|
||||
let lines = readFile(result).splitLines()
|
||||
result = lines[0]
|
||||
if not fileExists(result):
|
||||
raiseNimbleError("The .nimble-link file is pointing to a missing" &
|
||||
" file: " & result)
|
||||
|
||||
proc getInstalledPkgsMin*(libsDir: string, options: Options):
|
||||
seq[tuple[pkginfo: PackageInfo, meta: MetaData]] =
|
||||
|
|
@ -309,13 +317,15 @@ proc getInstalledPkgsMin*(libsDir: string, options: Options):
|
|||
let nimbleFile = findNimbleFile(path, false)
|
||||
if nimbleFile != "":
|
||||
let meta = readMetaData(path)
|
||||
let (name, version) = getNameVersion(nimbleFile)
|
||||
let (name, version) = getNameVersion(path)
|
||||
var pkg = initPackageInfo(nimbleFile)
|
||||
pkg.name = name
|
||||
pkg.version = version
|
||||
pkg.specialVersion = version
|
||||
pkg.isMinimal = true
|
||||
pkg.isInstalled = true
|
||||
pkg.isLinked =
|
||||
cmpPaths(nimbleFile.splitFile().dir, path) != 0
|
||||
result.add((pkg, meta))
|
||||
|
||||
proc withinRange*(pkgInfo: PackageInfo, verRange: VersionRange): bool =
|
||||
|
|
@ -369,7 +379,7 @@ proc findAllPkgs*(pkglist: seq[tuple[pkgInfo: PackageInfo, meta: MetaData]],
|
|||
|
||||
proc getRealDir*(pkgInfo: PackageInfo): string =
|
||||
## Returns the directory containing the package source files.
|
||||
if pkgInfo.srcDir != "" and not pkgInfo.isInstalled:
|
||||
if pkgInfo.srcDir != "" and (not pkgInfo.isInstalled or pkgInfo.isLinked):
|
||||
result = pkgInfo.mypath.splitFile.dir / pkgInfo.srcDir
|
||||
else:
|
||||
result = pkgInfo.mypath.splitFile.dir
|
||||
|
|
@ -515,6 +525,8 @@ when isMainModule:
|
|||
("package", "#head")
|
||||
doAssert getNameVersion("/home/user/.nimble/libs/package-#branch-with-dashes") ==
|
||||
("package", "#branch-with-dashes")
|
||||
# readPackageInfo (and possibly more) depends on this not raising.
|
||||
doAssert getNameVersion("/home/user/.nimble/libs/package") == ("package", "")
|
||||
|
||||
doAssert toValidPackageName("foo__bar") == "foo_bar"
|
||||
doAssert toValidPackageName("jhbasdh!£$@%#^_&*_()qwe") == "jhbasdh_qwe"
|
||||
|
|
|
|||
|
|
@ -292,6 +292,11 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
|
|||
result.version = minimalInfo.version
|
||||
result.isNimScript = true
|
||||
result.isMinimal = true
|
||||
|
||||
# It's possible this proc will receive a .nimble-link file eventually,
|
||||
# I added this assert to hopefully make this error clear for everyone.
|
||||
let msg = "No version detected. Received nimble-link?"
|
||||
assert result.version.len > 0, msg
|
||||
else:
|
||||
try:
|
||||
readPackageInfoFromNims(nf, options, result)
|
||||
|
|
@ -386,6 +391,8 @@ proc getInstalledPkgs*(libsDir: string, options: Options):
|
|||
raise exc
|
||||
|
||||
pkg.isInstalled = true
|
||||
pkg.isLinked =
|
||||
cmpPaths(nimbleFile.splitFile().dir, path) != 0
|
||||
result.add((pkg, meta))
|
||||
|
||||
proc isNimScript*(nf: string, options: Options): bool =
|
||||
|
|
@ -393,7 +400,9 @@ proc isNimScript*(nf: string, options: Options): bool =
|
|||
|
||||
proc toFullInfo*(pkg: PackageInfo, options: Options): PackageInfo =
|
||||
if pkg.isMinimal:
|
||||
return getPkgInfoFromFile(pkg.mypath, options)
|
||||
result = getPkgInfoFromFile(pkg.mypath, options)
|
||||
result.isInstalled = pkg.isInstalled
|
||||
result.isLinked = pkg.isLinked
|
||||
else:
|
||||
return pkg
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue