move more global variables into ConfigRef
This commit is contained in:
parent
a8a544a8f7
commit
3c4ceea427
11 changed files with 109 additions and 101 deletions
|
|
@ -287,7 +287,7 @@ proc processPath(conf: ConfigRef; path: string, info: TLineInfo,
|
||||||
elif notRelativeToProj:
|
elif notRelativeToProj:
|
||||||
getCurrentDir() / path
|
getCurrentDir() / path
|
||||||
else:
|
else:
|
||||||
options.gProjectPath / path
|
conf.projectPath / path
|
||||||
try:
|
try:
|
||||||
result = pathSubs(conf, p, info.toFullPath().splitFile().dir)
|
result = pathSubs(conf, p, info.toFullPath().splitFile().dir)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -366,22 +366,22 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
let path = processPath(conf, arg, info)
|
let path = processPath(conf, arg, info)
|
||||||
|
|
||||||
options.searchPaths.keepItIf(cmpPaths(it, path) != 0)
|
conf.searchPaths.keepItIf(cmpPaths(it, path) != 0)
|
||||||
options.lazyPaths.keepItIf(cmpPaths(it, path) != 0)
|
conf.lazyPaths.keepItIf(cmpPaths(it, path) != 0)
|
||||||
|
|
||||||
if (len(path) > 0) and (path[len(path) - 1] == DirSep):
|
if (len(path) > 0) and (path[len(path) - 1] == DirSep):
|
||||||
let strippedPath = path[0 .. (len(path) - 2)]
|
let strippedPath = path[0 .. (len(path) - 2)]
|
||||||
options.searchPaths.keepItIf(cmpPaths(it, strippedPath) != 0)
|
conf.searchPaths.keepItIf(cmpPaths(it, strippedPath) != 0)
|
||||||
options.lazyPaths.keepItIf(cmpPaths(it, strippedPath) != 0)
|
conf.lazyPaths.keepItIf(cmpPaths(it, strippedPath) != 0)
|
||||||
of "nimcache":
|
of "nimcache":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
options.nimcacheDir = processPath(conf, arg, info, true)
|
conf.nimcacheDir = processPath(conf, arg, info, true)
|
||||||
of "out", "o":
|
of "out", "o":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
options.outFile = arg
|
conf.outFile = arg
|
||||||
of "docseesrcurl":
|
of "docseesrcurl":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
options.docSeeSrcUrl = arg
|
conf.docSeeSrcUrl = arg
|
||||||
of "mainmodule", "m":
|
of "mainmodule", "m":
|
||||||
discard "allow for backwards compatibility, but don't do anything"
|
discard "allow for backwards compatibility, but don't do anything"
|
||||||
of "define", "d":
|
of "define", "d":
|
||||||
|
|
@ -579,10 +579,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
processOnOffSwitchG(conf, {optGenIndex}, arg, pass, info)
|
processOnOffSwitchG(conf, {optGenIndex}, arg, pass, info)
|
||||||
of "import":
|
of "import":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
if pass in {passCmd2, passPP}: implicitImports.add arg
|
if pass in {passCmd2, passPP}: conf.implicitImports.add arg
|
||||||
of "include":
|
of "include":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
if pass in {passCmd2, passPP}: implicitIncludes.add arg
|
if pass in {passCmd2, passPP}: conf.implicitIncludes.add arg
|
||||||
of "listcmd":
|
of "listcmd":
|
||||||
expectNoArg(conf, switch, arg, pass, info)
|
expectNoArg(conf, switch, arg, pass, info)
|
||||||
incl(gGlobalOptions, optListCmd)
|
incl(gGlobalOptions, optListCmd)
|
||||||
|
|
@ -655,7 +655,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info)
|
of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info)
|
||||||
of "lib":
|
of "lib":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
libpath = processPath(conf, arg, info, notRelativeToProj=true)
|
conf.libpath = processPath(conf, arg, info, notRelativeToProj=true)
|
||||||
of "putenv":
|
of "putenv":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
splitSwitch(conf, arg, key, val, pass, info)
|
splitSwitch(conf, arg, key, val, pass, info)
|
||||||
|
|
@ -751,17 +751,17 @@ proc processArgument*(pass: TCmdLinePass; p: OptParser;
|
||||||
if argsCount == 0:
|
if argsCount == 0:
|
||||||
# nim filename.nims is the same as "nim e filename.nims":
|
# nim filename.nims is the same as "nim e filename.nims":
|
||||||
if p.key.endswith(".nims"):
|
if p.key.endswith(".nims"):
|
||||||
options.command = "e"
|
config.command = "e"
|
||||||
options.gProjectName = unixToNativePath(p.key)
|
config.projectName = unixToNativePath(p.key)
|
||||||
config.arguments = cmdLineRest(p)
|
config.arguments = cmdLineRest(p)
|
||||||
result = true
|
result = true
|
||||||
elif pass != passCmd2:
|
elif pass != passCmd2:
|
||||||
options.command = p.key
|
config.command = p.key
|
||||||
else:
|
else:
|
||||||
if pass == passCmd1: options.commandArgs.add p.key
|
if pass == passCmd1: config.commandArgs.add p.key
|
||||||
if argsCount == 1:
|
if argsCount == 1:
|
||||||
# support UNIX style filenames everywhere for portable build scripts:
|
# support UNIX style filenames everywhere for portable build scripts:
|
||||||
options.gProjectName = unixToNativePath(p.key)
|
config.projectName = unixToNativePath(p.key)
|
||||||
config.arguments = cmdLineRest(p)
|
config.arguments = cmdLineRest(p)
|
||||||
result = true
|
result = true
|
||||||
inc argsCount
|
inc argsCount
|
||||||
|
|
|
||||||
|
|
@ -474,7 +474,7 @@ proc generateScript(conf: ConfigRef; projectFile: string, script: Rope) =
|
||||||
let (dir, name, ext) = splitFile(projectFile)
|
let (dir, name, ext) = splitFile(projectFile)
|
||||||
writeRope(script, getNimcacheDir(conf) / addFileExt("compile_" & name,
|
writeRope(script, getNimcacheDir(conf) / addFileExt("compile_" & name,
|
||||||
platform.OS[targetOS].scriptExt))
|
platform.OS[targetOS].scriptExt))
|
||||||
copyFile(libpath / "nimbase.h", getNimcacheDir(conf) / "nimbase.h")
|
copyFile(conf.libpath / "nimbase.h", getNimcacheDir(conf) / "nimbase.h")
|
||||||
|
|
||||||
proc getOptSpeed(conf: ConfigRef; c: TSystemCC): string =
|
proc getOptSpeed(conf: ConfigRef; c: TSystemCC): string =
|
||||||
result = getConfigVar(conf, c, ".options.speed")
|
result = getConfigVar(conf, c, ".options.speed")
|
||||||
|
|
@ -563,7 +563,7 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile): string =
|
||||||
var includeCmd, compilePattern: string
|
var includeCmd, compilePattern: string
|
||||||
if not noAbsolutePaths(conf):
|
if not noAbsolutePaths(conf):
|
||||||
# compute include paths:
|
# compute include paths:
|
||||||
includeCmd = CC[c].includeCmd & quoteShell(libpath)
|
includeCmd = CC[c].includeCmd & quoteShell(conf.libpath)
|
||||||
|
|
||||||
for includeDir in items(cIncludes):
|
for includeDir in items(cIncludes):
|
||||||
includeCmd.add(join([CC[c].includeCmd, includeDir.quoteShell]))
|
includeCmd.add(join([CC[c].includeCmd, includeDir.quoteShell]))
|
||||||
|
|
@ -592,14 +592,14 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile): string =
|
||||||
result = quoteShell(compilePattern % [
|
result = quoteShell(compilePattern % [
|
||||||
"file", cf, "objfile", objfile, "options", options,
|
"file", cf, "objfile", objfile, "options", options,
|
||||||
"include", includeCmd, "nim", getPrefixDir(conf),
|
"include", includeCmd, "nim", getPrefixDir(conf),
|
||||||
"nim", getPrefixDir(conf), "lib", libpath])
|
"nim", getPrefixDir(conf), "lib", conf.libpath])
|
||||||
add(result, ' ')
|
add(result, ' ')
|
||||||
addf(result, CC[c].compileTmpl, [
|
addf(result, CC[c].compileTmpl, [
|
||||||
"file", cf, "objfile", objfile,
|
"file", cf, "objfile", objfile,
|
||||||
"options", options, "include", includeCmd,
|
"options", options, "include", includeCmd,
|
||||||
"nim", quoteShell(getPrefixDir(conf)),
|
"nim", quoteShell(getPrefixDir(conf)),
|
||||||
"nim", quoteShell(getPrefixDir(conf)),
|
"nim", quoteShell(getPrefixDir(conf)),
|
||||||
"lib", quoteShell(libpath)])
|
"lib", quoteShell(conf.libpath)])
|
||||||
|
|
||||||
proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
|
proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
|
||||||
result = secureHash(
|
result = secureHash(
|
||||||
|
|
@ -655,12 +655,12 @@ proc compileCFile(conf: ConfigRef; list: CFileList, script: var Rope, cmds: var
|
||||||
proc getLinkCmd(conf: ConfigRef; projectfile, objfiles: string): string =
|
proc getLinkCmd(conf: ConfigRef; projectfile, objfiles: string): string =
|
||||||
if optGenStaticLib in gGlobalOptions:
|
if optGenStaticLib in gGlobalOptions:
|
||||||
var libname: string
|
var libname: string
|
||||||
if options.outFile.len > 0:
|
if conf.outFile.len > 0:
|
||||||
libname = options.outFile.expandTilde
|
libname = conf.outFile.expandTilde
|
||||||
if not libname.isAbsolute():
|
if not libname.isAbsolute():
|
||||||
libname = getCurrentDir() / libname
|
libname = getCurrentDir() / libname
|
||||||
else:
|
else:
|
||||||
libname = (libNameTmpl() % splitFile(gProjectName).name)
|
libname = (libNameTmpl() % splitFile(conf.projectName).name)
|
||||||
result = CC[cCompiler].buildLib % ["libfile", libname,
|
result = CC[cCompiler].buildLib % ["libfile", libname,
|
||||||
"objfiles", objfiles]
|
"objfiles", objfiles]
|
||||||
else:
|
else:
|
||||||
|
|
@ -679,8 +679,8 @@ proc getLinkCmd(conf: ConfigRef; projectfile, objfiles: string): string =
|
||||||
else:
|
else:
|
||||||
exefile = splitFile(projectfile).name & platform.OS[targetOS].exeExt
|
exefile = splitFile(projectfile).name & platform.OS[targetOS].exeExt
|
||||||
builddll = ""
|
builddll = ""
|
||||||
if options.outFile.len > 0:
|
if conf.outFile.len > 0:
|
||||||
exefile = options.outFile.expandTilde
|
exefile = conf.outFile.expandTilde
|
||||||
if not exefile.isAbsolute():
|
if not exefile.isAbsolute():
|
||||||
exefile = getCurrentDir() / exefile
|
exefile = getCurrentDir() / exefile
|
||||||
if not noAbsolutePaths(conf):
|
if not noAbsolutePaths(conf):
|
||||||
|
|
@ -697,13 +697,13 @@ proc getLinkCmd(conf: ConfigRef; projectfile, objfiles: string): string =
|
||||||
linkTmpl = CC[cCompiler].linkTmpl
|
linkTmpl = CC[cCompiler].linkTmpl
|
||||||
result = quoteShell(result % ["builddll", builddll,
|
result = quoteShell(result % ["builddll", builddll,
|
||||||
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
|
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
|
||||||
"exefile", exefile, "nim", getPrefixDir(conf), "lib", libpath])
|
"exefile", exefile, "nim", getPrefixDir(conf), "lib", conf.libpath])
|
||||||
result.add ' '
|
result.add ' '
|
||||||
addf(result, linkTmpl, ["builddll", builddll,
|
addf(result, linkTmpl, ["builddll", builddll,
|
||||||
"buildgui", buildgui, "options", linkOptions,
|
"buildgui", buildgui, "options", linkOptions,
|
||||||
"objfiles", objfiles, "exefile", exefile,
|
"objfiles", objfiles, "exefile", exefile,
|
||||||
"nim", quoteShell(getPrefixDir(conf)),
|
"nim", quoteShell(getPrefixDir(conf)),
|
||||||
"lib", quoteShell(libpath)])
|
"lib", quoteShell(conf.libpath)])
|
||||||
|
|
||||||
template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped): typed =
|
template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped): typed =
|
||||||
try:
|
try:
|
||||||
|
|
@ -903,7 +903,7 @@ proc writeMapping*(conf: ConfigRef; symbolMapping: Rope) =
|
||||||
getConfigVar(conf, cCompiler, ".options.linker")))
|
getConfigVar(conf, cCompiler, ".options.linker")))
|
||||||
|
|
||||||
add(code, "\n[Environment]\nlibpath=")
|
add(code, "\n[Environment]\nlibpath=")
|
||||||
add(code, strutils.escape(libpath))
|
add(code, strutils.escape(conf.libpath))
|
||||||
|
|
||||||
addf(code, "\n[Symbols]$n$1", [symbolMapping])
|
addf(code, "\n[Symbols]$n$1", [symbolMapping])
|
||||||
writeRope(code, joinPath(gProjectPath, "mapping.txt"))
|
writeRope(code, joinPath(conf.projectPath, "mapping.txt"))
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
|
||||||
let x = addFileExt(a, "nim")
|
let x = addFileExt(a, "nim")
|
||||||
if fileExists(x): return x
|
if fileExists(x): return x
|
||||||
for candidate in stdlibDirs:
|
for candidate in stdlibDirs:
|
||||||
attempt(options.libpath / candidate / modname)
|
attempt(conf.libpath / candidate / modname)
|
||||||
|
|
||||||
# hacky way to implement 'x / y /../ z':
|
# hacky way to implement 'x / y /../ z':
|
||||||
result = getModuleName(conf, n1)
|
result = getModuleName(conf, n1)
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ proc quit(conf: ConfigRef; msg: TMsgKind) =
|
||||||
else:
|
else:
|
||||||
styledMsgWriteln(fgRed, "No stack traceback available\n" &
|
styledMsgWriteln(fgRed, "No stack traceback available\n" &
|
||||||
"To create a stacktrace, rerun compilation with ./koch temp " &
|
"To create a stacktrace, rerun compilation with ./koch temp " &
|
||||||
options.command & " <file>")
|
conf.command & " <file>")
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) =
|
proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) =
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ import parseutils, strutils, strtabs, os, options, msgs, sequtils,
|
||||||
configuration
|
configuration
|
||||||
|
|
||||||
proc addPath*(conf: ConfigRef; path: string, info: TLineInfo) =
|
proc addPath*(conf: ConfigRef; path: string, info: TLineInfo) =
|
||||||
if not options.searchPaths.contains(path):
|
if not conf.searchPaths.contains(path):
|
||||||
options.searchPaths.insert(path, 0)
|
conf.searchPaths.insert(path, 0)
|
||||||
|
|
||||||
type
|
type
|
||||||
Version* = distinct string
|
Version* = distinct string
|
||||||
|
|
@ -112,9 +112,9 @@ proc addNimblePath(conf: ConfigRef; p: string, info: TLineInfo) =
|
||||||
if not path.isAbsolute():
|
if not path.isAbsolute():
|
||||||
path = p / path
|
path = p / path
|
||||||
|
|
||||||
if not contains(options.searchPaths, path):
|
if not contains(conf.searchPaths, path):
|
||||||
message(conf, info, hintPath, path)
|
message(conf, info, hintPath, path)
|
||||||
options.lazyPaths.insert(path, 0)
|
conf.lazyPaths.insert(path, 0)
|
||||||
|
|
||||||
proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
|
proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
|
||||||
var packages = newStringTable(modeStyleInsensitive)
|
var packages = newStringTable(modeStyleInsensitive)
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ proc loadConfigs*(cfg: string; cache: IdentCache; config: ConfigRef = nil) =
|
||||||
if optSkipUserConfigFile notin gGlobalOptions:
|
if optSkipUserConfigFile notin gGlobalOptions:
|
||||||
readConfigFile(getUserConfigPath(cfg), cache, config)
|
readConfigFile(getUserConfigPath(cfg), cache, config)
|
||||||
|
|
||||||
let pd = if gProjectPath.len > 0: gProjectPath else: getCurrentDir()
|
let pd = if config.projectPath.len > 0: config.projectPath else: getCurrentDir()
|
||||||
if optSkipParentConfigFiles notin gGlobalOptions:
|
if optSkipParentConfigFiles notin gGlobalOptions:
|
||||||
for dir in parentDirs(pd, fromRoot=true, inclusive=false):
|
for dir in parentDirs(pd, fromRoot=true, inclusive=false):
|
||||||
readConfigFile(dir / cfg, cache, config)
|
readConfigFile(dir / cfg, cache, config)
|
||||||
|
|
@ -247,13 +247,13 @@ proc loadConfigs*(cfg: string; cache: IdentCache; config: ConfigRef = nil) =
|
||||||
if optSkipProjConfigFile notin gGlobalOptions:
|
if optSkipProjConfigFile notin gGlobalOptions:
|
||||||
readConfigFile(pd / cfg, cache, config)
|
readConfigFile(pd / cfg, cache, config)
|
||||||
|
|
||||||
if gProjectName.len != 0:
|
if config.projectName.len != 0:
|
||||||
# new project wide config file:
|
# new project wide config file:
|
||||||
var projectConfig = changeFileExt(gProjectFull, "nimcfg")
|
var projectConfig = changeFileExt(config.projectFull, "nimcfg")
|
||||||
if not fileExists(projectConfig):
|
if not fileExists(projectConfig):
|
||||||
projectConfig = changeFileExt(gProjectFull, "nim.cfg")
|
projectConfig = changeFileExt(config.projectFull, "nim.cfg")
|
||||||
readConfigFile(projectConfig, cache, config)
|
readConfigFile(projectConfig, cache, config)
|
||||||
|
|
||||||
proc loadConfigs*(cfg: string; config: ConfigRef = nil) =
|
proc loadConfigs*(cfg: string; config: ConfigRef) =
|
||||||
# for backwards compatibility only.
|
# for backwards compatibility only.
|
||||||
loadConfigs(cfg, newIdentCache(), config)
|
loadConfigs(cfg, newIdentCache(), config)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ proc overwriteFiles*(conf: ConfigRef) =
|
||||||
let doStrip = options.getConfigVar(conf, "pretty.strip").normalize == "on"
|
let doStrip = options.getConfigVar(conf, "pretty.strip").normalize == "on"
|
||||||
for i in 0 .. high(gSourceFiles):
|
for i in 0 .. high(gSourceFiles):
|
||||||
if gSourceFiles[i].dirty and not gSourceFiles[i].isNimfixFile and
|
if gSourceFiles[i].dirty and not gSourceFiles[i].isNimfixFile and
|
||||||
(not gOnlyMainfile or gSourceFiles[i].fileIdx == gProjectMainIdx.FileIndex):
|
(not gOnlyMainfile or gSourceFiles[i].fileIdx == conf.projectMainIdx.FileIndex):
|
||||||
let newFile = if gOverWrite: gSourceFiles[i].fullpath
|
let newFile = if gOverWrite: gSourceFiles[i].fullpath
|
||||||
else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim")
|
else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim")
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,22 @@ type
|
||||||
## symbols are always guaranteed to be style
|
## symbols are always guaranteed to be style
|
||||||
## insensitive. Otherwise hell would break lose.
|
## insensitive. Otherwise hell would break lose.
|
||||||
packageCache*: StringTableRef
|
packageCache*: StringTableRef
|
||||||
|
searchPaths*: seq[string]
|
||||||
|
lazyPaths*: seq[string]
|
||||||
|
outFile*, prefixDir*, libpath*, nimcacheDir*: string
|
||||||
|
dllOverrides, moduleOverrides*: StringTableRef
|
||||||
|
projectName*: string # holds a name like 'nim'
|
||||||
|
projectPath*: string # holds a path like /home/alice/projects/nim/compiler/
|
||||||
|
projectFull*: string # projectPath/projectName
|
||||||
|
projectIsStdin*: bool # whether we're compiling from stdin
|
||||||
|
projectMainIdx*: int32 # the canonical path id of the main module
|
||||||
|
command*: string # the main command (e.g. cc, check, scan, etc)
|
||||||
|
commandArgs*: seq[string] # any arguments after the main command
|
||||||
|
keepComments*: bool # whether the parser needs to keep comments
|
||||||
|
implicitImports*: seq[string] # modules that are to be implicitly imported
|
||||||
|
implicitIncludes*: seq[string] # modules that are to be implicitly included
|
||||||
|
docSeeSrcUrl*: string # if empty, no seeSrc will be generated. \
|
||||||
|
# The string uses the formatting variables `path` and `line`.
|
||||||
|
|
||||||
const oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel}
|
const oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel}
|
||||||
|
|
||||||
|
|
@ -151,7 +167,24 @@ proc newConfigRef*(): ConfigRef =
|
||||||
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1],
|
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1],
|
||||||
configVars: newStringTable(modeStyleInsensitive),
|
configVars: newStringTable(modeStyleInsensitive),
|
||||||
symbols: newStringTable(modeStyleInsensitive),
|
symbols: newStringTable(modeStyleInsensitive),
|
||||||
packageCache: newPackageCache())
|
packageCache: newPackageCache(),
|
||||||
|
searchPaths: @[],
|
||||||
|
lazyPaths: @[],
|
||||||
|
outFile: "", prefixDir: "", libpath: "", nimcacheDir: "",
|
||||||
|
dllOverrides: newStringTable(modeCaseInsensitive),
|
||||||
|
moduleOverrides: newStringTable(modeStyleInsensitive),
|
||||||
|
projectName: "", # holds a name like 'nim'
|
||||||
|
projectPath: "", # holds a path like /home/alice/projects/nim/compiler/
|
||||||
|
projectFull: "", # projectPath/projectName
|
||||||
|
projectIsStdin: false, # whether we're compiling from stdin
|
||||||
|
projectMainIdx: 0'i32, # the canonical path id of the main module
|
||||||
|
command: "", # the main command (e.g. cc, check, scan, etc)
|
||||||
|
commandArgs: @[], # any arguments after the main command
|
||||||
|
keepComments: true, # whether the parser needs to keep comments
|
||||||
|
implicitImports: @[], # modules that are to be implicitly imported
|
||||||
|
implicitIncludes: @[], # modules that are to be implicitly included
|
||||||
|
docSeeSrcUrl: ""
|
||||||
|
)
|
||||||
|
|
||||||
proc newPartialConfigRef*(): ConfigRef =
|
proc newPartialConfigRef*(): ConfigRef =
|
||||||
## create a new ConfigRef that is only good enough for error reporting.
|
## create a new ConfigRef that is only good enough for error reporting.
|
||||||
|
|
@ -215,11 +248,6 @@ var
|
||||||
gExitcode*: int8
|
gExitcode*: int8
|
||||||
gCmd*: TCommands = cmdNone # the command
|
gCmd*: TCommands = cmdNone # the command
|
||||||
gSelectedGC* = gcRefc # the selected GC
|
gSelectedGC* = gcRefc # the selected GC
|
||||||
searchPaths*: seq[string] = @[]
|
|
||||||
lazyPaths*: seq[string] = @[]
|
|
||||||
outFile*: string = ""
|
|
||||||
docSeeSrcUrl*: string = "" # if empty, no seeSrc will be generated. \
|
|
||||||
# The string uses the formatting variables `path` and `line`.
|
|
||||||
#headerFile*: string = ""
|
#headerFile*: string = ""
|
||||||
gVerbosity* = 1 # how verbose the compiler is
|
gVerbosity* = 1 # how verbose the compiler is
|
||||||
gNumberOfProcessors*: int # number of processors
|
gNumberOfProcessors*: int # number of processors
|
||||||
|
|
@ -262,24 +290,6 @@ const
|
||||||
DocConfig* = "nimdoc.cfg"
|
DocConfig* = "nimdoc.cfg"
|
||||||
DocTexConfig* = "nimdoc.tex.cfg"
|
DocTexConfig* = "nimdoc.tex.cfg"
|
||||||
|
|
||||||
# additional configuration variables:
|
|
||||||
var
|
|
||||||
gDllOverrides = newStringTable(modeCaseInsensitive)
|
|
||||||
gModuleOverrides* = newStringTable(modeStyleInsensitive)
|
|
||||||
gPrefixDir* = "" # Overrides the default prefix dir in getPrefixDir proc.
|
|
||||||
libpath* = ""
|
|
||||||
gProjectName* = "" # holds a name like 'nim'
|
|
||||||
gProjectPath* = "" # holds a path like /home/alice/projects/nim/compiler/
|
|
||||||
gProjectFull* = "" # projectPath/projectName
|
|
||||||
gProjectIsStdin* = false # whether we're compiling from stdin
|
|
||||||
gProjectMainIdx*: int32 # the canonical path id of the main module
|
|
||||||
nimcacheDir* = ""
|
|
||||||
command* = "" # the main command (e.g. cc, check, scan, etc)
|
|
||||||
commandArgs*: seq[string] = @[] # any arguments after the main command
|
|
||||||
gKeepComments*: bool = true # whether the parser needs to keep comments
|
|
||||||
implicitImports*: seq[string] = @[] # modules that are to be implicitly imported
|
|
||||||
implicitIncludes*: seq[string] = @[] # modules that are to be implicitly included
|
|
||||||
|
|
||||||
const oKeepVariableNames* = true
|
const oKeepVariableNames* = true
|
||||||
|
|
||||||
template compilingLib*(conf: ConfigRef): bool =
|
template compilingLib*(conf: ConfigRef): bool =
|
||||||
|
|
@ -289,10 +299,10 @@ proc mainCommandArg*(conf: ConfigRef): string =
|
||||||
## This is intended for commands like check or parse
|
## This is intended for commands like check or parse
|
||||||
## which will work on the main project file unless
|
## which will work on the main project file unless
|
||||||
## explicitly given a specific file argument
|
## explicitly given a specific file argument
|
||||||
if commandArgs.len > 0:
|
if conf.commandArgs.len > 0:
|
||||||
result = commandArgs[0]
|
result = conf.commandArgs[0]
|
||||||
else:
|
else:
|
||||||
result = gProjectName
|
result = conf.projectName
|
||||||
|
|
||||||
proc existsConfigVar*(conf: ConfigRef; key: string): bool =
|
proc existsConfigVar*(conf: ConfigRef; key: string): bool =
|
||||||
result = hasKey(conf.configVars, key)
|
result = hasKey(conf.configVars, key)
|
||||||
|
|
@ -304,37 +314,36 @@ proc setConfigVar*(conf: ConfigRef; key, val: string) =
|
||||||
conf.configVars[key] = val
|
conf.configVars[key] = val
|
||||||
|
|
||||||
proc getOutFile*(conf: ConfigRef; filename, ext: string): string =
|
proc getOutFile*(conf: ConfigRef; filename, ext: string): string =
|
||||||
if options.outFile != "": result = options.outFile
|
if conf.outFile != "": result = conf.outFile
|
||||||
else: result = changeFileExt(filename, ext)
|
else: result = changeFileExt(filename, ext)
|
||||||
|
|
||||||
proc getPrefixDir*(conf: ConfigRef): string =
|
proc getPrefixDir*(conf: ConfigRef): string =
|
||||||
## Gets the prefix dir, usually the parent directory where the binary resides.
|
## Gets the prefix dir, usually the parent directory where the binary resides.
|
||||||
##
|
##
|
||||||
## This is overridden by some tools (namely nimsuggest) via the ``gPrefixDir``
|
## This is overridden by some tools (namely nimsuggest) via the ``conf.prefixDir``
|
||||||
## global.
|
## global.
|
||||||
if gPrefixDir != "": result = gPrefixDir
|
if conf.prefixDir != "": result = conf.prefixDir
|
||||||
else:
|
else: result = splitPath(getAppDir()).head
|
||||||
result = splitPath(getAppDir()).head
|
|
||||||
|
|
||||||
proc setDefaultLibpath*(conf: ConfigRef) =
|
proc setDefaultLibpath*(conf: ConfigRef) =
|
||||||
# set default value (can be overwritten):
|
# set default value (can be overwritten):
|
||||||
if libpath == "":
|
if conf.libpath == "":
|
||||||
# choose default libpath:
|
# choose default libpath:
|
||||||
var prefix = getPrefixDir(conf)
|
var prefix = getPrefixDir(conf)
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
if prefix == "/usr": libpath = "/usr/lib/nim"
|
if prefix == "/usr": conf.libpath = "/usr/lib/nim"
|
||||||
elif prefix == "/usr/local": libpath = "/usr/local/lib/nim"
|
elif prefix == "/usr/local": conf.libpath = "/usr/local/lib/nim"
|
||||||
else: libpath = joinPath(prefix, "lib")
|
else: conf.libpath = joinPath(prefix, "lib")
|
||||||
else: libpath = joinPath(prefix, "lib")
|
else: conf.libpath = joinPath(prefix, "lib")
|
||||||
|
|
||||||
# Special rule to support other tools (nimble) which import the compiler
|
# Special rule to support other tools (nimble) which import the compiler
|
||||||
# modules and make use of them.
|
# modules and make use of them.
|
||||||
let realNimPath = findExe("nim")
|
let realNimPath = findExe("nim")
|
||||||
# Find out if $nim/../../lib/system.nim exists.
|
# Find out if $nim/../../lib/system.nim exists.
|
||||||
let parentNimLibPath = realNimPath.parentDir.parentDir / "lib"
|
let parentNimLibPath = realNimPath.parentDir.parentDir / "lib"
|
||||||
if not fileExists(libpath / "system.nim") and
|
if not fileExists(conf.libpath / "system.nim") and
|
||||||
fileExists(parentNimlibPath / "system.nim"):
|
fileExists(parentNimlibPath / "system.nim"):
|
||||||
libpath = parentNimLibPath
|
conf.libpath = parentNimLibPath
|
||||||
|
|
||||||
proc canonicalizePath*(conf: ConfigRef; path: string): string =
|
proc canonicalizePath*(conf: ConfigRef; path: string): string =
|
||||||
# on Windows, 'expandFilename' calls getFullPathName which doesn't do
|
# on Windows, 'expandFilename' calls getFullPathName which doesn't do
|
||||||
|
|
@ -350,7 +359,7 @@ proc canonicalizePath*(conf: ConfigRef; path: string): string =
|
||||||
|
|
||||||
proc shortenDir*(conf: ConfigRef; dir: string): string =
|
proc shortenDir*(conf: ConfigRef; dir: string): string =
|
||||||
## returns the interesting part of a dir
|
## returns the interesting part of a dir
|
||||||
var prefix = gProjectPath & DirSep
|
var prefix = conf.projectPath & DirSep
|
||||||
if startsWith(dir, prefix):
|
if startsWith(dir, prefix):
|
||||||
return substr(dir, len(prefix))
|
return substr(dir, len(prefix))
|
||||||
prefix = getPrefixDir(conf) & DirSep
|
prefix = getPrefixDir(conf) & DirSep
|
||||||
|
|
@ -366,25 +375,24 @@ proc removeTrailingDirSep*(path: string): string =
|
||||||
|
|
||||||
proc disableNimblePath*(conf: ConfigRef) =
|
proc disableNimblePath*(conf: ConfigRef) =
|
||||||
gNoNimblePath = true
|
gNoNimblePath = true
|
||||||
lazyPaths.setLen(0)
|
conf.lazyPaths.setLen(0)
|
||||||
|
|
||||||
include packagehandling
|
include packagehandling
|
||||||
|
|
||||||
proc getNimcacheDir*(conf: ConfigRef): string =
|
proc getNimcacheDir*(conf: ConfigRef): string =
|
||||||
result = if nimcacheDir.len > 0: nimcacheDir else: shortenDir(conf, gProjectPath) /
|
result = if conf.nimcacheDir.len > 0: conf.nimcacheDir
|
||||||
genSubDir
|
else: shortenDir(conf, conf.projectPath) / genSubDir
|
||||||
|
|
||||||
|
|
||||||
proc pathSubs*(conf: ConfigRef; p, config: string): string =
|
proc pathSubs*(conf: ConfigRef; p, config: string): string =
|
||||||
let home = removeTrailingDirSep(os.getHomeDir())
|
let home = removeTrailingDirSep(os.getHomeDir())
|
||||||
result = unixToNativePath(p % [
|
result = unixToNativePath(p % [
|
||||||
"nim", getPrefixDir(conf),
|
"nim", getPrefixDir(conf),
|
||||||
"lib", libpath,
|
"lib", conf.libpath,
|
||||||
"home", home,
|
"home", home,
|
||||||
"config", config,
|
"config", config,
|
||||||
"projectname", options.gProjectName,
|
"projectname", conf.projectName,
|
||||||
"projectpath", options.gProjectPath,
|
"projectpath", conf.projectPath,
|
||||||
"projectdir", options.gProjectPath,
|
"projectdir", conf.projectPath,
|
||||||
"nimcache", getNimcacheDir(conf)])
|
"nimcache", getNimcacheDir(conf)])
|
||||||
if "~/" in result:
|
if "~/" in result:
|
||||||
result = result.replace("~/", home & '/')
|
result = result.replace("~/", home & '/')
|
||||||
|
|
@ -410,28 +418,28 @@ proc completeGeneratedFilePath*(conf: ConfigRef; f: string, createSubDir: bool =
|
||||||
#echo "completeGeneratedFilePath(", f, ") = ", result
|
#echo "completeGeneratedFilePath(", f, ") = ", result
|
||||||
|
|
||||||
proc rawFindFile(conf: ConfigRef; f: string): string =
|
proc rawFindFile(conf: ConfigRef; f: string): string =
|
||||||
for it in searchPaths:
|
for it in conf.searchPaths:
|
||||||
result = joinPath(it, f)
|
result = joinPath(it, f)
|
||||||
if existsFile(result):
|
if existsFile(result):
|
||||||
return canonicalizePath(conf, result)
|
return canonicalizePath(conf, result)
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
proc rawFindFile2(conf: ConfigRef; f: string): string =
|
proc rawFindFile2(conf: ConfigRef; f: string): string =
|
||||||
for i, it in lazyPaths:
|
for i, it in conf.lazyPaths:
|
||||||
result = joinPath(it, f)
|
result = joinPath(it, f)
|
||||||
if existsFile(result):
|
if existsFile(result):
|
||||||
# bring to front
|
# bring to front
|
||||||
for j in countDown(i,1):
|
for j in countDown(i,1):
|
||||||
swap(lazyPaths[j], lazyPaths[j-1])
|
swap(conf.lazyPaths[j], conf.lazyPaths[j-1])
|
||||||
|
|
||||||
return canonicalizePath(conf, result)
|
return canonicalizePath(conf, result)
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
template patchModule(conf: ConfigRef) {.dirty.} =
|
template patchModule(conf: ConfigRef) {.dirty.} =
|
||||||
if result.len > 0 and gModuleOverrides.len > 0:
|
if result.len > 0 and conf.moduleOverrides.len > 0:
|
||||||
let key = getPackageName(conf, result) & "_" & splitFile(result).name
|
let key = getPackageName(conf, result) & "_" & splitFile(result).name
|
||||||
if gModuleOverrides.hasKey(key):
|
if conf.moduleOverrides.hasKey(key):
|
||||||
let ov = gModuleOverrides[key]
|
let ov = conf.moduleOverrides[key]
|
||||||
if ov.len > 0: result = ov
|
if ov.len > 0: result = ov
|
||||||
|
|
||||||
proc findFile*(conf: ConfigRef; f: string): string {.procvar.} =
|
proc findFile*(conf: ConfigRef; f: string): string {.procvar.} =
|
||||||
|
|
@ -492,10 +500,10 @@ proc canonDynlibName(s: string): string =
|
||||||
result = s.substr(start)
|
result = s.substr(start)
|
||||||
|
|
||||||
proc inclDynlibOverride*(conf: ConfigRef; lib: string) =
|
proc inclDynlibOverride*(conf: ConfigRef; lib: string) =
|
||||||
gDllOverrides[lib.canonDynlibName] = "true"
|
conf.dllOverrides[lib.canonDynlibName] = "true"
|
||||||
|
|
||||||
proc isDynlibOverride*(conf: ConfigRef; lib: string): bool =
|
proc isDynlibOverride*(conf: ConfigRef; lib: string): bool =
|
||||||
result = gDynlibOverrideAll or gDllOverrides.hasKey(lib.canonDynlibName)
|
result = gDynlibOverrideAll or conf.dllOverrides.hasKey(lib.canonDynlibName)
|
||||||
|
|
||||||
proc binaryStrSearch*(x: openArray[string], y: string): int =
|
proc binaryStrSearch*(x: openArray[string], y: string): int =
|
||||||
var a = 0
|
var a = 0
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,8 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream,
|
||||||
# modules to include between compilation runs? we'd need to track that
|
# modules to include between compilation runs? we'd need to track that
|
||||||
# in ROD files. I think we should enable this feature only
|
# in ROD files. I think we should enable this feature only
|
||||||
# for the interactive mode.
|
# for the interactive mode.
|
||||||
processImplicits graph.config, implicitImports, nkImportStmt, a, module
|
processImplicits graph.config, graph.config.implicitImports, nkImportStmt, a, module
|
||||||
processImplicits graph.config, implicitIncludes, nkIncludeStmt, a, module
|
processImplicits graph.config, graph.config.implicitIncludes, nkIncludeStmt, a, module
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if graph.stopCompile(): break
|
if graph.stopCompile(): break
|
||||||
|
|
|
||||||
|
|
@ -918,7 +918,7 @@ proc handleSymbolFile*(module: PSym; cache: IdentCache; conf: ConfigRef): PRodRe
|
||||||
if gSymbolFiles in {disabledSf, writeOnlySf, v2Sf}:
|
if gSymbolFiles in {disabledSf, writeOnlySf, v2Sf}:
|
||||||
module.id = getID()
|
module.id = getID()
|
||||||
return nil
|
return nil
|
||||||
idgen.loadMaxIds(conf, options.gProjectPath / options.gProjectName)
|
idgen.loadMaxIds(conf, conf.projectPath / conf.projectName)
|
||||||
let fileIdx = module.fileIdx
|
let fileIdx = module.fileIdx
|
||||||
discard checkDep(fileIdx, cache, conf)
|
discard checkDep(fileIdx, cache, conf)
|
||||||
#if gMods[fileIdx.int32].reason == rrEmpty: internalError("handleSymbolFile")
|
#if gMods[fileIdx.int32].reason == rrEmpty: internalError("handleSymbolFile")
|
||||||
|
|
|
||||||
|
|
@ -653,7 +653,7 @@ proc myClose(graph: ModuleGraph; c: PPassContext, n: PNode): PNode =
|
||||||
result = process(c, n)
|
result = process(c, n)
|
||||||
var w = PRodWriter(c)
|
var w = PRodWriter(c)
|
||||||
writeRod(w)
|
writeRod(w)
|
||||||
idgen.saveMaxIds(graph.config, options.gProjectPath / options.gProjectName)
|
idgen.saveMaxIds(graph.config, graph.config.projectPath / graph.config.projectName)
|
||||||
|
|
||||||
const rodwritePass* = makePass(open = myOpen, close = myClose, process = process)
|
const rodwritePass* = makePass(open = myOpen, close = myClose, process = process)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue