diff options
| author | ruki <[email protected]> | 2023-09-22 22:54:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-22 22:54:09 +0800 |
| commit | 3d4343f0044601da7f331c4bf879969eb3bd9bf2 (patch) | |
| tree | 84449f0385aba07410ce010dd3738fd5af4b52e9 | |
| parent | cb30d6458a236f498e6b6be917c9f653576577ca (diff) | |
improve to parse gcc deps with modules
| -rw-r--r-- | xmake/modules/core/project/depend.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/tools/gcc/parse_deps.lua | 39 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/gcc.lua | 2 |
5 files changed, 39 insertions, 28 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index c66830521..5e96c7b2a 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -28,8 +28,8 @@ import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"}) import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"}) -- load depfiles -function _load_depfiles(parser, dependinfo, depfiles) - depfiles = parser(depfiles, dependinfo) +function _load_depfiles(parser, dependinfo, depfiles, opt) + depfiles = parser(depfiles, opt) if depfiles then if dependinfo.files then table.join2(dependinfo.files, depfiles) @@ -40,7 +40,7 @@ function _load_depfiles(parser, dependinfo, depfiles) end -- load dependent info from the given file (.d) -function load(dependfile) +function load(dependfile, opt) if os.isfile(dependfile) then -- may be the depend file has been incomplete when if the compilation process is abnormally interrupted @@ -48,19 +48,19 @@ function load(dependfile) if dependinfo then -- attempt to load depfiles from the compilers if dependinfo.depfiles_gcc then - _load_depfiles(parse_deps_gcc, dependinfo, dependinfo.depfiles_gcc) + _load_depfiles(parse_deps_gcc, dependinfo, dependinfo.depfiles_gcc, opt) dependinfo.depfiles_gcc = nil elseif dependinfo.depfiles_cl_json then - _load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json) + _load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json, opt) dependinfo.depfiles_cl_json = nil elseif dependinfo.depfiles_cl then - _load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl) + _load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl, opt) dependinfo.depfiles_cl = nil elseif dependinfo.depfiles_rc then - _load_depfiles(parse_deps_rc, dependinfo, dependinfo.depfiles_rc) + _load_depfiles(parse_deps_rc, dependinfo, dependinfo.depfiles_rc, opt) dependinfo.depfiles_rc = nil elseif dependinfo.depfiles_armcc then - _load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc) + _load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc, opt) dependinfo.depfiles_armcc = nil end return dependinfo diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 828380c15..93525848f 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -721,13 +721,6 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags) return self:program(), table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile) end --- get modules cache directory -function _modules_cachedir(target) - if target and target.autogendir and target:data("cxx.has_modules") then -- we need to ignore option instance - return path.join(target:autogendir(), "rules", "modules", "cache") - end -end - -- make the compile arguments list function compargv(self, sourcefile, objectfile, flags) -- precompiled header? @@ -831,7 +824,6 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) if depfile and os.isfile(depfile) then if dependinfo then dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) - dependinfo.modules_cachedir = _modules_cachedir(opt.target) end -- remove the temporary dependent file diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index ea6f3035a..486c2e7ce 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -43,7 +43,7 @@ function _do_build_file(target, sourcefile, opt) local compflags = compinst:compflags({target = target, sourcefile = sourcefile, configs = opt.configs}) -- load dependent info - local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {}) + local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile, {target = target}) or {}) -- dry run? local dryrun = option.get("dry-run") diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua index d46b5538b..eadcdcd1e 100644 --- a/xmake/modules/private/tools/gcc/parse_deps.lua +++ b/xmake/modules/private/tools/gcc/parse_deps.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.project.config") import("core.project.project") import("core.base.hashset") @@ -44,6 +45,20 @@ function _normailize_dep(dep, projectdir) end end +-- get the path of module mapper +function _get_module_mapper(target) + return path.join(config.buildir(), target:name(), "mapper.txt") +end + +-- get a module from mapper +function _get_module_from_mapper(file, module) + for line in io.lines(file) do + if line:startswith(module .. " ") then + return line:split(" ", {plain = true}) + end + end +end + -- parse depsfiles from string -- -- parse_deps(io.readfile(depfile, {continuation = "\\"})) @@ -97,27 +112,31 @@ function main(depsdata, opt) end end end + + -- translate .c++m module file path -- with c++ modules (gcc): -- CXX_IMPORTS += bar.c++m cat.c++m\ -- -- @see https://github.com/xmake-io/xmake/issues/3000 - opt = opt or {} - if opt.modules_cachedir and line:find("CXX_IMPORTS += ", 1, true) then + -- https://github.com/xmake-io/xmake/issues/4215 + local target = opt and opt.target + if target and line:find("CXX_IMPORTS += ", 1, true) then + local mapperfile = _get_module_mapper(target) local modulefiles = line:split("CXX_IMPORTS += ", plain)[2] if modulefiles then for _, modulefile in ipairs(modulefiles:split(' ', plain)) do - modulefile = modulefile:replace(".c++m", ".gcm", plain) - if #modulefile > 0 then - if not path.is_absolute(modulefile) then - modulefile = path.absolute(modulefile, opt.modules_cachedir) - end - modulefile = _normailize_dep(modulefile, projectdir) - if modulefile then - results:insert(modulefile) + if modulefile:endswith(".c++m") then + local modulekey = modulefile:sub(1, #modulefile - 5) + local moduleinfo = _get_module_from_mapper(mapperfile, modulekey) + local modulepath = moduleinfo[2] + if modulepath then + modulepath = _normailize_dep(modulepath, projectdir) + results:insert(modulepath) end end end end end + return results:to_array() end diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 762810f08..6cc5c29d6 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -123,7 +123,7 @@ function _build_modulefile(target, sourcefile, opt) local dependfile = opt.dependfile local compinst = compiler.load("cxx", {target = target}) local compflags = table.join("-x", "c++", compinst:compflags({sourcefile = sourcefile, target = target})) - local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {}) + local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile, {target = target}) or {}) -- need build this object? local dryrun = option.get("dry-run") |
