summaryrefslogtreecommitdiff
path: root/xmake/scripts/tools
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-04 14:08:40 +0800
committerruki <[email protected]>2015-06-04 14:08:40 +0800
commit1481ec887abef9ce33f4cff93f7a0e6ab04b5741 (patch)
tree609560fefb90242fb8deabd525201e00cd078b12 /xmake/scripts/tools
parent2f468e35a6c681a22308d1c6d1d37764c386c00c (diff)
modify some tool interfaces
Diffstat (limited to 'xmake/scripts/tools')
-rw-r--r--xmake/scripts/tools/cp.lua26
-rw-r--r--xmake/scripts/tools/echo.lua26
-rw-r--r--xmake/scripts/tools/mkdir.lua27
-rw-r--r--xmake/scripts/tools/mv.lua25
-rw-r--r--xmake/scripts/tools/rm.lua27
-rw-r--r--xmake/scripts/tools/rmdir.lua27
-rw-r--r--xmake/scripts/tools/tools.lua14
-rw-r--r--xmake/scripts/tools/verbose.lua28
8 files changed, 154 insertions, 46 deletions
diff --git a/xmake/scripts/tools/cp.lua b/xmake/scripts/tools/cp.lua
index 344e3e1dd..4d400a19b 100644
--- a/xmake/scripts/tools/cp.lua
+++ b/xmake/scripts/tools/cp.lua
@@ -20,11 +20,25 @@
-- @file cp.lua
--
--- cp it
-local pathes = ...
-if pathes and table.getn(pathes) == 2 then
- return os.cp(pathes[1], pathes[2])
+-- define module: cp
+local cp = cp or {}
+
+-- load modules
+local os = require("base/os")
+
+-- the main function
+function cp.main(...)
+
+ -- cp it
+ local pathes = ...
+ if pathes and table.getn(pathes) == 2 then
+ return os.cp(pathes[1], pathes[2])
+ end
+
+ -- failed
+ return false
+
end
--- failed
-return false
+-- return module: cp
+return cp
diff --git a/xmake/scripts/tools/echo.lua b/xmake/scripts/tools/echo.lua
index 2180ce0d4..197cebedc 100644
--- a/xmake/scripts/tools/echo.lua
+++ b/xmake/scripts/tools/echo.lua
@@ -20,11 +20,25 @@
-- @file echo.lua
--
--- echo all
-for _, v in ipairs(...) do
- io.write(string.format("%s ", v:gsub("%%20", " ")))
+-- define module: echo
+local echo = echo or {}
+
+-- load modules
+local io = require("base/io")
+local string = require("base/string")
+
+-- the main function
+function echo.main(...)
+
+ -- echo all
+ for _, v in ipairs(...) do
+ io.write(string.format("%s ", v:gsub("%%20", " ")))
+ end
+ io.write("\n")
+
+ -- ok
+ return true
end
-io.write("\n")
--- ok
-return true
+-- return module: echo
+return echo
diff --git a/xmake/scripts/tools/mkdir.lua b/xmake/scripts/tools/mkdir.lua
index 0cd1eeafe..4b5ac1a7f 100644
--- a/xmake/scripts/tools/mkdir.lua
+++ b/xmake/scripts/tools/mkdir.lua
@@ -20,14 +20,27 @@
-- @file mkdir.lua
--
--- mkdir all
-for _, dir in ipairs(...) do
- if not os.exists(dir) then
- if not os.mkdir(dir) then
- return false
+-- define module: mkdir
+local mkdir = mkdir or {}
+
+-- load modules
+local os = require("base/os")
+
+-- the main function
+function mkdir.main(...)
+
+ -- mkdir all
+ for _, dir in ipairs(...) do
+ if not os.exists(dir) then
+ if not os.mkdir(dir) then
+ return false
+ end
end
end
+
+ -- ok
+ return true
end
--- ok
-return true
+-- return module: mkdir
+return mkdir
diff --git a/xmake/scripts/tools/mv.lua b/xmake/scripts/tools/mv.lua
index 5fc204f7d..2fa2be735 100644
--- a/xmake/scripts/tools/mv.lua
+++ b/xmake/scripts/tools/mv.lua
@@ -20,11 +20,24 @@
-- @file mv.lua
--
--- mv it
-local pathes = ...
-if pathes and table.getn(pathes) == 2 then
- return os.mv(pathes[1], pathes[2])
+-- define module: mv
+local mv = mv or {}
+
+-- load modules
+local os = require("base/os")
+
+-- the main function
+function mv.main(...)
+
+ -- mv it
+ local pathes = ...
+ if pathes and table.getn(pathes) == 2 then
+ return os.mv(pathes[1], pathes[2])
+ end
+
+ -- failed
+ return false
end
--- failed
-return false
+-- return module: mv
+return mv
diff --git a/xmake/scripts/tools/rm.lua b/xmake/scripts/tools/rm.lua
index 7759be01d..b05289b3b 100644
--- a/xmake/scripts/tools/rm.lua
+++ b/xmake/scripts/tools/rm.lua
@@ -20,14 +20,27 @@
-- @file rm.lua
--
--- rm all
-for _, file_or_dir in ipairs(...) do
- if os.exists(file_or_dir) then
- if not os.rm(file_or_dir) then
- return false
+-- define module: rm
+local rm = rm or {}
+
+-- load modules
+local os = require("base/os")
+
+-- the main function
+function rm.main(...)
+
+ -- rm all
+ for _, file_or_dir in ipairs(...) do
+ if os.exists(file_or_dir) then
+ if not os.rm(file_or_dir) then
+ return false
+ end
end
end
+
+ -- ok
+ return true
end
--- ok
-return true
+-- return module: rm
+return rm
diff --git a/xmake/scripts/tools/rmdir.lua b/xmake/scripts/tools/rmdir.lua
index 9df57b1c9..23eb8ca61 100644
--- a/xmake/scripts/tools/rmdir.lua
+++ b/xmake/scripts/tools/rmdir.lua
@@ -20,14 +20,27 @@
-- @file rmdir.lua
--
--- rmdir all
-for _, dir in ipairs(...) do
- if os.isdir(dir) then
- if not os.rmdir(dir) then
- return false
+-- define module: rmdir
+local rmdir = rmdir or {}
+
+-- load modules
+local os = require("base/os")
+
+-- the main function
+function rmdir.main(...)
+
+ -- rmdir all
+ for _, dir in ipairs(...) do
+ if os.isdir(dir) then
+ if not os.rmdir(dir) then
+ return false
+ end
end
end
+
+ -- ok
+ return true
end
--- ok
-return true
+-- return module: rmdir
+return rmdir
diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua
index 09e43dc94..4c0d0da14 100644
--- a/xmake/scripts/tools/tools.lua
+++ b/xmake/scripts/tools/tools.lua
@@ -101,6 +101,12 @@ function tools.load(name, root)
-- check
assert(name)
+ -- get it directly from cache dirst
+ tools._TOOLS = tools._TOOLS or {}
+ if tools._TOOLS[name] then
+ return tools._TOOLS[name]
+ end
+
-- find the tool file path
local toolpath = tools.find(name, root)
@@ -121,10 +127,18 @@ function tools.load(name, root)
tool.init()
end
+ -- save tool to the cache
+ tools._TOOLS[name] = tool
+
-- ok?
return tool
end
end
+-- get the given tool from the current platform
+function tools.get(name)
+ return tools.load(platform.tool(name))
+end
+
-- return module: tools
return tools
diff --git a/xmake/scripts/tools/verbose.lua b/xmake/scripts/tools/verbose.lua
index 0054ba620..a5fa6e606 100644
--- a/xmake/scripts/tools/verbose.lua
+++ b/xmake/scripts/tools/verbose.lua
@@ -20,13 +20,27 @@
-- @file verbose.lua
--
--- verbose all
-if xmake._OPTIONS.verbose then
- for _, v in ipairs(...) do
- io.write(string.format("%s ", v:gsub("%%20", " ")))
+
+-- define module: verbose
+local verbose = verbose or {}
+
+-- load modules
+local io = require("base/io")
+
+-- the main function
+function verbose.main(...)
+
+ -- verbose all
+ if xmake._OPTIONS.verbose then
+ for _, v in ipairs(...) do
+ io.write(string.format("%s ", v:gsub("%%20", " ")))
+ end
+ io.write("\n")
end
- io.write("\n")
+
+ -- ok
+ return true
end
--- ok
-return true
+-- return module: verbose
+return verbose