diff options
author | Araq <rumpf_a@web.de> | 2017-01-03 14:24:57 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-01-03 17:06:31 +0100 |
commit | 70708219c9111e869f41a51fc007d30dd815b112 (patch) | |
tree | 81484f1f7cd2549cc83fee21c3015da1b95dd46a /lib | |
parent | 9c0319d211a95af10388036f3a00be5d9581e627 (diff) | |
download | Nim-70708219c9111e869f41a51fc007d30dd815b112.tar.gz |
distros.nim: also try 'lsb_release -a'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/distros.nim | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/pure/distros.nim b/lib/pure/distros.nim index e004f33d2..cdda72089 100644 --- a/lib/pure/distros.nim +++ b/lib/pure/distros.nim @@ -131,14 +131,16 @@ const LacksDevPackages* = {Distribution.Gentoo, Distribution.Slackware, Distribution.ArchLinux} -var unameRes: string ## we cache the result of the 'uname -a' execution for - ## faster platform detections. +var unameRes, releaseRes: string ## we cache the result of the 'uname -a' + ## execution for faster platform detections. -template uname(): untyped = - const cmd = "uname -a" - if unameRes.len == 0: - unameRes = (when defined(nimscript): gorge(cmd) else: execProcess(cmd)) - unameRes +template unameRelease(cmd, cache): untyped = + if cache.len == 0: + cache = (when defined(nimscript): gorge(cmd) else: execProcess(cmd)) + cache + +template uname(): untyped = unameRelease("uname -a", unameRes) +template release(): untyped = unameRelease("lsb_release -a", releaseRes) proc detectOsImpl(d: Distribution): bool = case d @@ -148,7 +150,7 @@ proc detectOsImpl(d: Distribution): bool = of Distribution.MacOSX: result = defined(macosx) of Distribution.Linux: result = defined(linux) of Distribution.Ubuntu, Distribution.Gentoo, Distribution.FreeBSD, - Distribution.OpenBSD, Distribution.Fedora: + Distribution.OpenBSD: result = ("-" & $d & " ") in uname() of Distribution.RedHat: result = "Red Hat" in uname() @@ -165,7 +167,8 @@ proc detectOsImpl(d: Distribution): bool = let uname = toLowerAscii(uname()) result = ("sun" in uname) or ("solaris" in uname) 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 = ## Distro/OS detection. For convenience the |