summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support
diff options
context:
space:
mode:
authorruki <[email protected]>2023-05-14 09:37:16 +0800
committerGitHub <[email protected]>2023-05-14 09:37:16 +0800
commita038cdea407f3403590d75e6fdb46b17c126e551 (patch)
tree0ab305fcf4828079dc54eae601a98e051c162572 /xmake/rules/c++/modules/modules_support
parent34eb729eb862e7415028c84970f3b2c830d95cd9 (diff)
parentc8626425999d369846f5dad8d35567ca240e6780 (diff)
Merge pull request #3739 from xmake-io/modules
improve to install modules #3730
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua5
-rw-r--r--xmake/rules/c++/modules/modules_support/common.lua38
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua5
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua5
4 files changed, 24 insertions, 29 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 8f233b58a..a8df13d28 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -576,15 +576,12 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
local fileconfig = target:fileconfig(cppfile)
if fileconfig and fileconfig.install then
batchjobs:addjob(name .. "_metafile", function(index, total)
- local outputdir = common.get_outputdir(target, cppfile)
- local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info")
+ local metafilepath = common.get_metafile(target, cppfile)
depend.on_changed(function()
progress.show(opt.progress, "${color.build.object}generating.module.metadata %s", name)
local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires)
json.savefile(metafilepath, metadata)
-
end, {dependfile = target:dependfile(metafilepath), files = {cppfile}})
-
end, {rootjob = flushjob})
end
end
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua
index 8996d0ddf..a2e06ff69 100644
--- a/xmake/rules/c++/modules/modules_support/common.lua
+++ b/xmake/rules/c++/modules/modules_support/common.lua
@@ -138,19 +138,18 @@ function get_all_package_modules(target, modules, opt)
local package_modules
-- parse all meta-info and append their informations to the package store
- for name, package in pairs(target:pkgs()) do
+ for _, package in pairs(target:pkgs()) do
package_modules = package_modules or {}
- local modules_dir = path.join(package:installdir(), "modules", name)
- local metafiles = os.files(path.join(modules_dir, "**.meta-info"))
+ local modulesdir = path.join(package:installdir(), "modules")
+ local metafiles = os.files(path.join(modulesdir, "*", "*.meta-info"))
for _, metafile in ipairs(metafiles) do
local modulefile, name, metadata = parse_meta_info(target, metafile)
package_modules[name] = {
- file = path.join(modules_dir, modulefile),
+ file = path.join(modulesdir, modulefile),
metadata = metadata
}
end
end
-
return package_modules
end
@@ -694,8 +693,8 @@ function generate_meta_module_info(target, name, sourcefile, requires)
end
end
- module_metadata._VENDOR_extension = { xmake = { name = name, file = path.filename(sourcefile) }}
-
+ local modulehash = get_modulehash(target, sourcefile)
+ module_metadata._VENDOR_extension = { xmake = { name = name, file = path.join(modulehash, path.filename(sourcefile)) }}
return module_metadata
end
@@ -703,16 +702,12 @@ function install_module_target(target)
local sourcebatch = target:sourcebatches()["c++.build.modules.install"]
if sourcebatch and sourcebatch.sourcefiles then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local prefixdir = path.join("modules", target:name())
- local fileconfig = target:fileconfig(sourcefile)
- if fileconfig and fileconfig.prefixdir then
- prefixdir = fileconfig.prefixdir
- end
local install = (fileconfig and not fileconfig.install) and false or true
if install then
+ local modulehash = get_modulehash(target, sourcefile)
+ prefixdir = path.join("modules", modulehash)
target:add("installfiles", sourcefile, {prefixdir = prefixdir})
- local outputdir = get_outputdir(target,sourcefile)
- local metafile = path.join(outputdir, path.filename(sourcefile) .. ".meta-info")
+ local metafile = get_metafile(target, sourcefile)
if os.exists(metafile) then
target:add("installfiles", metafile, {prefixdir = prefixdir})
end
@@ -721,6 +716,16 @@ function install_module_target(target)
end
end
+function get_modulehash(target, modulepath)
+ local key = path.directory(modulepath) .. target:name()
+ return hash.uuid(key):split("-", {plain = true})[1]:lower()
+end
+
+function get_metafile(target, modulefile)
+ local outputdir = get_outputdir(target, modulefile)
+ return path.join(outputdir, path.filename(modulefile) .. ".meta-info")
+end
+
function get_outputdir(target, module)
local cachedir = modules_cachedir(target)
local modulepath = module.path or module
@@ -731,9 +736,8 @@ function get_outputdir(target, module)
end
return cached
else
- local key = path.directory(modulepath) .. target:name()
- local hashed = hash.uuid(key):split("-", {plain = true})[1]:lower()
- local moduledir = path.join(cachedir, hashed)
+ local modulehash = get_modulehash(target, modulepath)
+ local moduledir = path.join(cachedir, modulehash)
localcache():set2("modules_paths", modulepath, moduledir)
if not os.exists(moduledir) then
os.mkdir(moduledir)
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index 5ebcb1128..a528a57ae 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -390,15 +390,12 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
local fileconfig = target:fileconfig(cppfile)
if fileconfig and fileconfig.install then
batchjobs:addjob(name .. "_metafile", function(index, total)
- local outputdir = common.get_outputdir(target, cppfile)
- local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info")
+ local metafilepath = common.get_metafile(target, cppfile)
depend.on_changed(function()
progress.show((index * 100) / total, "${color.build.object}generating.module.metadata %s", name)
local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires)
json.savefile(metafilepath, metadata)
-
end, {dependfile = target:dependfile(metafilepath), files = {cppfile}})
-
end, {rootjob = opt.rootjob})
end
end
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index e849c24b8..3ee88715c 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -445,15 +445,12 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
local fileconfig = target:fileconfig(cppfile)
if fileconfig and fileconfig.install then
batchjobs:addjob(name .. "_metafile", function(index, total)
- local outputdir = common.get_outputdir(target, cppfile)
- local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info")
+ local metafilepath = common.get_metafile(target, cppfile)
depend.on_changed(function()
progress.show((index * 100) / total, "${color.build.object}generating.module.metadata %s", name)
local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires)
json.savefile(metafilepath, metadata)
-
end, {dependfile = target:dependfile(metafilepath), files = {cppfile}})
-
end, {rootjob = flushjob})
end
end