diff options
| author | ruki <[email protected]> | 2024-02-18 17:08:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-18 17:08:22 +0800 |
| commit | bc1a30db6041c2c14ca79ccf0aa35b2d550e64e5 (patch) | |
| tree | 0f96654f6213b39d71d605054edda6e5db414593 | |
| parent | af3461d51c86520c6a1a3a8de029b9ea74b80b1c (diff) | |
improve should_build for modules
4 files changed, 38 insertions, 57 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 diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 44787615b..6a912bed4 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -214,9 +214,10 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) end end - local build + local build, dependinfo + local dependfile = target:dependfile(bmifile or opt.objectfile) if provide or compiler_support.has_module_extension(opt.cppfile) then - build = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) + build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) -- needed to detect rebuild of dependencies if provide and build then @@ -231,17 +232,9 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) -- for cpp file we need to check after appendings the flags if build == nil then - build = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) + build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) end - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) - - local dependfile = target:dependfile(bmifile or opt.objectfile) - local dependinfo = depend.load(dependfile) or {} - dependinfo.files = {} - local depvalues = {compinst:program(), compflags} - if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then @@ -276,11 +269,8 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) else os.tryrm(opt.objectfile) -- force rebuild for .cpp files end + depend.save(dependinfo, dependfile) end - - table.insert(dependinfo.files, opt.cppfile) - dependinfo.values = depvalues - depend.save(dependinfo, dependfile) end)} end diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index 173c12fe2..9b8ed1212 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -200,21 +200,14 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) end - local build = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) + local dependfile = target:dependfile(bmifile or opt.objectfile) + local build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) -- needed to detect rebuild of dependencies if provide and build then mark_build(target, name) end - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) - - local dependfile = target:dependfile(bmifile or opt.objectfile) - local dependinfo = depend.load(dependfile) or {} - dependinfo.files = {} - local depvalues = {compinst:program(), compflags} - if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then @@ -251,10 +244,8 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) else os.tryrm(opt.objectfile) -- force rebuild for .cpp files end + depend.save(dependinfo, dependfile) end - table.insert(dependinfo.files, opt.cppfile) - dependinfo.values = depvalues - depend.save(dependinfo, dependfile) end)} end diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 996b9984c..5bb9fc4d8 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -278,9 +278,10 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) end end - local build + local build, dependinfo + local dependfile = target:dependfile(bmifile or opt.objectfile) if provide or compiler_support.has_module_extension(opt.cppfile) then - build = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) + build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) -- needed to detect rebuild of dependencies if provide and build then @@ -295,17 +296,9 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) -- for cpp file we need to check after appendings the flags if build == nil then - build = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) + build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) end - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) - - local dependfile = target:dependfile(bmifile or opt.objectfile) - local dependinfo = depend.load(dependfile) or {} - dependinfo.files = {} - local depvalues = {compinst:program(), compflags} - if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then @@ -340,11 +333,8 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) else os.tryrm(opt.objectfile) -- force rebuild for .cpp files end + depend.save(dependinfo, dependfile) end - - table.insert(dependinfo.files, opt.cppfile) - dependinfo.values = depvalues - depend.save(dependinfo, dependfile) end)} end |
