compile pragma: cache the result sooner (#19554)

extccomp.addExternalFileToCompile() relies on hashes to decide whether
an external C file needs recompilation or not.

Due to short-circuit evaluation of boolean expressions, the procedure
that generates a corresponding hash file is not called the first time an
external file is compiled, so an avoidable recompilation is triggered
the next build.

This patch fixes that by moving the proc call with a desired side
effect from its boolean expression, so it's executed unconditionally.
This commit is contained in:
Ștefan Talpalaru 2022-02-24 08:31:40 +01:00 • committed by GitHub
commit 0c915b5e47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -649,8 +649,10 @@ proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool =
close(f) close(f)
proc addExternalFileToCompile*(conf: ConfigRef; c: var Cfile) = proc addExternalFileToCompile*(conf: ConfigRef; c: var Cfile) =
# we want to generate the hash file unconditionally
let extFileChanged = externalFileChanged(conf, c)
if optForceFullMake notin conf.globalOptions and fileExists(c.obj) and if optForceFullMake notin conf.globalOptions and fileExists(c.obj) and
not externalFileChanged(conf, c): not extFileChanged:
c.flags.incl CfileFlag.Cached c.flags.incl CfileFlag.Cached
else: else:
# make sure Nim keeps recompiling the external file on reruns # make sure Nim keeps recompiling the external file on reruns