Renamed myVersion to version and version to specialVersion.
This commit is contained in:
parent
2886059817
commit
432c91b938
5 changed files with 43 additions and 35 deletions
|
|
@ -210,7 +210,7 @@ proc addRevDep(options: Options, dep: tuple[name, version: string],
|
|||
options.nimbleData["reverseDeps"][dep.name] = newJObject()
|
||||
if not options.nimbleData["reverseDeps"][dep.name].hasKey(dep.version):
|
||||
options.nimbleData["reverseDeps"][dep.name][dep.version] = newJArray()
|
||||
let revDep = %{ "name": %pkg.name, "version": %pkg.version}
|
||||
let revDep = %{ "name": %pkg.name, "version": %pkg.specialVersion}
|
||||
let thisDep = options.nimbleData["reverseDeps"][dep.name][dep.version]
|
||||
if revDep notin thisDep:
|
||||
thisDep.add revDep
|
||||
|
|
@ -225,7 +225,7 @@ proc removeRevDep(options: Options, pkg: PackageInfo) =
|
|||
var newVal = newJArray()
|
||||
for revDep in val:
|
||||
if not (revDep["name"].str == pkg.name and
|
||||
revDep["version"].str == pkg.version):
|
||||
revDep["version"].str == pkg.specialVersion):
|
||||
newVal.add revDep
|
||||
thisDep[ver] = newVal
|
||||
|
||||
|
|
@ -263,7 +263,7 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
|
|||
result = @[]
|
||||
assert(not pkginfo.isMinimal, "processDeps needs pkginfo.requires")
|
||||
display("Verifying",
|
||||
"dependencies for $1@$2" % [pkginfo.name, pkginfo.version],
|
||||
"dependencies for $1@$2" % [pkginfo.name, pkginfo.specialVersion],
|
||||
priority = HighPriority)
|
||||
|
||||
let pkglist = getInstalledPkgs(options.getPkgsDir(), options)
|
||||
|
|
@ -290,7 +290,7 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
|
|||
result.add(pkg.mypath.splitFile.dir)
|
||||
# Process the dependencies of this dependency.
|
||||
result.add(processDeps(pkg, options))
|
||||
reverseDeps.add((pkg.name, pkg.version))
|
||||
reverseDeps.add((pkg.name, pkg.specialVersion))
|
||||
|
||||
# Check if two packages of the same name (but different version) are listed
|
||||
# in the path.
|
||||
|
|
@ -298,11 +298,11 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
|
|||
for p in result:
|
||||
let pkgInfo = getPkgInfo(p, options)
|
||||
if pkgsInPath.hasKey(pkgInfo.name) and
|
||||
pkgsInPath[pkgInfo.name] != pkgInfo.version:
|
||||
pkgsInPath[pkgInfo.name] != pkgInfo.specialVersion:
|
||||
raise newException(NimbleError,
|
||||
"Cannot satisfy the dependency on $1 $2 and $1 $3" %
|
||||
[pkgInfo.name, pkgInfo.version, pkgsInPath[pkgInfo.name]])
|
||||
pkgsInPath[pkgInfo.name] = pkgInfo.version
|
||||
[pkgInfo.name, pkgInfo.specialVersion, pkgsInPath[pkgInfo.name]])
|
||||
pkgsInPath[pkgInfo.name] = pkgInfo.specialVersion
|
||||
|
||||
# We add the reverse deps to the JSON file here because we don't want
|
||||
# them added if the above errorenous condition occurs
|
||||
|
|
@ -406,7 +406,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
|||
|
||||
# Overwrite the version if the requested version is "#head" or similar.
|
||||
if requestedVer.kind == verSpecial:
|
||||
pkgInfo.version = $requestedVer.spe
|
||||
pkgInfo.specialVersion = $requestedVer.spe
|
||||
|
||||
# Dependencies need to be processed before the creation of the pkg dir.
|
||||
result.paths = processDeps(pkginfo, depsOptions)
|
||||
|
|
@ -415,14 +415,14 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
|||
result.pkg = pkgInfo
|
||||
return result
|
||||
|
||||
display("Installing", "$1 $2" % [pkginfo.name, pkginfo.version],
|
||||
display("Installing", "$1@$2" % [pkginfo.name, pkginfo.specialVersion],
|
||||
priority = HighPriority)
|
||||
|
||||
# Build before removing an existing package (if one exists). This way
|
||||
# if the build fails then the old package will still be installed.
|
||||
if pkgInfo.bin.len > 0: buildFromDir(pkgInfo, result.paths, true)
|
||||
|
||||
let versionStr = '-' & pkgInfo.version
|
||||
let versionStr = '-' & pkgInfo.specialVersion
|
||||
|
||||
let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr)
|
||||
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"):
|
||||
|
|
@ -713,7 +713,7 @@ proc listInstalled(options: Options) =
|
|||
for x in pkgs.items():
|
||||
let
|
||||
pName = x.pkginfo.name
|
||||
pVer = x.pkginfo.version
|
||||
pVer = x.pkginfo.specialVersion
|
||||
if not h.hasKey(pName): h[pName] = @[]
|
||||
var s = h[pName]
|
||||
add(s, pVer)
|
||||
|
|
@ -755,8 +755,8 @@ proc listPaths(options: Options) =
|
|||
if hasSpec:
|
||||
var pkgInfo = getPkgInfo(path, options)
|
||||
var v: VersionAndPath
|
||||
v.version = newVersion(pkgInfo.version)
|
||||
v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.version)
|
||||
v.version = newVersion(pkgInfo.specialVersion)
|
||||
v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.specialVersion)
|
||||
installed.add(v)
|
||||
else:
|
||||
display("Warning:", "No .nimble file found for " & path, Warning,
|
||||
|
|
@ -891,7 +891,7 @@ proc uninstall(options: Options) =
|
|||
for pkg in pkgList:
|
||||
# Check whether any packages depend on the ones the user is trying to
|
||||
# uninstall.
|
||||
let thisPkgsDep = options.nimbleData["reverseDeps"]{pkg.name}{pkg.version}
|
||||
let thisPkgsDep = options.nimbleData["reverseDeps"]{pkg.name}{pkg.specialVersion}
|
||||
if not thisPkgsDep.isNil:
|
||||
var reason = ""
|
||||
if thisPkgsDep.len == 1:
|
||||
|
|
@ -905,7 +905,7 @@ proc uninstall(options: Options) =
|
|||
reason.add ", "
|
||||
reason.add " depend on it"
|
||||
errors.add("Cannot uninstall $1 ($2) because $3" % [pkgTup.name,
|
||||
pkg.version, reason])
|
||||
pkg.specialVersion, reason])
|
||||
else:
|
||||
pkgsToDelete.add pkg
|
||||
|
||||
|
|
@ -916,7 +916,7 @@ proc uninstall(options: Options) =
|
|||
for i in 0 .. <pkgsToDelete.len:
|
||||
if i != 0: pkgNames.add ", "
|
||||
let pkg = pkgsToDelete[i]
|
||||
pkgNames.add("$1 ($2)" % [pkg.name, pkg.version])
|
||||
pkgNames.add("$1 ($2)" % [pkg.name, pkg.specialVersion])
|
||||
|
||||
# Let's confirm that the user wants these packages removed.
|
||||
let msg = ("The following packages will be removed:\n $1\n" &
|
||||
|
|
@ -931,8 +931,8 @@ proc uninstall(options: Options) =
|
|||
# a minimal pkg info.
|
||||
let pkgFull = getPkgInfo(pkg.mypath.splitFile.dir, options) # TODO: Simplify
|
||||
removeRevDep(options, pkgFull)
|
||||
removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.version), options)
|
||||
display("Removed", "$1 ($2)" % [pkg.name, $pkg.version], Success,
|
||||
removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.specialVersion), options)
|
||||
display("Removed", "$1 ($2)" % [pkg.name, $pkg.specialVersion], Success,
|
||||
HighPriority)
|
||||
|
||||
proc listTasks(options: Options) =
|
||||
|
|
|
|||
|
|
@ -15,16 +15,16 @@ when not defined(nimscript):
|
|||
|
||||
PackageInfo* = object
|
||||
myPath*: string ## The path of this .nimble file
|
||||
## The version specified in the .nimble file.Assuming info is non-minimal,
|
||||
## it will always be a non-special version such as '0.1.4'
|
||||
myVersion*: string
|
||||
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
|
||||
postHooks*: HashSet[string] ## Useful to know so that Nimble doesn't execHook unnecessarily
|
||||
preHooks*: HashSet[string]
|
||||
name*: string
|
||||
version*: string ## Either `myVersion` or a special version such as #head.
|
||||
## The version specified in the .nimble file.Assuming info is non-minimal,
|
||||
## it will always be a non-special version such as '0.1.4'
|
||||
version*: string
|
||||
specialVersion*: string ## Either `myVersion` or a special version such as #head.
|
||||
author*: string
|
||||
description*: string
|
||||
license*: string
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type
|
|||
|
||||
proc initPackageInfo*(path: string): PackageInfo =
|
||||
result.myPath = path
|
||||
result.myVersion = ""
|
||||
result.specialVersion = ""
|
||||
result.preHooks.init()
|
||||
result.postHooks.init()
|
||||
# reasonable default:
|
||||
|
|
@ -195,11 +195,19 @@ proc getInstalledPkgsMin*(libsDir: string, options: Options):
|
|||
var pkg = initPackageInfo(nimbleFile)
|
||||
pkg.name = name
|
||||
pkg.version = version
|
||||
pkg.specialVersion = version
|
||||
pkg.isMinimal = true
|
||||
pkg.isInstalled = true
|
||||
result.add((pkg, meta))
|
||||
|
||||
proc findPkg*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
|
||||
proc withinRange*(pkgInfo: PackageInfo, verRange: VersionRange): bool =
|
||||
## Determines whether the specified package's version is within the
|
||||
## specified range. The check works with ordinary versions as well as
|
||||
## special ones.
|
||||
return withinRange(newVersion(pkgInfo.version), verRange) or
|
||||
withinRange(newVersion(pkgInfo.specialVersion), verRange)
|
||||
|
||||
proc findPkg*(pkglist: seq[tuple[pkgInfo: PackageInfo, meta: MetaData]],
|
||||
dep: PkgTuple,
|
||||
r: var PackageInfo): bool =
|
||||
## Searches ``pkglist`` for a package of which version is within the range
|
||||
|
|
@ -211,22 +219,23 @@ proc findPkg*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
|
|||
for pkg in pkglist:
|
||||
if cmpIgnoreStyle(pkg.pkginfo.name, dep.name) != 0 and
|
||||
cmpIgnoreStyle(pkg.meta.url, dep.name) != 0: continue
|
||||
if withinRange(newVersion(pkg.pkginfo.myVersion), dep.ver) or
|
||||
withinRange(newVersion(pkg.pkginfo.version), dep.ver):
|
||||
if not result or newVersion(r.version) < newVersion(pkg.pkginfo.myVersion):
|
||||
if withinRange(pkg.pkgInfo, dep.ver):
|
||||
let isNewer = (not r.version.isNil) and
|
||||
newVersion(r.version) < newVersion(pkg.pkginfo.version)
|
||||
if not result or isNewer:
|
||||
r = pkg.pkginfo
|
||||
result = true
|
||||
|
||||
proc findAllPkgs*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
|
||||
proc findAllPkgs*(pkglist: seq[tuple[pkgInfo: PackageInfo, meta: MetaData]],
|
||||
dep: PkgTuple): seq[PackageInfo] =
|
||||
## Searches ``pkglist`` for packages of which version is within the range
|
||||
## of ``dep.ver``. This is similar to ``findPkg`` but returns multiple
|
||||
## packages if multiple are found.
|
||||
result = @[]
|
||||
for pkg in pkglist:
|
||||
if cmpIgnoreStyle(pkg.pkginfo.name, dep.name) != 0 and
|
||||
if cmpIgnoreStyle(pkg.pkgInfo.name, dep.name) != 0 and
|
||||
cmpIgnoreStyle(pkg.meta.url, dep.name) != 0: continue
|
||||
if withinRange(newVersion(pkg.pkginfo.version), dep.ver):
|
||||
if withinRange(pkg.pkgInfo, dep.ver):
|
||||
result.add pkg.pkginfo
|
||||
|
||||
proc getRealDir*(pkgInfo: PackageInfo): string =
|
||||
|
|
|
|||
|
|
@ -273,6 +273,7 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
|
|||
if onlyMinimalInfo:
|
||||
result.name = minimalInfo.name
|
||||
result.version = minimalInfo.version
|
||||
result.specialVersion = result.version
|
||||
result.isNimScript = true
|
||||
result.isMinimal = true
|
||||
else:
|
||||
|
|
@ -287,21 +288,18 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
|
|||
" " & getCurrentExceptionMsg() & "."
|
||||
raise newException(NimbleError, msg)
|
||||
|
||||
# Validate version ahead of time, we will be potentially overwriting it soon.
|
||||
result.myVersion = result.version
|
||||
validateVersion(result.version)
|
||||
|
||||
# The package directory name may include a "special" version
|
||||
# (example #head). If so, it is given higher priority and therefore
|
||||
# overwrites the .nimble file's version.
|
||||
let version = parseVersionRange(minimalInfo.version)
|
||||
if version.kind == verSpecial:
|
||||
result.version = minimalInfo.version
|
||||
result.specialVersion = minimalInfo.version
|
||||
|
||||
if not result.isMinimal:
|
||||
options.pkgInfoCache[nf] = result
|
||||
|
||||
# Validate the rest of the package info last.
|
||||
validateVersion(result.version)
|
||||
validatePackageInfo(result, options)
|
||||
|
||||
proc getPkgInfoFromFile*(file: NimbleFile, options: Options): PackageInfo =
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
|||
quotedArgs = quoted_args.map((x: string) => ("\"" & x & "\""))
|
||||
|
||||
result = execCmdEx(quotedArgs.join(" "))
|
||||
echo(result.output)
|
||||
|
||||
proc processOutput(output: string): seq[string] =
|
||||
output.strip.splitLines().filter((x: string) => (x.len > 0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue