distros.nim: also try 'lsb_release -a'
This commit is contained in:
parent
9c0319d211
commit
70708219c9
1 changed files with 12 additions and 9 deletions
|
|
@ -131,14 +131,16 @@ const
|
||||||
LacksDevPackages* = {Distribution.Gentoo, Distribution.Slackware,
|
LacksDevPackages* = {Distribution.Gentoo, Distribution.Slackware,
|
||||||
Distribution.ArchLinux}
|
Distribution.ArchLinux}
|
||||||
|
|
||||||
var unameRes: string ## we cache the result of the 'uname -a' execution for
|
var unameRes, releaseRes: string ## we cache the result of the 'uname -a'
|
||||||
## faster platform detections.
|
## execution for faster platform detections.
|
||||||
|
|
||||||
template uname(): untyped =
|
template unameRelease(cmd, cache): untyped =
|
||||||
const cmd = "uname -a"
|
if cache.len == 0:
|
||||||
if unameRes.len == 0:
|
cache = (when defined(nimscript): gorge(cmd) else: execProcess(cmd))
|
||||||
unameRes = (when defined(nimscript): gorge(cmd) else: execProcess(cmd))
|
cache
|
||||||
unameRes
|
|
||||||
|
template uname(): untyped = unameRelease("uname -a", unameRes)
|
||||||
|
template release(): untyped = unameRelease("lsb_release -a", releaseRes)
|
||||||
|
|
||||||
proc detectOsImpl(d: Distribution): bool =
|
proc detectOsImpl(d: Distribution): bool =
|
||||||
case d
|
case d
|
||||||
|
|
@ -148,7 +150,7 @@ proc detectOsImpl(d: Distribution): bool =
|
||||||
of Distribution.MacOSX: result = defined(macosx)
|
of Distribution.MacOSX: result = defined(macosx)
|
||||||
of Distribution.Linux: result = defined(linux)
|
of Distribution.Linux: result = defined(linux)
|
||||||
of Distribution.Ubuntu, Distribution.Gentoo, Distribution.FreeBSD,
|
of Distribution.Ubuntu, Distribution.Gentoo, Distribution.FreeBSD,
|
||||||
Distribution.OpenBSD, Distribution.Fedora:
|
Distribution.OpenBSD:
|
||||||
result = ("-" & $d & " ") in uname()
|
result = ("-" & $d & " ") in uname()
|
||||||
of Distribution.RedHat:
|
of Distribution.RedHat:
|
||||||
result = "Red Hat" in uname()
|
result = "Red Hat" in uname()
|
||||||
|
|
@ -165,7 +167,8 @@ proc detectOsImpl(d: Distribution): bool =
|
||||||
let uname = toLowerAscii(uname())
|
let uname = toLowerAscii(uname())
|
||||||
result = ("sun" in uname) or ("solaris" in uname)
|
result = ("sun" in uname) or ("solaris" in uname)
|
||||||
else:
|
else:
|
||||||
result = toLowerAscii($d) in toLowerAscii(uname())
|
let dd = toLowerAscii($d)
|
||||||
|
result = dd in toLowerAscii(uname()) or dd in toLowerAscii(release())
|
||||||
|
|
||||||
template detectOs*(d: untyped): bool =
|
template detectOs*(d: untyped): bool =
|
||||||
## Distro/OS detection. For convenience the
|
## Distro/OS detection. For convenience the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue