summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-17 09:31:11 +0800
committerruki <[email protected]>2017-07-17 09:31:11 +0800
commita9330f8d12a76f7c5cd8488937cdd3bfc09fff6a (patch)
tree498522cdfc39836c4e5f16f1fe17e2bbe3580a19
parent6a222cf4f73536a9c56820451c5e68435b24a620 (diff)
improve option check script
-rw-r--r--xmake/actions/config/configheader.lua6
-rw-r--r--xmake/actions/package/main.lua2
-rw-r--r--xmake/core/project/option.lua136
-rw-r--r--xmake/core/project/project.lua2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_package.lua4
5 files changed, 87 insertions, 63 deletions
diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua
index cc58c2943..1aa0aabdb 100644
--- a/xmake/actions/config/configheader.lua
+++ b/xmake/actions/config/configheader.lua
@@ -72,10 +72,12 @@ function _make_for_target(files, target)
for _, opt in ipairs(target:options()) do
-- get the option defines
- table.join2(defines, opt:get("defines_h_if_ok"))
+ table.join2(defines, opt:get("defines_h"))
+ table.join2(defines, opt:get("defines_h_if_ok")) -- deprecated
-- get the option undefines
- table.join2(undefines, opt:get("undefines_h_if_ok"))
+ table.join2(undefines, opt:get("undefines_h"))
+ table.join2(undefines, opt:get("undefines_h_if_ok")) -- deprecated
end
-- make the defines
diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua
index 59387936a..e9255635b 100644
--- a/xmake/actions/package/main.lua
+++ b/xmake/actions/package/main.lua
@@ -89,7 +89,7 @@ option("[targetname]")
set_languages("c99", "cxx11")
-- add defines to config.h if checking ok
- add_defines_h_if_ok("$(prefix)_PACKAGE_HAVE_[TARGETNAME]")
+ add_defines_h("$(prefix)_PACKAGE_HAVE_[TARGETNAME]")
-- add links for checking
add_links("[targetname]")
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 222c5ba93..d9d6d87ba 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -55,6 +55,25 @@ function option._cache()
return option._CACHE
end
+-- save the option info to the cache
+function option:_save()
+
+ -- clear scripts for caching to file
+ self:set("check", nil)
+ self:set("check_after", nil)
+ self:set("check_before", nil)
+
+ -- save this option to cache
+ option._cache():set(self:name(), self._INFO)
+ option._cache():flush()
+end
+
+-- clear the option info for cache
+function option:_clear()
+ option._cache():set(self:name(), nil)
+ option._cache():flush()
+end
+
-- check option for c/c++
function option:_cx_check()
@@ -86,9 +105,9 @@ function option:_cx_check()
return false, results_or_errors
end
- -- not pass?
- if not results_or_errors then
- return false
+ -- passed?
+ if results_or_errors then
+ self:enable(true)
end
end
end
@@ -103,29 +122,20 @@ function option:_on_check()
-- get check script
local check = self:get("check")
if check then
-
- -- check it
- local ok, results_or_errors = sandbox.load(check, self)
- if not ok then
- return false, results_or_errors
- else
- return results_or_errors
- end
+ return sandbox.load(check, self)
+ else
+ return self:_cx_check()
end
end
-- check option
function option:_check()
+ -- disable this option first
+ self:enable(false)
+
-- check it
- local ok = nil
- local errors = nil
- for _, check in ipairs({self._on_check, self._cx_check}) do
- ok, errors = check(self)
- if ok ~= nil then
- break
- end
- end
+ local ok, errors = self:_on_check()
-- get name
local name = self:name()
@@ -134,13 +144,10 @@ function option:_check()
end
-- trace
- utils.cprint("checking for the %s ... %s", name, utils.ifelse(ok, "${green}ok", "${red}no"))
- if not ok and errors then
+ utils.cprint("checking for the %s ... %s", name, utils.ifelse(self:is_enabled(), "${green}ok", "${red}no"))
+ if not ok then
os.raise(errors)
end
-
- -- ok?
- return ok
end
-- attempt to check option
@@ -172,35 +179,18 @@ function option:check(force)
-- use it directly if the default value exists
if default ~= nil then
-
- -- save the default value
- config.set(name, default)
-
- -- save this option to configure
- self:save()
-
+ self:set_value(default)
-- check option as boolean switch automatically if the default value not exists
- elseif default == nil and self:_check() then
-
- -- enable this option
- config.set(name, true)
-
- -- save this option to configure
- self:save()
+ elseif default == nil then
+ self:_check()
+ -- disable this option in other case
else
-
- -- disable this option
- config.set(name, false)
-
- -- clear this option to configure
- self:clear()
+ self:enable(false)
end
- -- no check
+ -- no check? save this option to configure directly
elseif config.get(name) then
-
- -- save this option to configure directly
- self:save()
+ self:_save()
end
-- after check
@@ -208,15 +198,43 @@ function option:check(force)
check_after(self)
end
+ -- flush the option cache
+ self:_flush()
+
-- checked
self._CHECKED = true
end
+-- get the option value
+function option:value()
+ return config.get(self:name())
+end
+
+-- set the option value
+function option:set_value(value)
+ config.set(self:name(), value)
+ self:_save()
+end
+
-- this option is enabled?
-function option:enabled()
+function option:is_enabled()
return config.get(self:name())
end
+-- enable or disable this option
+function option:enable(is_enabled)
+
+ -- enable or disable this option?
+ config.set(self:name(), is_enabled)
+
+ -- save or clear this option in cache
+ if is_enabled then
+ self:_save()
+ else
+ self:_clear()
+ end
+end
+
-- dump this option
function option:dump()
table.dump(self._INFO)
@@ -261,23 +279,27 @@ function option:deps()
end
-- save the option info to the cache
-function option:save()
+function option:_save()
+ option._cache():set(self:name(), self._INFO)
+end
+
+-- clear the option info for cache
+function option:_clear()
+ option._cache():set(self:name(), nil)
+end
+
+-- flush the option cache to file
+function option:_flush()
-- clear scripts for caching to file
self:set("check", nil)
self:set("check_after", nil)
self:set("check_before", nil)
- -- save this option to cache
- option._cache():set(self:name(), self._INFO)
+ -- flush cache
option._cache():flush()
end
--- clear the option info for cache
-function option:clear()
- option._cache():set(self:name(), nil)
-end
-
-- get the option name
function option:name()
return self._NAME
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 5195df00b..dca8c946d 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -506,7 +506,7 @@ function project.options(enable_filter)
instance._INFO = optioninfo
-- save it
- table.insert(options,instance)
+ table.insert(options, instance)
end
-- ok?
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
index 626f652cd..17d3f319d 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
@@ -160,7 +160,7 @@ end
-- find package
--
-- @param name the package name
--- @param opt the package options. e.g. {plat = "iphoneos", arch = "arm64", version = "1.0.1", pathes = {"/usr/lib"}, links = {"ssl"}, includes = {"ssl.h"}}
+-- @param opt the package options. e.g. {verbose = false, plat = "iphoneos", arch = "arm64", version = "1.0.1", pathes = {"/usr/lib"}, links = {"ssl"}, includes = {"ssl.h"}}
--
-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}
--
@@ -201,7 +201,7 @@ function sandbox_lib_detect_find_package.main(name, opt)
cache.save(key, cacheinfo)
-- trace
- if option.get("verbose") then
+ if opt.verbose or option.get("verbose") then
if result then
utils.cprint("checking for the %s ... ${green}ok", name)
else