diff options
| author | ruki <[email protected]> | 2018-08-11 00:37:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-08-10 21:43:38 +0800 |
| commit | 155587617e5e21a569911a4d93e7b5e39e44e0f5 (patch) | |
| tree | 148a5cfedd48f346aca990c4a6c8dc22ffde4771 | |
| parent | a114fc03b467a5de249496ddc0b32e138d934f44 (diff) | |
add has_configs and is_config
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 50 | ||||
| -rw-r--r-- | xmake/core/project/deprecated/project.lua | 25 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 18 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/has_configs.lua | 27 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/is_config.lua | 27 |
6 files changed, 111 insertions, 38 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e45f000c5..69b8322e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features * Support fasm assembler +* Add `has_configs` and `is_config` apis ### Changes @@ -474,6 +475,7 @@ ### 新特性 * 新增fasm汇编器支持 +* 添加`has_configs`和`is_config`接口去快速判断option和配置值 ### 改进 diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 9ed77a7f8..48f6bc9c1 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -239,44 +239,38 @@ end -- the current mode is belong to the given modes? function config.is_mode(...) - - -- get the current mode - local mode = config.get("mode") - if not mode then return false end - - -- exists this mode? - for _, m in ipairs(table.join(...)) do - if m and type(m) == "string" and m == mode then - return true - end - end + return config.is_value("mode", ...) end -- the current platform is belong to the given platforms? function config.is_plat(...) + return config.is_value("plat", ...) +end - -- get the current platform - local plat = config.get("plat") - if not plat then return false end +-- the current platform is belong to the given architectures? +function config.is_arch(...) + return config.is_value("arch", ...) +end + +-- the current config is belong to the given config values? +function config.is_value(name, ...) - -- exists this platform? and escape '-' - for _, p in ipairs(table.join(...)) do - if p and type(p) == "string" and plat:find("^" .. p:gsub("%-", "%%-") .. "$") then + -- get the current config value + local value = config.get(name) + if not value then return false end + + -- exists this value? and escape '-' + for _, v in ipairs(table.join(...)) do + if v and type(v) == "string" and value:find("^" .. v:gsub("%-", "%%-") .. "$") then return true end end end --- the current platform is belong to the given architectures? -function config.is_arch(...) - - -- get the current architecture - local arch = config.get("arch") - if not arch then return false end - - -- exists this architecture? and escape '-' - for _, a in ipairs(table.join(...)) do - if a and type(a) == "string" and arch:find("^" .. a:gsub("%-", "%%-") .. "$") then +-- some configs are enabled or exists? +function config.has(...) + for _, name in ipairs(table.join(...)) do + if name and type(name) == "string" and config.get(name) then return true end end @@ -284,8 +278,6 @@ end -- dump the configure function config.dump() - - -- dump if not option.get("quiet") then table.dump(config.options(), "__%w*", "configure") end diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua index ce0d6ab15..e1528fdab 100644 --- a/xmake/core/project/deprecated/project.lua +++ b/xmake/core/project/deprecated/project.lua @@ -119,6 +119,28 @@ function deprecated_project._api_option_set_enable(interp, ...) end) end +-- enable options? +function deprecated_project._api_is_option(interp, ...) + + -- make values + local values = "" + for _, v in ipairs(table.join(...)) do + if v and type(v) == "string" then + if #values == 0 then + values = v + else + values = values .. ", " .. v + end + end + end + + -- deprecated + deprecated.add("has_configs(\"%s\")", "is_option(\"%s\")", values) + + -- done + return config.has(...) +end + -- register api function deprecated_project.api_register(interp) @@ -128,6 +150,9 @@ function deprecated_project.api_register(interp) -- register api: add_pkgs() to root interp:api_register(nil, "add_pkgs", deprecated_project._api_add_packages) + -- register api: is_option() to root + interp:api_register(nil, "is_option", deprecated_project._api_is_option) + -- register api: set_enable() to option interp:api_register("option", "set_enable", deprecated_project._api_option_set_enable) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index e68d1086e..8fa47ab38 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -98,15 +98,14 @@ function project._api_is_host(interp, ...) return os.is_host(...) end --- enable options? -function project._api_is_option(interp, ...) +-- the current config is belong to the given config values? +function project._api_is_config(interp, name, ...) + return config.is_value(name, ...) +end - -- some options are enabled? - for _, o in ipairs(table.join(...)) do - if o and type(o) == "string" and config.get(o) then - return true - end - end +-- some configs are enabled? +function project._api_has_configs(interp, ...) + return config.has(...) end -- add module directories @@ -200,7 +199,8 @@ function project.interpreter() , {"is_mode", project._api_is_mode } , {"is_plat", project._api_is_plat } , {"is_arch", project._api_is_arch } - , {"is_option", project._api_is_option } + , {"is_config", project._api_is_config } + , {"has_configs", project._api_has_configs } -- add_xxx , {"add_moduledirs", project._api_add_moduledirs } , {"add_plugindirs", project._api_add_plugindirs } diff --git a/xmake/core/sandbox/modules/has_configs.lua b/xmake/core/sandbox/modules/has_configs.lua new file mode 100644 index 000000000..172a258f8 --- /dev/null +++ b/xmake/core/sandbox/modules/has_configs.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_configs.lua +-- + +-- return module +return require("project/config").has + diff --git a/xmake/core/sandbox/modules/is_config.lua b/xmake/core/sandbox/modules/is_config.lua new file mode 100644 index 000000000..2cce8d5e8 --- /dev/null +++ b/xmake/core/sandbox/modules/is_config.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file is_config.lua +-- + +-- return module +return require("project/config").is_value + |
