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