diff options
| author | ruki <[email protected]> | 2019-03-14 23:19:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-03-14 13:58:10 +0800 |
| commit | 98673a8aaf92c8cf5c8bddeb49f1c02a69952ac1 (patch) | |
| tree | a7307436a09cd093a84c81c1038e944fe4f6b0dd /xmake/actions/require/impl/package.lua | |
| parent | fbf5ca5b9f93713dd2d7017674aebcdd31aaa2aa (diff) | |
improve package.configs
Diffstat (limited to 'xmake/actions/require/impl/package.lua')
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index b7945d5d4..8e9aabe1b 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -294,6 +294,50 @@ function _sort_packages_urls(packages) end end +-- check the configurations of packages +-- +-- package("pcre2") +-- add_configs("bitwidth", {description = "Set the code unit width.", default = "8", values = {"8", "16", "32"}}) +-- add_configs("bitwidth", {type = "number", values = {8, 16, 32}}) +-- add_configs("bitwidth", {constraint = function(value) if tonumber(value) < 100 then return true end}) +-- +function _check_packages_configs(packages) + for _, package in ipairs(packages) do + local configs_defined = {} + for _, name in ipairs(package:get("configs")) do + configs_defined[name] = package:extraconf("configs", name) or {} + end + for name, value in pairs(package:configs()) do + local conf = configs_defined[name] + if conf then + local config_type = conf.type or "string" + if type(value) ~= config_type then + raise("package(%s %s): invalid type(%s) for config(%s), need type(%s)!", package:name(), package:version_str(), type(value), name, config_type) + end + if conf.values then + local found = false + for _, config_value in ipairs(conf.values) do + if tostring(value) == tostring(config_value) then + found = true + break + end + end + if not found then + raise("package(%s %s): invalid value(%s) for config(%s), please run `xmake require --info %s` to get all valid values!", package:name(), package:version_str(), value, name, package:name()) + end + end + if conf.constraint then + if not conf.constraint(value) then + raise("package(%s %s): invalid value(%s) for config(%s)!", package:name(), 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:name(), package:version_str(), name, package:name()) + end + end + end +end + -- select packages version function _select_packages_version(packages) @@ -442,6 +486,9 @@ function install_packages(requires, opt) -- load packages local packages = load_packages(requires, opt) + -- check the configurations of packages + _check_packages_configs(packages) + -- fetch packages (with system) from local first if not option.get("force") then process.runjobs(function (index) |
