summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-23 22:36:52 +0800
committerruki <[email protected]>2024-01-25 12:09:58 +0800
commit0b4aa5644e51a62aa69e8d41f81b48629910a5c2 (patch)
tree3dc6e984d46fcdccf1fad679a59926946becf8a3
parentad109d0818b38889e703a038514a3acb0d90cdd7 (diff)
improve to check runtimes
-rw-r--r--xmake/modules/private/action/require/impl/package.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 7a9d89bf8..c46a62025 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -354,9 +354,23 @@ function _add_package_configurations(package)
package:add("configs", "asan", {builtin = true, description = "Enable the address sanitizer.", type = "boolean"})
end
if package:extraconf("configs", "runtimes", "default") == nil then
- package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = {
- "MT", "MTd", "MD", "MDd",
- "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"}})
+ local values = {"MT", "MTd", "MD", "MDd",
+ "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"}
+ package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", values = values, restrict = function (value)
+ local values_set = hashset.from(values)
+ if type(value) == "string" then
+ if not values_set:has(value) then
+ return false
+ end
+ elseif type(value) == "table" then
+ for _, item in ipairs(value) do
+ if not values_set:has(item) then
+ return false
+ end
+ end
+ end
+ return true
+ end})
end
if package:extraconf("configs", "toolchains", "default") == nil then
package:add("configs", "toolchains", {builtin = true, description = "Set package toolchains only for cross-compilation."})
@@ -447,7 +461,11 @@ function _check_package_configurations(package)
if config_type ~= nil and type(value) ~= config_type then
raise("package(%s %s): invalid type(%s) for config(%s), need type(%s)!", package:displayname(), package:version_str(), type(value), name, config_type)
end
- if conf.values then
+ if conf.restrict then
+ if not conf.restrict(value) then
+ raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), string.serialize(value, {indent = false}), name)
+ end
+ elseif conf.values then
local found = false
for _, config_value in ipairs(conf.values) do
if tostring(value) == tostring(config_value) then
@@ -459,11 +477,6 @@ function _check_package_configurations(package)
raise("package(%s %s): invalid value(%s) for config(%s), please run `xmake require --info %s` to get all valid values!", package:displayname(), package:version_str(), value, name, package:name())
end
end
- if conf.restrict then
- if not conf.restrict(value) then
- raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), value, name)
- end
- end
else
raise("package(%s %s): invalid config(%s), please run `xmake require --info %s` to get all configurations!", package:displayname(), package:version_str(), name, package:name())
end