diff options
| author | ruki <[email protected]> | 2026-04-07 22:12:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-07 22:12:32 +0800 |
| commit | e384407fde291f889638d078af1054e19826f82f (patch) | |
| tree | d88e6cfae6f6e5c33696c3b74cb544daf1c55b5c | |
| parent | 5271c90286fa0fc80fda695bb399516bb8c6b4b4 (diff) | |
Improve error handling in scanner.lua
Refactor assertions for better error handling and clarity.
| -rw-r--r-- | xmake/rules/c++/modules/scanner.lua | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua index 400e8a0dd..22b96bb0d 100644 --- a/xmake/rules/c++/modules/scanner.lua +++ b/xmake/rules/c++/modules/scanner.lua @@ -283,9 +283,12 @@ function _get_targetdeps_modules(target) fileconfig.undefines = _fileconfig.undefines fileconfig.includedirs = _fileconfig.includedirs end + -- only propagate public/interface defines, not private ones + -- e.g. add_defines("LIB") is private and should not leak into the consumer's BMI + -- @see https://github.com/xmake-io/xmake/issues/7436 fileconfig.defines = table.join(fileconfig.defines or {}, dep:get("defines", {interface = true}) or {}) fileconfig.undefines = table.join(fileconfig.undefines or {}, dep:get("undefines", {interface = true}) or {}) - fileconfig.includedirs = table.join(fileconfig.includedirs or {}, dep:get("includedirs", {interface = true}) or {}, dep:get("sysincludedirs", {interface = true}) or {}) + fileconfig.includedirs = table.join(fileconfig.includedirs or {}, dep:get("includedirs", {interface = true}) or {}) if not dep:is_phony() then if target:namespace() == dep:namespace() then fileconfig.from_dep = dep:name() @@ -385,7 +388,7 @@ function _patch_sourcebatch(target, sourcebatch) local strict = target:policy("build.c++.modules.reuse.strict") or target:policy("build.c++.modules.tryreuse.discriminate_on_defines") local dep = target:dep(fileconfig.from_dep) - assert(dep, "dep target <%s> for <%s> not found", fileconfig.from_dep, target:fullname()) + assert(dep, "dep target(%s) for target(%s) not found", fileconfig.from_dep, target:fullname()) local can_reuse = nocheck or _are_flags_compatible(target, dep, sourcefile, {strict = strict}) if can_reuse then local _reused, from = support.is_reused(dep, sourcefile) @@ -556,7 +559,7 @@ function _schedule_module_dependencies_scan(target, jobgraph, sourcebatch) local changed = memcache:get2(target:fullname(), "modules.changed") if changed then modules = modules or {} - local moduleinfo = support.load_moduleinfo(target, sourcefile) + local moduleinfo = assert(support.load_moduleinfo(target, sourcefile)) local module, headerunitsinfo = _parse_moduleinfo(target, moduleinfo) modules[module.sourcefile] = module for _, headerunitinfo in ipairs(headerunitsinfo) do @@ -883,7 +886,15 @@ end function get_modules(target) local modules = support.localcache():get2(target:fullname(), "c++.modules") - assert(modules, "no modules! (" .. target:fullname() .. ")") + if not modules then + local targets = support.memcache():get("targets") + assert(targets, "module scanner did not run, maybe a custom `on_prepare()` script overrides the modules one.") + + local target_fullname = target:fullname() + assert(targets[target_fullname], "module scanner did not run for target(%s), maybe a custom `on_prepare()` script overrides the modules one.", target_fullname) + assert(targets[target_fullname].finished_parsing, "target(%s): tried getting modules before scanner finished parsing.", target_fullname) + assert(false, "target(%s): no modules found!", target_fullname) + end return modules end |
