Skip to content

Commit 5a580f0

Browse files
authored
Merge pull request #6422 from Arthapz/fix-built-artifacts
(C++ modules support) fix nil built_artifacts error when an error occur during the module sorting
2 parents 755820a + 774eca8 commit 5a580f0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

xmake/rules/c++/modules/scanner.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,11 @@ end
637637
-- topological sort
638638
function sort_modules_by_dependencies(target, modules)
639639

640-
local changed = support.memcache():get2(target:fullname(), "modules.changed")
641-
if changed then
640+
local memcache = support.memcache()
641+
local localcache = support.localcache()
642+
local changed = memcache:get2(target:fullname(), "modules.changed")
643+
local built_artifacts = localcache:get2(target:fullname(), "c++.modules.built_artifacts")
644+
if changed or not built_artifacts then
642645
local built_modules = {}
643646
local built_headerunits = {}
644647
local objectfiles = {}
@@ -751,11 +754,12 @@ function sort_modules_by_dependencies(target, modules)
751754
table.sort(objectfiles)
752755
built_headerunits = table.unique(built_headerunits)
753756

754-
support.localcache():set2(target:fullname(), "c++.modules.built_artifacts", {modules = built_modules, headerunits = built_headerunits, objectfiles = objectfiles})
755-
support.localcache():save()
756-
support.memcache():set2(target:fullname(), "modules.changed", false)
757+
built_artifacts = {modules = built_modules, headerunits = built_headerunits, objectfiles = objectfiles}
758+
localcache:set2(target:fullname(), "c++.modules.built_artifacts", built_artifacts)
759+
localcache:save()
760+
memcache:set2(target:fullname(), "modules.changed", false)
757761
end
758-
local built_artifacts = support.localcache():get2(target:fullname(), "c++.modules.built_artifacts")
762+
assert(built_artifacts, "shouldn't assert here, please open an issue")
759763
return built_artifacts.modules, built_artifacts.headerunits, built_artifacts.objectfiles
760764
end
761765

0 commit comments

Comments
 (0)