diff options
| author | ruki <[email protected]> | 2015-05-30 22:41:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-30 22:41:02 +0800 |
| commit | ad9d27ef9a74603063755857b0a0191e486c1e8d (patch) | |
| tree | 6284b7af6b5d8460c1609d96c9b379c4dcf637fe /xmake/scripts | |
| parent | 87683f4d3ba6d41c0b8900244e05dee4f84e2e62 (diff) | |
add run target and lua actions
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/_xmake_main.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/action/_create.lua | 39 | ||||
| -rw-r--r-- | xmake/scripts/action/_install.lua | 39 | ||||
| -rw-r--r-- | xmake/scripts/action/_lua.lua | 80 | ||||
| -rw-r--r-- | xmake/scripts/action/_run.lua | 39 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 70 | ||||
| -rw-r--r-- | xmake/scripts/tool/echo.lua | 27 |
7 files changed, 295 insertions, 3 deletions
diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua index 2aeeef35f..a81c37511 100644 --- a/xmake/scripts/_xmake_main.lua +++ b/xmake/scripts/_xmake_main.lua @@ -28,12 +28,12 @@ xmake._ARCH = _ARCH xmake._VERSION = "XMake v1.0.1" xmake._PROGRAM_DIR = _PROGRAM_DIR xmake._PROJECT_DIR = _PROJECT_DIR -xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/" +xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts" xmake._OPTIONS = {} xmake._CONFIGS = {} -- init package path -package.path = xmake._SCRIPTS_DIR .. "?.lua;" .. package.path +package.path = xmake._SCRIPTS_DIR .. "/?.lua;" .. package.path -- load modules local main = require("base/main") diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua new file mode 100644 index 000000000..f60666d71 --- /dev/null +++ b/xmake/scripts/action/_create.lua @@ -0,0 +1,39 @@ +--!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 _create.lua +-- + +-- define module: _create +local _create = _create or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") + +-- done the given config +function _create.done() + + + -- ok + return true +end + +-- return module: _create +return _create diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua new file mode 100644 index 000000000..5f5bfac9b --- /dev/null +++ b/xmake/scripts/action/_install.lua @@ -0,0 +1,39 @@ +--!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 _install.lua +-- + +-- define module: _install +local _install = _install or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") + +-- done the given config +function _install.done() + + + -- ok + return true +end + +-- return module: _install +return _install diff --git a/xmake/scripts/action/_lua.lua b/xmake/scripts/action/_lua.lua new file mode 100644 index 000000000..6389a6925 --- /dev/null +++ b/xmake/scripts/action/_lua.lua @@ -0,0 +1,80 @@ +--!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 _lua.lua +-- + +-- define module: _lua +local _lua = _lua or {} + +-- load modules +local os = require("base/os") +local utils = require("base/utils") +local config = require("base/config") + +-- done the given config +function _lua.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- no script? + if not options.script then + return false + end + + -- the arguments + local arguments = options.arguments + + -- is string script? + if options.string then + -- load and run string + local script = loadstring(options.script) + if script then + return script(arguments) + end + else + -- attempt to load script from the given file if exists + local file = options.script + if not path.is_absolute(file) then + file = path.absolute(file) + end + + -- attempt to load script from the xmake tool directory + if not os.isfile(file) then + file = xmake._SCRIPTS_DIR .. "/tool/" .. options.script .. ".lua" + end + + -- load and run the script file + if os.isfile(file) then + local script = loadfile(file) + if script then + return script(arguments) + end + end + end + + -- failed + utils.error("cannot run this script: %s", options.script) + return false +end + +-- return module: _lua +return _lua diff --git a/xmake/scripts/action/_run.lua b/xmake/scripts/action/_run.lua new file mode 100644 index 000000000..92972aa0b --- /dev/null +++ b/xmake/scripts/action/_run.lua @@ -0,0 +1,39 @@ +--!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 _run.lua +-- + +-- define module: _run +local _run = _run or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") + +-- done the given config +function _run.done() + + + -- ok + return true +end + +-- return module: _run +return _run diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 9767010e2..1df26898a 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -54,7 +54,7 @@ local menu = , description = "Build the project if no given action." , -- actions - actions = {"create", "config", "global", "install", "clean"} + actions = {"create", "config", "global", "install", "clean", "run", "lua"} -- options , options = @@ -313,6 +313,69 @@ local menu = , {nil, "target", "v", "all", "Clean for the given target." } } } + + -- run target: xmake run +, run = + { + -- xmake r + shortname = 'r' + + -- usage + , usage = "xmake run|r [options] [target] [arguments]" + + -- description + , description = "Run the project target." + + -- options + , options = + { + {'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." } + , {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'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" } + } + } + + -- run lua: xmake lua +, lua = + { + -- xmake l + shortname = 'l' + + -- usage + , usage = "xmake lua|l [options] [script] [arguments]" + + -- description + , description = "Run the lua script." + + -- options + , options = + { + {'s', "string", "k", nil, "Run the lua string script." } + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "script", "v", nil, "Run the given lua script." + , " - The script name from the xmake tool directory" + , " - The script file" + , " - The script string" } + , {nil, "arguments", "v", nil, "The script arguments" } + } + } } -- prepare project @@ -428,6 +491,11 @@ function main._done_option() return true end + -- done lua? + if options._ACTION == "lua" then + return action.done("lua") + end + -- done global? if options._ACTION == "global" then return main._done_global() diff --git a/xmake/scripts/tool/echo.lua b/xmake/scripts/tool/echo.lua new file mode 100644 index 000000000..df4f7fa98 --- /dev/null +++ b/xmake/scripts/tool/echo.lua @@ -0,0 +1,27 @@ +--!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 echo.lua +-- + +-- echo it +print(...) + +-- ok +return true |
