vccwrapper with nim-like command line args

This commit is contained in:
Fredrik Høisæther Rasch 2016-10-25 19:19:58 +02:00
commit 1af0ac9d2c
2 changed files with 32 additions and 33 deletions

View file

@ -182,14 +182,14 @@ vcc.linkerexe = "vccexe.exe"
# set the options for specific platforms: # set the options for specific platforms:
@if i386: @if i386:
vcc.options.always = "/nologo /vcvars:platform:x86" vcc.options.always = "--platform:x86 /nologo"
vcc.options.linker.always = "/nologo /vcvars:platform:x86" vcc.options.linker.always = "--platform:x86 /nologo"
@elif amd64: @elif amd64:
vcc.options.always = "/nologo /vcvars:platform:amd64" vcc.options.always = "--platform:am64 /nologo"
vcc.options.linker.always = "/nologo /vcvars:platform:amd64" vcc.options.linker.always = "--platform:amd64 /nologo"
@elif arm: @elif arm:
vcc.options.always = "/nologo /vcvars:platform:arm" vcc.options.always = "--platform:arm /nologo"
vcc.options.linker.always = "/nologo /vcvars:platform:arm" vcc.options.linker.always = "--platform:arm /nologo"
@else: @else:
vcc.options.always = "/nologo" vcc.options.always = "/nologo"
vcc.options.linker.always = "/nologo" vcc.options.linker.always = "/nologo"

View file

@ -1,4 +1,4 @@
import strutils, strtabs, os, osproc, vccenv import strutils, strtabs, os, osproc, parseopt, vccenv
when defined(release): when defined(release):
let vccOptions = {poParentStreams} let vccOptions = {poParentStreams}
@ -6,14 +6,12 @@ else:
let vccOptions = {poEchoCmd, poParentStreams} let vccOptions = {poEchoCmd, poParentStreams}
const const
vcvarsArgPrefix = "vcvars:" platformPrefix = "--platform"
platformArgPrefix = "platform:" winstorePrefix = "--winstore"
storeArgPrefix = "store" sdkversionPrefix = "--sdkversion"
sdkArgPrefix = "sdk:"
vcvarsArgIdx = 1 # vcvars comes after - or / char in argument platformSepIdx = platformPrefix.len
argsToken1Idx = vcvarsArgIdx + vcvarsArgPrefix.len sdkversionSepIdx = sdkversionPrefix.len
platformArgValueIdx = argsToken1Idx + platformArgPrefix.len
sdkArgValueIdx = argsToken1Idx + sdkArgPrefix.len
HelpText = """ HelpText = """
+-----------------------------------------------------------------+ +-----------------------------------------------------------------+
@ -24,32 +22,33 @@ const
Usage: Usage:
vccexe [options] [compileroptions] vccexe [options] [compileroptions]
Options: Options:
/vcvars:platform:<arch> Specify the Compiler Platform Tools architecture --platform:<arch> Specify the Compiler Platform Tools architecture
<arch>: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm <arch>: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
/vcvars:store Use Windows Store (rather than desktop) development tools --winstore Use Windows Store (rather than desktop) development tools
/vcvars:sdk:<version> Use a specific Windows SDK version: --sdkversion:<v> Use a specific Windows SDK version:
<version> is either the full Windows 10 SDK version number or <v> is either the full Windows 10 SDK version number or
"8.1" to use the windows 8.1 SDK "8.1" to use the windows 8.1 SDK
Other command line arguments are passed on to the
Microsoft C/C++ compiler for the specified SDK toolset
""" """
when isMainModule: when isMainModule:
var platformArg: string = nil var platformArg: string = nil
var storeArg: bool = false
var sdkVersionArg: string = nil var sdkVersionArg: string = nil
var storeArg: bool = false
var clArgs: seq[TaintedString] = @[] var clArgs: seq[TaintedString] = @[]
var wrapperArgs = commandLineParams() var wrapperArgs = commandLineParams()
for wargv in wrapperArgs: for wargv in wrapperArgs:
# Check whether the current argument contains vcvars prefix # Check whether the current argument contains -- prefix
if cmpIgnoreCase(wargv.substr(vcvarsArgIdx, argsToken1Idx - 1), vcvarsArgPrefix) == 0: if wargv.startsWith(platformPrefix): # Check for platform
# Check for platform platformArg = wargv.substr(platformSepIdx + 1)
if cmpIgnoreCase(wargv.substr(argsToken1Idx, platformArgValueIdx - 1), platformArgPrefix) == 0: elif wargv == winstorePrefix: # Check for winstore
platformArg = wargv.substr(platformArgValueIdx)
# Check for store
elif cmpIgnoreCase(wargv.substr(argsToken1Idx), storeArgPrefix) == 0:
storeArg = true storeArg = true
# Check for sdk elif wargv.startsWith(sdkversionPrefix): # Check for sdkversion
elif cmpIgnoreCase(wargv.substr(argsToken1Idx, sdkArgValueIdx - 1), sdkArgPrefix) == 0: sdkVersionArg = wargv.substr(sdkversionSepIdx + 1)
sdkVersionArg = wargv.substr(sdkArgValueIdx)
else: # Regular cl.exe argument -> store for final cl.exe invocation else: # Regular cl.exe argument -> store for final cl.exe invocation
if (wargv.len == 2) and (wargv[1] == '?'): if (wargv.len == 2) and (wargv[1] == '?'):
echo HelpText echo HelpText