Skip to content

Commit

Permalink
make bootstrapping more robust for people who have Nim inside /usr/bin (
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored Apr 3, 2020
1 parent 87e6b88 commit 2b3b24a
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions compiler/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,35 @@ proc staticWalkDirImpl(path: string, relative: bool): PNode =
result.add newTree(nkTupleConstr, newIntNode(nkIntLit, k.ord),
newStrNode(nkStrLit, f))

from std / compilesettings import SingleValueSetting, MultipleValueSetting

proc querySettingImpl(a: VmArgs, conf: ConfigRef, switch: BiggestInt): string =
case SingleValueSetting(switch)
of arguments: result = conf.arguments
of outFile: result = conf.outFile.string
of outDir: result = conf.outDir.string
of nimcacheDir: result = conf.nimcacheDir.string
of projectName: result = conf.projectName
of projectPath: result = conf.projectPath.string
of projectFull: result = conf.projectFull.string
of command: result = conf.command
of commandLine: result = conf.commandLine
of linkOptions: result = conf.linkOptions
of compileOptions: result = conf.compileOptions
of ccompilerPath: result = conf.cCompilerPath

proc querySettingSeqImpl(a: VmArgs, conf: ConfigRef, switch: BiggestInt): seq[string] =
template copySeq(field: untyped): untyped =
for i in field: result.add i.string

case MultipleValueSetting(switch)
of nimblePaths: copySeq(conf.nimblePaths)
of searchPaths: copySeq(conf.searchPaths)
of lazyPaths: copySeq(conf.lazyPaths)
of commandArgs: result = conf.commandArgs
of cincludes: copySeq(conf.cIncludes)
of clibs: copySeq(conf.cLibs)
when defined(nimHasInvariant):
from std / compilesettings import SingleValueSetting, MultipleValueSetting

proc querySettingImpl(a: VmArgs, conf: ConfigRef, switch: BiggestInt): string =
case SingleValueSetting(switch)
of arguments: result = conf.arguments
of outFile: result = conf.outFile.string
of outDir: result = conf.outDir.string
of nimcacheDir: result = conf.nimcacheDir.string
of projectName: result = conf.projectName
of projectPath: result = conf.projectPath.string
of projectFull: result = conf.projectFull.string
of command: result = conf.command
of commandLine: result = conf.commandLine
of linkOptions: result = conf.linkOptions
of compileOptions: result = conf.compileOptions
of ccompilerPath: result = conf.cCompilerPath

proc querySettingSeqImpl(a: VmArgs, conf: ConfigRef, switch: BiggestInt): seq[string] =
template copySeq(field: untyped): untyped =
for i in field: result.add i.string

case MultipleValueSetting(switch)
of nimblePaths: copySeq(conf.nimblePaths)
of searchPaths: copySeq(conf.searchPaths)
of lazyPaths: copySeq(conf.lazyPaths)
of commandArgs: result = conf.commandArgs
of cincludes: copySeq(conf.cIncludes)
of clibs: copySeq(conf.cLibs)

proc registerAdditionalOps*(c: PCtx) =
proc gorgeExWrapper(a: VmArgs) =
Expand Down Expand Up @@ -181,10 +182,11 @@ proc registerAdditionalOps*(c: PCtx) =
systemop getCurrentException
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
registerCallback c, "stdlib.compilesettings.querySetting", proc (a: VmArgs) {.nimcall.} =
setResult(a, querySettingImpl(a, c.config, getInt(a, 0)))
registerCallback c, "stdlib.compilesettings.querySettingSeq", proc (a: VmArgs) {.nimcall.} =
setResult(a, querySettingSeqImpl(a, c.config, getInt(a, 0)))
when defined(nimHasInvariant):
registerCallback c, "stdlib.compilesettings.querySetting", proc (a: VmArgs) {.nimcall.} =
setResult(a, querySettingImpl(a, c.config, getInt(a, 0)))
registerCallback c, "stdlib.compilesettings.querySettingSeq", proc (a: VmArgs) {.nimcall.} =
setResult(a, querySettingSeqImpl(a, c.config, getInt(a, 0)))

if defined(nimsuggest) or c.config.cmd == cmdCheck:
discard "don't run staticExec for 'nim suggest'"
Expand Down

0 comments on commit 2b3b24a

Please sign in to comment.