[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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ src/luarocks/site_config.lua: config.unix
echo "site_config.LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\
fi
echo "site_config.LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> src/luarocks/site_config.lua
echo "site_config.LUAROCKS_UNAME_R=[[$(LUAROCKS_UNAME_R)]]" >> src/luarocks/site_config.lua
echo "site_config.LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua
echo "site_config.LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua
echo "site_config.LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua
Expand Down
7 changes: 7 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ then
else
die "Could not determine operating system. 'uname -s' failed."
fi
if uname -r
then
LUAROCKS_UNAME_R=`uname -r`
else
die "Could not determine operating system version. 'uname -r' failed."
fi
echo_n "Configuring for architecture... "
if uname -m
then
Expand Down Expand Up @@ -449,6 +455,7 @@ LUA_BINDIR=$LUA_BINDIR
FORCE_CONFIG=$FORCE_CONFIG
LUAROCKS_UNAME_M=$LUAROCKS_UNAME_M
LUAROCKS_UNAME_S=$LUAROCKS_UNAME_S
LUAROCKS_UNAME_R=$LUAROCKS_UNAME_R
LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER
LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER
LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR
Expand Down
10 changes: 10 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ if USE_MINGW then
else
f:write("site_config.LUAROCKS_UNAME_S=[[WindowsNT]]\n")
end
local sys_ver
local windows_ver = io.popen("VER"):read("*l")
if windows_ver then
sys_ver = windows_ver:match("Windows[^%[]*%[.- (%d+%.%d[^%]]*)%]")
end
if sys_ver then
f:write("site_config.LUAROCKS_UNAME_R=[["..sys_ver.."]]\n")
else
f:write("site_config.LUAROCKS_UNAME_R=[[4.0]]\n")
end
f:write(S[=[
site_config.LUAROCKS_UNAME_M=[[$UNAME_M]]
site_config.LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]]
Expand Down
121 changes: 76 additions & 45 deletions src/luarocks/cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,56 +68,81 @@ end
-- System detection:

local detected = {}
local system,proc
local sys_name,sys_version,proc

-- A proper installation of LuaRocks will hardcode the system
-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M,
-- so that this detection does not run every time. When it is
-- performed, we use the Unix way to identify the system,
-- even on Windows (assuming UnxUtils or Cygwin).
system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l")
if proc:match("i[%d]86") then
proc = "x86"
elseif proc:match("amd64") or proc:match("x86_64") then
proc = "x86_64"
elseif proc:match("Power Macintosh") then
proc = "powerpc"
end

if system == "FreeBSD" then
detected.unix = true
detected.freebsd = true
detected.bsd = true
elseif system == "OpenBSD" then
detected.unix = true
detected.openbsd = true
detected.bsd = true
elseif system == "NetBSD" then
detected.unix = true
detected.netbsd = true
detected.bsd = true
elseif system == "Darwin" then
detected.unix = true
detected.macosx = true
detected.bsd = true
elseif system == "Linux" then
detected.unix = true
detected.linux = true
elseif system == "SunOS" then
detected.unix = true
detected.solaris = true
elseif system and system:match("^CYGWIN") then
detected.unix = true
detected.cygwin = true
elseif system and system:match("^Windows") then
detected.windows = true
elseif system and system:match("^MINGW") then
detected.windows = true
detected.mingw32 = true
sys_name = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
if not sys_name then
if os.getenv("OS") == "Windows_NT" then
sys_name = "Windows"
proc = os.getenv("PROCESSOR_ARCHITECTURE")
local windows_ver = io.popen("ver"):read("*l")
if windows_ver then
sys_name,sys_version = windows_ver:match("(Windows[^%[]*)%[.- (%d+%.%d[^%]]*)%]")
end
else
proc = "unknown"
end
else
sys_version = site_config.LUAROCKS_UNAME_R or io.popen("uname -r"):read("*l")
proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l")
end

if proc and proc ~= "" then
if proc:match("i[%d]86") then
proc = "x86"
elseif proc:match("amd64") or proc:match("x86_64") then
proc = "x86_64"
elseif proc:match("Power Macintosh") then
proc = "powerpc"
end
else
detected.unix = true
-- Fall back to Unix in unknown systems.
proc = "unknown"
end

if sys_version == "" then
sys_version = nil
end

if sys_name then
if sys_name == "FreeBSD" then
detected.unix = true
detected.freebsd = true
detected.bsd = true
elseif sys_name == "OpenBSD" then
detected.unix = true
detected.openbsd = true
detected.bsd = true
elseif sys_name == "NetBSD" then
detected.unix = true
detected.netbsd = true
detected.bsd = true
elseif sys_name == "Darwin" then
detected.unix = true
detected.macosx = true
detected.bsd = true
elseif sys_name == "Linux" then
detected.unix = true
detected.linux = true
elseif sys_name == "SunOS" then
detected.unix = true
detected.solaris = true
elseif sys_name:match("^CYGWIN") then
detected.unix = true
detected.cygwin = true
elseif sys_name:match("^Windows") then
detected.windows = true
elseif sys_name:match("^MINGW") then
detected.windows = true
detected.mingw32 = true
else
detected.unix = true
-- Fall back to Unix in unknown systems.
end
end

-- Path configuration:
Expand Down Expand Up @@ -209,7 +234,10 @@ local defaults = {
lib_modules_path = "/lib/lua/"..cfg.lua_version,
rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks",

system = sys_name,
system_version = sys_version,
arch = "unknown",
platforms = {},
lib_extension = "unknown",
obj_extension = "unknown",

Expand Down Expand Up @@ -301,7 +329,7 @@ if detected.windows then
home_config_file = home_config_file and home_config_file:gsub("\\","/")
defaults.fs_use_modules = false
defaults.arch = "win32-"..proc
defaults.platforms = {"win32", "windows" }
defaults.platforms = { "win32", "windows" }
defaults.lib_extension = "dll"
defaults.external_lib_extension = "dll"
defaults.obj_extension = "obj"
Expand Down Expand Up @@ -355,7 +383,7 @@ if detected.windows then
end

if detected.mingw32 then
defaults.platforms = { "win32", "mingw32", "windows" }
defaults.platforms = { "win32", "windows", "mingw32" }
defaults.obj_extension = "o"
defaults.cmake_generator = "MinGW Makefiles"
defaults.variables.MAKE = "mingw32-make"
Expand Down Expand Up @@ -574,6 +602,9 @@ end
cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.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 cfg.is_platform(query)
Expand Down
43 changes: 32 additions & 11 deletions src/luarocks/deps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,30 @@ function deps.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 deps.match_platform(plat)
assert(type(plat) == "string")

local dep, err = deps.parse_dep(plat)
if not dep then return nil, err end
local version = deps.parse_version(cfg.system_version)
for index, platform in ipairs(cfg.platforms) do
if platform == dep.name then
if deps.match_constraints(version, dep.constraints) then
return index, platform
end
end
end
if cfg.system:lower():match("^"..dep.name:lower()) and deps.match_constraints(version, dep.constraints) 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 All @@ -419,29 +443,26 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
local install = require("luarocks.install")

if rockspec.supported_platforms then
if not deps.platforms_set then
deps.platforms_set = values_set(cfg.platforms)
end
local supported = nil
for _, plat in pairs(rockspec.supported_platforms) do
local neg, plat = plat:match("^(!?)(.*)")
if neg == "!" then
if deps.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 deps.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
27 changes: 18 additions & 9 deletions src/luarocks/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ end
-- Overrides values of table with the contents of the appropriate
-- subset of its "platforms" field. The "platforms" field should
-- be a table containing subtables keyed with strings representing
-- platform names. Names that match the contents of the global
-- cfg.platforms setting are used. For example, if
-- cfg.platforms= {"foo"}, then the fields of
-- tbl.platforms.foo will overwrite those of tbl with the same
-- names. For table values, the operation is performed recursively
-- platform name queries. Names that match the contents of the global
-- cfg.platforms setting are used. The query is a case-insensitive
-- pattern anchored at the start of the string. For example, if
-- cfg.platforms= {"foo-bar"}, then the fields of
-- tbl.platforms.Foo will overwrite those of tbl with the same
-- names. But not tbl.platforms.FooBar.
-- For table values, the operation is performed recursively
-- (tbl.platforms.foo.x.y.z overrides tbl.x.y.z; other contents of
-- tbl.x are preserved).
-- @param tbl table or nil: Table which may contain a "platforms" field;
Expand All @@ -156,14 +158,21 @@ function util.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
for _, platform in ipairs(cfg.platforms) do
local platform_tbl = tbl.platforms[platform]
if platform_tbl then
util.deep_merge(tbl, platform_tbl)
local platform_order = {}
for query, platform_tbl in pairs(tbl.platforms) do
local index = deps.match_platform(query)
if index then
platform_order[index] = platform_tbl
end
end
for ix = 1, #cfg.platforms+1 do
if platform_order[ix] then
deep_merge(tbl, platform_order[ix])
end
end
end
Expand Down