From 733935aec221c1bce476e7cfea7b5e64d280f71e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 13 Apr 2016 20:14:48 +0800 Subject: add make tool --- xmake/core/sandbox/modules/import.lua | 8 ++- .../sandbox/modules/import/core/platform/tool.lua | 57 --------------------- .../core/sandbox/modules/import/core/tool/tool.lua | 58 ++++++++++++++++++++++ xmake/core/sandbox/modules/os.lua | 10 ++++ xmake/core/sandbox/modules/tonumber.lua | 25 ++++++++++ xmake/core/sandbox/modules/tostring.lua | 25 ++++++++++ xmake/core/tool/tool.lua | 17 ++++--- 7 files changed, 134 insertions(+), 66 deletions(-) delete mode 100644 xmake/core/sandbox/modules/import/core/platform/tool.lua create mode 100644 xmake/core/sandbox/modules/import/core/tool/tool.lua create mode 100644 xmake/core/sandbox/modules/tonumber.lua create mode 100644 xmake/core/sandbox/modules/tostring.lua diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua index 4338ec221..6871abd53 100644 --- a/xmake/core/sandbox/modules/import.lua +++ b/xmake/core/sandbox/modules/import.lua @@ -70,7 +70,13 @@ function sandbox_import._loadfile(filepath, instance) end -- import module - return instance:import(), instance:script() + local result, errors = instance:import() + if not result then + return nil, errors + end + + -- ok + return result, instance:script() end -- load module without sandbox diff --git a/xmake/core/sandbox/modules/import/core/platform/tool.lua b/xmake/core/sandbox/modules/import/core/platform/tool.lua deleted file mode 100644 index cc7811e21..000000000 --- a/xmake/core/sandbox/modules/import/core/platform/tool.lua +++ /dev/null @@ -1,57 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file tool.lua --- - --- define module -local sandbox_core_platform_tool = sandbox_core_platform_tool or {} - --- load modules -local tool = require("platform/tool") -local platform = require("platform/platform") -local raise = require("sandbox/modules/raise") - --- get the tool shell name -function sandbox_core_platform_tool.shellname(name) - - -- get it - return platform.tool(name) -end - --- run the tool -function sandbox_core_platform_tool.run(name, ...) - - -- check - assert(name) - - -- get the tool instance - local instance, errors = tool.get(name) - if not instance then - raise(errors) - end - - -- run it - if not instance:main(...) then - raise("run tool: %s failed!", name) - end -end - --- return module -return sandbox_core_platform_tool diff --git a/xmake/core/sandbox/modules/import/core/tool/tool.lua b/xmake/core/sandbox/modules/import/core/tool/tool.lua new file mode 100644 index 000000000..f02fb1c15 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/tool/tool.lua @@ -0,0 +1,58 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file tool.lua +-- + +-- define module +local sandbox_core_tool = sandbox_core_tool or {} + +-- load modules +local tool = require("tool/tool") +local platform = require("platform/platform") +local raise = require("sandbox/modules/raise") + +-- get the tool shell name +function sandbox_core_tool.shellname(name) + + -- get it + return platform.tool(name) +end + +-- run the tool +function sandbox_core_tool.run(name, ...) + + -- check + assert(name) + + -- load the tool instance + local instance, errors = tool.load(name) + if not instance then + raise(errors) + end + + -- run it + local ok, errors = instance:run(...) + if not ok then + raise(errors) + end +end + +-- return module +return sandbox_core_tool diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 44bef94e1..e6fa1018a 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -172,6 +172,16 @@ function sandbox_os.run(cmd, ...) end end +-- execute shell +function sandbox_os.execute(cmd, ...) + + -- make command + cmd = vformat(cmd, ...) + + -- run it + return os.execute(cmd) +end + -- match files or directories function sandbox_os.match(pattern, findir) diff --git a/xmake/core/sandbox/modules/tonumber.lua b/xmake/core/sandbox/modules/tonumber.lua new file mode 100644 index 000000000..5bbe2cbbf --- /dev/null +++ b/xmake/core/sandbox/modules/tonumber.lua @@ -0,0 +1,25 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file tonumber.lua +-- + +-- load module +return tonumber + diff --git a/xmake/core/sandbox/modules/tostring.lua b/xmake/core/sandbox/modules/tostring.lua new file mode 100644 index 000000000..aaec1fddf --- /dev/null +++ b/xmake/core/sandbox/modules/tostring.lua @@ -0,0 +1,25 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file tostring.lua +-- + +-- load module +return tostring + diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index b38bd6ee2..bca361388 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -169,14 +169,15 @@ function tool._directories(name) -- the kinds local kinds = { - cc = "compiler" - , cxx = "compiler" - , mm = "compiler" - , mxx = "compiler" - , sc = "compiler" - , ar = "archiver" - , sh = "linker" - , ld = "linker" + cc = "compiler" + , cxx = "compiler" + , mm = "compiler" + , mxx = "compiler" + , sc = "compiler" + , ar = "archiver" + , sh = "linker" + , ld = "linker" + , make = "other" } -- get kind sub-directory -- cgit v1.3.1