diff options
| author | ruki <[email protected]> | 2015-09-30 15:46:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-09-30 15:46:24 +0800 |
| commit | 34b6123628ccce51f23207cea7c9c5f025f0a3c1 (patch) | |
| tree | 37de731493a9af8e30400c9e1946a5d347c1a807 | |
| parent | 1f35bb4b02d5cdf16f9a858f8df3d10fcbca94a3 (diff) | |
fix set_installscript api and add import
| -rw-r--r-- | xmake/scripts/action/_install.lua | 54 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 15 | ||||
| -rw-r--r-- | xmake/scripts/module/os.lua | 46 | ||||
| -rw-r--r-- | xmake/scripts/module/path.lua | 25 | ||||
| -rw-r--r-- | xmake/scripts/module/project.lua | 73 | ||||
| -rw-r--r-- | xmake/scripts/module/string.lua | 24 | ||||
| -rw-r--r-- | xmake/scripts/module/utils.lua | 24 |
7 files changed, 259 insertions, 2 deletions
diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua index 300f02f8d..d9aec0b4f 100644 --- a/xmake/scripts/action/_install.lua +++ b/xmake/scripts/action/_install.lua @@ -39,6 +39,40 @@ function _install.need(name) return false end +-- make configure for the given target +function _install._makeconf(configs, target_name, target) + + -- check + assert(configs and target_name and target) + + -- init configs for targets + configs[target_name] = configs[target_name] or {} + local configs_target = configs[target_name] + + -- save the install script + local installscript = target.installscript + if type(installscript) == "string" and os.isfile(installscript) then + local script, errors = loadfile(installscript) + if script then + installscript = script() + if type(installscript) == "table" and installscript.main then + installscript = installscript.main + end + else + utils.error(errors) + return false + end + end + if target.installscript and type(installscript) ~= "function" then + utils.error("invalid package script!") + return false + end + configs_target.installscript = installscript + + -- ok + return true +end + -- package target function _install._package(target_name) @@ -55,7 +89,6 @@ function _install._package(target_name) -- ok return true end - -- done function _install.done() @@ -119,6 +152,25 @@ function _install.done() target.outputdir = options.installdir end + -- the targets + local targets = project.targets() + assert(targets) + + -- make configure for the given target + if target_name and target_name ~= "all" then + if not _install._makeconf(configs, target_name, targets[target_name]) then + utils.error("make target configure: %s failed!", target_name) + return false + end + else + for target_name, target in pairs(targets) do + if not _install._makeconf(configs, target_name, target) then + utils.error("make target configure: %s failed!", target_name) + return false + end + end + end + -- done install if not install.done(configs) then -- errors diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 9e003a59d..89bee0cd6 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -20,7 +20,7 @@ -- @file project.lua -- --- define module: config +-- define module: project local project = project or {} -- load modules @@ -35,6 +35,13 @@ local linker = require("base/linker") local compiler = require("base/compiler") local platform = require("platform/platform") +-- import module +function project._api_import(env, module) + + -- import + return require("module/" .. module) +end + -- the current os is belong to the given os? function project._api_os(env, ...) @@ -947,6 +954,9 @@ function project._load_options(file) end}) setfenv(script, newenv) + -- register import + newenv.import = function (module) return project._api_import(newenv, module) end + -- register interfaces for the condition newenv.os = function (...) return project._api_os(newenv, ...) end newenv.modes = function (...) return project._api_modes(newenv, ...) end @@ -1051,6 +1061,9 @@ function project._load_targets(file) end}) setfenv(script, newenv) + -- register import + newenv.import = function (module) return project._api_import(newenv, module) end + -- register interfaces for the condition newenv.os = function (...) return project._api_os(newenv, ...) end newenv.modes = function (...) return project._api_modes(newenv, ...) end diff --git a/xmake/scripts/module/os.lua b/xmake/scripts/module/os.lua new file mode 100644 index 000000000..3689086f2 --- /dev/null +++ b/xmake/scripts/module/os.lua @@ -0,0 +1,46 @@ +--!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 os.lua +-- + +-- load modules +local io = require("base/io") +local os = require("base/os") + +-- define module: _os +local _os = _os or {} + +-- cat the given file +function _os.cat(filepath, linecount) + + -- cat it + return io.cat(filepath, linecount) +end + +-- only copy the interfaces of os +for k, v in pairs(os) do + if type(v) == "function" then + _os[k] = v + end +end + +-- return module: _os +return _os + diff --git a/xmake/scripts/module/path.lua b/xmake/scripts/module/path.lua new file mode 100644 index 000000000..9de905667 --- /dev/null +++ b/xmake/scripts/module/path.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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file path.lua +-- + +-- return module: path +return require("base/path") + diff --git a/xmake/scripts/module/project.lua b/xmake/scripts/module/project.lua new file mode 100644 index 000000000..f3f726c6f --- /dev/null +++ b/xmake/scripts/module/project.lua @@ -0,0 +1,73 @@ +--!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 project.lua +-- + +-- define module: project +local project = project or {} + +-- load modules +local rule = require("base/rule") +local config = require("base/config") + +-- get the build directory +function project.buildir() + + -- get it + return config.get("buildir") +end + +-- get the project directory +function project.projectdir() + + -- get it + return xmake._PROJECT_DIR +end + +-- get the log file +function project.logfile() + + -- get it + return rule.logfile() +end + +-- get the current platform +function project.plat() + + -- get it + return config.get("plat") +end + +-- get the current architecture +function project.arch() + + -- get it + return config.get("arch") +end + +-- get the current mode +function project.mode() + + -- get it + return config.get("mode") +end + +-- return module: project +return project diff --git a/xmake/scripts/module/string.lua b/xmake/scripts/module/string.lua new file mode 100644 index 000000000..60d3408cf --- /dev/null +++ b/xmake/scripts/module/string.lua @@ -0,0 +1,24 @@ +--!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 string.lua +-- + +-- return module: string +return require("base/string") diff --git a/xmake/scripts/module/utils.lua b/xmake/scripts/module/utils.lua new file mode 100644 index 000000000..ab4d2c96f --- /dev/null +++ b/xmake/scripts/module/utils.lua @@ -0,0 +1,24 @@ +--!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 utils.lua +-- + +-- return module: utils +return require("base/utils") |
