summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-31 00:45:20 +0800
committerruki <[email protected]>2019-08-30 22:32:04 +0800
commitbb3a62022b775dc837cbd15359d6cc56588921ac (patch)
tree0477b7e94c3e05f37c12a193dd76a6e4726a774c
parentb58574872f3475ac541580ba29068a790a63ecaf (diff)
improve ccache
-rw-r--r--xmake/modules/core/tools/cparser.lua28
-rw-r--r--xmake/modules/core/tools/gcc.lua28
-rw-r--r--xmake/modules/core/tools/nvcc.lua28
-rw-r--r--xmake/modules/core/tools/swiftc.lua28
-rw-r--r--xmake/modules/core/tools/tcc.lua28
-rw-r--r--xmake/modules/private/tools/ccache.lua23
6 files changed, 32 insertions, 131 deletions
diff --git a/xmake/modules/core/tools/cparser.lua b/xmake/modules/core/tools/cparser.lua
index 80b903949..5e34fdd63 100644
--- a/xmake/modules/core/tools/cparser.lua
+++ b/xmake/modules/core/tools/cparser.lua
@@ -23,7 +23,7 @@ import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-import("detect.tools.find_ccache")
+import("private.tools.ccache")
-- init it
function init(self)
@@ -157,31 +157,7 @@ end
-- make the compile arguments list
function _compargv1(self, sourcefile, objectfile, flags)
-
- -- get ccache
- local ccache = nil
- if config.get("ccache") then
- ccache = find_ccache()
- end
-
- -- make argv
- local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
-
- -- uses cache?
- local program = self:program()
- if ccache then
-
- -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
- if not os.isexec(program) then
- argv = table.join(program:split("%s"), argv)
- else
- table.insert(argv, 1, program)
- end
- return ccache, argv
- end
-
- -- no cache
- return program, argv
+ return ccache.cmdargv(self:program(), table.join("-c", flags, "-o", objectfile, sourcefile))
end
-- compile the source file
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 9b96daf91..3574f869c 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -23,7 +23,7 @@ import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-import("detect.tools.find_ccache")
+import("private.tools.ccache")
import("private.tools.gcc.parse_deps")
-- init it
@@ -366,31 +366,7 @@ function _compargv1(self, sourcefile, objectfile, flags)
if (extension:startswith(".h") or extension == ".inl") then
return _compargv1_pch(self, sourcefile, objectfile, flags)
end
-
- -- get ccache
- local ccache = nil
- if config.get("ccache") then
- ccache = find_ccache()
- end
-
- -- make argv
- local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
-
- -- uses cache?
- local program = self:program()
- if ccache then
-
- -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
- if not os.isexec(program) then
- argv = table.join(program:split("%s"), argv)
- else
- table.insert(argv, 1, program)
- end
- return ccache, argv
- end
-
- -- no cache
- return program, argv
+ return ccache.cmdargv(self:program(), table.join("-c", flags, "-o", objectfile, sourcefile))
end
-- compile the source file
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index a4393d994..8c523cf2e 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -24,7 +24,7 @@ import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("core.language.language")
-import("detect.tools.find_ccache")
+import("private.tools.ccache")
import("private.tools.nvcc.parse_deps")
-- init it
@@ -276,31 +276,7 @@ end
-- make the compile arguments list
function _compargv1(self, sourcefile, objectfile, flags)
-
- -- get ccache
- local ccache = nil
- if config.get("ccache") then
- ccache = find_ccache()
- end
-
- -- make argv
- local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
-
- -- uses cache?
- local program = self:program()
- if ccache then
-
- -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
- if not os.isexec(program) then
- argv = table.join(program:split("%s"), argv)
- else
- table.insert(argv, 1, program)
- end
- return ccache, argv
- end
-
- -- no cache
- return program, argv
+ return ccache.cmdargv(self:program(), table.join("-c", flags, "-o", objectfile, sourcefile))
end
-- compile the source file
diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua
index 3f18c0b16..eb6fecb99 100644
--- a/xmake/modules/core/tools/swiftc.lua
+++ b/xmake/modules/core/tools/swiftc.lua
@@ -20,7 +20,7 @@
-- imports
import("core.project.config")
-import("detect.tools.find_ccache")
+import("private.tools.ccache")
-- init it
function init(self)
@@ -203,31 +203,7 @@ end
-- make the compile arguments list
function _compargv1(self, sourcefile, objectfile, flags)
-
- -- get ccache
- local ccache = nil
- if config.get("ccache") then
- ccache = find_ccache()
- end
-
- -- make argv
- local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
-
- -- uses cache?
- local program = self:program()
- if ccache then
-
- -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
- if not os.isexec(program) then
- argv = table.join(program:split("%s"), argv)
- else
- table.insert(argv, 1, program)
- end
- return ccache, argv
- end
-
- -- no cache
- return program, argv
+ return ccache.cmdargv(self.program(), table.join("-c", flags, "-o", objectfile, sourcefile))
end
-- compile the source file
diff --git a/xmake/modules/core/tools/tcc.lua b/xmake/modules/core/tools/tcc.lua
index 51a11df93..1df92293c 100644
--- a/xmake/modules/core/tools/tcc.lua
+++ b/xmake/modules/core/tools/tcc.lua
@@ -23,7 +23,7 @@ import("core.base.option")
import("core.project.config")
import("core.project.project")
import("core.language.language")
-import("detect.tools.find_ccache")
+import("private.tools.ccache")
-- init it
function init(self)
@@ -157,31 +157,7 @@ end
-- make the compile arguments list
function _compargv1(self, sourcefile, objectfile, flags)
-
- -- get ccache
- local ccache = nil
- if config.get("ccache") then
- ccache = find_ccache()
- end
-
- -- make argv
- local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
-
- -- uses cache?
- local program = self:program()
- if ccache then
-
- -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
- if not os.isexec(program) then
- argv = table.join(program:split("%s"), argv)
- else
- table.insert(argv, 1, program)
- end
- return ccache, argv
- end
-
- -- no cache
- return program, argv
+ return ccache.cmdargv(self:program(), table.join("-c", flags, "-o", objectfile, sourcefile))
end
-- compile the source file
diff --git a/xmake/modules/private/tools/ccache.lua b/xmake/modules/private/tools/ccache.lua
index d08b78d2b..5d3e6c6f0 100644
--- a/xmake/modules/private/tools/ccache.lua
+++ b/xmake/modules/private/tools/ccache.lua
@@ -19,12 +19,13 @@
--
-- imports
+import("core.project.config")
import("lib.detect.find_tool")
-- get ccache tool
function _ccache()
local ccache = _g.ccache
- if ccache == nil then
+ if ccache == nil and config.get("ccache") then
ccache = find_tool("ccache")
_g.ccache = ccache or false
end
@@ -36,3 +37,23 @@ function exists()
return _ccache() ~= nil
end
+-- uses ccache to wrap the program and arguments
+--
+-- e.g. ccache program argv
+--
+function cmdargv(program, argv)
+
+ -- uses ccache?
+ local ccache = _ccache()
+ if ccache then
+
+ -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
+ if not os.isexec(program) then
+ argv = table.join(program:split("%s"), argv)
+ else
+ table.insert(argv, 1, program)
+ end
+ return ccache.program, argv
+ end
+ return program, argv
+end