[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform version overrides #148

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Parse platform support as a dependency.
Platform strings used in override tables or the supported_platform list
is a dependency string. The deps.match_platform function will compare
this string to the detected platform and system name. The old
cfg.is_platform function matches only plain strings against built-in
platform names (like it always has).
  • Loading branch information
whoopdedo committed Aug 31, 2013
commit 96159d02ee332e2412603b1fdce56927e2a09e91
13 changes: 6 additions & 7 deletions src/luarocks/cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,17 @@ end
user_agent = "LuaRocks/"..program_version.." "..arch

--- Check if platform was detected
-- Compare a string against the standard system names.
-- If you want to match the full system name or version then use
-- deps.match_platform
-- @param query string: The platform name to check.
-- @return boolean: true if LuaRocks is currently running on queried platform.
function is_platform(query)
assert(type(query) == "string")

query = "^" .. query:lower()
for index, platform in ipairs(platforms) do
if platform:match(query) then
return index, platform
for _, platform in ipairs(platforms) do
if platform == query then
return true
end
end
if system:lower():match(query) then
return #platforms + 1, system
end
end
37 changes: 29 additions & 8 deletions src/luarocks/deps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,27 @@ function match_deps(rockspec, blacklist, deps_mode)
return matched, missing, no_upgrade
end

--- Match a platform dependency to the system name and version
-- @param plat string: A platform dependency as a string.
-- @return number, string: The index and name of the platform type
-- that was successfully matched against. The index is from the
-- cfg.platforms list or one past the length for the canonical
-- system name cfg.system.
function match_platform(plat)
assert(type(plat) == "string")

local plat_dep, err = parse_dep(plat)
if not plat_dep then return nil, err end
for index, platform in ipairs(cfg.platforms) do
if platform == plat_dep.name then
return index, platform
end
end
if cfg.system:lower():match("^"..plat_dep.name:lower()) then
return #cfg.platforms + 1, cfg.system
end
end

--- Return a set of values of a table.
-- @param tbl table: The input table.
-- @return table: The array of keys.
Expand Down Expand Up @@ -422,22 +443,22 @@ function fulfill_dependencies(rockspec, deps_mode)
for _, plat in pairs(rockspec.supported_platforms) do
local neg, plat = plat:match("^(!?)(.*)")
if neg == "!" then
if platforms_set[plat] then
return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms."
local ix, plat_name = match_platform(plat)
if ix then
return nil, "This rockspec for "..rockspec.package.." does not support "..plat_name.." platforms."
end
else
if platforms_set[plat] then
supported = true
else
if supported == nil then
if supported ~= true then
if match_platform(plat) then
supported = true
else
supported = false
end
end
end
end
if supported == false then
local plats = table.concat(cfg.platforms, ", ")
return nil, "This rockspec for "..rockspec.package.." does not support "..plats.." platforms."
return nil, "This rockspec for "..rockspec.package.." does not support "..cfg.system.." platforms."
end
end

Expand Down
3 changes: 2 additions & 1 deletion src/luarocks/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ function platform_overrides(tbl)
assert(type(tbl) == "table" or not tbl)

local cfg = require("luarocks.cfg")
local deps = require("luarocks.deps")

if not tbl then return end

if tbl.platforms then
local platform_order = {}
for query, platform_tbl in pairs(tbl.platforms) do
local index = cfg.is_platform(query)
local index = deps.match_platform(query)
if index then
platform_order[index] = platform_tbl
end
Expand Down