diff options
author | Roman Tsisyk <roman@tsisyk.com> | 2013-11-30 13:00:32 +0400 |
---|---|---|
committer | Roman Tsisyk <roman@tsisyk.com> | 2013-11-30 13:33:32 +0400 |
commit | ef05a02cf40c858ca91a9e84783d32322428fb47 (patch) | |
tree | 1028a9912bf4512d312b65717761ef65b31da07b | |
parent | 50e6d37d900cd4fbdc69cfc35011418e7771562b (diff) | |
download | luarocks-ef05a02cf40c858ca91a9e84783d32322428fb47.tar.gz luarocks-ef05a02cf40c858ca91a9e84783d32322428fb47.tar.bz2 luarocks-ef05a02cf40c858ca91a9e84783d32322428fb47.zip |
Add a configuration option to specify manually installed rocks.
The patch adds a new configuration option - cfg.rocks_provided.
This option contains a list of packages that are either builtin or
manually installed outside of LuaRocks package management system:
rocks_provided = {
[module_name] = module_version.."-"..rockspec_version,
-- ...
}
These settings are taken into account during dependency resolution
and when search and install commands are used. An attempt to install
a rock from the list causes an error.
LuaRocks automatically adds following modules to the list:
rocks_provided = {
lua = lua_version.."-1",
-- For Lua 5.2 or later:
bit32 = lua_version.."-1",
-- For LuaJIT:
luajit = lj_version.."-1",
jit = lj_version.."-1",
ffi = lj_version.."-1",
bit = lj_version.."-1",
luabitop = lj_version.."-1"
}
where lua_version extracted from _VERSION (e.g. 5.2),
lj_version extracted from jit.version (e.g. 2.0.2).
Built-in values can be overridden by configuration options.
Closes #177.
-rw-r--r-- | src/luarocks/cfg.lua | 31 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 18 | ||||
-rw-r--r-- | src/luarocks/search.lua | 12 |
3 files changed, 49 insertions, 12 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index f66ad1d9..3267389a 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -265,6 +265,8 @@ local defaults = { | |||
265 | lib = "lib", | 265 | lib = "lib", |
266 | include = "include" | 266 | include = "include" |
267 | }, | 267 | }, |
268 | |||
269 | rocks_provided = {} | ||
268 | } | 270 | } |
269 | 271 | ||
270 | if detected.windows then | 272 | if detected.windows then |
@@ -453,6 +455,24 @@ defaults.variables.OBJ_EXTENSION = defaults.obj_extension | |||
453 | defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX | 455 | defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX |
454 | defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter | 456 | defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter |
455 | 457 | ||
458 | -- Add built-in modules to rocks_provided | ||
459 | defaults.rocks_provided["lua"] = lua_version.."-1" | ||
460 | |||
461 | if lua_version >= "5.2" then | ||
462 | -- Lua 5.2+ | ||
463 | defaults.rocks_provided["bit32"] = lua_version.."-1" | ||
464 | end | ||
465 | |||
466 | if package.loaded.jit then | ||
467 | -- LuaJIT | ||
468 | local lj_version = package.loaded.jit.version:match("LuaJIT (%d%.%d%.%d)") | ||
469 | defaults.rocks_provided["luajit"] = lj_version.."-1" | ||
470 | defaults.rocks_provided["jit"] = lj_version.."-1" | ||
471 | defaults.rocks_provided["ffi"] = lj_version.."-1" | ||
472 | defaults.rocks_provided["bit"] = lj_version.."-1" | ||
473 | defaults.rocks_provided["luabitop"] = lj_version.."-1" | ||
474 | end | ||
475 | |||
456 | -- Use defaults: | 476 | -- Use defaults: |
457 | 477 | ||
458 | -- Populate values from 'defaults.variables' in 'variables' if they were not | 478 | -- Populate values from 'defaults.variables' in 'variables' if they were not |
@@ -466,6 +486,17 @@ for k,v in pairs(defaults.variables) do | |||
466 | end | 486 | end |
467 | end | 487 | end |
468 | 488 | ||
489 | -- Populate values from 'defaults.rocks_provided' in 'rocks_provided' if they | ||
490 | -- were not already set by user. | ||
491 | if not type(_M.rocks_provided) == "table" then | ||
492 | _M.rocks_provided = {} | ||
493 | end | ||
494 | for k,v in pairs(defaults.rocks_provided) do | ||
495 | if not _M.rocks_provided[k] then | ||
496 | _M.rocks_provided[k] = v | ||
497 | end | ||
498 | end | ||
499 | |||
469 | -- For values not set in the config file, use values from the 'defaults' table. | 500 | -- For values not set in the config file, use values from the 'defaults' table. |
470 | local cfg_mt = { | 501 | local cfg_mt = { |
471 | __index = function(t, k) | 502 | __index = function(t, k) |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 732f587c..1098779c 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -323,9 +323,10 @@ end | |||
323 | local function match_dep(dep, blacklist, deps_mode) | 323 | local function match_dep(dep, blacklist, deps_mode) |
324 | assert(type(dep) == "table") | 324 | assert(type(dep) == "table") |
325 | 325 | ||
326 | local versions | 326 | local versions = cfg.rocks_provided[dep.name] |
327 | if dep.name == "lua" then | 327 | if not cfg.rocks_provided[dep.name] then |
328 | versions = { cfg.lua_version } | 328 | -- provided rocks have higher priority than manifest's rocks |
329 | versions = { cfg.rocks_provided[dep.name] } | ||
329 | else | 330 | else |
330 | versions = manif_core.get_versions(dep.name, deps_mode) | 331 | versions = manif_core.get_versions(dep.name, deps_mode) |
331 | end | 332 | end |
@@ -360,11 +361,6 @@ local function match_dep(dep, blacklist, deps_mode) | |||
360 | end | 361 | end |
361 | end | 362 | end |
362 | 363 | ||
363 | local whitelist = {} | ||
364 | if cfg.lua_version == "5.2" then | ||
365 | whitelist["bit32"] = true | ||
366 | end | ||
367 | |||
368 | --- Attempt to match dependencies of a rockspec to installed rocks. | 364 | --- Attempt to match dependencies of a rockspec to installed rocks. |
369 | -- @param rockspec table: The rockspec loaded as a table. | 365 | -- @param rockspec table: The rockspec loaded as a table. |
370 | -- @param blacklist table or nil: Program versions to not use as valid matches. | 366 | -- @param blacklist table or nil: Program versions to not use as valid matches. |
@@ -382,12 +378,10 @@ function match_deps(rockspec, blacklist, deps_mode) | |||
382 | local matched, missing, no_upgrade = {}, {}, {} | 378 | local matched, missing, no_upgrade = {}, {}, {} |
383 | 379 | ||
384 | for _, dep in ipairs(rockspec.dependencies) do | 380 | for _, dep in ipairs(rockspec.dependencies) do |
385 | if not whitelist[dep.name] then | 381 | if not cfg.rocks_provided[dep.name] then |
386 | local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode) | 382 | local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode) |
387 | if found then | 383 | if found then |
388 | if dep.name ~= "lua" then | 384 | matched[dep] = found |
389 | matched[dep] = found | ||
390 | end | ||
391 | else | 385 | else |
392 | if dep.constraints[1] and dep.constraints[1].no_upgrade then | 386 | if dep.constraints[1] and dep.constraints[1].no_upgrade then |
393 | no_upgrade[dep.name] = dep | 387 | no_upgrade[dep.name] = dep |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 1fc1f9a1..2db55d9e 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -209,6 +209,12 @@ function search_repos(query) | |||
209 | end | 209 | end |
210 | end | 210 | end |
211 | end | 211 | end |
212 | -- search through rocks in cfg.rocks_provided | ||
213 | local provided_repo = "built-in or listed in cfg.rocks_provided" | ||
214 | local name, versions | ||
215 | for name, versions in pairs(cfg.rocks_provided) do | ||
216 | store_if_match(results, provided_repo, name, versions, "installed", query) | ||
217 | end | ||
212 | return results | 218 | return results |
213 | end | 219 | end |
214 | 220 | ||
@@ -273,6 +279,12 @@ function find_suitable_rock(query) | |||
273 | if not first then | 279 | if not first then |
274 | return nil, "No results matching query were found." | 280 | return nil, "No results matching query were found." |
275 | elseif not next(results, first) then | 281 | elseif not next(results, first) then |
282 | if cfg.rocks_provided[query.name] ~= nil then | ||
283 | -- do not install versions that listed in cfg.rocks_provided | ||
284 | return nil, "The found rock "..query.name.. | ||
285 | " "..cfg.rocks_provided[query.name].. | ||
286 | " is either built-in or listed in cfg.rocks_provided!" | ||
287 | end | ||
276 | return pick_latest_version(query.name, results[first]) | 288 | return pick_latest_version(query.name, results[first]) |
277 | else | 289 | else |
278 | return results | 290 | return results |