diff options
| author | ruki <[email protected]> | 2017-06-30 22:20:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-30 22:20:23 +0800 |
| commit | 9c49f6fc62b248690e8a74627e1a749a8468c6e1 (patch) | |
| tree | bb61b6ab1bf053d904e6dad4830af5ed895fa9a4 | |
| parent | e588531d2ba580d3b9289aa18015a5f89f676423 (diff) | |
add option.on_check
| -rw-r--r-- | xmake/core/project/option.lua | 101 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 11 |
3 files changed, 85 insertions, 29 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 6ecf0c397..cc0fe97fb 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -56,52 +56,76 @@ function option._cache() end -- check option for c/c++ -function option:_check_cx(kind) +function option:_cx_check() - -- get snippets - local snippets = self:get(kind .. "snippet") + -- import has_cxsnippets() + self._has_cxsnippets = self._has_cxsnippets or import("lib.detect.has_cxsnippets") - -- get types - local types = self:get(kind .. "types") + -- check for c and c++ + for _, kind in ipairs({"c", "cxx"}) do - -- get funcs - local funcs = self:get(kind .. "funcs") + -- get conditions + local snippets = self:get(kind .. "snippet") + local types = self:get(kind .. "types") + local funcs = self:get(kind .. "funcs") + local links = self:get(kind .. "links") + local includes = self:get(kind .. "includes") - -- get links - local links = self:get(kind .. "links") + -- need check it? + if snippets or types or funcs or links or includes then - -- get includes - local includes = self:get(kind .. "includes") + -- init source kind + local sourcekind = kind + if kind == "c" then + sourcekind = "cc" + end - -- need not check it - if not snippets and not types and not funcs and not links and not includes then - return true - end + -- check it + local ok, results_or_errors = sandbox.load(self._has_cxsnippets, snippets, {target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes}) + if not ok then + return false, results_or_errors + end - -- init source kind - local sourcekind = kind - if kind == "c" then - sourcekind = "cc" + -- not pass? + if not results_or_errors then + return false + end + end end - -- import has_cxsnippets() - self._has_cxsnippets = self._has_cxsnippets or import("lib.detect.has_cxsnippets") + -- ok + return true +end - -- get the tool name from the program - local ok, results_or_errors = sandbox.load(self._has_cxsnippets, snippets, {target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes}) - if not ok then - return false, results_or_errors - end +-- on check +function option:_on_check() - -- ok? - return results_or_errors + -- 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 + end end -- check option function option:_check() -- check it - local ok = self:_check_cx("c") and self:_check_cx("cxx") + 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 -- get name local name = self:name() @@ -111,6 +135,9 @@ function option:_check() -- trace utils.cprint("checking for the %s ... %s", name, utils.ifelse(ok, "${green}ok", "${red}no")) + if not ok and option_.get("verbose") and errors then + utils.cprint("${red}%s", errors) + end -- ok? return ok @@ -178,6 +205,17 @@ function option:get(infoname) return self._INFO[infoname] end +-- set the value to the option info +function option:set(name_or_info, ...) + if type(name_or_info) == "string" then + self._INFO[name_or_info] = table.unique(table.join(...)) + elseif type(name_or_info) == "table" and #name_or_info == 0 then + for name, info in pairs(name_or_info) do + self:set(name, info) + end + end +end + -- add the value to the option info function option:add(name_or_info, ...) if type(name_or_info) == "string" then @@ -197,6 +235,11 @@ end -- save the option info to the cache function option:save() + + -- clear scripts for caching to file + self:set("check", nil) + + -- save this option to cache option._cache():set(self:name(), self._INFO) option._cache():flush() end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 06d578066..62ed8683b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -265,6 +265,8 @@ function project._interpreter() , "target.after_package" , "target.after_install" , "target.after_uninstall" + -- option.on_xxx + , "option.on_check" -- target.on_xxx , "task.on_run" } diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ace3a2a18..67c2a5d4e 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -70,6 +70,17 @@ function target:get(name) return self._INFO[name] end +-- set the value to the target info +function target:set(name_or_info, ...) + if type(name_or_info) == "string" then + self._INFO[name_or_info] = table.unique(table.join(...)) + elseif type(name_or_info) == "table" and #name_or_info == 0 then + for name, info in pairs(name_or_info) do + self:set(name, info) + end + end +end + -- add the value to the target info function target:add(name_or_info, ...) if type(name_or_info) == "string" then |
