summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-02 00:46:11 +0800
committerruki <[email protected]>2022-11-02 00:46:11 +0800
commita9a1788edab12cd63931278ce8d0e4ed02f5046d (patch)
tree2a88cc87646c01048759ad5c0fd33b93ed1aee04
parente639c493025b5d6c5cbdbe588759d34ff8d772b4 (diff)
paser gcc deps with modules
-rw-r--r--xmake/modules/core/project/depend.lua2
-rw-r--r--xmake/modules/core/tools/gcc.lua9
-rw-r--r--xmake/modules/private/tools/gcc/parse_deps.lua26
3 files changed, 33 insertions, 4 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index 632ecd70f..78150c117 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -29,7 +29,7 @@ import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"})
-- load depfiles
function _load_depfiles(parser, dependinfo, depfiles)
- depfiles = parser(depfiles)
+ depfiles = parser(depfiles, dependinfo)
if depfiles then
if dependinfo.files then
table.join2(dependinfo.files, depfiles)
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 897103404..3a916ac9a 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -604,6 +604,13 @@ 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 then -- we need 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?
@@ -621,6 +628,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
os.mkdir(path.directory(objectfile))
-- compile it
+ opt = opt or {}
local depfile = dependinfo and os.tmpfile() or nil
try
{
@@ -706,6 +714,7 @@ 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/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua
index 3b682753c..811119a9a 100644
--- a/xmake/modules/private/tools/gcc/parse_deps.lua
+++ b/xmake/modules/private/tools/gcc/parse_deps.lua
@@ -54,7 +54,7 @@ end
-- src/tbox/libc/string/../../prefix/../config.h \
-- build/iphoneos/x86_64/release/tbox.config.h \
--
--- with c++ modules:
+-- with c++ modules (gcc):
-- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o: src/foo.mpp\
-- build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o gcm.cache/foo.gcm: bar.c++m cat.c++m\
-- foo.c++m: gcm.cache/foo.gcm\
@@ -62,7 +62,7 @@ end
-- gcm.cache/foo.gcm:| build/.objs/dependence/linux/x86_64/release/src/foo.mpp.o\
-- CXX_IMPORTS += bar.c++m cat.c++m\
--
-function main(depsdata)
+function main(depsdata, opt)
-- we assume there is only one valid line
local block = 0
@@ -85,7 +85,7 @@ function main(depsdata)
end
else
includefile = includefile:replace(space_placeholder, ' ', plain)
- includefile = includefile:split("\n", {plain = true})[1]
+ includefile = includefile:split("\n", plain)[1]
if #includefile > 0 then
includefile = _normailize_dep(includefile, projectdir)
if includefile then
@@ -94,5 +94,25 @@ function main(depsdata)
end
end
end
+ -- with c++ modules (gcc):
+ -- CXX_IMPORTS += bar.c++m cat.c++m\
+ opt = opt or {}
+ if opt.modules_cachedir and line:find("CXX_IMPORTS += ", 1, true) then
+ 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)
+ end
+ end
+ end
+ end
+ end
return results:to_array()
end