summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-15 23:18:52 +0800
committerruki <[email protected]>2021-10-15 23:18:52 +0800
commit091e754eb4d5328385fed59d5c4f92e09355ff51 (patch)
tree5231c613bfc83e71734a727934ad5ebc0c045bd1
parent8ca0e848506b052bcf107c0b65d2f9d04247de26 (diff)
load module deps
-rw-r--r--xmake/rules/c++/modules/build_modules/clang.lua (renamed from xmake/rules/c++/modules/clang.lua)0
-rw-r--r--xmake/rules/c++/modules/build_modules/gcc.lua (renamed from xmake/rules/c++/modules/gcc.lua)0
-rw-r--r--xmake/rules/c++/modules/build_modules/module_parser.lua (renamed from xmake/rules/c++/modules/moduledeps.lua)34
-rw-r--r--xmake/rules/c++/modules/build_modules/msvc.lua (renamed from xmake/rules/c++/modules/msvc.lua)5
-rw-r--r--xmake/rules/c++/modules/xmake.lua8
5 files changed, 40 insertions, 7 deletions
diff --git a/xmake/rules/c++/modules/clang.lua b/xmake/rules/c++/modules/build_modules/clang.lua
index 7037c0767..7037c0767 100644
--- a/xmake/rules/c++/modules/clang.lua
+++ b/xmake/rules/c++/modules/build_modules/clang.lua
diff --git a/xmake/rules/c++/modules/gcc.lua b/xmake/rules/c++/modules/build_modules/gcc.lua
index d5ffbc57b..d5ffbc57b 100644
--- a/xmake/rules/c++/modules/gcc.lua
+++ b/xmake/rules/c++/modules/build_modules/gcc.lua
diff --git a/xmake/rules/c++/modules/moduledeps.lua b/xmake/rules/c++/modules/build_modules/module_parser.lua
index 9ae2b3cab..a3991a5e1 100644
--- a/xmake/rules/c++/modules/moduledeps.lua
+++ b/xmake/rules/c++/modules/build_modules/module_parser.lua
@@ -15,16 +15,27 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file moduledeps.lua
+-- @file module_parser.lua
--
-- imports
import("core.project.depend")
import("utils.progress")
+-- get depend file of module source file
+function _get_dependfile_of_modulesource(target, sourcefile)
+ return target:dependfile(sourcefile)
+end
+
+-- get depend file of module object file
+function _get_dependfile_of_moduleobject(target, sourcefile)
+ local objectfile = target:objectfile(sourcefile)
+ return target:dependfile(objectfile)
+end
+
-- generate module deps for the given file
function _generate_moduledeps(target, sourcefile, opt)
- local dependfile = target:dependfile(sourcefile)
+ local dependfile = _get_dependfile_of_modulesource(target, sourcefile)
depend.on_changed(function ()
-- trace progress
@@ -49,7 +60,8 @@ function _generate_moduledeps(target, sourcefile, opt)
-- save depend data
if module_name then
- io.save(dependfile, {name = module_name, deps = module_deps, file = sourcefile})
+ local dependinfo = {moduleinfo = {name = module_name, deps = module_deps, file = sourcefile}}
+ return dependinfo
end
end, {dependfile = dependfile, files = {sourcefile}})
@@ -62,3 +74,19 @@ function generate(target, sourcebatch, opt)
end
end
+-- load module deps
+function load(target, sourcebatch, opt)
+ local moduledeps
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local dependfile = _get_dependfile_of_modulesource(target, sourcefile)
+ if os.isfile(dependfile) then
+ local data = io.load(dependfile)
+ if data then
+ local moduleinfo = data.moduleinfo
+ moduledeps = moduledeps or {}
+ moduledeps[moduleinfo.name] = moduleinfo
+ end
+ end
+ end
+ return moduledeps
+end
diff --git a/xmake/rules/c++/modules/msvc.lua b/xmake/rules/c++/modules/build_modules/msvc.lua
index 6d100b96f..15be07a41 100644
--- a/xmake/rules/c++/modules/msvc.lua
+++ b/xmake/rules/c++/modules/build_modules/msvc.lua
@@ -21,6 +21,7 @@
-- imports
import("core.tool.compiler")
import("private.action.build.object", {alias = "objectbuilder"})
+import("module_parser")
-- build module files
function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
@@ -79,6 +80,10 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
table.insert(sourcebatch.dependfiles, dependfile)
end
+ -- load moduledeps
+ local moduledeps = module_parser.load(target, sourcebatch, opt)
+ print(moduledeps)
+
-- compile module files to object files
local rootjob = opt.rootjob
local count = 0
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 0e1e99d5d..ad36226eb 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -26,7 +26,7 @@ rule("c++.build.modules")
if sourcebatches then
local sourcebatch = sourcebatches["c++.build.modules"]
if sourcebatch then
- import("moduledeps").generate(target, sourcebatch, opt)
+ import("build_modules.module_parser").generate(target, sourcebatch, opt)
end
end
end)
@@ -38,11 +38,11 @@ rule("c++.build.modules")
-- build module files with batchjobs
local _, toolname = target:tool("cxx")
if toolname:find("clang", 1, true) then
- import("clang").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
+ import("build_modules.clang").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
elseif toolname:find("gcc", 1, true) then
- import("gcc").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
+ import("build_modules.gcc").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
elseif toolname == "cl" then
- import("msvc").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
+ import("build_modules.msvc").build_with_batchjobs(target, batchjobs, sourcebatch, opt)
else
raise("compiler(%s): does not support c++ module!", toolname)
end