diff options
| author | ruki <[email protected]> | 2016-02-27 20:11:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-27 20:11:22 +0800 |
| commit | dd8ae9c540d5da04a8ffc8a030dfbbd53b26daa9 (patch) | |
| tree | 6a0a9222796e509fffa5f2c3c53567a29be3921e /xmake/core/base | |
| parent | 4e56f11cf31ad1279505ee5ed7e29945c20f0639 (diff) | |
add raise interfaces for os
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/deprecated/interpreter.lua | 9 | ||||
| -rw-r--r-- | xmake/core/base/filter.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 15 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 15 | ||||
| -rw-r--r-- | xmake/core/base/sandbox.lua | 3 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/template.lua | 3 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 10 |
8 files changed, 29 insertions, 36 deletions
diff --git a/xmake/core/base/deprecated/interpreter.lua b/xmake/core/base/deprecated/interpreter.lua index aa88fa7e0..91c734660 100644 --- a/xmake/core/base/deprecated/interpreter.lua +++ b/xmake/core/base/deprecated/interpreter.lua @@ -52,8 +52,7 @@ function deprecated_interpreter.api_register_set_scope(self, ...) -- check if not scope_for_kind[scope_name] then utils.error("set_%s(\"%s\") failed, %s not found!", scope_kind, scope_name, scope_name) - utils.error("please uses add_%s(\"%s\") first!", scope_kind, scope_name) - utils.abort() + os.raise("please uses add_%s(\"%s\") first!", scope_kind, scope_name) end -- init scope for name @@ -92,8 +91,7 @@ function deprecated_interpreter.api_register_add_scope(self, ...) -- check if scope_for_kind[scope_name] then utils.error("add_%s(\"%s\") failed, %s have been defined!", scope_kind, scope_name, scope_name) - utils.error("please uses set_%s(\"%s\")!", scope_kind, scope_name) - utils.abort() + os.raise("please uses set_%s(\"%s\")!", scope_kind, scope_name) end -- init scope for name @@ -126,8 +124,7 @@ function deprecated_interpreter.api_register_set_script(self, scope_kind, prefix -- bind script and get new script with sandbox local newscript, errors = sandbox.bind(script, self) if not newscript then - utils.error("set_%s(): %s", name, errors) - utils.abort() + os.raise("set_%s(): %s", name, errors) end -- update script? diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua index 8d187c32c..faacbafc2 100644 --- a/xmake/core/base/filter.lua +++ b/xmake/core/base/filter.lua @@ -24,6 +24,7 @@ local filter = filter or {} -- load modules +local os = require("base/os") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") @@ -78,8 +79,7 @@ function filter.handle(self, value) -- invalid builtin variable? if result == nil then - utils.error("invalid variable: $(%s)", variable) - utils.abort() + os.raise("invalid variable: $(%s)", variable) end -- ok? diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index e8cf8841e..9afa12f1e 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -232,15 +232,13 @@ function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...) -- done interpreter local ok, errors = xpcall(script, interpreter._traceback) if not ok then - utils.error(errors) - utils.abort() + os.raise(errors) end -- get mtime of the file self._PRIVATE._MTIMES[path.relative(file, self._PRIVATE._ROOTDIR)] = os.mtime(file) else - utils.error(errors) - utils.abort() + os.raise(errors) end end end @@ -740,8 +738,7 @@ function interpreter.api_register_on_script(self, scope_kind, prefix, ...) -- bind script and get new script with sandbox local newscript, errors = sandbox.bind(script, self) if not newscript then - utils.error("on_%s(): %s", name, errors) - utils.abort() + os.raise("on_%s(): %s", name, errors) end -- update script? @@ -791,8 +788,7 @@ function interpreter.api_register_add_keyvalues(self, scope_kind, prefix, ...) -- check count if (count % 2) == 1 then - utils.error("add_%s() values must be key-value pair!", name) - utils.abort() + os.raise("add_%s() values must be key-value pair!", name) end -- done @@ -884,8 +880,7 @@ function interpreter.api_call(self, apiname, ...) -- get api function local apifunc = self._PUBLIC[apiname] if not apifunc then - utils.error("call %s() failed, the api %s not found!", apiname) - utils.abort() + os.raise("call %s() failed, the api %s not found!", apiname) end -- call api function diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 62b8043a0..78542d72f 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -233,5 +233,20 @@ function os.cd(dir) return true end +-- raise an exception and abort the current script +-- +-- the parent function will capture it if we uses pcall or xpcall +-- +function os.raise(msg, ...) + + -- raise it + if msg then + error(string.format(msg, ...)) + else + error() + end +end + + -- return module: os return os diff --git a/xmake/core/base/sandbox.lua b/xmake/core/base/sandbox.lua index 971feeb72..43a483526 100644 --- a/xmake/core/base/sandbox.lua +++ b/xmake/core/base/sandbox.lua @@ -111,8 +111,7 @@ function sandbox._init() -- load module local ok, results = xpcall(script, debug.traceback) if not ok then - utils.error(results) - utils.abort() + os.raise(results) end -- register module diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 11643ee7e..9225fa7a8 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -200,8 +200,7 @@ function task.menu() end else -- errors - utils.error("taskmenu: %s", results) - utils.abort() + os.raise("taskmenu: %s", results) end else table.insert(options_full, option) @@ -243,8 +242,7 @@ function task.menu() local ok, results = task._call(description) if not ok then -- errors - utils.error("taskmenu: %s", results) - utils.abort() + os.raise("taskmenu: %s", results) end -- ok diff --git a/xmake/core/base/template.lua b/xmake/core/base/template.lua index 76f5398c5..b80e38baf 100644 --- a/xmake/core/base/template.lua +++ b/xmake/core/base/template.lua @@ -132,8 +132,7 @@ function template.templates(language) local results, errors = interp:load(templatefile, nil, true, true) if not results then -- trace - utils.error(errors) - utils.abort() + os.raise(errors) end -- save template directory diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index f0664f294..a73034261 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -56,16 +56,6 @@ function utils.error(msg, ...) print("error: " .. string.format(msg, ...)) end --- the abort function, will raise an exception --- and the parent function can capture it --- --- so we do not use os.exit() -function utils.abort() - - -- trace - error() -end - -- the warning function function utils.warning(msg, ...) |
