From db1a45865998fb00bf46baeaada017d9f17f9da4 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 1 Mar 2016 08:43:00 +0800 Subject: import core --- xmake/actions/config/main.lua | 27 +++++++++++ xmake/actions/config/xmake.lua | 14 +++--- xmake/actions/create/xmake.lua | 4 +- xmake/actions/global/xmake.lua | 2 +- xmake/actions/package/xmake.lua | 2 +- xmake/core/sandbox/import.lua | 14 +++++- xmake/core/sandbox/import/core/platform.lua | 59 +++++++++++++++++++++++ xmake/core/sandbox/import/core/project.lua | 74 +++++++++++++++++++++++++++++ xmake/core/sandbox/import/core/template.lua | 52 ++++++++++++++++++++ xmake/core/sandbox/import/platform.lua | 59 ----------------------- xmake/core/sandbox/import/project.lua | 74 ----------------------------- xmake/core/sandbox/import/template.lua | 52 -------------------- 12 files changed, 234 insertions(+), 199 deletions(-) create mode 100755 xmake/actions/config/main.lua create mode 100644 xmake/core/sandbox/import/core/platform.lua create mode 100644 xmake/core/sandbox/import/core/project.lua create mode 100644 xmake/core/sandbox/import/core/template.lua delete mode 100644 xmake/core/sandbox/import/platform.lua delete mode 100644 xmake/core/sandbox/import/project.lua delete mode 100644 xmake/core/sandbox/import/template.lua diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua new file mode 100755 index 000000000..59da0ad0a --- /dev/null +++ b/xmake/actions/config/main.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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file main.lua +-- + + +function main() + + +end diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index bb4e71ec9..811393b8e 100755 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -28,9 +28,7 @@ task("config") -- on run on_task_run(function () - - print("run") - + end) -- set menu @@ -47,7 +45,7 @@ task("config") -- options , options = { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } , {} , {'p', "plat", "kv", "$(host)", "Compile for the given platform." @@ -56,7 +54,7 @@ task("config") , function () -- import platform - import("platform") + import("core/platform") -- make description local description = {} @@ -73,7 +71,7 @@ task("config") , function () -- import platform - import("platform") + import("core/platform") -- make description local description = {} @@ -101,7 +99,7 @@ task("config") , function () -- import platform - import("project") + import("core/project") -- get menu for project return project.menu() @@ -149,7 +147,7 @@ task("config") , function () -- import platform - import("platform") + import("core/platform") -- get menu for platform return platform.menu("config") diff --git a/xmake/actions/create/xmake.lua b/xmake/actions/create/xmake.lua index 9df66ae7d..e528bb842 100755 --- a/xmake/actions/create/xmake.lua +++ b/xmake/actions/create/xmake.lua @@ -44,7 +44,7 @@ task("create") , function () -- import template - import("template") + import("core/template") -- make description local description = {} @@ -61,7 +61,7 @@ task("create") , function () -- import template - import("template") + import("core/template") -- make description local description = {} diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua index 5d1abced7..3161884a7 100755 --- a/xmake/actions/global/xmake.lua +++ b/xmake/actions/global/xmake.lua @@ -51,7 +51,7 @@ task("global") , function () -- import platform - import("platform") + import("core/platform") -- get menu for platform return platform.menu("global") diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 17dd79b9c..305cd872d 100755 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -47,7 +47,7 @@ task("package") , function () -- import platform - import("platform") + import("core/platform") -- make description local description = {} diff --git a/xmake/core/sandbox/import.lua b/xmake/core/sandbox/import.lua index 27417a23b..236547eaf 100644 --- a/xmake/core/sandbox/import.lua +++ b/xmake/core/sandbox/import.lua @@ -22,6 +22,7 @@ -- load modules local os = require("base/os") +local path = require("base/path") local utils = require("base/utils") -- import module @@ -33,17 +34,26 @@ function sandbox_import(name) os.raise("cannot import module: %s", name) end + -- get module name + local modulename = path.basename(name) + if not modulename then + os.raise("cannot get module name for %s", name) + end + -- get the parent scope local scope_parent = getfenv(2) assert(scope_parent) -- this module has been imported? - if rawget(scope_parent, name) then + if rawget(scope_parent, modulename) then os.raise("this module: %s has been imported!", name) end -- import this module into the parent scope - scope_parent[name] = module + scope_parent[modulename] = module + + -- return it + return module end -- load module diff --git a/xmake/core/sandbox/import/core/platform.lua b/xmake/core/sandbox/import/core/platform.lua new file mode 100644 index 000000000..e6de93681 --- /dev/null +++ b/xmake/core/sandbox/import/core/platform.lua @@ -0,0 +1,59 @@ +--!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 platform.lua +-- + +-- define module +local sandbox_platform = sandbox_platform or {} + +-- load modules +local platform = require("base/platform") + +-- get the platform menu +function sandbox_platform.menu(action) + + -- get it + return platform.menu(action) +end + +-- get the all platforms +function sandbox_platform.plats() + + -- get it + local plats = platform.plats() + assert(plats) + + -- ok + return plats +end + +-- get the all architectures for the given platform +function sandbox_platform.archs(plat) + + -- get it + local archs = platform.archs(plat) + assert(archs) + + -- ok + return archs +end + +-- return module +return sandbox_platform diff --git a/xmake/core/sandbox/import/core/project.lua b/xmake/core/sandbox/import/core/project.lua new file mode 100644 index 000000000..3d65b8768 --- /dev/null +++ b/xmake/core/sandbox/import/core/project.lua @@ -0,0 +1,74 @@ +--!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 project.lua +-- + +-- define module +local sandbox_project = sandbox_project or {} + +-- load modules +local rule = require("base/rule") +local config = require("base/config") +local project = require("base/project") + +-- get the build directory +function sandbox_project.buildir() + + -- get it + return config.get("buildir") +end + +-- get the project directory +function sandbox_project.projectdir() + + -- get it + return xmake._PROJECT_DIR +end + +-- get the current platform +function sandbox_project.plat() + + -- get it + return config.get("plat") +end + +-- get the current architecture +function sandbox_project.arch() + + -- get it + return config.get("arch") +end + +-- get the current mode +function sandbox_project.mode() + + -- get it + return config.get("mode") +end + +-- get the menu +function sandbox_project.menu() + + -- get it + return project.menu() +end + +-- return module +return sandbox_project diff --git a/xmake/core/sandbox/import/core/template.lua b/xmake/core/sandbox/import/core/template.lua new file mode 100644 index 000000000..980e98a52 --- /dev/null +++ b/xmake/core/sandbox/import/core/template.lua @@ -0,0 +1,52 @@ +--!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 template.lua +-- + +-- define module +local sandbox_template = sandbox_template or {} + +-- load modules +local template = require("base/template") + +-- get all languages +function sandbox_template.languages() + + -- get it + local languages = template.languages() + assert(languages) + + -- ok + return languages +end + +-- load all templates from the given language +function sandbox_template.templates(language) + + -- get it + local templates = template.templates(language) + assert(templates) + + -- ok + return templates +end + +-- return module +return sandbox_template diff --git a/xmake/core/sandbox/import/platform.lua b/xmake/core/sandbox/import/platform.lua deleted file mode 100644 index e6de93681..000000000 --- a/xmake/core/sandbox/import/platform.lua +++ /dev/null @@ -1,59 +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 platform.lua --- - --- define module -local sandbox_platform = sandbox_platform or {} - --- load modules -local platform = require("base/platform") - --- get the platform menu -function sandbox_platform.menu(action) - - -- get it - return platform.menu(action) -end - --- get the all platforms -function sandbox_platform.plats() - - -- get it - local plats = platform.plats() - assert(plats) - - -- ok - return plats -end - --- get the all architectures for the given platform -function sandbox_platform.archs(plat) - - -- get it - local archs = platform.archs(plat) - assert(archs) - - -- ok - return archs -end - --- return module -return sandbox_platform diff --git a/xmake/core/sandbox/import/project.lua b/xmake/core/sandbox/import/project.lua deleted file mode 100644 index 3d65b8768..000000000 --- a/xmake/core/sandbox/import/project.lua +++ /dev/null @@ -1,74 +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 project.lua --- - --- define module -local sandbox_project = sandbox_project or {} - --- load modules -local rule = require("base/rule") -local config = require("base/config") -local project = require("base/project") - --- get the build directory -function sandbox_project.buildir() - - -- get it - return config.get("buildir") -end - --- get the project directory -function sandbox_project.projectdir() - - -- get it - return xmake._PROJECT_DIR -end - --- get the current platform -function sandbox_project.plat() - - -- get it - return config.get("plat") -end - --- get the current architecture -function sandbox_project.arch() - - -- get it - return config.get("arch") -end - --- get the current mode -function sandbox_project.mode() - - -- get it - return config.get("mode") -end - --- get the menu -function sandbox_project.menu() - - -- get it - return project.menu() -end - --- return module -return sandbox_project diff --git a/xmake/core/sandbox/import/template.lua b/xmake/core/sandbox/import/template.lua deleted file mode 100644 index 980e98a52..000000000 --- a/xmake/core/sandbox/import/template.lua +++ /dev/null @@ -1,52 +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 template.lua --- - --- define module -local sandbox_template = sandbox_template or {} - --- load modules -local template = require("base/template") - --- get all languages -function sandbox_template.languages() - - -- get it - local languages = template.languages() - assert(languages) - - -- ok - return languages -end - --- load all templates from the given language -function sandbox_template.templates(language) - - -- get it - local templates = template.templates(language) - assert(templates) - - -- ok - return templates -end - --- return module -return sandbox_template -- cgit v1.3.1