simplified code of the upcoming vccexe and vcclinkerexe tools
This commit is contained in:
parent
c15cef7d2d
commit
11dd0b3b51
4 changed files with 65 additions and 75 deletions
|
|
@ -1,67 +0,0 @@
|
||||||
import strtabs, os, osproc, streams, strutils
|
|
||||||
|
|
||||||
const
|
|
||||||
comSpecEnvKey = "ComSpec"
|
|
||||||
vsComnToolsEnvKeys = [
|
|
||||||
"VS140COMNTOOLS",
|
|
||||||
"VS130COMNTOOLS",
|
|
||||||
"VS120COMNTOOLS",
|
|
||||||
"VS110COMNTOOLS",
|
|
||||||
"VS100COMNTOOLS",
|
|
||||||
"VS90COMNTOOLS"
|
|
||||||
]
|
|
||||||
vcvarsallRelativePath = joinPath("..", "..", "VC", "vcvarsall")
|
|
||||||
|
|
||||||
proc getVsComnToolsPath*(): TaintedString =
|
|
||||||
for vsComnToolsEnvKey in vsComnToolsEnvKeys:
|
|
||||||
if existsEnv vsComnToolsEnvKey:
|
|
||||||
let vsComnToolsEnvVal = getEnv vsComnToolsEnvKey
|
|
||||||
if (not vsComnToolsEnvVal.isNil) and (vsComnToolsEnvVal.len > 0):
|
|
||||||
return vsComnToolsEnvVal
|
|
||||||
return nil
|
|
||||||
|
|
||||||
proc getVccEnv*(platform: string, windowsStoreSdk: bool = false, sdkVersion: string = nil): StringTableRef =
|
|
||||||
var comSpecCommandString: TaintedString
|
|
||||||
if existsEnv comSpecEnvKey:
|
|
||||||
comSpecCommandString = getEnv comSpecEnvKey
|
|
||||||
else:
|
|
||||||
comSpecCommandString = "cmd"
|
|
||||||
|
|
||||||
let vsComnToolsPath = getVsComnToolsPath()
|
|
||||||
if (isNil vsComnToolsPath) or (vsComnToolsPath.len < 1):
|
|
||||||
return nil
|
|
||||||
let vcvarsallPath = expandFilename joinPath(vsComnToolsPath, vcvarsallRelativePath)
|
|
||||||
|
|
||||||
var vcvarsallArgs: seq[string] = @[]
|
|
||||||
if (not isNil platform) and (platform.len > 0):
|
|
||||||
vcvarsallArgs.add(platform)
|
|
||||||
if windowsStoreSdk:
|
|
||||||
vcvarsallArgs.add("store")
|
|
||||||
if (not isNil sdkVersion) and (sdkVersion.len > 0):
|
|
||||||
vcvarsallArgs.add(sdkVersion)
|
|
||||||
var vcvarsallArgString: string
|
|
||||||
if vcvarsallArgs.len > 0:
|
|
||||||
vcvarsallArgString = vcvarsallArgs.join(" ")
|
|
||||||
else:
|
|
||||||
vcvarsallArgString = nil
|
|
||||||
|
|
||||||
var vcvarsallCommandString: string
|
|
||||||
if (not isNil vcvarsallArgString) and (vcvarsallArgString.len > 0):
|
|
||||||
vcvarsallCommandString = "\"$1\" $2" % [ vcvarsallPath, vcvarsallArgString ]
|
|
||||||
else:
|
|
||||||
vcvarsallCommandString = vcvarsallPath
|
|
||||||
|
|
||||||
let vcvarsallExecCommand = "\"$1\" /C \"$2 && SET\"" % [ comSpecCommandString, vcvarsallCommandString ]
|
|
||||||
when defined(release):
|
|
||||||
let vccvarsallOptions = { poEvalCommand, poDemon }
|
|
||||||
else:
|
|
||||||
let vccvarsallOptions = { poEchoCmd, poEvalCommand, poDemon }
|
|
||||||
let vcvarsallStdOut = execProcess(vcvarsallExecCommand, options = vccvarsallOptions)
|
|
||||||
let vcvarsallEnv = newStringTable(modeCaseInsensitive)
|
|
||||||
for vcvarsallEnvLine in vcvarsallStdOut.splitLines:
|
|
||||||
let vcvarsallEqualsIndex = vcvarsallEnvLine.find('=')
|
|
||||||
if vcvarsallEqualsIndex > 0:
|
|
||||||
let vcvarsallEnvKey = vcvarsallEnvLine[0..(vcvarsallEqualsIndex - 1)]
|
|
||||||
let vcvarsallEnvVal = vcvarsallEnvLine[(vcvarsallEqualsIndex + 1)..(vcvarsallEnvLine.len - 1)]
|
|
||||||
vcvarsallEnv[vcvarsallEnvKey] = vcvarsallEnvVal
|
|
||||||
return vcvarsallEnv
|
|
||||||
58
tools/vccenv/vccenv.nim
Normal file
58
tools/vccenv/vccenv.nim
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
import strtabs, os, osproc, streams, strutils
|
||||||
|
|
||||||
|
const
|
||||||
|
comSpecEnvKey = "ComSpec"
|
||||||
|
vsComnToolsEnvKeys = [
|
||||||
|
"VS140COMNTOOLS",
|
||||||
|
"VS130COMNTOOLS",
|
||||||
|
"VS120COMNTOOLS",
|
||||||
|
"VS110COMNTOOLS",
|
||||||
|
"VS100COMNTOOLS",
|
||||||
|
"VS90COMNTOOLS"
|
||||||
|
]
|
||||||
|
vcvarsallRelativePath = joinPath("..", "..", "VC", "vcvarsall")
|
||||||
|
|
||||||
|
proc getVsComnToolsPath*(): TaintedString =
|
||||||
|
for vsComnToolsEnvKey in vsComnToolsEnvKeys:
|
||||||
|
let vsComnToolsEnvVal = getEnv vsComnToolsEnvKey
|
||||||
|
if vsComnToolsEnvVal.len > 0:
|
||||||
|
return vsComnToolsEnvVal
|
||||||
|
|
||||||
|
proc getVccEnv*(platform: string, windowsStoreSdk: bool = false,
|
||||||
|
sdkVersion: string = nil): StringTableRef =
|
||||||
|
var comSpecCommandString = getEnv comSpecEnvKey
|
||||||
|
if comSpecCommandString.len == 0:
|
||||||
|
comSpecCommandString = "cmd"
|
||||||
|
|
||||||
|
let vsComnToolsPath = getVsComnToolsPath()
|
||||||
|
if vsComnToolsPath.len < 1:
|
||||||
|
return nil
|
||||||
|
let vcvarsallPath = expandFilename joinPath(vsComnToolsPath, vcvarsallRelativePath)
|
||||||
|
|
||||||
|
var vcvarsallArgs: seq[string] = @[]
|
||||||
|
if platform.len > 0:
|
||||||
|
vcvarsallArgs.add(platform)
|
||||||
|
if windowsStoreSdk:
|
||||||
|
vcvarsallArgs.add("store")
|
||||||
|
if sdkVersion.len > 0:
|
||||||
|
vcvarsallArgs.add(sdkVersion)
|
||||||
|
let vcvarsallArgString = vcvarsallArgs.join(" ")
|
||||||
|
|
||||||
|
var vcvarsallCommandString: string
|
||||||
|
if vcvarsallArgString.len > 0:
|
||||||
|
vcvarsallCommandString = "\"$1\" $2" % [vcvarsallPath, vcvarsallArgString]
|
||||||
|
else:
|
||||||
|
vcvarsallCommandString = vcvarsallPath
|
||||||
|
|
||||||
|
let vcvarsallExecCommand = "\"$1\" /C \"$2 && SET\"" %
|
||||||
|
[comSpecCommandString, vcvarsallCommandString]
|
||||||
|
when defined(release):
|
||||||
|
let vccvarsallOptions = {poEvalCommand, poDemon}
|
||||||
|
else:
|
||||||
|
let vccvarsallOptions = {poEchoCmd, poEvalCommand, poDemon}
|
||||||
|
let vcvarsallStdOut = execProcess(vcvarsallExecCommand, options = vccvarsallOptions)
|
||||||
|
result = newStringTable(modeCaseInsensitive)
|
||||||
|
for line in vcvarsallStdOut.splitLines:
|
||||||
|
let idx = line.find('=')
|
||||||
|
if idx > 0:
|
||||||
|
result[line[0..(idx - 1)]] = line[(idx + 1)..(line.len - 1)]
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import strtabs, os, osproc, vccenv
|
import strtabs, os, osproc, vccenv
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
let vccOptions = { poParentStreams }
|
let vccOptions = {poParentStreams}
|
||||||
else:
|
else:
|
||||||
let vccOptions = { poEchoCmd, poParentStreams }
|
let vccOptions = {poEchoCmd, poParentStreams}
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var vccEnvStrTab: StringTableRef = nil
|
var vccEnvStrTab: StringTableRef = nil
|
||||||
|
|
@ -17,9 +17,8 @@ when isMainModule:
|
||||||
for vccEnvKey, vccEnvVal in vccEnvStrTab:
|
for vccEnvKey, vccEnvVal in vccEnvStrTab:
|
||||||
putEnv(vccEnvKey, vccEnvVal)
|
putEnv(vccEnvKey, vccEnvVal)
|
||||||
let vccProcess = startProcess(
|
let vccProcess = startProcess(
|
||||||
"cl".addFileExt(ExeExt),
|
"cl.exe",
|
||||||
args = commandLineParams(),
|
args = commandLineParams(),
|
||||||
options = vccOptions
|
options = vccOptions
|
||||||
)
|
)
|
||||||
quit vccProcess.waitForExit()
|
quit vccProcess.waitForExit()
|
||||||
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import strtabs, os, osproc, vccenv
|
import strtabs, os, osproc, vccenv
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
let vccOptions = { poParentStreams }
|
let vccOptions = {poParentStreams}
|
||||||
else:
|
else:
|
||||||
let vccOptions = { poEchoCmd, poParentStreams }
|
let vccOptions = {poEchoCmd, poParentStreams}
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var vccEnvStrTab: StringTableRef = nil
|
var vccEnvStrTab: StringTableRef = nil
|
||||||
|
|
@ -17,9 +17,9 @@ when isMainModule:
|
||||||
for vccEnvKey, vccEnvVal in vccEnvStrTab:
|
for vccEnvKey, vccEnvVal in vccEnvStrTab:
|
||||||
putEnv(vccEnvKey, vccEnvVal)
|
putEnv(vccEnvKey, vccEnvVal)
|
||||||
let vccProcess = startProcess(
|
let vccProcess = startProcess(
|
||||||
"link".addFileExt(ExeExt),
|
"link.exe",
|
||||||
args = commandLineParams(),
|
args = commandLineParams(),
|
||||||
options = vccOptions
|
options = vccOptions
|
||||||
)
|
)
|
||||||
quit vccProcess.waitForExit()
|
quit vccProcess.waitForExit()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue