From 4134240b42ff8fe91d898c3748f3bb6f22ea866a Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 29 Dec 2016 19:20:23 +0100 Subject: [PATCH] finish tool: Check for installations in 'program files' et al --- tools/finish.nim | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/finish.nim b/tools/finish.nim index cac001d796..afb3d9fc10 100644 --- a/tools/finish.nim +++ b/tools/finish.nim @@ -85,14 +85,33 @@ when defined(windows): let arch = execProcess(gccExe, ["-dumpmachine"], nil, {poStdErrToStdOut, poUsePath}) when hostCPU == "i386": - result = arch.startsWith("i686-") + result = arch.contains("i686-") elif hostCPU == "amd64": - result = arch.startsWith("x86_64-") + result = arch.contains("x86_64-") else: {.error: "Unknown CPU for Windows.".} except OSError, IOError: result = false + proc defaultMingwLocations(): seq[string] = + proc probeDir(dir: string; result: var seq[string]) = + for k, x in walkDir(dir, relative=true): + if k in {pcDir, pcLinkToDir}: + if x.contains("mingw") or x.contains("posix"): + let dest = dir / x + probeDir(dest, result) + result.add(dest) + + result = @["dist/mingw", "../mingw", r"C:\mingw"] + let pfx86 = getEnv("programfiles(x86)") + let pf = getEnv("programfiles") + when hostCPU == "i386": + probeDir(pfx86, result) + probeDir(pf, result) + else: + probeDir(pf, result) + probeDir(pfx86, result) + proc tryDirs(incompat: var seq[string]; dirs: varargs[string]): string = let bits = $(sizeof(pointer)*8) for d in dirs: @@ -132,7 +151,7 @@ proc main() = addToPathEnv(desiredPath) if mingWchoices.len == 0: # No mingw in path, so try a few locations: - let alternative = tryDirs(incompat, "dist/mingw", "../mingw", r"C:\mingw") + let alternative = tryDirs(incompat, defaultMingwLocations()) if alternative.len == 0: if incompat.len > 0: echo "The following *incompatible* MingW installations exist"