diff options
| author | ruki <[email protected]> | 2019-02-18 22:33:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-18 10:09:01 +0800 |
| commit | 061366a4d5fdff013903ac2b6ddede59e69fdd1a (patch) | |
| tree | 1d8bcb0acbed4250e3148d15b37926e82413f01f | |
| parent | fe2584406d733ad09c6bd930a187da8b5b902bff (diff) | |
improve option:add and set
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 120 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 31 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 95 |
3 files changed, 127 insertions, 119 deletions
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index e8208dc3e..29e4d896e 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -220,6 +220,36 @@ function _instance:_api_set_pathes(name, ...) -- get the scope info local scope = self._INFO + + -- get interpreter + local interp = self:interpreter() + + -- get extra config + local values = {...} + local extra_config = values[#values] + if table.is_dictionary(extra_config) then + table.remove(values) + else + extra_config = nil + end + + -- translate pathes + local pathes = self:_api_translate_pathes(values) + + -- save values + scope[name] = self:_api_handle(pathes) + + -- save extra config + if extra_config then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + for _, value in ipairs(pathes) do + extrascope[value] = extra_config + end + end + + -- save api source info, .e.g call api() in sourcefile:linenumber + self:_api_save_sourceinfo_to_scope(scope, name, pathes) end -- add the api pathes to the scope info @@ -259,6 +289,32 @@ function _instance:_api_add_pathes(name, ...) self:_api_save_sourceinfo_to_scope(scope, name, pathes) end +-- remove the api pathes to the scope info +function _instance:_api_del_pathes(name, ...) + + -- get the scope info + local scope = self._INFO + + -- get interpreter + local interp = self:interpreter() + + -- translate pathes + local values = {...} + local pathes = interp:_api_translate_pathes(values) + + -- mark these pathes as deleted + local pathes_deleted = {} + for _, pathname in ipairs(pathes) do + table.insert(pathes_deleted, "__del_" .. pathname) + end + + -- save values + scope[name] = self:_api_handle(table.join2(table.wrap(scope[name]), pathes_deleted)) + + -- save api source info, .e.g call api() in sourcefile:linenumber + self:_api_save_sourceinfo_to_scope(scope, name, pathes) +end + -- get the scope kind function _instance:kind() return self._KIND @@ -289,7 +345,7 @@ function _instance:set(name, value) self._INFO[name] = value end --- set the api value to the scope info +-- set the api values to the scope info function _instance:apival_set(name, ...) if type(name) == "string" then local api_type = self:_api_type("set_" .. name) @@ -301,14 +357,31 @@ function _instance:apival_set(name, ...) os.raise("unknown apitype(%s) for %s:set(%s, ...)", api_type, self:kind(), name) end else - os.raise("unknown api(%s) for %s:set(%s, ...)", name, self:kind(), name) + -- unknown api values? only set values + self:_api_set_values(name, ...) + end + + -- set array, e.g. set({{links = ..}, {links = ..}}) + elseif table.is_array(name) then + local array = name + for _, dict in ipairs(array) do + for k, v in pairs(dict) do + self:apival_set(k, unpack(table.wrap(v))) + end + end + + -- set dictionary, e.g. set({links = ..}) + elseif table.is_dictionary(name) then + local dict = name + for k, v in pairs(dict) do + self:apival_set(k, unpack(table.wrap(v))) end else - -- TODO + os.raise("unknown type(%s) for %s:set(%s, ...)", type(name), self:kind(), name) end end --- add the api value to the scope info +-- add the api values to the scope info function _instance:apival_add(name, ...) if type(name) == "string" then local api_type = self:_api_type("add_" .. name) @@ -320,10 +393,47 @@ function _instance:apival_add(name, ...) os.raise("unknown apitype(%s) for %s:add(%s, ...)", api_type, self:kind(), name) end else - os.raise("unknown api(%s) for %s:add(%s, ...)", name, self:kind(), name) + -- unknown api values? only add values + self:_api_add_values(name, ...) + end + + -- add array, e.g. add({{links = ..}, {links = ..}}) + elseif table.is_array(name) then + local array = name + for _, dict in ipairs(array) do + for k, v in pairs(dict) do + self:apival_add(k, unpack(table.wrap(v))) + end + end + + -- add dictionary, e.g. add({links = ..}) + elseif table.is_dictionary(name) then + local dict = name + for k, v in pairs(dict) do + self:apival_add(k, unpack(table.wrap(v))) + end + else + os.raise("unknown type(%s) for %s:add(%s, ...)", type(name), self:kind(), name) + end +end + +-- remove the api values to the scope info +function _instance:apival_del(name, ...) + if type(name) == "string" then + local api_type = self:_api_type("del_" .. name) + if api_type then + local del_xxx = self["_api_del_" .. api_type] + if del_xxx then + del_xxx(self, name, ...) + else + os.raise("unknown apitype(%s) for %s:del(%s, ...)", api_type, self:kind(), name) + end + else + os.raise("unknown api(%s) for %s:del(%s, ...)", name, self:kind(), name) end else -- TODO + os.raise("cannot support to remove a dictionary!") end end diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index be0d8ba16..e76fe2237 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -296,31 +296,18 @@ function _instance:get(name) end -- set the value to the option info -function _instance:set(name_or_info, ...) - if type(name_or_info) == "string" then - local args = ... - if args ~= nil then - self._INFO:set(name_or_info, table.unwrap(table.unique(table.join(...)))) - else - self._INFO:set(name_or_info, nil) - end - elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do - self:set(name, info) - end - end +function _instance:set(name, ...) + self._INFO:apival_set(name, ...) end -- add the value to the option info -function _instance:add(name_or_info, ...) - if type(name_or_info) == "string" then - local info = table.wrap(self._INFO:get(name_or_info)) - self._INFO:set(name_or_info, table.unwrap(table.unique(table.join(info, ...)))) - elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do - self:add(name, info) - end - end +function _instance:add(name, ...) + self._INFO:apival_add(name, ...) +end + +-- remove the value to the option info +function _instance:del(name, ...) + self._INFO:apival_del(name, ...) end -- get the given dependent option diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 607d57346..979befbb7 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -337,104 +337,15 @@ function target:set(name, ...) self._INFO:apival_set(name, ...) end ---[[ -function target:set(name_or_info, ...) - - -- set values to the given key? - if type(name_or_info) == "string" then - - -- get extra config - local values = {...} - local extra_config = values[#values] - if table.is_dictionary(extra_config) then - table.remove(values) - else - extra_config = nil - end - - -- set values - local name = name_or_info - if #values > 0 then - self._INFO:set(name, table.unwrap(table.unique(table.join(unpack(values))))) - else - self._INFO:set(name, nil) - end - - -- save extra config - if extra_config then - self._INFO:set("__extra_" .. name, self._INFO:get("__extra_" .. name) or {}) - local extrascope = self._INFO:get("__extra_" .. name) - for _, value in ipairs(values) do - extrascope[value] = extra_config - end - end - - -- set array, e.g. set({{links = ..}, {links = ..}}) - elseif table.is_array(name_or_info) then - for _, dict in pairs(name_or_info) do - for name, info in pairs(dict) do - self:set(name, info) - end - end - - -- set dictionary, e.g. set({links = ..}) - elseif table.is_dictionary(name_or_info) 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, ...) self._INFO:apival_add(name, ...) end ---[[ -function target:add(name_or_info, ...) - - -- add values to the given key? - if type(name_or_info) == "string" then - - -- get extra config - local values = {...} - local extra_config = values[#values] - if table.is_dictionary(extra_config) then - table.remove(values) - else - extra_config = nil - end - - -- add values - local name = name_or_info - local info = table.wrap(self._INFO:get(name)) - self._INFO:set(name, table.unwrap(table.unique(table.join(info, unpack(values))))) - - -- save extra config - if extra_config then - self._INFO:set("__extra_" .. name, self._INFO:get("__extra_" .. name) or {}) - local extrascope = self._INFO:get("__extra_" .. name) - for _, value in ipairs(values) do - extrascope[value] = extra_config - end - end - - -- add array, e.g. add({{links = ..}, {links = ..}}) - elseif table.is_array(name_or_info) then - for _, dict in pairs(name_or_info) do - for name, info in pairs(dict) do - self:add(name, info) - end - end - - -- add dictionary, e.g. add({links = ..}) - elseif table.is_dictionary(name_or_info) then - for name, info in pairs(name_or_info) do - self:add(name, info) - end - end +-- remove the value to the target info +function target:del(name, ...) + self._INFO:apival_del(name, ...) end -]] -- get user private data function target:data(name) |
