diff options
Diffstat (limited to 'src/luarocks/deps.lua')
-rw-r--r-- | src/luarocks/deps.lua | 129 |
1 files changed, 60 insertions, 69 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 2a458b23..b8a36850 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -11,7 +11,6 @@ | |||
11 | -- comparison criteria is the source code of this module, but the | 11 | -- comparison criteria is the source code of this module, but the |
12 | -- test/test_deps.lua file included with LuaRocks provides some | 12 | -- test/test_deps.lua file included with LuaRocks provides some |
13 | -- insights on what these criteria are. | 13 | -- insights on what these criteria are. |
14 | --module("luarocks.deps", package.seeall) | ||
15 | local deps = {} | 14 | local deps = {} |
16 | package.loaded["luarocks.deps"] = deps | 15 | package.loaded["luarocks.deps"] = deps |
17 | 16 | ||
@@ -333,8 +332,7 @@ end | |||
333 | -- are program versions and values are 'true'. | 332 | -- are program versions and values are 'true'. |
334 | -- @param provided table: A table of auto-dependencies provided | 333 | -- @param provided table: A table of auto-dependencies provided |
335 | -- by this Lua implementation for the given dependency. | 334 | -- by this Lua implementation for the given dependency. |
336 | -- @return table or nil: A table containing fields 'name' and 'version' | 335 | -- @return string or nil: latest installed version of the rock matching the dependency |
337 | -- representing an installed rock which matches the given dependency, | ||
338 | -- or nil if it could not be matched. | 336 | -- or nil if it could not be matched. |
339 | local function match_dep(dep, blacklist, deps_mode, rocks_provided) | 337 | local function match_dep(dep, blacklist, deps_mode, rocks_provided) |
340 | assert(type(dep) == "table") | 338 | assert(type(dep) == "table") |
@@ -343,40 +341,25 @@ local function match_dep(dep, blacklist, deps_mode, rocks_provided) | |||
343 | local versions | 341 | local versions |
344 | local provided = rocks_provided[dep.name] | 342 | local provided = rocks_provided[dep.name] |
345 | if provided then | 343 | if provided then |
346 | -- provided rocks have higher priority than manifest's rocks | 344 | -- Provided rocks have higher priority than manifest's rocks. |
347 | versions = { provided } | 345 | versions = { provided } |
348 | else | 346 | else |
349 | versions = manif_core.get_versions(dep.name, deps_mode) | 347 | versions = manif_core.get_versions(dep.name, deps_mode) |
350 | end | 348 | end |
351 | if not versions then | 349 | |
352 | return nil | 350 | local latest_version |
353 | end | ||
354 | if blacklist then | ||
355 | local i = 1 | ||
356 | while versions[i] do | ||
357 | if blacklist[versions[i]] then | ||
358 | table.remove(versions, i) | ||
359 | else | ||
360 | i = i + 1 | ||
361 | end | ||
362 | end | ||
363 | end | ||
364 | local candidates = {} | ||
365 | for _, vstring in ipairs(versions) do | 351 | for _, vstring in ipairs(versions) do |
366 | local version = deps.parse_version(vstring) | 352 | if not blacklist or not blacklist[vstring] then |
367 | if deps.match_constraints(version, dep.constraints) then | 353 | local version = deps.parse_version(vstring) |
368 | table.insert(candidates, version) | 354 | if deps.match_constraints(version, dep.constraints) then |
355 | if not latest_version or version > latest_version then | ||
356 | latest_version = version | ||
357 | end | ||
358 | end | ||
369 | end | 359 | end |
370 | end | 360 | end |
371 | if #candidates == 0 then | 361 | |
372 | return nil | 362 | return latest_version and latest_version.string |
373 | else | ||
374 | table.sort(candidates) | ||
375 | return { | ||
376 | name = dep.name, | ||
377 | version = candidates[#candidates].string | ||
378 | } | ||
379 | end | ||
380 | end | 363 | end |
381 | 364 | ||
382 | --- Attempt to match dependencies of a rockspec to installed rocks. | 365 | --- Attempt to match dependencies of a rockspec to installed rocks. |
@@ -399,7 +382,7 @@ function deps.match_deps(rockspec, blacklist, deps_mode) | |||
399 | local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode, rockspec.rocks_provided) | 382 | local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode, rockspec.rocks_provided) |
400 | if found then | 383 | if found then |
401 | if not rockspec.rocks_provided[dep.name] then | 384 | if not rockspec.rocks_provided[dep.name] then |
402 | matched[dep] = found | 385 | matched[dep] = {name = dep.name, version = found} |
403 | end | 386 | end |
404 | else | 387 | else |
405 | if dep.constraints[1] and dep.constraints[1].no_upgrade then | 388 | if dep.constraints[1] and dep.constraints[1].no_upgrade then |
@@ -423,6 +406,13 @@ local function values_set(tbl) | |||
423 | return set | 406 | return set |
424 | end | 407 | end |
425 | 408 | ||
409 | local function rock_status(name, deps_mode, rocks_provided) | ||
410 | local search = require("luarocks.search") | ||
411 | local installed = match_dep(search.make_query(name), nil, deps_mode, rocks_provided) | ||
412 | local installation_type = rocks_provided[name] and "provided by VM" or "installed" | ||
413 | return installed and installed.." "..installation_type or "not installed" | ||
414 | end | ||
415 | |||
426 | --- Check dependencies of a rock and attempt to install any missing ones. | 416 | --- Check dependencies of a rock and attempt to install any missing ones. |
427 | -- Packages are installed using the LuaRocks "install" command. | 417 | -- Packages are installed using the LuaRocks "install" command. |
428 | -- Aborts the program if a dependency could not be fulfilled. | 418 | -- Aborts the program if a dependency could not be fulfilled. |
@@ -462,52 +452,53 @@ function deps.fulfill_dependencies(rockspec, deps_mode) | |||
462 | end | 452 | end |
463 | end | 453 | end |
464 | 454 | ||
465 | local _, missing, no_upgrade = deps.match_deps(rockspec, nil, deps_mode) | 455 | local first_missing_dep = true |
466 | 456 | ||
467 | if next(no_upgrade) then | 457 | for _, dep in ipairs(rockspec.dependencies) do |
468 | util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") | 458 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then |
469 | for _, dep in pairs(no_upgrade) do | 459 | if first_missing_dep then |
470 | util.printerr(deps.show_dep(dep)) | 460 | util.printout(("Missing dependencies for %s %s:"):format(rockspec.name, rockspec.version)) |
471 | end | 461 | first_missing_dep = false |
472 | if next(missing) then | ||
473 | for _, dep in pairs(missing) do | ||
474 | util.printerr(deps.show_dep(dep)) | ||
475 | end | 462 | end |
463 | |||
464 | util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided))) | ||
476 | end | 465 | end |
477 | util.printerr() | ||
478 | for _, dep in pairs(no_upgrade) do | ||
479 | util.printerr("This version of "..rockspec.name.." is designed for use with") | ||
480 | util.printerr(deps.show_dep(dep)..", but is configured to avoid upgrading it") | ||
481 | util.printerr("automatically. Please upgrade "..dep.name.." with") | ||
482 | util.printerr(" luarocks install "..dep.name) | ||
483 | util.printerr("or choose an older version of "..rockspec.name.." with") | ||
484 | util.printerr(" luarocks search "..rockspec.name) | ||
485 | end | ||
486 | return nil, "Failed matching dependencies." | ||
487 | end | 466 | end |
488 | 467 | ||
489 | if next(missing) then | 468 | first_missing_dep = true |
490 | util.printerr() | 469 | |
491 | util.printerr("Missing dependencies for "..rockspec.name..":") | 470 | for _, dep in ipairs(rockspec.dependencies) do |
492 | for _, dep in pairs(missing) do | 471 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then |
493 | util.printerr(deps.show_dep(dep)) | 472 | if first_missing_dep then |
494 | end | 473 | util.printout() |
495 | util.printerr() | 474 | first_missing_dep = false |
496 | 475 | end | |
497 | for _, dep in pairs(missing) do | 476 | |
498 | -- Double-check in case dependency was filled during recursion. | 477 | util.printout(("%s %s depends on %s (%s)"):format( |
499 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then | 478 | rockspec.name, rockspec.version, deps.show_dep(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided))) |
500 | local url, err = search.find_suitable_rock(dep) | 479 | |
501 | if not url then | 480 | if dep.constraints[1] and dep.constraints[1].no_upgrade then |
502 | return nil, "Could not satisfy dependency "..deps.show_dep(dep)..": "..err | 481 | util.printerr("This version of "..rockspec.name.." is designed for use with") |
503 | end | 482 | util.printerr(deps.show_dep(dep)..", but is configured to avoid upgrading it") |
504 | local ok, err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode)) | 483 | util.printerr("automatically. Please upgrade "..dep.name.." with") |
505 | if not ok then | 484 | util.printerr(" luarocks install "..dep.name) |
506 | return nil, "Failed installing dependency: "..url.." - "..err, errcode | 485 | util.printerr("or choose an older version of "..rockspec.name.." with") |
507 | end | 486 | util.printerr(" luarocks search "..rockspec.name) |
487 | return nil, "Failed matching dependencies" | ||
488 | end | ||
489 | |||
490 | local url, search_err = search.find_suitable_rock(dep) | ||
491 | if not url then | ||
492 | return nil, "Could not satisfy dependency "..deps.show_dep(dep)..": "..search_err | ||
493 | end | ||
494 | util.printout("Installing "..url) | ||
495 | local ok, install_err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode)) | ||
496 | if not ok then | ||
497 | return nil, "Failed installing dependency: "..url.." - "..install_err, errcode | ||
508 | end | 498 | end |
509 | end | 499 | end |
510 | end | 500 | end |
501 | |||
511 | return true | 502 | return true |
512 | end | 503 | end |
513 | 504 | ||