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:
Jake Leahy 2022-12-16 05:22:45 +11:00 • committed by GitHub
commit d00477dffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -513,6 +513,9 @@ proc processCompile(c: PContext, n: PNode) =
var cf = Cfile(nimname: splitFile(src).name, var cf = Cfile(nimname: splitFile(src).name,
cname: src, obj: dest, flags: {CfileFlag.External}, cname: src, obj: dest, flags: {CfileFlag.External},
customArgs: customArgs) customArgs: customArgs)
if not fileExists(src):
localError(c.config, n.info, "cannot find: " & src.string)
else:
extccomp.addExternalFileToCompile(c.config, cf) extccomp.addExternalFileToCompile(c.config, cf)
recordPragma(c, it, "compile", src.string, dest.string, customArgs) recordPragma(c, it, "compile", src.string, dest.string, customArgs)

View file

@ -0,0 +1,5 @@
discard """
joinable: false
errormsg: "cannot find: noexist.c"
"""
{.compile: "noexist.c".}