diff options
| author | ruki <[email protected]> | 2022-05-28 23:31:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-28 23:31:23 +0800 |
| commit | fdc84716dd3796c9b1497a01223cff436a72fba3 (patch) | |
| tree | 3b22a8f7d4f5e852834c636680293540dde358e3 | |
| parent | 5d70ef54c67908120159570254d2c194bb6c6f75 (diff) | |
add policies config
| -rw-r--r-- | xmake/actions/config/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/option.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 17 |
3 files changed, 21 insertions, 2 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 3b81d88b6..5383bb892 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -179,6 +179,10 @@ task("config") {'m', "mode", "kv", "auto" , "Compile for the given mode.", values = _mode_values}, {'k', "kind", "kv", "static" , "Compile for the given target kind.", values = {"static", "shared", "binary"}}, {nil, "host", "kv", "$(host)" , "Set the current host environment."}, + {nil, "policies", "kv", nil , "Set the project policies.", + " e.g.", + " - xmake f --policies=package.fetch_only", + " - xmake f --policies=package.precompiled:n,package.install_only"}, {category = "Package Configuration"}, {nil, "require", "kv", nil , "Require all dependent packages?", values = {"yes", "no"}}, {nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package." diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 6289cf05e..6e3ae0c67 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -412,8 +412,6 @@ end -- get the given default option value for the current task function option.default(name) - - -- check assert(name) -- the defaults diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index c40cfbac0..9a80da1aa 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -31,6 +31,7 @@ local table = require("base/table") local global = require("base/global") local process = require("base/process") local hashset = require("base/hashset") +local baseoption = require("base/option") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") local memcache = require("cache/memcache") @@ -908,7 +909,23 @@ 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}) + if #splitinfo > 1 then + policies = policies or {} + policies[splitinfo[1]] = baseoption.boolean(splitinfo[2]) + else + policies = policies or {} + policies[splitinfo[1]] = true + end + end + end project._memcache():set("policies", policies) if policies then local defined_policies = policy.policies() |
