mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 19:34:12 +00:00
Check file exists in {.compile.} pragma (#21105)
* Add test * Check file exists before adding it into compilation * Make error message look like other error messages i.e. following the format `error msg: file`
This commit is contained in:
@@ -513,8 +513,11 @@ proc processCompile(c: PContext, n: PNode) =
|
||||
var cf = Cfile(nimname: splitFile(src).name,
|
||||
cname: src, obj: dest, flags: {CfileFlag.External},
|
||||
customArgs: customArgs)
|
||||
extccomp.addExternalFileToCompile(c.config, cf)
|
||||
recordPragma(c, it, "compile", src.string, dest.string, customArgs)
|
||||
if not fileExists(src):
|
||||
localError(c.config, n.info, "cannot find: " & src.string)
|
||||
else:
|
||||
extccomp.addExternalFileToCompile(c.config, cf)
|
||||
recordPragma(c, it, "compile", src.string, dest.string, customArgs)
|
||||
|
||||
proc getStrLit(c: PContext, n: PNode; i: int): string =
|
||||
n[i] = c.semConstExpr(c, n[i])
|
||||
|
||||
5
tests/pragmas/tcompile_missing_file.nim
Normal file
5
tests/pragmas/tcompile_missing_file.nim
Normal file
@@ -0,0 +1,5 @@
|
||||
discard """
|
||||
joinable: false
|
||||
errormsg: "cannot find: noexist.c"
|
||||
"""
|
||||
{.compile: "noexist.c".}
|
||||
Reference in New Issue
Block a user