Fixes compilation without windows module (0.11.3). Ref #150.

This commit is contained in:
Dominik Picheta 2015-07-26 22:24:08 +01:00
commit 43f7e4c310

View file

@ -12,7 +12,20 @@ import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
when not defined(windows): when not defined(windows):
from posix import getpid from posix import getpid
else: else:
from windows import GetVersionExA, OSVERSIONINFO, WINBOOL, DWORD # This is just for Win XP support.
# TODO: Drop XP support?
from winlean import WINBOOL, DWORD
type
OSVERSIONINFO* {.final, pure.} = object
dwOSVersionInfoSize*: DWORD
dwMajorVersion*: DWORD
dwMinorVersion*: DWORD
dwBuildNumber*: DWORD
dwPlatformId*: DWORD
szCSDVersion*: array[0..127, char]
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
dynlib: "kernel32", importc: "GetVersionExA".}
type type
Options = object Options = object
@ -578,14 +591,18 @@ proc installFromDir(dir: string, latest: bool, options: Options,
# But this workaround brokes code page on newer systems, so we need to detect OS version # But this workaround brokes code page on newer systems, so we need to detect OS version
var osver = OSVERSIONINFO() var osver = OSVERSIONINFO()
osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO)) osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO))
if GetVersionExA(addr osver) == WINBOOL(0): if GetVersionExA(osver) == WINBOOL(0):
quit "Can't detect OS version: GetVersionExA call failed" raise newException(NimbleError,
"Can't detect OS version: GetVersionExA call failed")
let fixChcp = osver.dwMajorVersion <= 5 let fixChcp = osver.dwMajorVersion <= 5
let dest = binDir / cleanBin.changeFileExt("cmd") let dest = binDir / cleanBin.changeFileExt("cmd")
echo("Creating stub: ", pkgDestDir / bin, " -> ", dest) echo("Creating stub: ", pkgDestDir / bin, " -> ", dest)
var contents = "@" var contents = "@"
if options.config.chcp: if options.config.chcp:
if fixChcp: contents.add "chcp 65001 > nul && " else: contents.add "chcp 65001 > nul\n@" if fixChcp:
contents.add "chcp 65001 > nul && "
else: contents.add "chcp 65001 > nul\n@"
contents.add "\"" & pkgDestDir / bin & "\" %*\n" contents.add "\"" & pkgDestDir / bin & "\" %*\n"
writeFile(dest, contents) writeFile(dest, contents)
# For bash on Windows (Cygwin/Git bash). # For bash on Windows (Cygwin/Git bash).