Skip to content

Commit

Permalink
Merge pull request #3739 from xmake-io/modules
Browse files Browse the repository at this point in the history
improve to install modules #3730
  • Loading branch information
waruqi authored May 14, 2023
2 parents 34eb729 + c862642 commit a038cde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
5 changes: 1 addition & 4 deletions xmake/rules/c++/modules/modules_support/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 21 additions & 17 deletions xmake/rules/c++/modules/modules_support/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -694,25 +693,21 @@ 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

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
Expand All @@ -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
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions xmake/rules/c++/modules/modules_support/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions xmake/rules/c++/modules/modules_support/msvc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a038cde

Please sign in to comment.