diff options
| author | ruki <[email protected]> | 2020-05-14 23:02:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-14 12:12:09 +0800 |
| commit | c2e533cef2040461bb77a64349d28db924d4150b (patch) | |
| tree | b1fb0622cd61514be099ec30c3f282c1b3f169e4 | |
| parent | f7ece67bf3f768f98b22818aa13afd65a00831d7 (diff) | |
check flags policy
| -rw-r--r-- | xmake/core/base/interpreter.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 52 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/policy.lua | 34 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/module.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 29 |
8 files changed, 117 insertions, 26 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index fe56aa44a..1c301e891 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -490,7 +490,7 @@ function interpreter:_handle(scope, remove_repeat, enable_filter) -- remove repeat first for each slice with deleted item (__del_xxx) if remove_repeat and not table.is_dictionary(values) then - values = table.unique(values, function (v) return v:startswith("__del_") end) + values = table.unique(values, function (v) return type(v) == "string" and v:startswith("__del_") end) end -- filter values @@ -1118,6 +1118,9 @@ function interpreter:api_register_set_keyvalues(scope_kind, ...) extra_config = nil end + -- expand values if only one + values = table.unwrap(values) + -- save values to "name" scope[name] = scope[name] or {} scope[name][key] = values @@ -1162,9 +1165,12 @@ function interpreter:api_register_add_keyvalues(scope_kind, ...) extra_config = nil end + -- expand values if only one + values = table.unwrap(values) + -- save values to "name" scope[name] = scope[name] or {} - scope[name][key] = table.join2(scope[name][key] or {}, values) + scope[name][key] = table.join2(table.wrap(scope[name][key]), values) -- save values to "name.key" local name_key = name .. "." .. key diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 85fb0d0fd..05337e4c8 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -173,8 +173,8 @@ function _instance:_api_set_keyvalues(name, key, ...) extra_config = nil end - -- expand values - values = table.join(unpack(values)) + -- expand values if only one + values = table.unwrap(values) -- save values to "name" scope[name] = scope[name] or {} @@ -213,8 +213,8 @@ function _instance:_api_add_keyvalues(name, key, ...) extra_config = nil end - -- expand values - values = table.join(unpack(values)) + -- expand values if only one + values = table.unwrap(values) -- save values to "name" scope[name] = scope[name] or {} diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua new file mode 100644 index 000000000..6b097845c --- /dev/null +++ b/xmake/core/project/policy.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file policy.lua +-- + +-- define module: policy +local policy = policy or {} + +-- load modules +local os = require("base/os") +local io = require("base/io") +local path = require("base/path") +local table = require("base/table") +local utils = require("base/utils") +local string = require("base/string") + +-- get all defined policies +function policy.policies() + local policies = policy._POLICIES + if not policies then + policies = + { + ["check.auto_ignore_flags"] = { description = "Enable check and ignore unsupported flags automatically.", default = true, type = "boolean"}, + ["check.auto_map_flags"] = { description = "Enable map gcc flags to the current compiler and linker automatically.", default = true, type = "boolean"} + } + policy._POLICIES = policies + end + return policies +end + +-- check policy value +function policy.check(name, value) + return value +end + +-- return module: policy +return policy diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index f7abb5de1..59bcac984 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -36,6 +36,7 @@ local rule = require("project/rule") local target = require("project/target") local config = require("project/config") local option = require("project/option") +local policy = require("project/policy") local requireinfo = require("project/requireinfo") local deprecated_project = require("project/deprecated/project") local package = require("package/package") @@ -812,8 +813,7 @@ end function project.policy(name) local policies = project.get("target.policy") if policies then - local value = policies[name] - return value and table.unwrap(value) + return policy.check(name, policies[name]) end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index b466c9e2e..3382910d7 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -33,6 +33,7 @@ local deprecated = require("base/deprecated") local rule = require("project/rule") local option = require("project/option") local config = require("project/config") +local policy = require("project/policy") local requireinfo = require("project/requireinfo") local tool = require("tool/tool") local linker = require("tool/linker") @@ -472,8 +473,7 @@ end function _instance:policy(name) local policies = self:get("policy") if policies then - local value = policies[name] - return value and table.unwrap(value) + return policy.check(name, policies[name]) end end diff --git a/xmake/core/sandbox/modules/import/core/project/policy.lua b/xmake/core/sandbox/modules/import/core/project/policy.lua new file mode 100644 index 000000000..0d5f921f5 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/project/policy.lua @@ -0,0 +1,34 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file policy.lua +-- + +-- define module +local sandbox_core_project_policy = sandbox_core_project_policy or {} + +-- load modules +local table = require("base/table") +local policy = require("project/policy") +local project = require("project/project") +local raise = require("sandbox/modules/raise") + +-- export some readonly interfaces +sandbox_core_project_policy.policies = policy.policies + +-- return module +return sandbox_core_project_policy diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua index 0ddde0d27..633a7390a 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua @@ -165,7 +165,7 @@ function core_sandbox_module._load(dir, name, instance, module) end -- bind main entry - if result.main then + if type(result) == "table" and result.main then setmetatable(result, { __call = function (_, ...) return result.main(...) end}) end diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 8478988ad..9c741f664 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -50,7 +50,7 @@ function builder:_targetkind() end -- map gcc flag to the given builder flag -function builder:_mapflag(flag, flagkind, mapflags) +function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags) -- attempt to map it directly local flag_mapped = mapflags[flag] @@ -67,7 +67,7 @@ function builder:_mapflag(flag, flagkind, mapflags) end -- has this flag? - if self:has_flags(flag, flagkind) then + if auto_ignore_flags == false or self:has_flags(flag, flagkind) then return flag else utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` if you want to set it.", flagkind, flag) @@ -75,22 +75,23 @@ function builder:_mapflag(flag, flagkind, mapflags) end -- map gcc flags to the given builder flags -function builder:_mapflags(flags, flagkind) +function builder:_mapflags(flags, flagkind, target) local results = {} local mapflags = self:get("mapflags") + local auto_map_flags = target and target:policy("check.auto_map_flags") + local auto_ignore_flags = target and target:policy("check.auto_ignore_flags") flags = table.wrap(flags) - if mapflags then + if mapflags and (auto_map_flags ~= false) then for _, flag in pairs(flags) do - local flag_mapped = self:_mapflag(flag, flagkind, mapflags) + local flag_mapped = self:_mapflag(flag, flagkind, mapflags, auto_ignore_flags) if flag_mapped then table.insert(results, flag_mapped) end end - else for _, flag in pairs(flags) do - if self:has_flags(flag, flagkind) then + if auto_ignore_flags == false or self:has_flags(flag, flagkind) then table.insert(results, flag) else utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` if you want to set it.", flagkind, flag) @@ -136,11 +137,11 @@ function builder:_add_flags_from_flagkind(flags, target, flagkind, opt) if flagconf and flagconf.force then table.join2(flags, flag) else - table.join2(flags, self:_mapflags(flag, flagkind)) + table.join2(flags, self:_mapflags(flag, flagkind, target)) end end else - table.join2(flags, self:_mapflags(targetflags, flagkind)) + table.join2(flags, self:_mapflags(targetflags, flagkind, target)) end end @@ -162,9 +163,9 @@ function builder:_add_flags_from_option(flags, opt) end -- add flags from the package -function builder:_add_flags_from_package(flags, pkg) +function builder:_add_flags_from_package(flags, pkg, target) for _, flagkind in ipairs(self:_flagkinds()) do - table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind)) + table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind, target)) end end @@ -199,7 +200,7 @@ function builder:_add_flags_from_target(flags, target) -- add flags from packages for _, pkg in ipairs(target:orderpkgs()) do - self:_add_flags_from_package(targetflags, pkg) + self:_add_flags_from_package(targetflags, pkg, target) end -- inherit flags (public/interface) from all dependent targets @@ -226,7 +227,7 @@ function builder:_add_flags_from_argument(flags, target, args) for _, flagkind in ipairs(self:_flagkinds()) do -- add auto mapping flags - table.join2(flags, self:_mapflags(args[flagkind], flagkind)) + table.join2(flags, self:_mapflags(args[flagkind], flagkind, target)) -- add original flags local original_flags = (args.force or {})[flagkind] @@ -388,8 +389,6 @@ end -- get the format of the given target kind function builder:format(targetkind) - - -- get formats local formats = self:get("formats") if formats then return formats[targetkind] |
