diff options
| author | ruki <[email protected]> | 2016-03-30 11:09:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-30 11:09:48 +0800 |
| commit | 9a71fdfde331506e9c5eb2da93f1f95641e66de5 (patch) | |
| tree | e8e1ad17ed952abcd311b4f4b8a07b0310aa2635 | |
| parent | 6e2aa359d0636c0224cccee04723408d9a3ae046 (diff) | |
run task and impl rebuild
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/task.lua | 56 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 12 |
2 files changed, 65 insertions, 3 deletions
diff --git a/xmake/core/sandbox/modules/import/core/project/task.lua b/xmake/core/sandbox/modules/import/core/project/task.lua index 18d595ac7..82e550d99 100644 --- a/xmake/core/sandbox/modules/import/core/project/task.lua +++ b/xmake/core/sandbox/modules/import/core/project/task.lua @@ -26,18 +26,68 @@ local sandbox_core_project_task = sandbox_core_project_task or {} -- load modules local os = require("base/os") local io = require("base/io") +local table = require("base/table") +local option = require("base/option") local string = require("base/string") local task = require("project/task") local raise = require("sandbox/modules/raise") -- run the given task -function sandbox_core_project_task.run(taskname, args) +function sandbox_core_project_task.run(taskname, options, ...) + + -- init values + local values = table.wrap(...) + + -- init options + options = table.wrap(options) + + -- inherit some parent options + for _, name in ipairs({"file", "project", "verbose"}) do + if not options[name] and option.get(name) then + options[name] = option.get(name) + end + end -- make command local cmd = "xmake " .. (taskname or "") - for name, value in pairs(args) do + for name, value in pairs(options) do cmd = string.format("%s --%s=%s", cmd, name, tostring(value)) end + for _, value in pairs(values) do + cmd = string.format("%s %s", cmd, value) + end + + -- run command + if 0 ~= os.execute(cmd) then + io.cat(log) + os.raise("run task: %s failed!", taskname or cmd) + end +end + +-- quietly run the given task +function sandbox_core_project_task.qrun(taskname, options, ...) + + -- init values + local values = table.wrap(...) + + -- init options + options = table.wrap(options) + + -- inherit some parent options + for _, name in ipairs({"file", "project", "verbose"}) do + if not options[name] and option.get(name) then + options[name] = option.get(name) + end + end + + -- make command + local cmd = "xmake " .. (taskname or "") + for name, value in pairs(options) do + cmd = string.format("%s --%s=%s", cmd, name, tostring(value)) + end + for _, value in pairs(values) do + cmd = string.format("%s %s", cmd, value) + end -- make temporary log file log = os.tmpname() @@ -45,7 +95,7 @@ function sandbox_core_project_task.run(taskname, args) -- run command if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then io.cat(log) - os.raise("run: %s failed!", taskname or cmd) + os.raise("run task: %s failed!", taskname or cmd) end -- remove the temporary log file diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 2dcc46233..f3a3c0702 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -165,6 +165,18 @@ function sandbox_os.run(cmd, ...) -- make command cmd = vformat(cmd, ...) + -- run command + if 0 ~= os.execute(cmd) then + os.raise("run: %s failed!", cmd) + end +end + +-- quietly run shell +function sandbox_os.qrun(cmd, ...) + + -- make command + cmd = vformat(cmd, ...) + -- make temporary log file log = os.tmpname() |
