summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-02-03 00:49:42 +0800
committerruki <[email protected]>2023-02-03 00:49:42 +0800
commit743399e488b2371511235bde557daeeedcd653ce (patch)
tree97d14620fb66df30749be37a5f1f2b00d455efdd
parentc68a29c3dede70aad99f6a36f16391f1ae0ce31b (diff)
improve sourceinfo
-rw-r--r--xmake/core/base/scopeinfo.lua11
-rw-r--r--xmake/core/project/target.lua5
-rw-r--r--xmake/plugins/check/checkers/api/api_checker.lua2
3 files changed, 17 insertions, 1 deletions
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index f6dd7d475..359bcba9e 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -664,6 +664,17 @@ function _instance:extraconf_set(name, item, key, value)
end
end
+-- get configuration source information of the given api item
+--
+-- e.g.
+-- self:get("defines", "TEST")
+-- - add_defines("TEST")
+-- - src/xmake.lua:10
+--
+function _instance:sourceinfo(name, item)
+ return (self:get("__sourceinfo_" .. name) or {})[item]
+end
+
-- clone a new instance from the current
function _instance:clone()
return _instance.new(self:kind(), table.clone(self:info()), {interpreter = self:interpreter(), deduplicate = self._DEDUPLICATE, enable_filter = self._ENABLE_FILTER})
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index e991d288c..04227ab4b 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -488,6 +488,11 @@ function _instance:extraconf_set(name, item, key, value)
self._INFO:extraconf_set(name, item, key, value)
end
+-- get configuration source information of the given api item
+function _instance:sourceinfo(name, item)
+ return self._INFO:sourceinfo(name, item)
+end
+
-- get user private data
function _instance:data(name)
return self._DATA and self._DATA[name]
diff --git a/xmake/plugins/check/checkers/api/api_checker.lua b/xmake/plugins/check/checkers/api/api_checker.lua
index 44cecad28..5ebd7094f 100644
--- a/xmake/plugins/check/checkers/api/api_checker.lua
+++ b/xmake/plugins/check/checkers/api/api_checker.lua
@@ -49,7 +49,7 @@ function _show(apiname, value, target, opt)
end
-- get source information
- local sourceinfo = (target:get("__sourceinfo_" .. apiname) or {})[value] or {}
+ local sourceinfo = target:sourceinfo(apiname, value) or {}
local sourcetips = sourceinfo.file or ""
if sourceinfo.line then
sourcetips = sourcetips .. ":" .. sourceinfo.line .. ": "