This commit is contained in:
Andreas Rumpf 2019-05-14 12:02:26 +02:00
commit 651ae68567
5 changed files with 22 additions and 16 deletions

View file

@ -1898,7 +1898,6 @@ proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
# it would generate multiple 'main' procs, for instance. # it would generate multiple 'main' procs, for instance.
proc writeModule(m: BModule, pending: bool) = proc writeModule(m: BModule, pending: bool) =
# generate code for the init statements of the module:
let cfile = getCFile(m) let cfile = getCFile(m)
if true or optForceFullMake in m.config.globalOptions: if true or optForceFullMake in m.config.globalOptions:
@ -1910,7 +1909,8 @@ proc writeModule(m: BModule, pending: bool) =
add(m.s[cfsProcHeaders], m.g.mainModProcs) add(m.s[cfsProcHeaders], m.g.mainModProcs)
generateThreadVarsSize(m) generateThreadVarsSize(m)
var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {}) var cf = Cfile(nimname: m.module.name.s, cname: cfile,
obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
var code = genModule(m, cf) var code = genModule(m, cf)
if code != nil: if code != nil:
when hasTinyCBackend: when hasTinyCBackend:
@ -1921,7 +1921,8 @@ proc writeModule(m: BModule, pending: bool) =
if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached} if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached}
addFileToCompile(m.config, cf) addFileToCompile(m.config, cf)
elif pending and mergeRequired(m) and sfMainModule notin m.module.flags: elif pending and mergeRequired(m) and sfMainModule notin m.module.flags:
let cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {}) let cf = Cfile(nimname: m.module.name.s, cname: cfile,
obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
mergeFiles(cfile, m) mergeFiles(cfile, m)
genInitCode(m) genInitCode(m)
finishTypeDescriptions(m) finishTypeDescriptions(m)
@ -1934,14 +1935,16 @@ proc writeModule(m: BModule, pending: bool) =
# Consider: first compilation compiles ``system.nim`` and produces # Consider: first compilation compiles ``system.nim`` and produces
# ``system.c`` but then compilation fails due to an error. This means # ``system.c`` but then compilation fails due to an error. This means
# that ``system.o`` is missing, so we need to call the C compiler for it: # that ``system.o`` is missing, so we need to call the C compiler for it:
var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {}) var cf = Cfile(nimname: m.module.name.s, cname: cfile,
obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
if not fileExists(cf.obj): cf.flags = {CfileFlag.Cached} if not fileExists(cf.obj): cf.flags = {CfileFlag.Cached}
addFileToCompile(m.config, cf) addFileToCompile(m.config, cf)
close(m.ndi) close(m.ndi)
proc updateCachedModule(m: BModule) = proc updateCachedModule(m: BModule) =
let cfile = getCFile(m) let cfile = getCFile(m)
var cf = Cfile(cname: cfile, obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {}) var cf = Cfile(nimname: m.module.name.s, cname: cfile,
obj: completeCFilePath(m.config, toObjFile(m.config, cfile)), flags: {})
if mergeRequired(m) and sfMainModule notin m.module.flags: if mergeRequired(m) and sfMainModule notin m.module.flags:
mergeFiles(cfile, m) mergeFiles(cfile, m)

View file

@ -504,30 +504,29 @@ proc noAbsolutePaths(conf: ConfigRef): bool {.inline.} =
# `optGenMapping` is included here for niminst. # `optGenMapping` is included here for niminst.
result = conf.globalOptions * {optGenScript, optGenMapping} != {} result = conf.globalOptions * {optGenScript, optGenMapping} != {}
proc cFileSpecificOptions(conf: ConfigRef; cfilename: AbsoluteFile): string = proc cFileSpecificOptions(conf: ConfigRef; nimname: string): string =
result = conf.compileOptions result = conf.compileOptions
for option in conf.compileOptionsCmd: for option in conf.compileOptionsCmd:
if strutils.find(result, option, 0) < 0: if strutils.find(result, option, 0) < 0:
addOpt(result, option) addOpt(result, option)
let trunk = splitFile(cfilename).name
if optCDebug in conf.globalOptions: if optCDebug in conf.globalOptions:
let key = trunk & ".debug" let key = nimname & ".debug"
if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key)) if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
else: addOpt(result, getDebug(conf, conf.cCompiler)) else: addOpt(result, getDebug(conf, conf.cCompiler))
if optOptimizeSpeed in conf.options: if optOptimizeSpeed in conf.options:
let key = trunk & ".speed" let key = nimname & ".speed"
if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key)) if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
else: addOpt(result, getOptSpeed(conf, conf.cCompiler)) else: addOpt(result, getOptSpeed(conf, conf.cCompiler))
elif optOptimizeSize in conf.options: elif optOptimizeSize in conf.options:
let key = trunk & ".size" let key = nimname & ".size"
if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key)) if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
else: addOpt(result, getOptSize(conf, conf.cCompiler)) else: addOpt(result, getOptSize(conf, conf.cCompiler))
let key = trunk & ".always" let key = nimname & ".always"
if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key)) if existsConfigVar(conf, key): addOpt(result, getConfigVar(conf, key))
proc getCompileOptions(conf: ConfigRef): string = proc getCompileOptions(conf: ConfigRef): string =
result = cFileSpecificOptions(conf, AbsoluteFile"__dummy__") result = cFileSpecificOptions(conf, "__dummy__")
proc getLinkOptions(conf: ConfigRef): string = proc getLinkOptions(conf: ConfigRef): string =
result = conf.linkOptions & " " & conf.linkOptionsCmd & " " result = conf.linkOptions & " " & conf.linkOptionsCmd & " "
@ -557,7 +556,7 @@ proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string =
proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile, isMainFile = false): string = proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile, isMainFile = false): string =
var c = conf.cCompiler var c = conf.cCompiler
var options = cFileSpecificOptions(conf, cfile.cname) var options = cFileSpecificOptions(conf, cfile.nimname)
var exe = getConfigVar(conf, c, ".exe") var exe = getConfigVar(conf, c, ".exe")
if exe.len == 0: exe = getCompilerExe(conf, c, cfile.cname) if exe.len == 0: exe = getCompilerExe(conf, c, cfile.cname)
@ -647,7 +646,7 @@ proc addExternalFileToCompile*(conf: ConfigRef; c: var Cfile) =
conf.toCompile.add(c) conf.toCompile.add(c)
proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) = proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) =
var c = Cfile(cname: filename, var c = Cfile(nimname: splitFile(filename).name, cname: filename,
obj: toObjFile(conf, completeCFilePath(conf, filename, false)), obj: toObjFile(conf, completeCFilePath(conf, filename, false)),
flags: {CfileFlag.External}) flags: {CfileFlag.External})
addExternalFileToCompile(conf, c) addExternalFileToCompile(conf, c)

