diff options
| author | ruki <[email protected]> | 2016-02-01 16:22:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:26 +0800 |
| commit | d986b3ac89b3054e256dea9520a6e07ba6ddb5d1 (patch) | |
| tree | 78ce5eaa34dcdb1b0fbe0defc676da7943a17fcf | |
| parent | 319d430b6befbddaa4b10584a43a52b47dd8aaf0 (diff) | |
add os run interfaces for sandbox
| -rw-r--r-- | xmake/core/base/sandbox.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/os.lua | 51 |
2 files changed, 52 insertions, 1 deletions
diff --git a/xmake/core/base/sandbox.lua b/xmake/core/base/sandbox.lua index 37c9edab7..d1c1ab7f2 100644 --- a/xmake/core/base/sandbox.lua +++ b/xmake/core/base/sandbox.lua @@ -48,7 +48,7 @@ function sandbox._traceback(errors) local info = debug.getinfo(level, "Sln") -- end? - if not info or (info.name and info.name == "xpcall") then + if not info or (info.name and (info.name == "xpcall" or info.name == "load")) then break end diff --git a/xmake/core/sandbox/builtin/os.lua b/xmake/core/sandbox/builtin/os.lua index 717fa2453..77b79fd09 100644 --- a/xmake/core/sandbox/builtin/os.lua +++ b/xmake/core/sandbox/builtin/os.lua @@ -88,11 +88,62 @@ function sandbox_builtin_os.cd(dir) end +-- create directory +function sandbox_builtin_os.mkdir(dir) + + -- check + assert(dir) + + -- done + if not os.mkdir(dir) then + utils.error("create directory: %s failed!", dir) + utils.abort() + end + +end + +-- remove directory +function sandbox_builtin_os.rmdir(dir) + + -- check + assert(dir) + + -- done + if os.isdir(dir) then + if not os.rmdir(dir) then + utils.error("remove directory: %s failed!", dir) + utils.abort() + end + end + +end + +-- run shell +function sandbox_builtin_os.run(cmd, ...) + + -- make command + cmd = string.format(cmd, ...) + + -- make temporary log file + log = os.tmpname() + + -- run command + if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then + io.cat(log) + utils.error("run: %s failed!", cmd) + utils.abort() + end + + -- remove the temporary log file + os.rm(log) +end + -- register some public interfaces sandbox_builtin_os.match = os.match sandbox_builtin_os.isdir = os.isdir sandbox_builtin_os.isfile = os.isfile sandbox_builtin_os.curdir = os.curdir +sandbox_builtin_os.execute = os.execute -- return module return sandbox_builtin_os |
