summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-06-13 11:46:17 +0800
committerruki <[email protected]>2016-06-13 11:46:17 +0800
commit3f007becf54fad56d25d4386423443d0f3df182f (patch)
treeca91bed2fb8c889796324c70a16d93bacb8726e2
parent04619be0d8ff954508bffc017507cbd1e5ea058c (diff)
add deps and check scripts for option
-rw-r--r--xmake/core/project/option.lua89
-rw-r--r--xmake/core/project/project.lua36
2 files changed, 102 insertions, 23 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index dcc61c4bd..232addc5a 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -385,7 +385,7 @@ function option:_check_cxxtypes(cxxfile, objectfile, targetfile)
end
-- check option
-function option:_check()
+function option:_check_condition()
-- the files
local cfile = path.join(os.tmpdir(), "__checking.c")
@@ -429,8 +429,8 @@ function option:_check()
return true
end
--- attempt to check option
-function option:check()
+-- check option
+function option:_check()
-- the option name
local name = self:name()
@@ -442,27 +442,18 @@ function option:check()
local enable = self:get("enable")
if enable ~= nil and enable then
- -- enable this option
- config.set(name, true)
-
- -- save this option to configure
- self:save()
+ -- enable option
+ self:enable()
-- check option
- elseif enable == nil and self:_check() then
-
- -- enable this option
- config.set(name, true)
+ elseif enable == nil and self:_check_condition() then
- -- save this option to configure
- self:save()
+ -- enable option
+ self:enable()
else
- -- disable this option
- config.set(name, false)
-
- -- clear this option to configure
- self:clear()
+ -- disable option
+ self:disable()
end
-- no check
@@ -470,7 +461,55 @@ function option:check()
-- save this option to configure directly
self:save()
+ end
+end
+
+-- enable this option
+function option:enable()
+
+ -- enable this option
+ config.set(self:name(), true)
+
+ -- save this option to configure
+ self:save()
+end
+
+-- disable this option
+function option:disable()
+
+ -- disable this option
+ config.set(self:name(), false)
+
+ -- clear this option to configure
+ self:clear()
+end
+
+-- attempt to check option
+function option:check()
+
+ -- have been checked?
+ if self._CHECKED then
+ return
+ end
+
+ -- 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
+ script(self)
+ end
end
+
+ -- checked
+ self._CHECKED = true
end
-- get the option info
@@ -481,10 +520,18 @@ function option:get(infoname)
end
-- save the option info to the cache
-function option:save(is_clear)
+function option:save()
+
+ -- remove functions first before saving option
+ local info = {}
+ for k, v in pairs(self._INFO) do
+ if type(v) ~= "function" then
+ info[k] = v
+ end
+ end
-- save it
- cache:set(self:name(), self._INFO)
+ cache:set(self:name(), info)
cache:flush()
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 7d8f97df8..f6fb8c3be 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -413,7 +413,8 @@ function project._interpreter()
, "description")
-- register api: add_values() to option
- interp:api_register_add_values("option", "links"
+ interp:api_register_add_values("option", "deps"
+ , "links"
, "cincludes"
, "cxxincludes"
, "cfuncs"
@@ -438,6 +439,15 @@ function project._interpreter()
-- register api: add_pathes() to option
interp:api_register_add_pathes("option", "linkdirs"
, "includedirs")
+
+ -- register api: on_action() to option
+ interp:api_register_on_script("option", "check")
+
+ -- register api: before_action() to option
+ interp:api_register_before_script("option", "check")
+
+ -- register api: after_action() to option
+ interp:api_register_after_script("option", "check")
-- register api: add_cfunc() to target
interp:api_register("target", "add_cfunc", project._api_add_cfunc)
@@ -518,6 +528,28 @@ function project._interpreter()
return interp
end
+-- check option
+function project._check(options, opt)
+
+ -- exists the dependent options?
+ for _, dep in ipairs(table.wrap(opt:get("deps"))) do
+
+ -- get the dependent option
+ opt = options[dep]
+
+ -- no this option?
+ if not opt then
+ raise("invalid dependent option: %s", dep)
+ end
+
+ -- check this dependent option
+ project._check(options, opt)
+ end
+
+ -- check option
+ opt:check()
+end
+
-- get the project directory
function project.directory()
@@ -545,7 +577,7 @@ function project.check()
-- check all options
for _, opt in pairs(options) do
- opt:check()
+ project._check(options, opt)
end
-- leave toolchains environment