fixes a 'break search loop' bug; got rid of most compiler warnings

This commit is contained in:
Araq 2016-11-06 23:06:37 +01:00
commit ee3ad4353e
8 changed files with 30 additions and 34 deletions

View file

@ -1,9 +1,11 @@
# Copyright (C) Dominik Picheta. All rights reserved. # Copyright (C) Dominik Picheta. All rights reserved.
# BSD License. Look at license.txt for more info. # BSD License. Look at license.txt for more info.
import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils, import httpclient, parseopt, os, osproc, pegs, tables, parseutils,
strtabs, json, algorithm, sets, uri strtabs, json, algorithm, sets, uri
import strutils except toLower
from unicode import toLower
from sequtils import toSeq from sequtils import toSeq
import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools, import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
@ -82,7 +84,7 @@ proc update(options: Options) =
echo("Downloaded packages.json file is invalid, discarding.") echo("Downloaded packages.json file is invalid, discarding.")
continue continue
copyFile(tempPath, copyFile(tempPath,
options.getNimbleDir() / "packages_$1.json" % list.name.toLower()) options.getNimbleDir() / "packages_$1.json" % list.name.toLowerAscii())
echo("Done.") echo("Done.")
break break
@ -609,7 +611,6 @@ proc compile(options: Options) =
var pkgInfo = getPkgInfo(getCurrentDir(), options) var pkgInfo = getPkgInfo(getCurrentDir(), options)
nimScriptHint(pkgInfo) nimScriptHint(pkgInfo)
let paths = processDeps(pkginfo, options) let paths = processDeps(pkginfo, options)
let realDir = pkgInfo.getRealDir()
var args = "" var args = ""
for path in paths: args.add("--path:\"" & path & "\" ") for path in paths: args.add("--path:\"" & path & "\" ")
@ -642,23 +643,24 @@ proc search(options: Options) =
raise newException(NimbleError, "Please run nimble refresh.") raise newException(NimbleError, "Please run nimble refresh.")
let pkgList = getPackageList(options) let pkgList = getPackageList(options)
var found = false var found = false
template onFound: stmt = template onFound {.dirty.} =
echoPackage(pkg) echoPackage(pkg)
if options.queryVersions: if options.queryVersions:
echoPackageVersions(pkg) echoPackageVersions(pkg)
echo(" ") echo(" ")
found = true found = true
break break forPkg
for pkg in pkgList: for pkg in pkgList:
for word in options.action.search: block forPkg:
# Search by name. for word in options.action.search:
if word.toLower() in pkg.name.toLower(): # Search by name.
onFound() if word.toLower() in pkg.name.toLower():
# Search by tag.
for tag in pkg.tags:
if word.toLower() in tag.toLower():
onFound() onFound()
# Search by tag.
for tag in pkg.tags:
if word.toLower() in tag.toLower():
onFound()
if not found: if not found:
echo("No package found.") echo("No package found.")

View file

