summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-04 18:14:47 +0800
committerGitHub <[email protected]>2026-04-04 18:14:47 +0800
commit2976f6c0d0fa7c17262899245cd1da17cd79de48 (patch)
tree6da20e9c2c9a44f675b9349a462cc37bed0185fd
parent4ebfd2f067bffbfe838736ce5aa82df6308057e4 (diff)
parent825ab605b940bcb7be693552112c6be68106e9d0 (diff)
Merge pull request #7435 from Shiffted/improve_module_errors
improve module errors
-rw-r--r--xmake/rules/c++/modules/scanner.lua14
-rw-r--r--xmake/rules/c++/modules/support.lua19
2 files changed, 26 insertions, 7 deletions
diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua
index 2bcee1f12..72adea260 100644
--- a/xmake/rules/c++/modules/scanner.lua
+++ b/xmake/rules/c++/modules/scanner.lua
@@ -385,7 +385,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 +556,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 +883,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
diff --git a/xmake/rules/c++/modules/support.lua b/xmake/rules/c++/modules/support.lua
index 0767c88af..1dd7625bb 100644
--- a/xmake/rules/c++/modules/support.lua
+++ b/xmake/rules/c++/modules/support.lua
@@ -281,15 +281,26 @@ end
function load_moduleinfo(target, sourcefile)
local reused, from = is_reused(target, sourcefile)
local dependfile = reused and from:dependfile(sourcefile) or target:dependfile(sourcefile)
- local moduleinfo
- if os.isfile(dependfile) then
+
+ local is_file = os.isfile(dependfile)
+ if is_file then
local data = io.load(dependfile)
if data then
- moduleinfo = json.decode(data.moduleinfo)
+ local moduleinfo = json.decode(data.moduleinfo)
moduleinfo.sourcefile = sourcefile
+ return moduleinfo
end
end
- return moduleinfo
+
+ local targets = memcache():get("targets")
+ local target_fullname = reused and from:fullname() or target:fullname()
+ if not (targets and targets[target_fullname]) then
+ return nil, string.format("module scanner did not run for target(%s), maybe a custom `on_prepare()` script overrides the modules one", target_fullname)
+ end
+ if not is_file then
+ return nil, string.format("target(%s): dependfile for '%s' not found at '%s'", target_fullname, sourcefile, dependfile)
+ end
+ return nil, string.format("target(%s): failed to load moduleinfo for '%s'", target_fullname, sourcefile)
end
function find_quote_header_file(sourcefile, file)