View file

@ -147,6 +147,7 @@ type
External ## file was introduced via .compile pragma External ## file was introduced via .compile pragma
Cfile* = object Cfile* = object
nimname*: string
cname*, obj*: AbsoluteFile cname*, obj*: AbsoluteFile
flags*: set[CFileFlag] flags*: set[CFileFlag]
CfileList* = seq[Cfile] CfileList* = seq[Cfile]

View file

@ -471,7 +471,8 @@ proc relativeFile(c: PContext; n: PNode; ext=""): AbsoluteFile =
proc processCompile(c: PContext, n: PNode) = proc processCompile(c: PContext, n: PNode) =
proc docompile(c: PContext; it: PNode; src, dest: AbsoluteFile) = proc docompile(c: PContext; it: PNode; src, dest: AbsoluteFile) =
var cf = Cfile(cname: src, obj: dest, flags: {CfileFlag.External}) var cf = Cfile(nimname: splitFile(src).name,
cname: src, obj: dest, flags: {CfileFlag.External})
extccomp.addExternalFileToCompile(c.config, cf) extccomp.addExternalFileToCompile(c.config, cf)
recordPragma(c, it, "compile", src.string, dest.string) recordPragma(c, it, "compile", src.string, dest.string)

View file

@ -846,7 +846,9 @@ proc replay(g: ModuleGraph; module: PSym; n: PNode) =
of "error": localError(g.config, n.info, errUser, n[1].strVal) of "error": localError(g.config, n.info, errUser, n[1].strVal)
of "compile": of "compile":
internalAssert g.config, n.len == 3 and n[2].kind == nkStrLit internalAssert g.config, n.len == 3 and n[2].kind == nkStrLit
var cf = Cfile(cname: AbsoluteFile n[1].strVal, obj: AbsoluteFile n[2].strVal, let cname = AbsoluteFile n[1].strVal,
var cf = Cfile(nimname: splitFile(cname).name, cname: cname,
obj: AbsoluteFile n[2].strVal,
flags: {CfileFlag.External}) flags: {CfileFlag.External})
extccomp.addExternalFileToCompile(g.config, cf) extccomp.addExternalFileToCompile(g.config, cf)
of "link": of "link":