summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-22 00:36:30 +0800
committerruki <[email protected]>2023-09-22 00:36:30 +0800
commit8dcf8c655bbe13a6b10204d98310a6c178ba8ef5 (patch)
tree4f7e8b770ffc78d7830379ba773eea3ae3182cbb
parent3cd87cce3601759b2405b1dbf41828ae3c16513a (diff)
add global policies
-rw-r--r--xmake/actions/global/xmake.lua5
-rw-r--r--xmake/core/project/project.lua28
2 files changed, 30 insertions, 3 deletions
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index 508942b02..f9bd90921 100644
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -39,7 +39,10 @@ task("global")
{category = "Build Configuration"},
{nil, "build_warning", "kv", nil , "Enable the warnings output by default when building." },
{nil, "cachedir", "kv", nil , "The global cache directory." },
-
+ {nil, "policies", "kv", nil , "Set the global project policies.",
+ " e.g.",
+ " - xmake g --policies=run.autobuild",
+ " - xmake g --policies=build.warning" },
-- network configuration
{category = "Network Configuration"},
{nil, "network", "kv", "public" , "Set the network mode."
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index e25d05f44..020ca80f4 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -826,23 +826,47 @@ end
function project.policy(name)
local policies = project._memcache():get("policies")
if not policies then
+
-- get policies from project, e.g. set_policy("xxx", true)
policies = project.get("target.policy")
+
-- get policies from config, e.g. xmake f --policies=package.precompiled:n,package.install_only
-- @see https://github.com/xmake-io/xmake/issues/2318
local policies_config = config.get("policies")
if policies_config then
for _, policy in ipairs(policies_config:split(",", {plain = true})) do
local splitinfo = policy:split(":", {limit = 2})
+ local name = splitinfo[1]
+ if #splitinfo > 1 then
+ policies = policies or {}
+ policies[name] = baseoption.boolean(splitinfo[2])
+ else
+ policies = policies or {}
+ policies[name] = true
+ end
+ end
+ end
+
+ -- get policies from global, e.g. xmake g --policies=run.autobuild
+ local policies_config_global = global.get("policies")
+ if policies_config_global then
+ for _, policy in ipairs(policies_config_global:split(",", {plain = true})) do
+ local splitinfo = policy:split(":", {limit = 2})
+ local name = splitinfo[1]
if #splitinfo > 1 then
policies = policies or {}
- policies[splitinfo[1]] = baseoption.boolean(splitinfo[2])
+ if policies[name] == nil then
+ policies[name] = baseoption.boolean(splitinfo[2])
+ end
else
policies = policies or {}
- policies[splitinfo[1]] = true
+ if policies[name] == nil then
+ policies[name] = true
+ end
end
end
end
+
project._memcache():set("policies", policies)
if policies then
local defined_policies = policy.policies()