list available options for --cpu, --os and --cc if the passed option is not found (#11328)

This commit is contained in:
Ico Doornekamp
2019-05-25 20:22:57 +02:00
committed by Andreas Rumpf
parent 2f610d621f
commit 70fb3a93e9
3 changed files with 20 additions and 3 deletions

View File

@@ -615,14 +615,18 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
expectArg(conf, switch, arg, pass, info)
if pass in {passCmd1, passPP}:
let theOS = platform.nameToOS(arg)
if theOS == osNone: localError(conf, info, "unknown OS: '$1'" % arg)
if theOS == osNone:
let osList = platform.listOSnames().join(", ")
localError(conf, info, "unknown OS: '$1'. Available options are: $2" % [arg, $osList])
elif theOS != conf.target.hostOS:
setTarget(conf.target, theOS, conf.target.targetCPU)
of "cpu":
expectArg(conf, switch, arg, pass, info)
if pass in {passCmd1, passPP}:
let cpu = platform.nameToCPU(arg)
if cpu == cpuNone: localError(conf, info, "unknown CPU: '$1'" % arg)
if cpu == cpuNone:
let cpuList = platform.listCPUnames().join(", ")
localError(conf, info, "unknown CPU: '$1'. Available options are: $2" % [ arg, cpuList])
elif cpu != conf.target.hostCPU:
setTarget(conf.target, conf.target.targetOS, cpu)
of "run", "r":

View File

@@ -375,6 +375,10 @@ proc nameToCC*(name: string): TSystemCC =
return i
result = ccNone
proc listCCnames(): seq[string] =
for i in succ(ccNone) .. high(TSystemCC):
result.add CC[i].name
proc isVSCompatible*(conf: ConfigRef): bool =
return conf.cCompiler == ccVcc or
conf.cCompiler == ccClangCl or
@@ -408,7 +412,8 @@ proc getConfigVar(conf: ConfigRef; c: TSystemCC, suffix: string): string =
proc setCC*(conf: ConfigRef; ccname: string; info: TLineInfo) =
conf.cCompiler = nameToCC(ccname)
if conf.cCompiler == ccNone:
localError(conf, info, "unknown C compiler: '$1'" % ccname)
let ccList = listCCnames().join(", ")
localError(conf, info, "unknown C compiler: '$1'. Available options are: $2" % [ccname, ccList])
conf.compileOptions = getConfigVar(conf, conf.cCompiler, ".options.always")
conf.linkOptions = ""
conf.ccompilerpath = getConfigVar(conf, conf.cCompiler, ".path")

View File

@@ -242,12 +242,20 @@ proc nameToOS*(name: string): TSystemOS =
return i
result = osNone
proc listOSnames*(): seq[string] =
for i in succ(osNone) .. high(TSystemOS):
result.add OS[i].name
proc nameToCPU*(name: string): TSystemCPU =
for i in succ(cpuNone) .. high(TSystemCPU):
if cmpIgnoreStyle(name, CPU[i].name) == 0:
return i
result = cpuNone
proc listCPUnames*(): seq[string] =
for i in succ(cpuNone) .. high(TSystemCPU):
result.add CPU[i].name
proc setTargetFromSystem*(t: var Target) =
t.hostOS = nameToOS(system.hostOS)
t.hostCPU = nameToCPU(system.hostCPU)