summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/project/depend.lua2
-rw-r--r--xmake/modules/core/tools/cl.lua3
-rw-r--r--xmake/modules/core/tools/gcc.lua14
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/cache/build_cache.lua35
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua4
-rw-r--r--xmake/modules/private/tools/cl/parse_deps_json.lua45
-rw-r--r--xmake/modules/private/tools/gcc/parse_deps.lua28
8 files changed, 111 insertions, 22 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/cl.lua b/xmake/modules/core/tools/cl.lua
index 31bdce256..7905668a9 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -514,6 +514,7 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
+ opt = opt or {}
local function _compile_fallback()
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
return vstool.iorunv(program, argv, {envs = self:runenvs()})
@@ -524,7 +525,7 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
target = opt.target, tool = self, remote = true})
- elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then
+ elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true}))
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 1c3a29c01..a3888ac34 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -555,6 +555,7 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
+ opt = opt or {}
local program, argv = compargv(self, sourcefile, objectfile, compflags)
local function _compile_fallback()
return os.iorunv(program, argv, {envs = self:runenvs()})
@@ -564,7 +565,7 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
cppinfo = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self, remote = true})
- elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then
+ elseif build_cache.is_enabled(opt.target) and build_cache.is_supported(self:kind()) then
cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),
preprocess = _preprocess, compile = _compile_preprocessed_file, compile_fallback = _compile_fallback,
tool = self})
@@ -603,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 and target:data("cxx.has_modules") 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?
@@ -614,12 +622,13 @@ function compargv(self, sourcefile, objectfile, flags)
end
-- compile the source file
-function compile(self, sourcefile, objectfile, dependinfo, flags)
+function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
+ opt = opt or {}
local depfile = dependinfo and os.tmpfile() or nil
try
{
@@ -705,6 +714,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags)
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/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index a89b149ff..00493cf4d 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -67,7 +67,7 @@ function _do_build_file(target, sourcefile, opt)
-- exists ccache or distcc?
-- we just show cache/distc to avoid confusion with third-party ccache/distcc
local prefix = ""
- if build_cache.is_enabled() and build_cache.is_supported(sourcekind) then
+ if build_cache.is_enabled(target) and build_cache.is_supported(sourcekind) then
prefix = "cache "
end
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 4cb1be5ca..24124417c 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -21,12 +21,23 @@
-- imports
import("core.base.bytes")
import("core.base.hashset")
+import("core.cache.memcache")
import("core.project.config")
import("core.project.policy")
import("core.project.project")
import("private.service.client_config")
import("private.service.remote_cache.client", {alias = "remote_cache_client"})
+-- get memcache
+function _memcache()
+ local cache = _g.memcache
+ if not cache then
+ cache = memcache.cache("build_cache")
+ _g.memcache = cache
+ end
+ return cache
+end
+
-- get exist info
function _get_existinfo()
local existinfo = _g.existinfo
@@ -38,21 +49,27 @@ function _get_existinfo()
end
-- is enabled?
-function is_enabled()
- local build_cache = _g.build_cache
- if build_cache == nil then
- if build_cache == nil and os.isfile(os.projectfile()) then
+function is_enabled(target)
+ local key = tostring(target or "all")
+ local result = _memcache():get2("enabled", key)
+ if result == nil then
+ -- target may be option instance
+ if target and target.policy then
+ result = target:policy("build.ccache")
+ end
+ if result == nil and os.isfile(os.projectfile()) then
local policy = project.policy("build.ccache")
if policy ~= nil then
- build_cache = policy
+ result = policy
end
end
- if build_cache == nil then
- build_cache = config.get("ccache") or false
+ if result == nil then
+ result = config.get("ccache")
end
- _g.build_cache = build_cache
+ result = result or false
+ _memcache():set2("enabled", key)
end
- return build_cache or false
+ return result
end
-- is supported?
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index 50bf82f21..38b2145ef 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -244,7 +244,7 @@ function distcc_build_client:compile(program, argv, opt)
-- get objectfile from the build cache first
local cached = false
local cachekey
- if build_cache.is_enabled() then
+ if build_cache.is_enabled(opt.target) then
cachekey = build_cache.cachekey(program, cppinfo, opt.envs)
local objectfile_cached, objectfile_infofile = build_cache.get(cachekey)
if objectfile_cached then
@@ -341,7 +341,7 @@ function distcc_build_client:compile(program, argv, opt)
else
compile(program, cppinfo, opt)
end
- if build_cache.is_enabled() then
+ if build_cache.is_enabled(opt.target) then
local cachekey = build_cache.cachekey(program, cppinfo, opt.envs)
if cachekey then
local extrainfo
diff --git a/xmake/modules/private/tools/cl/parse_deps_json.lua b/xmake/modules/private/tools/cl/parse_deps_json.lua
index f274dc382..459a8b112 100644
--- a/xmake/modules/private/tools/cl/parse_deps_json.lua
+++ b/xmake/modules/private/tools/cl/parse_deps_json.lua
@@ -80,15 +80,54 @@ function _normailize_dep(dep, projectdir)
end
-- parse depsfiles from string
+--
+--[[
+{
+ "Version": "1.2",
+ "Data": {
+ "Source": "c:\users\ruki\desktop\user_headerunit\src\main.cpp",
+ "ProvidedModule": "",
+ "Includes": [],
+ "ImportedModules": [
+ {
+ "Name": "hello",
+ "BMI": "c:\users\ruki\desktop\user_headerunit\src\hello.ifc"
+ }
+ ],
+ "ImportedHeaderUnits": [
+ {
+ "Header": "c:\users\ruki\desktop\user_headerunit\src\header.hpp",
+ "BMI": "c:\users\ruki\desktop\user_headerunit\src\header.hpp.ifc"
+ }
+ ]
+ }
+}]]
function main(depsdata)
-- decode json data first
depsdata = json.decode(depsdata)
-- get includes
- local includes
- if depsdata and depsdata.Data then
- includes = depsdata.Data.Includes
+ local data
+ if depsdata then
+ data = depsdata.Data
+ end
+ if data then
+ includes = data.Includes
+ for _, item in ipairs(data.ImportedModules) do
+ local bmifile = item.BMI
+ if bmifile then
+ includes = includes or {}
+ table.insert(includes, bmifile)
+ end
+ end
+ for _, item in ipairs(data.ImportedHeaderUnits) do
+ local bmifile = item.BMI
+ if bmifile then
+ includes = includes or {}
+ table.insert(includes, bmifile)
+ end
+ end
end
-- translate it
diff --git a/xmake/modules/private/tools/gcc/parse_deps.lua b/xmake/modules/private/tools/gcc/parse_deps.lua
index 3b682753c..3bc067861 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,27 @@ function main(depsdata)
end
end
end
+ -- with c++ modules (gcc):
+ -- CXX_IMPORTS += bar.c++m cat.c++m\
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/3000
+ 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