Application installation support, 'copying...' status messages also shows where it's copying to now.
This commit is contained in:
parent
6dda085611
commit
4bbaece157
2 changed files with 58 additions and 29 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import "babel/parser", "babel/version", osproc, strutils, re, os, parseutils
|
import parser, version, osproc, strutils, re, os, parseutils, streams
|
||||||
|
|
||||||
type
|
type
|
||||||
EInstall = object of EBase
|
EInstall = object of EBase
|
||||||
|
|
@ -26,6 +26,14 @@ proc getNimVersion(cmd: string = "nimrod"): String =
|
||||||
|
|
||||||
return nimrodVersion
|
return nimrodVersion
|
||||||
|
|
||||||
|
proc compile*(file: string, flags: string = "") =
|
||||||
|
var args: string = flags & "c " & file
|
||||||
|
echo("Compiling " & file & "...")
|
||||||
|
var code = execShellCmd(findExe("nimrod") & " " & args)
|
||||||
|
if code != quitSuccess:
|
||||||
|
raise newException(EInstall, "Compilation failed: Nimrod returned exit code " &
|
||||||
|
$code)
|
||||||
|
|
||||||
proc dependExists(name: string, verRange: PVersionRange): Bool =
|
proc dependExists(name: string, verRange: PVersionRange): Bool =
|
||||||
if name == "nimrod":
|
if name == "nimrod":
|
||||||
var nimVer = getNimVersion()
|
var nimVer = getNimVersion()
|
||||||
|
|
@ -38,14 +46,16 @@ proc dependExists(name: string, verRange: PVersionRange): Bool =
|
||||||
if kind == pcFile:
|
if kind == pcFile:
|
||||||
var file = path.extractFilename()
|
var file = path.extractFilename()
|
||||||
if file == name.addFileExt("babel"):
|
if file == name.addFileExt("babel"):
|
||||||
var conf = parseBabel(path)
|
if verRange.kind != verAny:
|
||||||
var verRet = conf.verify()
|
var conf = parseBabel(path)
|
||||||
if verRet == "":
|
var verRet = conf.verify()
|
||||||
if withinRange(newVersion(conf.version), verRange):
|
if verRet == "":
|
||||||
return True
|
if withinRange(newVersion(conf.version), verRange):
|
||||||
else:
|
return True
|
||||||
raise newException(EInstall, "Package has an invalid .babel file: " &
|
else:
|
||||||
verRet)
|
raise newException(EInstall, "Package has an invalid .babel file: " &
|
||||||
|
verRet)
|
||||||
|
else: return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -84,35 +94,43 @@ proc copyFiles(proj: TProject) =
|
||||||
var babelDir = getBabelDir()
|
var babelDir = getBabelDir()
|
||||||
|
|
||||||
var dirs = @[babelDir, babelDir / "lib", babelDir / "bin", babelDir / "packages"]
|
var dirs = @[babelDir, babelDir / "lib", babelDir / "bin", babelDir / "packages"]
|
||||||
|
createDirs(dirs)
|
||||||
if proj.library:
|
if proj.library:
|
||||||
# TODO: How will we handle multiple versions?
|
# TODO: How will we handle multiple versions?
|
||||||
var projDir = babelDir / "lib" / proj.name # $babel/lib/name
|
var projDir = babelDir / "lib" / proj.name # $babel/lib/name
|
||||||
dirs.add(projDir)
|
createDir(projDir)
|
||||||
createDirs(dirs)
|
|
||||||
# Copy the files
|
# Copy the files
|
||||||
for i in items(proj.modules):
|
for i in items(proj.modules):
|
||||||
var file = proj.confDir / i.addFileExt("nim")
|
var file = proj.confDir / i.addFileExt("nim")
|
||||||
stdout.write("Copying " & file & "...")
|
var copyTo = projDir / i.addFileExt("nim")
|
||||||
copyFile(file, projDir / i.addFileExt("nim"))
|
stdout.write("Copying " & file & " to " & copyTo & "...")
|
||||||
|
copyFile(file, copyTo)
|
||||||
echo(" Done!")
|
echo(" Done!")
|
||||||
if proj.files.len > 0:
|
if proj.files.len > 0:
|
||||||
for i in items(proj.files):
|
for i in items(proj.files):
|
||||||
var file = proj.confDir / i
|
var file = proj.confDir / i
|
||||||
stdout.write("Copying " & file & "...")
|
var copyTo = projDir / i
|
||||||
copyFile(file, projDir / i)
|
stdout.write("Copying " & file & " to " & copyTo & "...")
|
||||||
echo(" Done!")
|
copyFile(file, copyTo)
|
||||||
|
echo(" Done!")
|
||||||
# Copy the .babel file into the packages folder.
|
|
||||||
var babelFile = proj.confDir / proj.name.addFileExt("babel")
|
|
||||||
stdout.write("Copying " & babelFile & "...")
|
|
||||||
copyFile(babelFile, babelDir / "packages" / babelFile)
|
|
||||||
echo(" Done!")
|
|
||||||
|
|
||||||
elif proj.executable:
|
elif proj.executable:
|
||||||
# TODO: Copy files for executable.
|
var exeSrcFile = proj.confDir / proj.exeFile.addFileExt("nim")
|
||||||
assert(false)
|
# Compile
|
||||||
|
compile(exeSrcFile)
|
||||||
|
|
||||||
|
var exeCmpFile = exeSrcFile.changeFileExt(ExeExt)
|
||||||
|
var copyTo = babelDir / "bin" / proj.exeFile.addFileExt(ExeExt)
|
||||||
|
stdout.write("Copying " & exeCmpFile & " to " & copyTo & "...")
|
||||||
|
copyFile(exeCmpFile, copyTo)
|
||||||
|
echo(" Done!")
|
||||||
|
|
||||||
|
# Copy the .babel file into the packages folder.
|
||||||
|
var babelFile = proj.confDir / proj.name.addFileExt("babel")
|
||||||
|
var copyTo = babelDir / "packages" / proj.name.addFileExt("babel")
|
||||||
|
stdout.write("Copying " & babelFile & " to " & copyTo & "...")
|
||||||
|
copyFile(babelFile, copyTo)
|
||||||
|
echo(" Done!")
|
||||||
|
|
||||||
proc install*(name: string, filename: string = "") =
|
proc install*(name: string, filename: string = "") =
|
||||||
## Install package by the name of ``name``, filename specifies where to look for it
|
## Install package by the name of ``name``, filename specifies where to look for it
|
||||||
|
|
@ -132,7 +150,14 @@ proc install*(name: string, filename: string = "") =
|
||||||
var ret = babelFile.verify()
|
var ret = babelFile.verify()
|
||||||
if ret != "":
|
if ret != "":
|
||||||
raise newException(EInstall, "Verifying the .babel file failed: " & ret)
|
raise newException(EInstall, "Verifying the .babel file failed: " & ret)
|
||||||
|
|
||||||
|
# Check whether this package is already installed
|
||||||
|
# TODO: Different versions
|
||||||
|
# TODO: Commented for testing -- Uncomment.
|
||||||
|
#if dependExists(babelFile.name, newVRAny()):
|
||||||
|
# raise newException(EInstall,
|
||||||
|
# "This package is already installed: TODO: different versions.")
|
||||||
|
|
||||||
if babelFile.depends.len == 1:
|
if babelFile.depends.len == 1:
|
||||||
echo("Verifying 1 dependency...")
|
echo("Verifying 1 dependency...")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,10 @@ proc `$`*(verRange: PVersionRange): String =
|
||||||
|
|
||||||
result.add(string(verRange.ver))
|
result.add(string(verRange.ver))
|
||||||
|
|
||||||
|
proc newVRAny*(): PVersionRange =
|
||||||
|
new(result)
|
||||||
|
result.kind = verAny
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
assert(newVersion("1.0") < newVersion("1.4"))
|
assert(newVersion("1.0") < newVersion("1.4"))
|
||||||
assert(newVersion("1.0.1") > newVersion("1.0"))
|
assert(newVersion("1.0.1") > newVersion("1.0"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue