summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-28 13:36:54 +0800
committerruki <[email protected]>2021-11-28 13:36:54 +0800
commit6a315bad9fd1370c41ddd0f6cd48ae51dbf0d3f9 (patch)
treeca751702a5e42a9ec132314f6ac17dbac23add59
parent3726f42847029c73301a87937e80a9c78465fdb2 (diff)
add has_tool
-rw-r--r--xmake/core/package/package.lua16
-rw-r--r--xmake/core/project/target.lua16
-rw-r--r--xmake/core/tool/builder.lua10
3 files changed, 32 insertions, 10 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 2d7534878..d47858e55 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -845,6 +845,22 @@ function _instance:toolconfig(name)
end
end
+-- has the given tool for the current package?
+--
+-- e.g.
+--
+-- if package:has_tool("cc", "clang", "gcc") then
+-- ...
+-- end
+function _instance:has_tool(toolkind, ...)
+ local _, toolname = self:tool(toolkind)
+ for _, v in ipairs(table.join(...)) do
+ if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then
+ return true
+ end
+ end
+end
+
-- get the user private data
function _instance:data(name)
return self._DATA and self._DATA[name] or nil
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 572764c90..499db099c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1951,6 +1951,22 @@ function _instance:toolconfig(name)
end})
end
+-- has the given tool for the current target?
+--
+-- e.g.
+--
+-- if target:has_tool("cc", "clang", "gcc") then
+-- ...
+-- end
+function _instance:has_tool(toolkind, ...)
+ local _, toolname = self:tool(toolkind)
+ for _, v in ipairs(table.join(...)) do
+ if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then
+ return true
+ end
+ end
+end
+
-- get target apis
function target.apis()
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index e3c5de456..91bb707f8 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -442,16 +442,6 @@ function builder:map_flags(name, values, opt)
end
end
--- is the given name?
-function builder:is(...)
- local name = self:name()
- for _, v in ipairs(table.join(...)) do
- if v and name:find("^" .. v:gsub("%-", "%%-") .. "$") then
- return true
- end
- end
-end
-
-- get the format of the given target kind
function builder:format(targetkind)
local formats = self:get("formats")