diff options
| author | ruki <[email protected]> | 2017-01-05 15:41:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:09 +0800 |
| commit | ac637c7c104bf2bd9269379b15184b44d03e75dd (patch) | |
| tree | 010c27a3350d17431a686ab52d7e5132fb4067df | |
| parent | 61465cbf8df493c13c0adf2adfc985b679933bdd (diff) | |
add scanner and fix run target
| -rwxr-xr-x | xmake/actions/config/main.lua | 10 | ||||
| -rwxr-xr-x | xmake/actions/config/scanner.lua | 71 | ||||
| -rwxr-xr-x | xmake/actions/run/main.lua | 19 | ||||
| -rw-r--r-- | xmake/core/language/language.lua | 27 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/language/language.lua | 38 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 12 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 22 |
7 files changed, 173 insertions, 26 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 96eb05ef9..8b5ad7e0f 100755 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -27,6 +27,7 @@ import("core.project.global") import("core.project.project") import("core.platform.platform") import("core.project.cache") +import("scanner") import("configheader") -- filter option @@ -133,14 +134,9 @@ function main() return end - -- check xmake.lua + -- scan project and generate it if xmake.lua not exists if not os.isfile(project.file()) then - - -- remove config directory if exists because the current directory is not a project - os.rm(config.directory()) - - -- error - raise("xmake.lua not found!") + scanner.make() end -- the target name diff --git a/xmake/actions/config/scanner.lua b/xmake/actions/config/scanner.lua new file mode 100755 index 000000000..68d7278da --- /dev/null +++ b/xmake/actions/config/scanner.lua @@ -0,0 +1,71 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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 scanner.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.language.language") + +-- scan project and generate xmake.lua automaticlly if the project codes exist +function make() + + -- scan source files for the current directory + local sourcefiles = {} + for _, sourcekind in ipairs(language.sourcekinds()) do + for _, sourcefile in ipairs(os.files("*" .. sourcekind)) do + table.insert(sourcefiles, sourcefile) + end + end + sourcefiles = table.unique(sourcefiles) + + -- project not found + if #sourcefiles == 0 then + + -- remove config directory if exists because the current directory is not a project + os.rm(config.directory()) + + -- error + raise("xmake.lua not found!") + end + + -- generate xmake.lua + local file = io.open("xmake.lua", "w") + if file then + + -- save file + file:print("-- define target") + file:print("target(\"%s\")", "demo") + file:print("") + file:print(" -- set kind") + file:print(" set_kind(\"binary\")") + file:print("") + file:print(" -- add files") + for _, sourcefile in ipairs(sourcefiles) do + file:print(" add_files(\"%s\")", sourcefile) + end + file:print("") + + -- exit file + file:close() + end +end diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 65ff7658a..633ffee6d 100755 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -95,8 +95,23 @@ function main() -- enter project directory local olddir = os.cd(project.directory()) - -- run the current target - _run(project.target(targetname)) + -- get target + local target = nil + if targetname then + target = project.target(targetname) + else + -- find the first binary target + for _, t in pairs(project.targets()) do + if t:get("kind") == "binary" then + target = t + break + end + end + end + assert(target, "target(%s) not found!", targetname or "unknown") + + -- run the given target + _run(target) -- leave project directory os.cd(olddir) diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index ad5c64367..53daeb093 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -249,5 +249,32 @@ function language.apis() return apis end +-- get language sourcekinds +function language.sourcekinds() + + -- attempt to get it from cache + if language._SOURCEKINDS then + return language._SOURCEKINDS + end + + -- load all languages + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + + -- merge apis for each language + local sourcekinds = {} + for name, instance in pairs(languages) do + table.join2(sourcekinds, table.wrap(instance:sourcekinds())) + end + + -- cache it + language._SOURCEKINDS = table.unique(sourcekinds) + + -- ok + return language._SOURCEKINDS +end + -- return module return language diff --git a/xmake/core/sandbox/modules/import/core/language/language.lua b/xmake/core/sandbox/modules/import/core/language/language.lua new file mode 100644 index 000000000..06a947b3c --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/language/language.lua @@ -0,0 +1,38 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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 language.lua +-- + +-- define module +local sandbox_core_language = sandbox_core_language or {} + +-- load modules +local language = require("language/language") +local raise = require("sandbox/modules/raise") + +-- get the sourcekinds of all languages +function sandbox_core_language.sourcekinds() + + -- get all + return language.sourcekinds() +end + +-- return module +return sandbox_core_language diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index e16e186d3..a3a7f6453 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -21,14 +21,14 @@ -- -- define module -local sandbox_core_platform_platform = sandbox_core_platform_platform or {} +local sandbox_core_platform = sandbox_core_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) +function sandbox_core_platform.load(plat) -- load the platform configure local ok, errors = platform.load(plat) @@ -38,7 +38,7 @@ function sandbox_core_platform_platform.load(plat) end -- get the all platforms -function sandbox_core_platform_platform.plats() +function sandbox_core_platform.plats() -- get it local plats = platform.plats() @@ -49,7 +49,7 @@ function sandbox_core_platform_platform.plats() end -- get the all architectures for the given platform -function sandbox_core_platform_platform.archs(plat) +function sandbox_core_platform.archs(plat) -- get it local archs = platform.archs(plat) @@ -60,11 +60,11 @@ function sandbox_core_platform_platform.archs(plat) end -- get the current platform configure -function sandbox_core_platform_platform.get(name, plat) +function sandbox_core_platform.get(name, plat) -- get the given platform configure return platform.get(name, plat) end -- return module -return sandbox_core_platform_platform +return sandbox_core_platform diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 7fd70f698..6ab362d7c 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -21,7 +21,7 @@ -- -- define module -local sandbox_core_project_project = sandbox_core_project_project or {} +local sandbox_core_project = sandbox_core_project or {} -- load modules local table = require("base/table") @@ -30,7 +30,7 @@ local project = require("project/project") local raise = require("sandbox/modules/raise") -- load project -function sandbox_core_project_project.load() +function sandbox_core_project.load() -- load it local ok, errors = project.load() @@ -40,7 +40,7 @@ function sandbox_core_project_project.load() end -- check project options -function sandbox_core_project_project.check() +function sandbox_core_project.check() -- check it local ok, errors = project.check() @@ -50,14 +50,14 @@ function sandbox_core_project_project.check() end -- get the given target -function sandbox_core_project_project.target(targetname) +function sandbox_core_project.target(targetname) -- get it return project.target(targetname) end -- get the all targets -function sandbox_core_project_project.targets() +function sandbox_core_project.targets() -- get targets local targets = project.targets() @@ -68,28 +68,28 @@ function sandbox_core_project_project.targets() end -- get the project file -function sandbox_core_project_project.file() +function sandbox_core_project.file() -- get it return xmake._PROJECT_FILE end -- get the project directory -function sandbox_core_project_project.directory() +function sandbox_core_project.directory() -- get it return xmake._PROJECT_DIR end -- get the project mtimes -function sandbox_core_project_project.mtimes() +function sandbox_core_project.mtimes() -- get it return project.mtimes() end -- get the project version -function sandbox_core_project_project.version() +function sandbox_core_project.version() -- get version for _, target in pairs(table.wrap(project.targets())) do @@ -101,7 +101,7 @@ function sandbox_core_project_project.version() end -- get the project name -function sandbox_core_project_project.name() +function sandbox_core_project.name() -- get version for _, target in pairs(table.wrap(project.targets())) do @@ -116,4 +116,4 @@ function sandbox_core_project_project.name() end -- return module -return sandbox_core_project_project +return sandbox_core_project |