@ -141,7 +141,7 @@ proc doDownload*(url: string, downloadDir: string, verRange: VersionRange,
## method. ## method.
## ##
## Returns the version of the repository which has been downloaded. ## Returns the version of the repository which has been downloaded.
template getLatestByTag(meth: stmt): stmt {.dirty, immediate.} = template getLatestByTag(meth: untyped) {.dirty.} =
echo("Found tags...") echo("Found tags...")
# Find latest version that fits our ``verRange``. # Find latest version that fits our ``verRange``.
var latest = findLatest(verRange, versions) var latest = findLatest(verRange, versions)

View file

@ -94,10 +94,10 @@ proc setupVM(module: PSym; scriptName: string,
proc listDirs(a: VmArgs, filter: set[PathComponent]) = proc listDirs(a: VmArgs, filter: set[PathComponent]) =
let dir = getString(a, 0) let dir = getString(a, 0)
var result: seq[string] = @[] var res: seq[string] = @[]
for kind, path in walkDir(dir): for kind, path in walkDir(dir):
if kind in filter: result.add path if kind in filter: res.add path
setResult(a, result) setResult(a, res)
template cbconf(name, body) {.dirty.} = template cbconf(name, body) {.dirty.} =
result.registerCallback "stdlib.system." & astToStr(name), result.registerCallback "stdlib.system." & astToStr(name),
@ -346,7 +346,7 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
elif cmpIgnoreStyle(backend, "javascript") == 0: elif cmpIgnoreStyle(backend, "javascript") == 0:
result.backend = "js" result.backend = "js"
else: else:
result.backend = backend.toLower() result.backend = backend.toLowerAscii()
# Grab all the global procs # Grab all the global procs
for i in thisModule.tab.data: for i in thisModule.tab.data:
@ -395,8 +395,8 @@ proc execHook*(scriptName, actionName: string, before: bool,
result.flags = newStringTable() result.flags = newStringTable()
compiler_options.command = internalCmd compiler_options.command = internalCmd
let hookName = let hookName =
if before: actionName.toLower & "Before" if before: actionName.toLowerAscii & "Before"
else: actionName.toLower & "After" else: actionName.toLowerAscii & "After"
echo("Attempting to execute hook ", hookName, " in ", scriptName) echo("Attempting to execute hook ", hookName, " in ", scriptName)
let thisModule = execScript(scriptName, result.flags, options) let thisModule = execScript(scriptName, result.flags, options)

View file

@ -293,11 +293,6 @@ proc parseCmdLine*(): Options =
if result.action.typ == actionNil: if result.action.typ == actionNil:
writeHelp() writeHelp()
# TODO: Remove this after a couple of versions.
if getNimrodVersion() > newVersion("0.9.6"):
# Rename deprecated babel dir.
renameBabelToNimble(result)
proc getProxy*(options: Options): Proxy = proc getProxy*(options: Options): Proxy =
## Returns ``nil`` if no proxy is specified. ## Returns ``nil`` if no proxy is specified.
var url = "" var url = ""

View file

@ -140,7 +140,7 @@ proc getPackage*(pkg: string, options: Options,
for name, list in options.config.packageLists: for name, list in options.config.packageLists:
echo("Searching in \"", name, "\" package list...") echo("Searching in \"", name, "\" package list...")
let packages = parseFile(options.getNimbleDir() / let packages = parseFile(options.getNimbleDir() /
"packages_" & name.toLower() & ".json") "packages_" & name.toLowerAscii() & ".json")
for p in packages: for p in packages:
if normalize(p["name"].str) == normalize(pkg): if normalize(p["name"].str) == normalize(pkg):
resPkg = p.fromJson() resPkg = p.fromJson()
@ -152,7 +152,7 @@ proc getPackageList*(options: Options): seq[Package] =
var namesAdded = initSet[string]() var namesAdded = initSet[string]()
for name, list in options.config.packageLists: for name, list in options.config.packageLists:
let packages = parseFile(options.getNimbleDir() / let packages = parseFile(options.getNimbleDir() /
"packages_" & name.toLower() & ".json") "packages_" & name.toLowerAscii() & ".json")
for p in packages: for p in packages:
let pkg: Package = p.fromJson() let pkg: Package = p.fromJson()
if pkg.name notin namesAdded: if pkg.name notin namesAdded:

View file

@ -7,8 +7,7 @@ import version, tools, common, nimscriptsupport, options, packageinfo
## because it depends on ``nimscriptsupport`` (``nimscriptsupport`` also ## because it depends on ``nimscriptsupport`` (``nimscriptsupport`` also
## depends on other procedures in ``packageinfo``. ## depends on other procedures in ``packageinfo``.
when not declared(system.map): from sequtils import apply
from sequtils import map
type type
NimbleFile* = string NimbleFile* = string
@ -105,7 +104,7 @@ proc multiSplit(s: string): seq[string] =
## done no entries are found in the list, the proc returns a sequence with ## done no entries are found in the list, the proc returns a sequence with
## the original string as the only entry. ## the original string as the only entry.
result = split(s, {char(0x0A), char(0x0D), ','}) result = split(s, {char(0x0A), char(0x0D), ','})
map(result, proc(x: var string) = x = x.strip()) apply(result, proc(x: var string) = x = x.strip())
for i in countdown(result.len()-1, 0): for i in countdown(result.len()-1, 0):
if len(result[i]) < 1: if len(result[i]) < 1:
result.del(i) result.del(i)
@ -154,7 +153,7 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
for i in ev.value.multiSplit: for i in ev.value.multiSplit:
result.bin.add(i.addFileExt(ExeExt)) result.bin.add(i.addFileExt(ExeExt))
of "backend": of "backend":
result.backend = ev.value.toLower() result.backend = ev.value.toLowerAscii()
case result.backend.normalize case result.backend.normalize
of "javascript": result.backend = "js" of "javascript": result.backend = "js"
else: discard else: discard

View file

@ -32,7 +32,7 @@ proc doCmdEx*(cmd: string): tuple[output: TaintedString, exitCode: int] =
raise newException(NimbleError, "'" & bin & "' not in PATH.") raise newException(NimbleError, "'" & bin & "' not in PATH.")
return execCmdEx(cmd) return execCmdEx(cmd)
template cd*(dir: string, body: stmt) = template cd*(dir: string, body: untyped) =
## Sets the current dir to ``dir``, executes ``body`` and restores the ## Sets the current dir to ``dir``, executes ``body`` and restores the
## previous working dir. ## previous working dir.
let lastDir = getCurrentDir() let lastDir = getCurrentDir()

View file

@ -40,11 +40,11 @@ proc newSpecial*(spe: string): Special = return Special(spe)
proc `$`*(ver: Version): string {.borrow.} proc `$`*(ver: Version): string {.borrow.}
proc hash*(ver: Version): THash {.borrow.} proc hash*(ver: Version): Hash {.borrow.}
proc `$`*(ver: Special): string {.borrow.} proc `$`*(ver: Special): string {.borrow.}
proc hash*(ver: Special): THash {.borrow.} proc hash*(ver: Special): Hash {.borrow.}
proc `<`*(ver: Version, ver2: Version): bool = proc `<`*(ver: Version, ver2: Version): bool =
var sVer = string(ver).split('.') var sVer = string(ver).split('.')
@ -79,7 +79,7 @@ proc `==`*(ver: Version, ver2: Version): bool =
return false return false
proc `==`*(spe: Special, spe2: Special): bool = proc `==`*(spe: Special, spe2: Special): bool =
return ($spe).toLower() == ($spe2).toLower() return ($spe).toLowerAscii() == ($spe2).toLowerAscii()
proc `<=`*(ver: Version, ver2: Version): bool = proc `<=`*(ver: Version, ver2: Version): bool =
return (ver == ver2) or (ver < ver2) return (ver == ver2) or (ver < ver2)