Merge branch 'out-of-mem' of https://github.com/yglukhov/nimble into yglukhov-out-of-mem
This commit is contained in:
commit
4050683a9c
4 changed files with 69 additions and 64 deletions
|
|
@ -449,7 +449,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
|||
createDir(pkgDestDir)
|
||||
# Copy this package's files based on the preferences specified in PkgInfo.
|
||||
var filesInstalled = initSet[string]()
|
||||
for file in getInstallFiles(realDir, pkgInfo, options):
|
||||
discard forEachInstallFile(realDir, pkgInfo, options) do(file: string) -> bool:
|
||||
createDir(changeRoot(realDir, pkgDestDir, file.splitFile.dir))
|
||||
let dest = changeRoot(realDir, pkgDestDir, file)
|
||||
filesInstalled.incl copyFileD(file, dest)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type
|
|||
showHelp*: bool
|
||||
showVersion*: bool
|
||||
noColor*: bool
|
||||
disableValidation*: bool
|
||||
|
||||
ActionType* = enum
|
||||
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
||||
|
|
@ -107,6 +108,9 @@ proc writeHelp*(quit=true) =
|
|||
proc writeVersion*() =
|
||||
echo("nimble v$# compiled at $# $#" %
|
||||
[nimbleVersion, CompileDate, CompileTime])
|
||||
const gitVersion = staticExec("git rev-parse HEAD")
|
||||
when gitVersion.len > 0:
|
||||
echo "git hash: ", gitVersion
|
||||
raise NimbleQuit(msg: "")
|
||||
|
||||
proc parseActionType*(action: string): ActionType =
|
||||
|
|
@ -252,6 +256,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
|
|||
of "verbose": result.verbosity = LowPriority
|
||||
of "debug": result.verbosity = DebugPriority
|
||||
of "nocolor": result.noColor = true
|
||||
of "disablevalidation": result.disableValidation = true
|
||||
# Action-specific flags.
|
||||
else:
|
||||
case result.action.typ
|
||||
|
|
|
|||
|
|
@ -431,30 +431,30 @@ proc checkInstallDir(pkgInfo: PackageInfo,
|
|||
if thisDir[0] == '.': result = true
|
||||
if thisDir == "nimcache": result = true
|
||||
|
||||
proc findWithExt(dir: string, pkgInfo: PackageInfo): seq[string] =
|
||||
## Returns the filenames of the files that should be copied.
|
||||
result = @[]
|
||||
proc forEachFileWithExt(dir: string, pkgInfo: PackageInfo,
|
||||
action: proc(f: string): bool): bool =
|
||||
## Runs `action` for each filename of the files that should be copied.
|
||||
## Stops if `action` returns `true`.
|
||||
for kind, path in walkDir(dir):
|
||||
if kind == pcDir:
|
||||
result.add findWithExt(path, pkgInfo)
|
||||
if forEachFileWithExt(path, pkgInfo, action): return true
|
||||
else:
|
||||
if path.splitFile.ext[1 .. ^1] in pkgInfo.installExt:
|
||||
result.add path
|
||||
if action(path): return true
|
||||
|
||||
proc getFilesInDir(dir: string): seq[string] =
|
||||
## Returns a list of paths to files inside the specified directory and any
|
||||
## subdirectories that are in it.
|
||||
result = @[]
|
||||
proc forEachFileInDir(dir: string, action: proc(f: string): bool): bool =
|
||||
## Runs `action` for each file in ``dir`` and any
|
||||
## subdirectories that are in it. Stops if `action` returns `true`.
|
||||
for kind, path in walkDir(dir):
|
||||
if kind == pcDir:
|
||||
result.add getFilesInDir(path)
|
||||
if forEachFileInDir(path, action): return true
|
||||
else:
|
||||
result.add path
|
||||
if action(path): return true
|
||||
|
||||
proc getInstallFiles*(realDir: string, pkgInfo: PackageInfo,
|
||||
options: Options): seq[string] =
|
||||
## Returns a list of files within the ``realDir`` that should be installed.
|
||||
result = @[]
|
||||
proc forEachInstallFile*(realDir: string, pkgInfo: PackageInfo,
|
||||
options: Options, action: proc(f: string): bool): bool =
|
||||
## Runs `action` for each file within the ``realDir`` that should be installed.
|
||||
## Stops if `action` returns `true`.
|
||||
let whitelistMode =
|
||||
pkgInfo.installDirs.len != 0 or
|
||||
pkgInfo.installFiles.len != 0 or
|
||||
|
|
@ -467,7 +467,7 @@ proc getInstallFiles*(realDir: string, pkgInfo: PackageInfo,
|
|||
continue
|
||||
else:
|
||||
raise NimbleQuit(msg: "")
|
||||
result.add src
|
||||
if action(src): return true
|
||||
|
||||
for dir in pkgInfo.installDirs:
|
||||
# TODO: Allow skipping files inside dirs?
|
||||
|
|
@ -478,9 +478,9 @@ proc getInstallFiles*(realDir: string, pkgInfo: PackageInfo,
|
|||
else:
|
||||
raise NimbleQuit(msg: "")
|
||||
|
||||
result.add getFilesInDir(src)
|
||||
if forEachFileInDir(src, action): return true
|
||||
|
||||
result.add findWithExt(realDir, pkgInfo)
|
||||
if forEachFileWithExt(realDir, pkgInfo, action): return true
|
||||
else:
|
||||
for kind, file in walkDir(realDir):
|
||||
if kind == pcDir:
|
||||
|
|
@ -488,13 +488,13 @@ proc getInstallFiles*(realDir: string, pkgInfo: PackageInfo,
|
|||
|
||||
if skip: continue
|
||||
|
||||
result.add getInstallFiles(file, pkgInfo, options)
|
||||
if forEachInstallFile(file, pkgInfo, options, action): return true
|
||||
else:
|
||||
let skip = pkgInfo.checkInstallFile(realDir, file)
|
||||
|
||||
if skip: continue
|
||||
|
||||
result.add file
|
||||
if action(file): return true
|
||||
|
||||
when isMainModule:
|
||||
doAssert getNameVersion("/home/user/.nimble/libs/packagea-0.1") ==
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ proc validatePackageStructure(pkgInfo: PackageInfo, options: Options) =
|
|||
pkgInfo.name & "pkg"
|
||||
else:
|
||||
pkgInfo.name
|
||||
for path in getInstallFiles(realDir, pkgInfo, options):
|
||||
|
||||
discard forEachInstallFile(realDir, pkgInfo, options) do(path: string) -> bool:
|
||||
# Remove the root to leave only the package subdirectories.
|
||||
# ~/package-0.1/package/utils.nim -> package/utils.nim.
|
||||
var trailPath = changeRoot(realDir, "", path)
|
||||
|
|
@ -87,9 +88,7 @@ proc validatePackageStructure(pkgInfo: PackageInfo, options: Options) =
|
|||
let (dir, file, ext) = trailPath.splitFile
|
||||
# We're only interested in nim files, because only they can pollute our
|
||||
# namespace.
|
||||
if ext != (ExtSep & "nim"):
|
||||
continue
|
||||
|
||||
if ext == (ExtSep & "nim"):
|
||||
if dir.len == 0:
|
||||
if file != pkgInfo.name:
|
||||
# A source file was found in the top level of srcDir that doesn't share
|
||||
|
|
@ -317,6 +316,7 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
|
|||
options.pkgInfoCache[nf] = result
|
||||
|
||||
# Validate the rest of the package info last.
|
||||
if not options.disableValidation:
|
||||
validateVersion(result.version)
|
||||
validatePackageInfo(result, options)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue