diff options
| author | ruki <[email protected]> | 2023-09-27 23:53:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-27 23:53:21 +0800 |
| commit | 6ffb48dd54c6d2d4e6168fac56943481d58e29c4 (patch) | |
| tree | 7a463c358d683d9a9ad047ed0e1a052c488ee8fa /xmake/core | |
| parent | d53b673e631873b21b07665498a142cc31059c81 (diff) | |
add groups for interpreter
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 67 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 60 | ||||
| -rw-r--r-- | xmake/core/language/language.lua | 4 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 1 |
4 files changed, 131 insertions, 1 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 8a64aaa58..ab25e927e 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1214,6 +1214,73 @@ function interpreter:api_register_set_keyvalues(scope_kind, ...) self:_api_register_xxx_values(scope_kind, "set", implementation, ...) end +-- register api for set_groups +function interpreter:api_register_set_groups(scope_kind, ...) + + -- define implementation + local implementation = function (self, scope, name, ...) + + -- 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 + + -- expand values + values = table.join(table.unpack(values)) + + -- save values + scope[name] = values + + -- save extra config + if extra_config and extra_config.name then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + extrascope[extra_config.name] = extra_config + end + end + + -- register implementation + self:_api_register_xxx_values(scope_kind, "set", implementation, ...) +end + +-- register api for add_groups +function interpreter:api_register_add_groups(scope_kind, ...) + + -- define implementation + local implementation = function (self, scope, name, ...) + + -- 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 + + -- expand values + values = table.join(table.unpack(values)) + + -- save values + scope[name] = scope[name] or {} + table.insert(scope[name], values) + + -- save extra config + if extra_config and extra_config.name then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + extrascope[extra_config.name] = extra_config + end + end + + -- register implementation + self:_api_register_xxx_values(scope_kind, "add", implementation, ...) +end + -- register api for add_keyvalues -- -- interp:api_register_add_keyvalues("scope_kind", "name1", "name2", ...) diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index d7215917f..8254ffc98 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -188,6 +188,66 @@ function _instance:_api_add_values(name, ...) end end +-- set the api groups to the scope info +function _instance:_api_set_groups(name, ...) + + -- get the scope info + local scope = self._INFO + + -- 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 + + -- expand values + values = table.join(table.unpack(values)) + + -- save values + scope[name] = values + + -- save extra config + if extra_config and extra_config.name then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + extrascope[extra_config.name] = extra_config + end +end + +-- add the api groups to the scope info +function _instance:_api_add_groups(name, ...) + + -- get the scope info + local scope = self._INFO + + -- 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 + + -- expand values + values = table.join(table.unpack(values)) + + -- save values + scope[name] = scope[name] or {} + table.insert(scope[name], values) + scope[name] = self:_api_handle(name, scope[name]) + + -- save extra config + if extra_config and extra_config.name then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + extrascope[extra_config.name] = extra_config + end +end + -- set the api key-values to the scope info function _instance:_api_set_keyvalues(name, key, ...) diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 557839959..73045c933 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -370,17 +370,19 @@ function language.apis() if not languages then os.raise(errors) end - apis = {values = {}, paths = {}, custom = {}, dictionary = {}} + apis = {values = {}, groups = {}, paths = {}, custom = {}, dictionary = {}} for name, instance in pairs(languages) do local instance_apis = instance:get("apis") if instance_apis then table.join2(apis.values, table.wrap(instance_apis.values)) + table.join2(apis.groups, table.wrap(instance_apis.groups)) table.join2(apis.paths, table.wrap(instance_apis.paths)) table.join2(apis.custom, table.wrap(instance_apis.custom)) table.join2(apis.dictionary, table.wrap(instance_apis.dictionary)) end end apis.values = table.unique(apis.values) + apis.groups = table.unique(apis.groups) apis.paths = table.unique(apis.paths) apis.custom = table.unique(apis.custom) language._APIS = apis diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index afee76583..9c44c2c71 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -449,6 +449,7 @@ function builder:_sort_links_of_items(target, items) if linkgroups and type(linkgroups) == "table" and #linkgroups > 1 then makegroups = true end + utils.dump(linkorders) -- get all links local links = {} |
