diff options
| author | ruki <[email protected]> | 2016-03-22 20:24:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-22 20:24:31 +0800 |
| commit | aca0257d26134ff95889acb419d49701fee4ec61 (patch) | |
| tree | c1a2f332156aba8295b0522fa70f08783e9633c6 | |
| parent | c1460e5be7f4b4e3356a8bda99703828c356cbfb (diff) | |
impl lua action
| -rwxr-xr-x | xmake/actions/config/main.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/lua/scripts/echo.lua (renamed from xmake/core/platform/tools/echo.lua) | 18 | ||||
| -rwxr-xr-x | xmake/actions/lua/xmake.lua | 44 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 73 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 44 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/config.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/print.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 10 |
9 files changed, 123 insertions, 83 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index aa0c11654..5936f94f1 100755 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -25,6 +25,7 @@ import("core.base.option") import("core.project.config") import("core.project.global") import("core.project.project") +import("core.platform.platform") import("config_h") import("makefile") @@ -76,6 +77,9 @@ function main() -- probe the configure with value: "auto" config.probe() + -- load platform + platform.load(config.plat()) + -- translate the build directory local buildir = option.get("buildir") if buildir and path.is_absolute(buildir) then diff --git a/xmake/core/platform/tools/echo.lua b/xmake/actions/lua/scripts/echo.lua index 9a858c765..40165df2b 100644 --- a/xmake/core/platform/tools/echo.lua +++ b/xmake/actions/lua/scripts/echo.lua @@ -20,25 +20,13 @@ -- @file echo.lua -- --- 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(self, ...) +function main(...) -- echo all for _, v in ipairs(...) do - io.write(string.format("%s ", v:decode())) + printf("%s ", v:decode()) end - io.write("\n") + print("") - -- ok - return true end - --- return module: echo -return echo diff --git a/xmake/actions/lua/xmake.lua b/xmake/actions/lua/xmake.lua index 0a7b4b6fa..96089d0b6 100755 --- a/xmake/actions/lua/xmake.lua +++ b/xmake/actions/lua/xmake.lua @@ -26,6 +26,40 @@ task("lua") -- set category set_task_category("action") + -- on run + on_task_run(function () + + -- imports + import("core.base.option") + import("core.project.config") + import("core.project.global") + import("core.platform.platform") + + -- do not load config if be not given -f or -P options + if option.get("file") or option.get("project") then + + -- load global configure + global.load() + + -- load project configure + config.load() + + -- load platform + platform.load(config.plat()) + + end + + -- get script name + local name = option.get("script") + if not name then + raise("no script!") + end + + -- import script + import("scripts." .. name).main(option.get("arguments")) + + end) + -- set menu set_task_menu({ -- usage @@ -40,14 +74,8 @@ task("lua") -- options , options = { - {'s', "string", "k", nil, "Run the lua string script." } - - , {} - , {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", "vs", nil, "The script arguments" } + {nil, "script", "v", nil, "Run the given lua script." } + , {nil, "arguments", "vs", nil, "The script arguments" } } }) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index c0e974460..f552ea3ef 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -27,7 +27,6 @@ local platform = platform or {} local os = require("base/os") local path = require("base/path") local utils = require("base/utils") -local option = require("base/option") local config = require("project/config") local global = require("project/global") @@ -123,8 +122,29 @@ function platform._load(plat) return module end --- get the configure of the given platform -function platform._configs(plat) +-- get the current platform module +function platform.module() + + -- get the platform + local plat = config.get("plat") + if plat then + -- load it + return platform._load(plat) + end +end + +-- get the current platform module directory +function platform.directory() + + -- load it + local module = platform.module() + if module then + return module._DIRECTORY + end +end + +-- load the configure of the given platform +function platform.load(plat) -- check assert(plat) @@ -154,38 +174,6 @@ function platform._configs(plat) return configs end --- get the current platform module -function platform.module() - - -- get the platform - local plat = config.get("plat") - if plat then - -- load it - return platform._load(plat) - end -end - --- get the current platform module directory -function platform.directory() - - -- load it - local module = platform.module() - if module then - return module._DIRECTORY - end -end - --- make the current platform configure -function platform.make() - - -- get the platform - local plat = config.get("plat") - assert(plat) - - -- make and get the current platform configure - return platform._configs(plat) -end - -- get the platform os function platform.os() @@ -204,7 +192,7 @@ function platform.get(name) assert(platform._CONFIGS) -- get the current platform configure - local configs = platform._configs(config.get("plat")) + local configs = platform.load(config.get("plat")) if configs then -- get it return configs[name] @@ -239,19 +227,6 @@ function platform.format(kind) end --- dump the platform configure -function platform.dump() - - -- check - assert(platform._CONFIGS) - - -- dump - if option.get("verbose") then - table.dump(platform._configs(config.get("plat"))) - end - -end - -- list all platforms function platform.plats() diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 1942ca5e6..58c04b256 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -151,10 +151,8 @@ end -- load the project configure function config.load(targetname) - -- check - if not targetname then - return false, "no target name!" - end + -- get the target name + targetname = targetname or "all" -- load configure from the file first local filepath = config._file() diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua new file mode 100644 index 000000000..f16ee8df2 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -0,0 +1,44 @@ +--!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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file platform.lua +-- + +-- define module +local sandbox_core_platform_platform = sandbox_core_platform_platform or {} + +-- load modules +local platform = require("platform/platform") +local raise = require("sandbox/modules/raise") + +-- load the current platform +function sandbox_core_platform_platform.load(plat) + + -- check + assert(plat) + + -- load the platform configure + if not platform.load(plat) then + raise("load platform: %s failed!", plat) + end +end + + +-- return module +return sandbox_core_platform_platform diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 9eb77847c..2d2820f4a 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -126,11 +126,6 @@ function sandbox_core_project_config.probe() raise("probe the project configure failed!") end - -- make the platform configure - if not platform.make() then - raise("make platform configure: %s failed!", config.get("plat")) - end - end -- dump the configure diff --git a/xmake/core/sandbox/modules/print.lua b/xmake/core/sandbox/modules/print.lua index 9e8502c16..7ed930575 100644 --- a/xmake/core/sandbox/modules/print.lua +++ b/xmake/core/sandbox/modules/print.lua @@ -21,5 +21,5 @@ -- -- load module -return print +return require("sandbox/modules/utils").print diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index f0cb95db9..395642268 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -21,6 +21,7 @@ -- -- load modules +local io = require("base/io") local utils = require("base/utils") local vformat = require("sandbox/modules/vformat") @@ -34,11 +35,18 @@ for k, v in pairs(utils) do end end +-- print with the builtin variables and newline +function sandbox_utils.print(format, ...) + + -- done + return io.write(vformat(format, ...) .. "\n") +end + -- printf with the builtin variables function sandbox_utils.printf(format, ...) -- done - return print(vformat(format, ...)) + return io.write(vformat(format, ...)) end -- return module |
