Slight change for .babel file format, dependExists now checks for installed packages.
This commit is contained in:
parent
89b7339c64
commit
d984032f1e
3 changed files with 25 additions and 14 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
; Babel library
|
; Babel library
|
||||||
|
[Package]
|
||||||
name = "babel"
|
name = "babel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
author = "Dominik Picheta"
|
author = "Dominik Picheta"
|
||||||
|
|
@ -9,8 +10,8 @@ description = """Babel framework: Specifies a common interface for programmers
|
||||||
[Library]
|
[Library]
|
||||||
Depends = "nimrod >= 0.8.10"
|
Depends = "nimrod >= 0.8.10"
|
||||||
ExposedModules = "parser, installer, version" ; No need for .nim
|
ExposedModules = "parser, installer, version" ; No need for .nim
|
||||||
Files = "babel.babel"
|
;Files = "babel.babel"
|
||||||
|
|
||||||
;[Bin babel]
|
;[Exe]
|
||||||
;Depends = "nimrod >= 0.8.11"
|
;Depends = "nimrod >= 0.8.11"
|
||||||
;
|
;Exe = "babel"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@ type
|
||||||
|
|
||||||
TDepend = tuple[name: String, verRange: PVersionRange]
|
TDepend = tuple[name: String, verRange: PVersionRange]
|
||||||
|
|
||||||
|
proc getBabelDir(): string =
|
||||||
|
when defined(windows):
|
||||||
|
result = getHomeDir() / "babel"
|
||||||
|
else:
|
||||||
|
result = getHomeDir() / ".babel"
|
||||||
|
|
||||||
proc getNimVersion(cmd: string = "nimrod"): String =
|
proc getNimVersion(cmd: string = "nimrod"): String =
|
||||||
var output = execProcess(cmd & " -v")
|
var output = execProcess(cmd & " -v")
|
||||||
var line = splitLines(output)[0]
|
var line = splitLines(output)[0]
|
||||||
|
|
@ -28,10 +34,15 @@ proc dependExists(name: string, verRange: PVersionRange): Bool =
|
||||||
nimVer & ") doesn't satisfy dependency")
|
nimVer & ") doesn't satisfy dependency")
|
||||||
else: return True
|
else: return True
|
||||||
else:
|
else:
|
||||||
# TODO: Figure out how to check whether a package has been installed...
|
for kind, path in walkDir(getBabelDir() / "lib"):
|
||||||
# ... Perhaps a list of all the packages that have been installed?
|
if kind == pcDir:
|
||||||
# ... or just look for the package in PATH + $nimrod/lib/babel/packageName
|
var dir = path.extractFilename()
|
||||||
assert(False)
|
if dir.startsWith(name):
|
||||||
|
var ver = copy(dir, name.len() + 1)
|
||||||
|
if withinRange(newVersion(ver), verRange):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
proc verifyDepends(proj: TProject): seq[TDepend] =
|
proc verifyDepends(proj: TProject): seq[TDepend] =
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
@ -43,7 +54,7 @@ proc verifyDepends(proj: TProject): seq[TDepend] =
|
||||||
nameStr = spl[0]
|
nameStr = spl[0]
|
||||||
elif spl.len > 1:
|
elif spl.len > 1:
|
||||||
nameStr = spl[0]
|
nameStr = spl[0]
|
||||||
spl.del(0)
|
spl.delete(0)
|
||||||
verStr = join(spl, " ")
|
verStr = join(spl, " ")
|
||||||
else:
|
else:
|
||||||
raise newException(EInstall, "Incorrect dependency got: " & i)
|
raise newException(EInstall, "Incorrect dependency got: " & i)
|
||||||
|
|
@ -65,10 +76,7 @@ proc createDirs(dirs: seq[string]) =
|
||||||
proc copyFiles(proj: TProject) =
|
proc copyFiles(proj: TProject) =
|
||||||
# This will create a $home/.babel and lib/ or bin/. It will also copy all the
|
# This will create a $home/.babel and lib/ or bin/. It will also copy all the
|
||||||
# files listed in proj.modules and proj.files.
|
# files listed in proj.modules and proj.files.
|
||||||
when defined(windows):
|
var babelDir = getBabelDir()
|
||||||
var babelDir = getHomeDir() / "babel"
|
|
||||||
else:
|
|
||||||
var babelDir = getHomeDir() / ".babel"
|
|
||||||
|
|
||||||
var dirs = @[babelDir, babelDir / "lib", babelDir / "bin"]
|
var dirs = @[babelDir, babelDir / "lib", babelDir / "bin"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ type
|
||||||
|
|
||||||
unknownFields*: seq[string] # TODO:
|
unknownFields*: seq[string] # TODO:
|
||||||
|
|
||||||
EParseErr* = object of EIO
|
EParseErr* = object of EInvalidValue
|
||||||
|
|
||||||
proc initProj(): TProject =
|
proc initProj(): TProject =
|
||||||
result.name = ""
|
result.name = ""
|
||||||
|
|
@ -63,7 +63,7 @@ proc parseBabel*(file: string): TProject =
|
||||||
break
|
break
|
||||||
of cfgKeyValuePair:
|
of cfgKeyValuePair:
|
||||||
case section
|
case section
|
||||||
of "":
|
of "package":
|
||||||
case normalize(e.key):
|
case normalize(e.key):
|
||||||
of "name":
|
of "name":
|
||||||
result.name = e.value
|
result.name = e.value
|
||||||
|
|
@ -110,6 +110,8 @@ proc parseBabel*(file: string): TProject =
|
||||||
result.library = True
|
result.library = True
|
||||||
of "bin":
|
of "bin":
|
||||||
result.executable = True
|
result.executable = True
|
||||||
|
of "package":
|
||||||
|
nil
|
||||||
else:
|
else:
|
||||||
p.parseErr("Unknown section: " & section)
|
p.parseErr("Unknown section: " & section)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue