summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2022-08-09 12:42:25 +0200
committerArthur LAURENT <[email protected]>2022-08-10 16:52:51 +0200
commiteb4dcb38f468d93cac4e471bce246eea6601ecea (patch)
treea977d6ae7cb3dcb43b915649f39c382f2fc37a79 /xmake/rules/c++/modules
parentb3ed3546872d175fea0f6fa9ac0899b1e218ec00 (diff)
don't rebuild headerunits build by other targets
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua48
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua31
2 files changed, 56 insertions, 23 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 2d6840f28..9c8ac3ac0 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -32,12 +32,23 @@ import("common")
-- e.g
-- -fmodule-file=foo=build/.gens/Foo/rules/modules/cache/foo.pcm
--
-function _add_module_to_mapper(target, bmi)
+function _add_module_to_mapper(target, name, bmi)
local mapflags = _get_mapflags_from_mapper(target)
local modulefileflag = get_modulefileflag(target)
- local mapflag = format("%s%s", modulefileflag, bmi)
- if table.contains(mapflags, mapflag) then
- return
+ local mapflag = format("%s%s=%s", modulefileflag, name, bmi)
+ local tosearch = format("%s%s=", modulefileflag, name)
+ for _, line in ipairs(mapflags) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ local mapflags = _get_mapflags_from_mapper(dep)
+ for _, line in ipairs(mapflags_) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
end
table.insert(mapflags, mapflag)
common.localcache():set2(_mapper_cachekey(target), mapflags)
@@ -50,14 +61,25 @@ end
-- add a header unit into the mapper
--
-- e.g
--- -fmodule-file=build/.gens/Foo/rules/modules/cache/foo.hpp.pcm
+-- -fmodule-file=foo.hpp=build/.gens/Foo/rules/modules/cache/foo.hpp.pcm
--
-function _add_headerunit_to_mapper(target, bmi)
+function _add_headerunit_to_mapper(target, name, bmi)
local mapflags = _get_mapflags_from_mapper(target)
local modulefileflag = get_modulefileflag(target)
- local mapflag = format("%s%s", modulefileflag, bmi)
- if table.contains(mapflags, mapflag) then
- return
+ local mapflag = format("%s%s=%s", modulefileflag, bmi)
+ local tosearch = format("%s%s=", modulefileflag, name)
+ for _, line in ipairs(mapflags) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ local mapflags = _get_mapflags_from_mapper(dep)
+ for _, line in ipairs(mapflags_) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
end
table.insert(mapflags, mapflag)
common.localcache():set(_mapper_cachekey(target), mapflags)
@@ -412,8 +434,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args))
os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, {bmifile}, {"-c", "-o", objectfile}))
end, {dependfile = target:dependfile(bmifile), files = {provide.sourcefile}})
- _add_module_to_mapper(target, bmifile)
- target:add("cxxflags", modulefileflag .. bmifile, {force = true})
+ _add_module_to_mapper(target, name, bmifile)
+ target:add("cxxflags", modulefileflag .. name .. "=" .. bmifile, {force = true})
end)
if m.requires then
moduleinfo.deps = table.keys(m.requires)
@@ -469,8 +491,8 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args))
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, {bmifile}, {"-c", "-o", objectfile}))
batchcmds:add_depfiles(provide.sourcefile)
- _add_module_to_mapper(target, bmifile)
- target:add("cxxflags", modulefileflag .. bmifile, {force = true})
+ _add_module_to_mapper(target, headerunit.name, bmifile)
+ target:add("cxxflags", modulefileflag .. name .. "=" .. bmifile, {force = true})
depmtime = math.max(depmtime, os.mtime(bmifile))
end
end
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index 46a20993e..5a89af95f 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -33,11 +33,22 @@ import("common")
-- /headerUnit:angle Foo=build/.gens/Foo/rules/modules/cache/Foo.ifc
-- /headerUnit:angle glm/mat4x4.hpp=Users\arthu\AppData\Local\.xmake\packages\g\glm\0.9.9+8\91454f3ee0be416cb9c7452970a2300f\include\glm\mat4x4.hpp.ifc
--
-function _add_module_to_mapper(target, argument, module)
+function _add_module_to_mapper(target, argument, module, bmifile)
local mapflags = _get_mapflags_from_mapper(target)
- local mapflag = format("%s %s", argument, module)
- if table.contains(mapflags, mapflag) then
- return
+ local mapflag = format("%s %s=%s", argument, module, bmifile)
+ local tosearch = format("%s %s=", argument, module)
+ for _, line in ipairs(mapflags) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ local mapflags_ = _get_mapflags_from_mapper(dep)
+ for _, line in ipairs(mapflags_) do
+ if line:startswith(tosearch) then
+ return
+ end
+ end
end
table.insert(mapflags, mapflag)
common.localcache():set(_mapper_cachekey(target), mapflags)
@@ -190,7 +201,7 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits,
end
end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
- _add_module_to_mapper(target, headerunitflag .. ":angle", headerunit.name .. "=" .. path.translate(bmifile))
+ _add_module_to_mapper(target, headerunitflag .. ":angle", headerunit.name, path.translate(bmifile))
end, {rootjob = flushjob})
_add_objectfile_to_link_arguments(target, objectfile)
end
@@ -225,7 +236,7 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
_add_objectfile_to_link_arguments(target, objectfile)
end
- _add_module_to_mapper(target, headerunitflag .. ":angle", headerunit.name .. "=" .. path.translate(bmifile))
+ _add_module_to_mapper(target, headerunitflag .. ":angle", headerunit.name, path.translate(bmifile))
depmtime = math.max(depmtime, os.mtime(bmifile))
end
batchcmds:set_depmtime(depmtime)
@@ -285,8 +296,8 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits,
common.localcache():set2(headerunit.name, "building", false)
end
+ _add_module_to_mapper(target, headerunitflag .. headerunit.type, headerunit.name, path.translate(bmifile))
end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
- _add_module_to_mapper(target, headerunitflag .. headerunit.type, headerunit.name .. "=" .. path.translate(bmifile))
end, {rootjob = flushjob})
_add_objectfile_to_link_arguments(target, objectfile)
end
@@ -332,7 +343,7 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits,
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
batchcmds:add_depfiles(headerunit.path)
- _add_module_to_mapper(target, headerunitflag .. headerunit.type, headerunit.name .. "=" .. path.translate(bmifile))
+ _add_module_to_mapper(target, headerunitflag .. headerunit.type, headerunit.name, path.translate(bmifile))
_add_objectfile_to_link_arguments(target, objectfile)
depmtime = math.max(depmtime, os.mtime(bmifile))
@@ -408,7 +419,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
end, {dependfile = target:dependfile(bmifile), files = {provide.sourcefile}})
local flag = name .. "=" .. path.translate(bmifile)
- _add_module_to_mapper(target, referenceflag, flag)
+ _add_module_to_mapper(target, referenceflag, name, path.translate(bmifile))
target:add("cxxflags", {referenceflag, flag}, {force = true, expand = false})
end)
if m.requires then
@@ -473,7 +484,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
batchcmds:add_depfiles(provide.sourcefile)
local flag = name .. "=" .. bmifile
- _add_module_to_mapper(target, referenceflag, flag)
+ _add_module_to_mapper(target, referenceflag, name, bmifile)
target:add("cxxflags", {referenceflag, flag}, {force = true, expand = false})
depmtime = math.max(depmtime, os.mtime(bmifile))
end