diff options
| author | ruki <[email protected]> | 2017-02-07 22:36:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-07 22:36:36 +0800 |
| commit | 81c6967e2c1b0466889375a374ab9282e7a20aa7 (patch) | |
| tree | cb706bbff10d9f0cc4269a5c8f7112f988c1781e | |
| parent | 03165a0481bad23d0dacd2e2afbe1703cc1b3bfe (diff) | |
add set_xmakever and check minimum version
| -rwxr-xr-x | core/src/xmake/machine.c | 4 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 38 | ||||
| -rw-r--r-- | xmake/core/base/option.lua | 44 | ||||
| -rw-r--r-- | xmake/core/main.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/task.lua | 33 |
5 files changed, 78 insertions, 49 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 38ba6d118..4dfa028d4 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -348,12 +348,12 @@ xm_machine_ref_t xm_machine_init() // 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); + tb_snprintf(version_cstr, sizeof(version_cstr), "%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); + tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u", version->major, version->minor, version->alter); lua_pushstring(impl->lua, version_cstr); lua_setglobal(impl->lua, "_VERSION_SHORT"); diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 87932e61a..54cf28f3d 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -36,6 +36,14 @@ local sandbox = require("sandbox/sandbox") -- traceback function interpreter._traceback(errors) + -- not verbose? + if errors then + local _, pos = errors:find("[nobacktrace]: ", 1, true) + if pos then + return errors:sub(pos + 1) + end + end + -- init results local results = "" if errors then @@ -490,6 +498,7 @@ function interpreter.new() -- register the builtin interfaces instance:api_register(nil, "add_subdirs", interpreter.api_builtin_add_subdirs) instance:api_register(nil, "add_subfiles", interpreter.api_builtin_add_subfiles) + instance:api_register(nil, "set_xmakever", interpreter.api_builtin_set_xmakever) -- load builtin module files local builtin_module_files = os.match(path.join(xmake._CORE_DIR, "sandbox/modules/interpreter/*.lua")) @@ -1281,6 +1290,35 @@ function interpreter:api_builtin_add_subfiles(...) return self:_api_builtin_add_subdirfiles(false, ...) end +-- the builtin api: set_xmakever() +function interpreter:api_builtin_set_xmakever(minver) + + -- no version + if not minver then + os.raise("[nobacktrace]: set_xmakever(): no version!") + end + + -- parse minimum version + local minvers = minver:split('.') + if not minvers or #minvers ~= 3 then + os.raise("[nobacktrace]: set_xmakever(\"%s\"): invalid version format!", minver) + end + + -- make minimum numerical version + local minvers_num = minvers[1] * 100 + minvers[2] * 10 + minvers[3] + + -- parse current version + local curvers = xmake._VERSION_SHORT:split('.') + + -- make current numerical version + local curvers_num = curvers[1] * 100 + curvers[2] * 10 + curvers[3] + + -- check version + if curvers_num < minvers_num then + os.raise("[nobacktrace]: xmake v%s < v%s, please upgrade xmake!", xmake._VERSION_SHORT, minver) + end +end + -- get api function function interpreter:api_func(apiname) diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 68d638e0f..06543c066 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -41,11 +41,13 @@ function option._translate(menu) local submenus_all = {} for k, submenu in pairs(menu) do if type(submenu) == "function" then - local _submenus = submenu() + local _submenus, errors = submenu() if _submenus then for k, m in pairs(_submenus) do submenus_all[k] = m end + else + return false, errors end else submenus_all[k] = submenu @@ -55,6 +57,9 @@ function option._translate(menu) -- save menu option._MENU = menu + + -- ok + return true end -- get the task menu @@ -181,7 +186,10 @@ function option.init(menu) assert(menu) -- translate menu - option._translate(menu) + local ok, errors = option._translate(menu) + if not ok then + return false, errors + end -- the main menu local main = option._taskmenu("main") @@ -236,10 +244,7 @@ function option.init(menu) option.show_menu(context.taskname) -- invalid option - print(colors("\n${bright red}error: ${default red}invalid option: " .. arg)) - - -- failed - return false + return false, "invalid option: " .. arg end -- --key=value or -k value or -k? @@ -283,10 +288,7 @@ function option.init(menu) option.show_menu(context.taskname) -- invalid option - print(colors("\n${bright red}error: ${default red}invalid option: " .. arg)) - - -- failed - return false + return false, "invalid option: " .. arg end -- -k value? continue to get the value @@ -303,10 +305,7 @@ function option.init(menu) option.show_menu(context.taskname) -- invalid option - print(colors("\n${bright red}error: ${default red}invalid option: " .. option._ifelse(idx, arg, key))) - - -- failed - return false + return false, "invalid option: " .. option._ifelse(idx, arg, key) end -- get value @@ -320,10 +319,7 @@ function option.init(menu) option.show_menu(context.taskname) -- invalid option - print(colors("\n${bright red}error: ${default red}invalid option: " .. arg)) - - -- failed - return false + return false, "invalid option: " .. arg end -- value is "true" or "false", translate it @@ -371,11 +367,7 @@ function option.init(menu) option.show_main() -- invalid task - print(colors("\n${bright red}error: ${default red}invalid task: " .. key)) - - -- failed - return false - + return false, "invalid task: " .. key end -- value? @@ -437,12 +429,8 @@ function option.init(menu) option.show_menu(context.taskname) -- invalid option - print(colors("\n${bright red}error: ${default red}invalid option: " .. arg)) - - -- failed - return false + return false, "invalid option: " .. arg end - end end diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 976747399..0228e2b38 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -39,7 +39,7 @@ local history = require("project/history") local menu = { -- title - title = xmake._VERSION .. ", The Make-like Build Utility based on Lua" + title = "XMake v" .. xmake._VERSION .. ", The Make-like Build Utility based on Lua" -- copyright , copyright = "Copyright (C) 2015-2016 Ruki Wang, ${underline}tboox.org${clear}, ${underline}xmake.io${clear}\nCopyright (C) 2005-2015 Mike Pall, ${underline}luajit.org${clear}" @@ -108,7 +108,9 @@ function main.done() main._init() -- init option - if not option.init(menu) then + local ok, errors = option.init(menu) + if not ok then + utils.error(errors) return -1 end @@ -126,7 +128,7 @@ function main.done() history.save("cmdlines", option.cmdline()) -- run task - local ok, errors = task.run(option.taskname() or "build") + ok, errors = task.run(option.taskname() or "build") if not ok then utils.error(errors) return -1 diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index 2dff95962..7c7787f02 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -78,7 +78,7 @@ function task._translate_menu(menu) end else -- errors - os.raise("taskmenu: %s", results) + return nil, string.format("taskmenu: %s", results) end else table.insert(options_full, opt) @@ -120,7 +120,7 @@ function task._translate_menu(menu) local ok, results = sandbox.load(description) if not ok then -- errors - os.raise("taskmenu: %s", results) + return nil, string.format("taskmenu: %s", results) end -- ok @@ -310,16 +310,13 @@ function task._load(filepath) -- load tasks local tasks, errors = interp:load(filepath, "task", true, true) if not tasks and os.isfile(filepath) then - -- trace - os.raise(errors) + return nil, errors end -- bind tasks for menu with an sandbox instance local ok, errors = task._bind(tasks) if not ok then - -- trace - os.raise(errors) - return + return nil, errors end -- ok? @@ -345,11 +342,13 @@ function task.tasks() for _, filepath in ipairs(files) do -- load tasks - local results = task._load(filepath) + local results, errors = task._load(filepath) -- save tasks if results then table.join2(tasks, results) + else + return nil, errors end end end @@ -365,9 +364,7 @@ function task.tasks() -- bind tasks for menu with an sandbox instance local ok, errors = task._bind(projectasks, interp) if not ok then - -- trace - os.raise(errors) - return + return nil, errors end -- save tasks @@ -379,7 +376,7 @@ function task.tasks() end end else - os.raise(errors) + return nil, errors end -- save it @@ -396,8 +393,10 @@ function task.run(name, ...) assert(name) -- load tasks - local tasks = task.tasks() - assert(tasks) + local tasks, errors = task.tasks() + if not tasks then + return false, errors + end -- the interpreter local interp = task._interpreter() @@ -431,8 +430,10 @@ end function task.menu() -- load tasks - local tasks = task.tasks() - assert(tasks) + local tasks, errors = task.tasks() + if not tasks then + return nil, errors + end -- make menu local menu = {} |
