Merge pull request #613 from LemonBoy/x1
Fix a handful of annoying things
This commit is contained in:
commit
587402fa1d
3 changed files with 39 additions and 9 deletions
|
|
@ -214,13 +214,20 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[PackageInfo] =
|
||||||
addRevDep(options.nimbleData, i, pkginfo)
|
addRevDep(options.nimbleData, i, pkginfo)
|
||||||
|
|
||||||
proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string],
|
proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string],
|
||||||
args: var seq[string]) =
|
args: var seq[string], options: Options) =
|
||||||
|
doAssert(options.action.typ == actionBuild)
|
||||||
|
|
||||||
## Builds a package as specified by ``pkgInfo``.
|
## Builds a package as specified by ``pkgInfo``.
|
||||||
if pkgInfo.bin.len == 0:
|
if pkgInfo.bin.len == 0:
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
"Nothing to build. Did you specify a module to build using the" &
|
"Nothing to build. Did you specify a module to build using the" &
|
||||||
" `bin` key in your .nimble file?")
|
" `bin` key in your .nimble file?")
|
||||||
let realDir = pkgInfo.getRealDir()
|
let realDir = pkgInfo.getRealDir()
|
||||||
|
|
||||||
|
cd realDir:
|
||||||
|
if not execHook(options, true):
|
||||||
|
raise newException(NimbleError, "Pre-hook prevented further execution.")
|
||||||
|
|
||||||
for path in paths: args.add("--path:\"" & path & "\" ")
|
for path in paths: args.add("--path:\"" & path & "\" ")
|
||||||
for bin in pkgInfo.bin:
|
for bin in pkgInfo.bin:
|
||||||
let outputOpt = "-o:\"" & pkgInfo.getOutputDir(bin) & "\""
|
let outputOpt = "-o:\"" & pkgInfo.getOutputDir(bin) & "\""
|
||||||
|
|
@ -244,13 +251,17 @@ proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string],
|
||||||
exc.hint = hint
|
exc.hint = hint
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) =
|
cd realDir:
|
||||||
|
discard execHook(options, false)
|
||||||
|
|
||||||
|
proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool,
|
||||||
|
options: Options) =
|
||||||
var args: seq[string]
|
var args: seq[string]
|
||||||
if forRelease:
|
if forRelease:
|
||||||
args = @["-d:release"]
|
args = @["-d:release"]
|
||||||
else:
|
else:
|
||||||
args = @[]
|
args = @[]
|
||||||
buildFromDir(pkgInfo, paths, args)
|
buildFromDir(pkgInfo, paths, args, options)
|
||||||
|
|
||||||
proc removePkgDir(dir: string, options: Options) =
|
proc removePkgDir(dir: string, options: Options) =
|
||||||
## Removes files belonging to the package in ``dir``.
|
## Removes files belonging to the package in ``dir``.
|
||||||
|
|
@ -325,6 +336,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
## to the packages this package depends on.
|
## to the packages this package depends on.
|
||||||
## The return value of this function is used by
|
## The return value of this function is used by
|
||||||
## ``processDeps`` to gather a list of paths to pass to the nim compiler.
|
## ``processDeps`` to gather a list of paths to pass to the nim compiler.
|
||||||
|
doAssert(options.action.typ == actionInstall)
|
||||||
|
|
||||||
# Handle pre-`install` hook.
|
# Handle pre-`install` hook.
|
||||||
if not options.depsOnly:
|
if not options.depsOnly:
|
||||||
|
|
@ -356,7 +368,9 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
# 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:
|
if pkgInfo.bin.len > 0:
|
||||||
let paths = result.deps.map(dep => dep.getRealDir())
|
let paths = result.deps.map(dep => dep.getRealDir())
|
||||||
buildFromDir(pkgInfo, paths, true)
|
var optsCopy = options.briefClone()
|
||||||
|
optsCopy.action.typ = actionBuild
|
||||||
|
buildFromDir(pkgInfo, paths, true, optsCopy)
|
||||||
|
|
||||||
let pkgDestDir = pkgInfo.getPkgDest(options)
|
let pkgDestDir = pkgInfo.getPkgDest(options)
|
||||||
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"):
|
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"):
|
||||||
|
|
@ -470,8 +484,14 @@ proc getDownloadInfo*(pv: PkgTuple, options: Options,
|
||||||
proc install(packages: seq[PkgTuple],
|
proc install(packages: seq[PkgTuple],
|
||||||
options: Options,
|
options: Options,
|
||||||
doPrompt = true): tuple[deps: seq[PackageInfo], pkg: PackageInfo] =
|
doPrompt = true): tuple[deps: seq[PackageInfo], pkg: PackageInfo] =
|
||||||
|
var optsCopy = options.briefClone()
|
||||||
|
optsCopy.action.typ = actionInstall
|
||||||
|
# Pass an empty seq here because we're executing `install` inside the package
|
||||||
|
# directory
|
||||||
|
optsCopy.action.packages = @[]
|
||||||
|
|
||||||
if packages == @[]:
|
if packages == @[]:
|
||||||
result = installFromDir(getCurrentDir(), newVRAny(), options, "")
|
result = installFromDir(getCurrentDir(), newVRAny(), optsCopy, "")
|
||||||
else:
|
else:
|
||||||
# Install each package.
|
# Install each package.
|
||||||
for pv in packages:
|
for pv in packages:
|
||||||
|
|
@ -480,7 +500,7 @@ proc install(packages: seq[PkgTuple],
|
||||||
let (downloadDir, downloadVersion) =
|
let (downloadDir, downloadVersion) =
|
||||||
downloadPkg(url, pv.ver, meth, subdir, options)
|
downloadPkg(url, pv.ver, meth, subdir, options)
|
||||||
try:
|
try:
|
||||||
result = installFromDir(downloadDir, pv.ver, options, url)
|
result = installFromDir(downloadDir, pv.ver, optsCopy, url)
|
||||||
except BuildFailed:
|
except BuildFailed:
|
||||||
# The package failed to build.
|
# The package failed to build.
|
||||||
# Check if we tried building a tagged version of the package.
|
# Check if we tried building a tagged version of the package.
|
||||||
|
|
@ -507,7 +527,7 @@ proc build(options: Options) =
|
||||||
let deps = processDeps(pkginfo, options)
|
let deps = processDeps(pkginfo, options)
|
||||||
let paths = deps.map(dep => dep.getRealDir())
|
let paths = deps.map(dep => dep.getRealDir())
|
||||||
var args = options.action.compileOptions
|
var args = options.action.compileOptions
|
||||||
buildFromDir(pkgInfo, paths, args)
|
buildFromDir(pkgInfo, paths, args, options)
|
||||||
|
|
||||||
proc execBackend(options: Options) =
|
proc execBackend(options: Options) =
|
||||||
let
|
let
|
||||||
|
|
@ -549,7 +569,8 @@ proc search(options: Options) =
|
||||||
## Searches for matches in ``options.action.search``.
|
## Searches for matches in ``options.action.search``.
|
||||||
##
|
##
|
||||||
## Searches are done in a case insensitive way making all strings lower case.
|
## Searches are done in a case insensitive way making all strings lower case.
|
||||||
assert options.action.typ == actionSearch
|
doAssert(options.action.typ == actionSearch)
|
||||||
|
|
||||||
if options.action.search == @[]:
|
if options.action.search == @[]:
|
||||||
raise newException(NimbleError, "Please specify a search string.")
|
raise newException(NimbleError, "Please specify a search string.")
|
||||||
if needsRefresh(options):
|
if needsRefresh(options):
|
||||||
|
|
@ -899,6 +920,8 @@ proc listTasks(options: Options) =
|
||||||
nimscriptsupport.listTasks(nimbleFile, options)
|
nimscriptsupport.listTasks(nimbleFile, options)
|
||||||
|
|
||||||
proc developFromDir(dir: string, options: Options) =
|
proc developFromDir(dir: string, options: Options) =
|
||||||
|
doAssert(options.action.typ == actionDevelop)
|
||||||
|
|
||||||
if options.depsOnly:
|
if options.depsOnly:
|
||||||
raiseNimbleError("Cannot develop dependencies only.")
|
raiseNimbleError("Cannot develop dependencies only.")
|
||||||
|
|
||||||
|
|
@ -993,6 +1016,11 @@ proc test(options: Options) =
|
||||||
## Executes all tests starting with 't' in the ``tests`` directory.
|
## Executes all tests starting with 't' in the ``tests`` directory.
|
||||||
## Subdirectories are not walked.
|
## Subdirectories are not walked.
|
||||||
var files = toSeq(walkDir(getCurrentDir() / "tests"))
|
var files = toSeq(walkDir(getCurrentDir() / "tests"))
|
||||||
|
|
||||||
|
if files.len < 1:
|
||||||
|
display("Warning:", "No tests found!", Warning, HighPriority)
|
||||||
|
return
|
||||||
|
|
||||||
files.sort((a, b) => cmp(a.path, b.path))
|
files.sort((a, b) => cmp(a.path, b.path))
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
|
||||||
|
|
@ -409,5 +409,7 @@ proc briefClone*(options: Options): Options =
|
||||||
var newOptions = initOptions()
|
var newOptions = initOptions()
|
||||||
newOptions.config = options.config
|
newOptions.config = options.config
|
||||||
newOptions.nimbleData = options.nimbleData
|
newOptions.nimbleData = options.nimbleData
|
||||||
|
newOptions.nimbleDir = options.nimbleDir
|
||||||
|
newOptions.forcePrompts = options.forcePrompts
|
||||||
newOptions.pkgInfoCache = options.pkgInfoCache
|
newOptions.pkgInfoCache = options.pkgInfoCache
|
||||||
return newOptions
|
return newOptions
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ proc parseVersionRange*(s: string): VersionRange =
|
||||||
|
|
||||||
of ' ':
|
of ' ':
|
||||||
# Make sure '0.9 8.03' is not allowed.
|
# Make sure '0.9 8.03' is not allowed.
|
||||||
if version != "" and i < s.len:
|
if version != "" and i < s.len - 1:
|
||||||
if s[i+1] in {'0'..'9', '.'}:
|
if s[i+1] in {'0'..'9', '.'}:
|
||||||
raise newException(ParseVersionError,
|
raise newException(ParseVersionError,
|
||||||
"Whitespace is not allowed in a version literal.")
|
"Whitespace is not allowed in a version literal.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue