summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support/builder.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-18 17:08:22 +0800
committerruki <[email protected]>2024-02-18 17:08:22 +0800
commitbc1a30db6041c2c14ca79ccf0aa35b2d550e64e5 (patch)
tree0f96654f6213b39d71d605054edda6e5db414593 /xmake/rules/c++/modules/modules_support/builder.lua
parentaf3461d51c86520c6a1a3a8de029b9ea74b80b1c (diff)
improve should_build for modules
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/builder.lua')
-rw-r--r--xmake/rules/c++/modules/modules_support/builder.lua40
1 files changed, 25 insertions, 15 deletions
diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua
index 505ba07fb..523a421b0 100644
--- a/xmake/rules/c++/modules/modules_support/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/builder.lua
@@ -142,9 +142,16 @@ end
-- should we build this module or headerunit ?
function should_build(target, sourcefile, bmifile, opt)
+ opt = opt or {}
+ local objectfile = opt.objectfile
+ local compinst = compiler.load("cxx", {target = target})
+ local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
+ local dependfile = target:dependfile(bmifile or objectfile)
+ local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {})
+ local depvalues = {compinst:program(), compflags}
-- force rebuild a module if any of its module dependency is rebuilt
- local requires = opt and opt.requires
+ local requires = opt.requires
if requires then
for required, _ in table.orderpairs(requires) do
local m = get_from_target_mapper(target, required)
@@ -152,34 +159,37 @@ function should_build(target, sourcefile, bmifile, opt)
local rebuild = (m.opt and m.opt.target) and compiler_support.memcache():get2("should_build_in_" .. m.opt.target:name(), m.key)
or compiler_support.memcache():get2("should_build_in_" .. target:name(), m.key)
if rebuild then
- return true
+ dependinfo.files = {}
+ table.insert(dependinfo.files, sourcefile)
+ dependinfo.values = depvalues
+ return true, dependinfo
end
end
end
end
-- reused
- if opt and opt.name then
+ if opt.name then
local m = get_from_target_mapper(target, opt.name)
if m and m.opt and m.opt.target then
- return compiler_support.memcache():get2("should_build_in_" .. m.opt.target:name(), m.key)
+ local rebuild = compiler_support.memcache():get2("should_build_in_" .. m.opt.target:name(), m.key)
+ if rebuild then
+ dependinfo.files = {}
+ table.insert(dependinfo.files, sourcefile)
+ dependinfo.values = depvalues
+ end
+ return rebuild, dependinfo
end
end
- -- or rebuild it if the file changed
- local objectfile = opt.objectfile
- local dryrun = option.get("dry-run")
- local compinst = compiler.load("cxx", {target = target})
- local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
-
- local dependfile = target:dependfile(bmifile or objectfile)
- local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {})
-
-- need build this object?
- local depvalues = {compinst:program(), compflags}
+ local dryrun = option.get("dry-run")
local lastmtime = os.isfile(bmifile or objectfile) and os.mtime(dependfile) or 0
if dryrun or depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then
- return true
+ dependinfo.files = {}
+ table.insert(dependinfo.files, sourcefile)
+ dependinfo.values = depvalues
+ return true, dependinfo
end
return false
end