Skip to content

Commit abe7d65

Browse files
committed
(C++ modules support) cache stealed sourcebatch
1 parent 3db4ea1 commit abe7d65

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ end
416416
function _do_parse(target, sourcebatch)
417417

418418
profiler.enter(target:fullname(), "c++ modules", "scanner", "parse module dependencies and compute dependency graph")
419+
local localcache = support.localcache()
419420
local changed = support.memcache():get2(target:fullname(), "modules.changed")
420421
local modules
421422
if changed then
422423
local moduleinfos = support.load_moduleinfos(target, sourcebatch)
423424
modules = _parse_dependencies_data(target, moduleinfos)
424-
local localcache = support.localcache()
425425
localcache:set2(target:fullname(), "c++.modules", modules)
426426

427427
mapper.feed(target, modules, sourcebatch.sourcefiles)
@@ -440,30 +440,36 @@ function _do_parse(target, sourcebatch)
440440
end
441441
end
442442
end
443-
else
444-
modules = get_modules(target)
445-
end
446-
447-
-- steal from c++.build sourcebatch named modules with cpp extensions
448-
local sourcebatches = target:sourcebatches()
449-
if sourcebatches and sourcebatches["c++.build"] then
450-
local cxx_sourcebatch = sourcebatches["c++.build"]
451-
cxx_sourcebatch.sourcefiles = {}
452-
cxx_sourcebatch.dependfiles = {}
453-
cxx_sourcebatch.objectfiles = {}
454-
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
455-
local module = mapper.get(target, sourcefile)
456-
local insert = true
457-
if module then
458-
insert = not module.name
459-
end
443+
-- steal from c++.build sourcebatch named modules with cpp extensions
444+
local sourcebatches = target:sourcebatches()
445+
if sourcebatches and sourcebatches["c++.build"] then
446+
local cxx_sourcebatch = sourcebatches["c++.build"]
447+
cxx_sourcebatch.sourcefiles = {}
448+
cxx_sourcebatch.dependfiles = {}
449+
cxx_sourcebatch.objectfiles = {}
450+
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
451+
local insert = true
452+
if module then
453+
insert = not module.name
454+
end
460455

461-
if insert then
462-
table.insert(cxx_sourcebatch.sourcefiles, sourcefile)
463-
local objectfile = target:objectfile(sourcefile)
464-
table.insert(cxx_sourcebatch.dependfiles, target:dependfile(objectfile))
465-
table.insert(cxx_sourcebatch.objectfiles, objectfile)
456+
if insert then
457+
table.insert(cxx_sourcebatch.sourcefiles, sourcefile)
458+
local objectfile = target:objectfile(sourcefile)
459+
table.insert(cxx_sourcebatch.dependfiles, target:dependfile(objectfile))
460+
table.insert(cxx_sourcebatch.objectfiles, objectfile)
461+
end
466462
end
463+
localcache:set2("c++.modules", target:fullname() .. ".c++.build.sourcebatch", cxx_sourcebatch)
464+
end
465+
else
466+
modules = get_modules(target)
467+
local cxx_sourcebatch_cached = localcache:get2("c++.modules", target:fullname() .. ".c++.build.sourcebatch")
468+
if cxx_sourcebatch_cached then
469+
local cxx_sourcebatch = target:sourcebatches()["c++.build"]
470+
cxx_sourcebatch.sourcefiles = cxx_sourcebatch_cached.sourcefiles
471+
cxx_sourcebatch.dependfiles = cxx_sourcebatch_cached.dependfiles
472+
cxx_sourcebatch.objectfiles = cxx_sourcebatch_cached.objectfiles
467473
end
468474
end
469475

0 commit comments

Comments
 (0)