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
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) expectArg(conf, switch, arg, pass, info)
if pass in {passCmd1, passPP}: if pass in {passCmd1, passPP}:
let theOS = platform.nameToOS(arg) 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: elif theOS != conf.target.hostOS:
setTarget(conf.target, theOS, conf.target.targetCPU) setTarget(conf.target, theOS, conf.target.targetCPU)
of "cpu": of "cpu":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
if pass in {passCmd1, passPP}: if pass in {passCmd1, passPP}:
let cpu = platform.nameToCPU(arg) 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: elif cpu != conf.target.hostCPU:
setTarget(conf.target, conf.target.targetOS, cpu) setTarget(conf.target, conf.target.targetOS, cpu)
of "run", "r": of "run", "r":

View file

@ -375,6 +375,10 @@ proc nameToCC*(name: string): TSystemCC =
return i return i
result = ccNone result = ccNone
proc listCCnames(): seq[string] =
for i in succ(ccNone) .. high(TSystemCC):
result.add CC[i].name
proc isVSCompatible*(conf: ConfigRef): bool = proc isVSCompatible*(conf: ConfigRef): bool =
return conf.cCompiler == ccVcc or return conf.cCompiler == ccVcc or
conf.cCompiler == ccClangCl 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) = proc setCC*(conf: ConfigRef; ccname: string; info: TLineInfo) =
conf.cCompiler = nameToCC(ccname) conf.cCompiler = nameToCC(ccname)
if conf.cCompiler == ccNone: 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.compileOptions = getConfigVar(conf, conf.cCompiler, ".options.always")
conf.linkOptions = "" conf.linkOptions = ""
conf.ccompilerpath = getConfigVar(conf, conf.cCompiler, ".path") conf.ccompilerpath = getConfigVar(conf, conf.cCompiler, ".path")

View file

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