diff options
| author | ruki <[email protected]> | 2016-06-13 14:06:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-06-13 14:06:47 +0800 |
| commit | d960300a20f47a9787d4881dd4e7dd5d2f6150d9 (patch) | |
| tree | 30d9cf3256b229cc3d7e1e17697c9e9c8766da67 | |
| parent | 3f007becf54fad56d25d4386423443d0f3df182f (diff) | |
add on_result for option
| -rw-r--r-- | xmake/core/project/option.lua | 96 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 5 |
2 files changed, 61 insertions, 40 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 232addc5a..9e7e0ede0 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -34,6 +34,7 @@ local config = require("project/config") local cache = require("project/cache")("local.option") local linker = require("tool/linker") local compiler = require("tool/compiler") +local sandbox = require("sandbox/sandbox") -- check link function option:_check_link(sourcefile, objectfile, targetfile) @@ -432,36 +433,23 @@ end -- check option function option:_check() - -- the option name - local name = self:name() - - -- need check? - if config.get(name) == nil then + -- enable it? + local enable = self:get("enable") + if enable ~= nil and enable then - -- enable it? - local enable = self:get("enable") - if enable ~= nil and enable then + -- enable option + self:enable() - -- enable option - self:enable() + -- check option + elseif enable == nil and self:_check_condition() then - -- check option - elseif enable == nil and self:_check_condition() then + -- enable option + self:enable() + else - -- enable option - self:enable() - else - - -- disable option - self:disable() - end - - -- no check - elseif config.get(name) then - - -- save this option to configure directly - self:save() - end + -- disable option + self:disable() + end end -- enable this option @@ -484,6 +472,13 @@ function option:disable() self:clear() end +-- is enabled? +function option:enabled() + + -- ok? + return config.get(self:name()) +end + -- attempt to check option function option:check() @@ -492,19 +487,44 @@ function option:check() return end - -- the option scripts - local scripts = - { - self:get("check_before") - , self:get("check") or option._check - , self:get("check_after") - } + -- the option name + local name = self:name() + + -- need check? + if config.get(name) == nil then + + -- the option scripts + local scripts = + { + self:get("check_before") + , self:get("check") or option._check + , self:get("check_after") + } + + -- run the target scripts + for i = 1, 3 do + local script = scripts[i] + if script ~= nil then + local ok, errors = sandbox.load(script, self) + if not ok then + os.raise(errors) + end + end + end + + -- no check + elseif config.get(name) then + + -- save this option to configure directly + self:save() + end - -- run the target scripts - for i = 1, 3 do - local script = scripts[i] - if script ~= nil then - script(self) + -- on result + local on_result = self:get("result") + if on_result ~= nil then + local ok, errors = sandbox.load(on_result, self, self:enabled()) + if not ok then + os.raise(errors) end end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index f6fb8c3be..8dec86a2b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -441,7 +441,8 @@ function project._interpreter() , "includedirs") -- register api: on_action() to option - interp:api_register_on_script("option", "check") + interp:api_register_on_script("option", "check" + , "result") -- register api: before_action() to option interp:api_register_before_script("option", "check") @@ -539,7 +540,7 @@ function project._check(options, opt) -- no this option? if not opt then - raise("invalid dependent option: %s", dep) + os.raise("invalid dependent option: %s", dep) end -- check this dependent option |
