diff options
| author | ruki <[email protected]> | 2015-05-31 11:32:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-31 11:32:38 +0800 |
| commit | 529a623ed4eadb802b5174db0957c595af32d5e5 (patch) | |
| tree | 361a0e7fd30f73af0395886e098d2a3ca2b7164e /xmake/scripts | |
| parent | ad9d27ef9a74603063755857b0a0191e486c1e8d (diff) | |
add some tools
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_lua.lua | 21 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 6 | ||||
| -rw-r--r-- | xmake/scripts/base/option.lua | 37 | ||||
| -rw-r--r-- | xmake/scripts/tool/cp.lua | 30 | ||||
| -rw-r--r-- | xmake/scripts/tool/echo.lua | 7 | ||||
| -rw-r--r-- | xmake/scripts/tool/mkdir.lua | 31 | ||||
| -rw-r--r-- | xmake/scripts/tool/mv.lua | 30 | ||||
| -rw-r--r-- | xmake/scripts/tool/rm.lua | 31 | ||||
| -rw-r--r-- | xmake/scripts/tool/rmdir.lua | 31 |
9 files changed, 215 insertions, 9 deletions
diff --git a/xmake/scripts/action/_lua.lua b/xmake/scripts/action/_lua.lua index 6389a6925..34f45e84f 100644 --- a/xmake/scripts/action/_lua.lua +++ b/xmake/scripts/action/_lua.lua @@ -25,8 +25,10 @@ local _lua = _lua or {} -- load modules local os = require("base/os") +local path = require("base/path") local utils = require("base/utils") local config = require("base/config") +local string = require("base/string") -- done the given config function _lua.done() @@ -41,13 +43,29 @@ function _lua.done() end -- the arguments - local arguments = options.arguments + local arguments = options.arguments or {} + if type(arguments) ~= "table" then + arguments = {} + end + + -- init new environment + local newenv = {} + setmetatable(newenv, {__index = _G}) + newenv.os = os + newenv.path = path + newenv.utils = utils + newenv.string = string -- is string script? if options.string then + + -- trace + utils.verbose("script: %s", options.script) + -- load and run string local script = loadstring(options.script) if script then + setfenv(script, newenv) return script(arguments) end else @@ -66,6 +84,7 @@ function _lua.done() if os.isfile(file) then local script = loadfile(file) if script then + setfenv(script, newenv) return script(arguments) end end diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 1df26898a..2d4e0ea10 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -341,8 +341,8 @@ local menu = , {'h', "help", "k", nil, "Print this help message and exit." } , {} - , {nil, "target", "v", "all", "Run the given target." } - , {nil, "arguments", "v", nil, "The target arguments" } + , {nil, "target", "v", nil, "Run the given target." } + , {nil, "arguments", "vs", nil, "The target arguments" } } } @@ -373,7 +373,7 @@ local menu = , " - The script name from the xmake tool directory" , " - The script file" , " - The script string" } - , {nil, "arguments", "v", nil, "The script arguments" } + , {nil, "arguments", "vs", nil, "The script arguments" } } } } diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua index 3da4850c0..5393e0f9b 100644 --- a/xmake/scripts/base/option.lua +++ b/xmake/scripts/base/option.lua @@ -240,19 +240,49 @@ function option.init(argv, menu) local opt = nil for _, o in ipairs(menu[xmake._OPTIONS._ACTION or "main"].options) do + -- the mode + local mode = o[3] + + -- the name + local name = o[2] + -- check - assert(o and (o[3] ~= "v" or o[2])) + assert(o and ((mode ~= "v" and mode ~= "vs") or name)) -- is value and with name? - if o[3] == "v" and o[2] and not xmake._OPTIONS[o[2]] then + if mode == "v" and name and not xmake._OPTIONS[name] then opt = o break + -- is values and with name? + elseif mode == "vs" and name then + opt = o + break end end -- ok? save this value with name opt[2] if opt then - xmake._OPTIONS[opt[2]] = key + + -- the mode + local mode = opt[3] + + -- the name + local name = opt[2] + + -- save value + if mode == "v" then + xmake._OPTIONS[name] = key + elseif mode == "vs" then + -- the option + local o = xmake._OPTIONS[name] + if not o then + xmake._OPTIONS[name] = {} + o = xmake._OPTIONS[name] + end + + -- append value + o[table.getn(o) + 1] = key + end else -- invalid option print("invalid option: " .. arg) @@ -319,6 +349,7 @@ function option.print_menu(action) -- print usage if action.usage then + print("") print("Usage: " .. action.usage) end diff --git a/xmake/scripts/tool/cp.lua b/xmake/scripts/tool/cp.lua new file mode 100644 index 000000000..344e3e1dd --- /dev/null +++ b/xmake/scripts/tool/cp.lua @@ -0,0 +1,30 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file cp.lua +-- + +-- cp it +local pathes = ... +if pathes and table.getn(pathes) == 2 then + return os.cp(pathes[1], pathes[2]) +end + +-- failed +return false diff --git a/xmake/scripts/tool/echo.lua b/xmake/scripts/tool/echo.lua index df4f7fa98..eb6cff396 100644 --- a/xmake/scripts/tool/echo.lua +++ b/xmake/scripts/tool/echo.lua @@ -20,8 +20,11 @@ -- @file echo.lua -- --- echo it -print(...) +-- echo all +for _, v in ipairs(...) do + io.write(string.format("%s ", v)) +end +io.write("\n") -- ok return true diff --git a/xmake/scripts/tool/mkdir.lua b/xmake/scripts/tool/mkdir.lua new file mode 100644 index 000000000..b0c41b310 --- /dev/null +++ b/xmake/scripts/tool/mkdir.lua @@ -0,0 +1,31 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file mkdir.lua +-- + +-- mkdir all +for _, dir in ipairs(...) do + if not os.exists(dir) then + os.mkdir(dir) + end +end + +-- ok +return true diff --git a/xmake/scripts/tool/mv.lua b/xmake/scripts/tool/mv.lua new file mode 100644 index 000000000..5fc204f7d --- /dev/null +++ b/xmake/scripts/tool/mv.lua @@ -0,0 +1,30 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file mv.lua +-- + +-- mv it +local pathes = ... +if pathes and table.getn(pathes) == 2 then + return os.mv(pathes[1], pathes[2]) +end + +-- failed +return false diff --git a/xmake/scripts/tool/rm.lua b/xmake/scripts/tool/rm.lua new file mode 100644 index 000000000..370cffd7f --- /dev/null +++ b/xmake/scripts/tool/rm.lua @@ -0,0 +1,31 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file rm.lua +-- + +-- rm all +for _, file_or_dir in ipairs(...) do + if os.exists(file_or_dir) then + os.rm(file_or_dir) + end +end + +-- ok +return true diff --git a/xmake/scripts/tool/rmdir.lua b/xmake/scripts/tool/rmdir.lua new file mode 100644 index 000000000..b9b4944a7 --- /dev/null +++ b/xmake/scripts/tool/rmdir.lua @@ -0,0 +1,31 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file rmdir.lua +-- + +-- rmdir all +for _, dir in ipairs(...) do + if os.isdir(dir) then + os.rmdir(dir) + end +end + +-- ok +return true |
