diff options
| author | ruki <[email protected]> | 2016-05-23 10:40:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-05-23 10:40:50 +0800 |
| commit | c8454a31c38bbf25b56d0dd4a9a7c8d71ca59419 (patch) | |
| tree | 126433106bc622ee8671f73aaf1fb5870c9427b9 | |
| parent | 273e6abaea05b469bdb10b5cce57ff064886fe52 (diff) | |
impl run action
| -rwxr-xr-x | core/src/xmake/machine.c | 20 | ||||
| -rwxr-xr-x | xmake/actions/run/main.lua | 99 | ||||
| -rwxr-xr-x | xmake/actions/run/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/core/_xmake_main.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/cache.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/global.lua | 2 |
7 files changed, 119 insertions, 12 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 5f499a963..3b11aef70 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -309,17 +309,21 @@ xm_machine_ref_t xm_machine_init() #endif lua_setglobal(impl->lua, "_NULDEV"); - // init version + // get version tb_version_t const* version = xm_version(); - if (version) - { - tb_char_t version_cstr[256] = {0}; - tb_snprintf(version_cstr, sizeof(version_cstr), "XMake v%u.%u.%u.%llu", version->major, version->minor, version->alter, version->build); - lua_pushstring(impl->lua, version_cstr); - } - else lua_pushstring(impl->lua, "XMake"); + tb_assert_and_check_break(version); + + // init version string + tb_char_t version_cstr[256] = {0}; + tb_snprintf(version_cstr, sizeof(version_cstr), "XMake v%u.%u.%u.%llu", version->major, version->minor, version->alter, version->build); + lua_pushstring(impl->lua, version_cstr); lua_setglobal(impl->lua, "_VERSION"); + // init short version string + tb_snprintf(version_cstr, sizeof(version_cstr), "XMake v%u.%u.%u", version->major, version->minor, version->alter); + lua_pushstring(impl->lua, version_cstr); + lua_setglobal(impl->lua, "_VERSION_SHORT"); + // init namespace: xmake lua_newtable(impl->lua); lua_setglobal(impl->lua, "xmake"); diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua new file mode 100755 index 000000000..84d5435e2 --- /dev/null +++ b/xmake/actions/run/main.lua @@ -0,0 +1,99 @@ +--!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 main.lua +-- + +-- imports +import("core.base.option") +import("core.project.task") +import("core.project.config") +import("core.project.global") +import("core.project.project") +import("core.platform.platform") + +-- run binary target +function _run_binary(target) + + -- run it + os.execute("%s %s", target:targetfile(), table.concat(option.get("arguments") or {}, " ")) +end + +-- run target +function _run_target(target) + + -- get kind + local kind = target:get("kind") + + -- get script + local scripts = + { + binary = _run_binary + } + + -- check + assert(scripts[kind], "this target(%s) with kind(%s) is not executable!", target:name(), kind) + + -- run it + scripts[kind](target) +end + +-- run the given target +function _run(target) + + -- the target scripts + local scripts = + { + target:get("run_before") + , target:get("run") or _run_target + , target:get("run_after") + } + + -- run the target scripts + for i = 1, 3 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end +end + +-- main +function main() + + -- check xmake.lua + if not os.isfile(project.file()) then + raise("xmake.lua not found!") + end + + -- get the target name + local targetname = option.get("target") + + -- build it first + task.run("build", {target = targetname}) + + -- enter project directory + os.cd(project.directory()) + + -- run the current target + _run(project.target(targetname)) + + -- leave project directory + os.cd("-") +end diff --git a/xmake/actions/run/xmake.lua b/xmake/actions/run/xmake.lua index d161c8dbc..bc5890f34 100755 --- a/xmake/actions/run/xmake.lua +++ b/xmake/actions/run/xmake.lua @@ -26,6 +26,9 @@ task("run") -- set category set_task_category("action") + -- on run + on_task_run("main") + -- set menu set_task_menu({ -- usage diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 77e27f9e8..2289b9141 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -27,6 +27,7 @@ xmake._HOST = _HOST xmake._ARCH = _ARCH xmake._NULDEV = _NULDEV xmake._VERSION = _VERSION +xmake._VERSION_SHORT = _VERSION_SHORT xmake._PROGRAM_DIR = _PROGRAM_DIR xmake._PROJECT_DIR = _PROJECT_DIR xmake._CORE_DIR = _PROGRAM_DIR .. "/core" diff --git a/xmake/core/project/cache.lua b/xmake/core/project/cache.lua index 9a7491aed..5ea212dfc 100644 --- a/xmake/core/project/cache.lua +++ b/xmake/core/project/cache.lua @@ -67,7 +67,7 @@ function cache._instance(scopename) if results then instance._CACHEDATA = results end - instance._CACHEDATA = instance._CACHEDATA or {__version = xmake._VERSION} + instance._CACHEDATA = instance._CACHEDATA or {__version = xmake._VERSION_SHORT} -- save instance instances[scopename] = instance @@ -94,7 +94,7 @@ end function cache:clear() -- clear it - self._CACHEDATA = {__version = xmake._VERSION} + self._CACHEDATA = {__version = xmake._VERSION_SHORT} end -- flush to cache file diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index a79292bea..a732baed3 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -149,7 +149,7 @@ function config.save(targetname) end -- add version - results.__version = xmake._VERSION + results.__version = xmake._VERSION_SHORT -- update options for the given target local target = nil diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua index 9d72e73c1..4649139b5 100644 --- a/xmake/core/project/global.lua +++ b/xmake/core/project/global.lua @@ -123,7 +123,7 @@ function global.save() assert(options) -- add version - options.__version = xmake._VERSION + options.__version = xmake._VERSION_SHORT -- save it return io.save(global._file(), options) |
