diff options
| -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 |
