diff options
author | Fredrik Høisæther Rasch <fredrik.rasch@gmail.com> | 2016-10-25 01:49:18 +0200 |
---|---|---|
committer | Fredrik Høisæther Rasch <fredrik.rasch@gmail.com> | 2016-10-25 01:49:18 +0200 |
commit | e99f35ff23ae05e6f7c8d5826fdaced852c8ff40 (patch) | |
tree | f30c5e85eafad0e1549679aaf2077cc128c601cb /tools/vccenv | |
parent | 01afff495cdf1b9bb0646894dac74fcfdb59d072 (diff) | |
download | Nim-e99f35ff23ae05e6f7c8d5826fdaced852c8ff40.tar.gz |
VCC wrappers with vcvars args.
VCC wrappers no longer wrap for compile-time specific target VCC wrappers now peek into the command line args and evaluate vcvars prefixed arguments
Diffstat (limited to 'tools/vccenv')
-rw-r--r-- | tools/vccenv/vccexe.nim | 61 | ||||
-rw-r--r-- | tools/vccenv/vcclinkerexe.nim | 62 |
2 files changed, 104 insertions, 19 deletions
diff --git a/tools/vccenv/vccexe.nim b/tools/vccenv/vccexe.nim index 48ae8c8da..3193dbbba 100644 --- a/tools/vccenv/vccexe.nim +++ b/tools/vccenv/vccexe.nim @@ -1,24 +1,67 @@ -import strtabs, os, osproc, vccenv +import strutils, strtabs, os, osproc, vccenv when defined(release): let vccOptions = {poParentStreams} else: let vccOptions = {poEchoCmd, poParentStreams} +const + vcvarsArgPrefix = "vcvars:" + platformArgPrefix = "platform:" + storeArgPrefix = "store" + sdkArgPrefix = "sdk:" + vcvarsArgIdx = 1 # vcvars comes after - or / char in argument + argsToken1Idx = vcvarsArgIdx + vcvarsArgPrefix.len + platformArgValueIdx = argsToken1Idx + platformArgPrefix.len + sdkArgValueIdx = argsToken1Idx + sdkArgPrefix.len + + HelpText = """ ++-----------------------------------------------------------------+ +| Microsoft C/C++ compiler wrapper for Nim | +| (c) 2016 Fredrik Høisæther Rasch | ++-----------------------------------------------------------------+ + +Usage: + vccexe [options] [compileroptions] +Options: + /vcvars:platform:<arch> Specify the Compiler Platform Tools architecture + <arch>: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm + /vcvars:store Use Windows Store (rather than desktop) development tools + /vcvars:sdk:<version> Use a specific Windows SDK version: + <version> is either the full Windows 10 SDK version number or + "8.1" to use the windows 8.1 SDK +""" + when isMainModule: - var vccEnvStrTab: StringTableRef = nil - when defined(i386): - vccEnvStrTab = getVccEnv "x86" - when defined(amd64): - vccEnvStrTab = getVccEnv "amd64" - when defined(arm): - vccEnvStrTab = getVccEnv "arm" + var platformArg: string = nil + var storeArg: bool = false + var sdkVersionArg: string = nil + var clArgs: seq[TaintedString] = @[] + var wrapperArgs = commandLineParams() + for wargv in wrapperArgs: + # Check whether the current argument contains vcvars prefix + if cmpIgnoreCase(wargv.substr(vcvarsArgIdx, argsToken1Idx - 1), vcvarsArgPrefix) == 0: + # Check for platform + if cmpIgnoreCase(wargv.substr(argsToken1Idx, platformArgValueIdx - 1), platformArgPrefix) == 0: + platformArg = wargv.substr(platformArgValueIdx) + # Check for store + elif cmpIgnoreCase(wargv.substr(argsToken1Idx), storeArgPrefix) == 0: + storeArg = true + # Check for sdk + elif cmpIgnoreCase(wargv.substr(argsToken1Idx, sdkArgValueIdx - 1), sdkArgPrefix) == 0: + sdkVersionArg = wargv.substr(sdkArgValueIdx) + else: # Regular cl.exe argument -> store for final cl.exe invocation + if (wargv.len == 2) and (wargv[1] == '?'): + echo HelpText + clArgs.add(wargv) + + var vccEnvStrTab = getVccEnv(platformArg, storeArg, sdkVersionArg) if vccEnvStrTab != nil: for vccEnvKey, vccEnvVal in vccEnvStrTab: putEnv(vccEnvKey, vccEnvVal) let vccProcess = startProcess( "cl.exe", - args = commandLineParams(), + args = clArgs, options = vccOptions ) quit vccProcess.waitForExit() diff --git a/tools/vccenv/vcclinkerexe.nim b/tools/vccenv/vcclinkerexe.nim index 51c778f38..59cccd6f8 100644 --- a/tools/vccenv/vcclinkerexe.nim +++ b/tools/vccenv/vcclinkerexe.nim @@ -1,25 +1,67 @@ -import strtabs, os, osproc, vccenv +import strutils, strtabs, os, osproc, vccenv when defined(release): let vccOptions = {poParentStreams} else: let vccOptions = {poEchoCmd, poParentStreams} +const + vcvarsArgPrefix = "vcvars:" + platformArgPrefix = "platform:" + storeArgPrefix = "store" + sdkArgPrefix = "sdk:" + vcvarsArgIdx = 1 # vcvars comes after - or / char in argument + argsToken1Idx = vcvarsArgIdx + vcvarsArgPrefix.len + platformArgValueIdx = argsToken1Idx + platformArgPrefix.len + sdkArgValueIdx = argsToken1Idx + sdkArgPrefix.len + + HelpText = """ ++-----------------------------------------------------------------+ +| Microsoft C/C++ compiler wrapper for Nim | +| (c) 2016 Fredrik Høisæther Rasch | ++-----------------------------------------------------------------+ + +Usage: + vccexe [options] [compileroptions] +Options: + /vcvars:platform:<arch> Specify the Compiler Platform Tools architecture + <arch>: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm + /vcvars:store Use Windows Store (rather than desktop) development tools + /vcvars:sdk:<version> Use a specific Windows SDK version: + <version> is either the full Windows 10 SDK version number or + "8.1" to use the windows 8.1 SDK +""" + when isMainModule: - var vccEnvStrTab: StringTableRef = nil - when defined(i386): - vccEnvStrTab = getVccEnv "x86" - when defined(amd64): - vccEnvStrTab = getVccEnv "amd64" - when defined(arm): - vccEnvStrTab = getVccEnv "arm" + var platformArg: string = nil + var storeArg: bool = false + var sdkVersionArg: string = nil + var clArgs: seq[TaintedString] = @[] + var wrapperArgs = commandLineParams() + for wargv in wrapperArgs: + # Check whether the current argument contains vcvars prefix + if cmpIgnoreCase(wargv.substr(vcvarsArgIdx, argsToken1Idx - 1), vcvarsArgPrefix) == 0: + # Check for platform + if cmpIgnoreCase(wargv.substr(argsToken1Idx, platformArgValueIdx - 1), platformArgPrefix) == 0: + platformArg = wargv.substr(platformArgValueIdx) + # Check for store + elif cmpIgnoreCase(wargv.substr(argsToken1Idx), storeArgPrefix) == 0: + storeArg = true + # Check for sdk + elif cmpIgnoreCase(wargv.substr(argsToken1Idx, sdkArgValueIdx - 1), sdkArgPrefix) == 0: + sdkVersionArg = wargv.substr(sdkArgValueIdx) + else: # Regular cl.exe argument -> store for final cl.exe invocation + if (wargv.len == 2) and (wargv[1] == '?'): + echo HelpText + clArgs.add(wargv) + + var vccEnvStrTab = getVccEnv(platformArg, storeArg, sdkVersionArg) if vccEnvStrTab != nil: for vccEnvKey, vccEnvVal in vccEnvStrTab: putEnv(vccEnvKey, vccEnvVal) let vccProcess = startProcess( "link.exe", - args = commandLineParams(), + args = clArgs, options = vccOptions ) quit vccProcess.waitForExit() - |