summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-27 23:53:21 +0800
committerruki <[email protected]>2023-09-27 23:53:21 +0800
commit6ffb48dd54c6d2d4e6168fac56943481d58e29c4 (patch)
tree7a463c358d683d9a9ad047ed0e1a052c488ee8fa
parentd53b673e631873b21b07665498a142cc31059c81 (diff)
add groups for interpreter
-rw-r--r--tests/projects/c++/linkorders/xmake.lua3
-rw-r--r--xmake/core/base/interpreter.lua67
-rw-r--r--xmake/core/base/scopeinfo.lua60
-rw-r--r--xmake/core/language/language.lua4
-rw-r--r--xmake/core/tool/builder.lua1
-rw-r--r--xmake/languages/asm/load.lua7
-rw-r--r--xmake/languages/c++/load.lua7
-rw-r--r--xmake/languages/dlang/load.lua7
-rw-r--r--xmake/languages/objc++/load.lua7
9 files changed, 153 insertions, 10 deletions
diff --git a/tests/projects/c++/linkorders/xmake.lua b/tests/projects/c++/linkorders/xmake.lua
index 41fee8897..09fd30378 100644
--- a/tests/projects/c++/linkorders/xmake.lua
+++ b/tests/projects/c++/linkorders/xmake.lua
@@ -17,7 +17,8 @@ target("demo")
if is_plat("macosx") then
add_frameworks("Foundation", "CoreFoundation")
end
- add_linkorders("framework::Foundation", "png16", "foo", "m", "pthread")
+ add_linkorders("framework::Foundation", "png16", "foo")
+ add_linkorders("m", "pthread")
add_linkgroups("m", "pthread")
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 = {}
diff --git a/xmake/languages/asm/load.lua b/xmake/languages/asm/load.lua
index 4cf15a3d6..94eaa2c51 100644
--- a/xmake/languages/asm/load.lua
+++ b/xmake/languages/asm/load.lua
@@ -31,8 +31,6 @@ function _get_apis()
, "target.add_defines"
, "target.add_undefines"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
- , "target.add_linkorders"
- , "target.add_linkgroups"
-- option.add_xxx
, "option.add_links"
, "option.add_syslinks"
@@ -70,6 +68,11 @@ function _get_apis()
, "toolchain.add_includedirs"
, "toolchain.add_sysincludedirs"
}
+ apis.groups = {
+ -- target.add_xxx
+ "target.add_linkorders"
+ , "target.add_linkgroups"
+ }
apis.paths = {
-- target.add_xxx
"target.add_headerfiles"
diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua
index ccf75a099..b35938783 100644
--- a/xmake/languages/c++/load.lua
+++ b/xmake/languages/c++/load.lua
@@ -36,8 +36,6 @@ function _get_apis()
, "target.add_frameworks"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
, "target.add_forceincludes"
- , "target.add_linkorders"
- , "target.add_linkgroups"
-- option.add_xxx
, "option.add_cincludes"
, "option.add_cxxincludes"
@@ -92,6 +90,11 @@ function _get_apis()
, "toolchain.add_sysincludedirs"
, "toolchain.add_frameworkdirs"
}
+ apis.groups = {
+ -- target.add_xxx
+ "target.add_linkorders"
+ , "target.add_linkgroups"
+ }
apis.paths = {
-- target.set_xxx
"target.set_pcheader"
diff --git a/xmake/languages/dlang/load.lua b/xmake/languages/dlang/load.lua
index acf45f0bd..f11fd8005 100644
--- a/xmake/languages/dlang/load.lua
+++ b/xmake/languages/dlang/load.lua
@@ -29,8 +29,6 @@ function _get_apis()
, "target.add_arflags"
, "target.add_shflags"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
- , "target.add_linkorders"
- , "target.add_linkgroups"
-- option.add_xxx
, "option.add_links"
, "option.add_syslinks"
@@ -62,6 +60,11 @@ function _get_apis()
, "toolchain.add_includedirs"
, "toolchain.add_sysincludedirs"
}
+ apis.groups = {
+ -- target.add_xxx
+ "target.add_linkorders"
+ , "target.add_linkgroups"
+ }
apis.paths = {
-- target.add_xxx
"target.add_linkdirs"
diff --git a/xmake/languages/objc++/load.lua b/xmake/languages/objc++/load.lua
index f01498cf8..8f4ae8a24 100644
--- a/xmake/languages/objc++/load.lua
+++ b/xmake/languages/objc++/load.lua
@@ -35,8 +35,6 @@ function _get_apis()
, "target.add_frameworks"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
, "target.add_forceincludes"
- , "target.add_linkorders"
- , "target.add_linkgroups"
-- option.add_xxx
, "option.add_cincludes"
, "option.add_cxxincludes"
@@ -91,6 +89,11 @@ function _get_apis()
, "toolchain.add_sysincludedirs"
, "toolchain.add_frameworkdirs"
}
+ apis.groups = {
+ -- target.add_xxx
+ "target.add_linkorders"
+ , "target.add_linkgroups"
+ }
apis.paths = {
-- target.set_xxx
"target.set_pmheader"