summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-14 23:07:12 +0800
committerruki <[email protected]>2020-05-14 12:43:17 +0800
commit0648c5178d1fabbaa082db10aeb1fa6bf822bd6a (patch)
tree1ec16af65d357a0761b90117e57135c58ccbc541
parentc2e533cef2040461bb77a64349d28db924d4150b (diff)
get default policy value
-rw-r--r--xmake/core/project/policy.lua15
-rw-r--r--xmake/core/project/project.lua4
-rw-r--r--xmake/core/project/target.lua4
-rw-r--r--xmake/core/tool/builder.lua4
4 files changed, 18 insertions, 9 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 6b097845c..4f70aa92c 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -45,7 +45,20 @@ end
-- check policy value
function policy.check(name, value)
- return value
+ local defined_policy = policy.policies()[name]
+ if defined_policy then
+ if value == nil then
+ value = defined_policy.default
+ else
+ local valtype = type(value)
+ if valtype ~= defined_policy.type then
+ utils.warning("policy(%s): invalid value type(%s), it shound be '%s'!", name, valtype, defined_policy.type)
+ end
+ end
+ return value
+ else
+ os.raise("unknown policy(%s)!", name)
+ end
end
-- return module: policy
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 59bcac984..2f9fd629c 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -812,9 +812,7 @@ end
-- get the project policy, the root policy of the target scope
function project.policy(name)
local policies = project.get("target.policy")
- if policies then
- return policy.check(name, policies[name])
- end
+ return policy.check(name, policies and policies[name])
end
-- clear project cache to reload targets and options
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3382910d7..ac1b45fbe 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -472,9 +472,7 @@ end
-- get the target policy
function _instance:policy(name)
local policies = self:get("policy")
- if policies then
- return policy.check(name, policies[name])
- end
+ return policy.check(name, policies and policies[name])
end
-- get the base name of target file
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 9c741f664..bb65acc0b 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -70,7 +70,7 @@ function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags)
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)
+ utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, flag)
end
end
@@ -94,7 +94,7 @@ function builder:_mapflags(flags, flagkind, target)
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)
+ utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, flag)
end
end
end