diff options
| author | Arthur LAURENT <[email protected]> | 2025-08-12 11:33:34 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-08-12 11:35:11 +0200 |
| commit | d7fbdd461df84c443c325b15f1a2bf95d7dbe67a (patch) | |
| tree | 910ba37a8dc8d35d7025961c3f22213b513d39b6 | |
| parent | 4f16fd80688304613bdb06e26f8f02bc30183b32 (diff) | |
fix(c++ modules) fix xmake not updating module mapper when module file is removed
4 files changed, 43 insertions, 1 deletions
diff --git a/tests/projects/c++/modules/add_move_remove_module/src/foo.mpp b/tests/projects/c++/modules/add_move_remove_module/src/foo.mpp new file mode 100644 index 000000000..fb1e52d3f --- /dev/null +++ b/tests/projects/c++/modules/add_move_remove_module/src/foo.mpp @@ -0,0 +1,5 @@ +export module foo; + +export { + inline int foo() { return 1; } +} diff --git a/tests/projects/c++/modules/add_move_remove_module/test.lua b/tests/projects/c++/modules/add_move_remove_module/test.lua new file mode 100644 index 000000000..627688f6c --- /dev/null +++ b/tests/projects/c++/modules/add_move_remove_module/test.lua @@ -0,0 +1,28 @@ +inherit(".test_base") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +CLANG_MIN_VER = is_subhost("windows") and "19" or "17" +GCC_MIN_VER = "11" +MSVC_MIN_VER = "14.29" + +function _build(check_outdata) + local flags = "" + if ci_is_running() then + flags = "-vD" + end + os.run("xmake -r " .. flags) + io.writefile("src/bar.mpp", "export module bar;\n export {\n inline int bar() { return 0; }\n}") + os.run("xmake " .. flags) + os.rm("src/bar.mpp") + os.run("xmake " .. flags) + os.mv("src/foo.mpp", "src/bar.mpp") + os.run("xmake " .. flags) + os.mv("src/bar.mpp", "src/foo.mpp") +end + +function main(_) + local clang_options = {compiler = "clang", version = CLANG_MIN_VER, build = _build} + local gcc_options = {compiler = "gcc", version = GCC_MIN_VER, build = _build} + local msvc_options = {version = MSVC_MIN_VER, build = _build} + run_tests(clang_options, gcc_options, msvc_options) +end diff --git a/tests/projects/c++/modules/add_move_remove_module/xmake.lua b/tests/projects/c++/modules/add_move_remove_module/xmake.lua new file mode 100644 index 000000000..aaf2a8bcb --- /dev/null +++ b/tests/projects/c++/modules/add_move_remove_module/xmake.lua @@ -0,0 +1,8 @@ + +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("mod") + set_kind("static") + add_files("src/*.mpp", {public = true}) + diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua index cd23746e2..ff1c0f700 100644 --- a/xmake/rules/c++/modules/scanner.lua +++ b/xmake/rules/c++/modules/scanner.lua @@ -374,6 +374,7 @@ function _patch_sourcebatch(target, sourcebatch) keys = keys .. (#externalmodules > 0 and table.concat(table.orderkeys(externalmodules)) or " ") local md5sum = hash.md5(bytes(keys)) local localcache = support.localcache() + local cached_patched_sourcebatch = localcache:get2(target:fullname(), "patched_sourcebatch") if not cached_patched_sourcebatch or md5sum ~= cached_patched_sourcebatch.md5sum then local reuse = target:policy("build.c++.modules.reuse") or @@ -403,7 +404,6 @@ function _patch_sourcebatch(target, sourcebatch) end table.insert(sourcebatch.sourcefiles, sourcefile) target:fileconfig_add(sourcefile, fileconfig) - memcache:set2(target:fullname(), "modules.changed", true) end sourcebatch.sourcekind = "cxx" sourcebatch.objectfiles = {} @@ -416,6 +416,7 @@ function _patch_sourcebatch(target, sourcebatch) table.insert(sourcebatch.dependfiles, dependfile) end localcache:set2(target:fullname(), "patched_sourcebatch", {sourcefiles = sourcebatch.sourcefiles, dependfiles = sourcebatch.dependfiles, reused = reused, md5sum = md5sum}) + memcache:set2(target:fullname(), "modules.changed", true) else local reused = hashset.from(cached_patched_sourcebatch.reused) for sourcefile, fileconfig in pairs(externalmodules) do |
