Skip to content

Commit

Permalink
add compatibility.version policy #5527
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Sep 15, 2024
1 parent 0c42d25 commit f9196df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
14 changes: 13 additions & 1 deletion xmake/core/project/policy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 22 additions & 0 deletions xmake/core/project/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit f9196df

Please sign in to comment.