diff options
| author | ruki <[email protected]> | 2024-09-15 21:55:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-09-15 21:55:21 +0800 |
| commit | f9196dfa7073e3c3511230072d606c89f28a075d (patch) | |
| tree | dc503526c03a44896aad437346ef59830622168a | |
| parent | 0c42d253e0b9cb39ebdd4cdd22516f80cea7dc0e (diff) | |
add compatibility.version policy #5527
| -rw-r--r-- | xmake/core/project/policy.lua | 14 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 22 |
2 files changed, 35 insertions, 1 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 7327918a2..e82774a0c 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -149,13 +149,25 @@ function policy.policies() ["diagnosis.check_build_deps"] = {description = "Show diagnosis info for checking build dependencies", default = false, type = "boolean"}, -- Set the network mode, e.g. public/private -- private: it will disable fetch remote package repositories - ["network.mode"] = {description = "Set the network mode", type = "string"} + ["network.mode"] = {description = "Set the network mode", type = "string"}, + -- Set the compatibility version, e.g. 2.0, 3.0 + ["compatibility.version"] = {description = "Set the compatibility version", type = "string"} } policy._POLICIES = policies end return policies end +-- set policy default value +function policy.set_default(name, value) + local defined_policy = policy.policies()[name] + if defined_policy then + defined_policy.default = value + else + os.raise("unknown policy(%s)!", name) + end +end + -- check policy value function policy.check(name, value) local defined_policy = policy.policies()[name] diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 5878ffead..836ece6b6 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -32,6 +32,7 @@ local global = require("base/global") local process = require("base/process") local hashset = require("base/hashset") local baseoption = require("base/option") +local semver = require("base/semver") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") local instance_deps = require("base/private/instance_deps") @@ -819,11 +820,32 @@ function project.version() return project.get("target.version") end +-- init default policies +-- @see https://github.com/xmake-io/xmake/issues/5527 +function project._init_default_policies() + local compatibility_version = project.policy("compatibility.version") + if compatibility_version then + if semver.compare(compatibility_version, "3.0") >= 0 then + policy.set_default("package.cmake_generator.ninja", true) + else + policy.set_default("package.cmake_generator.ninja", false) + end + end +end + -- get the project policy, the root policy of the target scope function project.policy(name) local policies = project._memcache():get("policies") if not policies then + -- init default policies + if name ~= "compatibility.version" then + if not project._DEFAULT_POLICIES_INITED then + project._init_default_policies() + project._DEFAULT_POLICIES_INITED = true + end + end + -- get policies from project, e.g. set_policy("xxx", true) policies = project.get("target.policy") |
