summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-26 00:53:12 +0800
committerruki <[email protected]>2025-09-26 00:53:12 +0800
commit41071f11cb134a124734b922fe51ef6d8f5cfc20 (patch)
tree0c74bc9481babb9fed827cd790b98be622d7f8cc
parent4321dfa63bb08dc761ab6810e758a8274cc46162 (diff)
improve to has_tool
-rw-r--r--xmake/core/package/package.lua12
-rw-r--r--xmake/core/project/target.lua12
-rw-r--r--xmake/modules/private/utils/target.lua22
3 files changed, 32 insertions, 14 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 3caa0ac2f..0eec73407 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1408,14 +1408,12 @@ end
-- ...
-- end
function _instance:has_tool(toolkind, ...)
- local _, toolname = self:tool(toolkind)
- if toolname then
- for _, v in ipairs(table.join(...)) do
- if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then
- return true
- end
- end
+ local target_utils = target._target_utils
+ if target_utils == nil then
+ target_utils = sandbox_module.import("private.utils.target", {anonymous = true})
+ target._target_utils = target_utils
end
+ return target_utils.has_tool(self, toolkind, ...)
end
-- get the user private data
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3b08223a6..73d53cbe6 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2678,14 +2678,12 @@ end
-- ...
-- end
function _instance:has_tool(toolkind, ...)
- local _, toolname = self:tool(toolkind)
- if toolname then
- for _, v in ipairs(table.pack(...)) do
- if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then
- return true
- end
- end
+ local target_utils = target._target_utils
+ if target_utils == nil then
+ target_utils = sandbox_module.import("private.utils.target", {anonymous = true})
+ target._target_utils = target_utils
end
+ return target_utils.has_tool(self, toolkind, ...)
end
-- has the given c funcs?
diff --git a/xmake/modules/private/utils/target.lua b/xmake/modules/private/utils/target.lua
index 84c307788..67fb79577 100644
--- a/xmake/modules/private/utils/target.lua
+++ b/xmake/modules/private/utils/target.lua
@@ -22,6 +22,28 @@
import("core.base.option")
import("core.project.project")
+-- Is this target has these tools?
+function has_tool(target, toolkind, ...)
+ local _, toolname = target:tool(toolkind)
+ if toolname then
+ -- We need compatibility with gcc/g++, clang/clang++ for c++ compiler/linker
+ -- @see https://github.com/xmake-io/xmake/issues/6852
+ local trim_xx = false
+ if toolname == "clangxx" or toolname == "gxx" then
+ toolname = toolname:rtrim("xx")
+ trim_xx = true
+ end
+ for _, v in ipairs(table.pack(...)) do
+ if trim_xx then
+ v = v:rtrim("xx")
+ end
+ if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then
+ return true
+ end
+ end
+ end
+end
+
-- does this flag belong to this tool?
-- @see https://github.com/xmake-io/xmake/issues/3022
--