diff options
| author | Arthur LAURENT <[email protected]> | 2022-08-05 04:41:46 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2022-08-05 04:41:46 +0200 |
| commit | 9051b99608fe2f339eea7ac4c9eab8b799e230df (patch) | |
| tree | 0c366c9a9592ac3c311d0564cf33dbea6f8d9542 | |
| parent | b370625fbf37fe5e957677ec4c04ec3503d0da90 (diff) | |
Move headerunits extracting into a dedicated function
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/common.lua | 31 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/xmake.lua | 28 |
3 files changed, 34 insertions, 27 deletions
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index a8b36e0fa..18647ded1 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -26,6 +26,7 @@ import("core.tool.compiler") import("core.cache.memcache", {alias = "_memcache"}) import("core.project.project") import("lib.detect.find_file") +import("stl_headers") -- get memcache function memcache() @@ -53,12 +54,38 @@ function modules_cachedir(target) return cachedir end +-- get headerunits info +function get_headerunits(target, sourcebatch) + local headerunits + local stl_headerunits + local modules = target:data("cxx.modules") + for _, objectfile in ipairs(sourcebatch.objectfiles) do + local m = modules[objectfile] + if m then + for name, r in pairs(m.requires) do + if r.method ~= "by-name" then + local unittype = r.method == "include-angle" and ":angle" or ":quote" + + if stl_headers.is_stl_header(name) then + stl_headerunits = stl_headerunits or {} + table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) + else + headerunits = headerunits or {} + table.insert(headerunits, {name = name, path = r.path, type = unittype}) + end + end + end + end + end + return headerunits, stl_headerunits +end + -- patch sourcebatch function patch_sourcebatch(target, sourcebatch, opt) local cachedir = modules_cachedir(target) sourcebatch.sourcekind = "cxx" - sourcebatch.objectfiles = sourcebatch.objectfiles or {} - sourcebatch.dependfiles = sourcebatch.dependfiles or {} + sourcebatch.objectfiles = {} + sourcebatch.dependfiles = {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = target:objectfile(sourcefile) local dependfile = target:dependfile(objectfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 04d34f02c..2c3818995 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -183,7 +183,7 @@ function generate_user_headerunits(target, batchcmds, headerunits, opt) local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) batchcmds:mkdir(path.directory(objectfile)) - local args = {headernameflag .. headerunit.type, headerunit.path, ifcoutputflag, outputdir, "/Fo" .. objectfile} + local args = {headernameflag .. headerunit.type, path.normalize(headerunit.path), ifcoutputflag, outputdir, "/Fo" .. objectfile} batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name) batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 7c68f25e0..45ba38ca8 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -82,35 +82,14 @@ rule("c++.build.modules.builder") return end - -- patch sourcebatch import("modules_support.common") import("modules_support.stl_headers") - sourcebatch.objectfiles = {} - sourcebatch.dependfiles = {} + + -- patch sourcebatch common.patch_sourcebatch(target, sourcebatch, opt) -- get headerunits info - local headerunits - local stl_headerunits - local modules = target:data("cxx.modules") - for _, objectfile in ipairs(sourcebatch.objectfiles) do - local m = modules[objectfile] - if m then - for name, r in pairs(m.requires) do - if r.method ~= "by-name" then - local unittype = r.method == "include-angle" and ":angle" or ":quote" - - if stl_headers.is_stl_header(name) then - stl_headerunits = stl_headerunits or {} - table.insert(stl_headerunits, {name = name, path = r.path, type = unittype}) - else - headerunits = headerunits or {} - table.insert(headerunits, {name = name, path = r.path, type = unittype,}) - end - end - end - end - end + local headerunits, stl_headerunits = common.get_headerunits(target, sourcebatch) -- generate headerunits local headerunits_flags @@ -132,6 +111,7 @@ rule("c++.build.modules.builder") end -- topological sort + local modules = target:data("cxx.modules") local objectfiles = common.sort_modules_by_dependencies(sourcebatch.objectfiles, modules) modules_support.build_modules(target, batchcmds, objectfiles, modules, opt) end) |
