aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/deps.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/luarocks/deps.lua70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 756ba6bd..dcebec9b 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -400,6 +400,28 @@ local function rock_status(name, deps_mode)
400 return installed and installed.." "..installation_type or "not installed" 400 return installed and installed.." "..installation_type or "not installed"
401end 401end
402 402
403--- Check depenendencies of a package and report any missing ones.
404-- @param name string: package name.
405-- @param version string: package version.
406-- @param dependencies table: array of dependencies.
407-- @param deps_mode string: Which trees to check dependencies for:
408-- "one" for the current default tree, "all" for all trees,
409-- "order" for all trees with priority >= the current default, "none" for no trees.
410function deps.report_missing_dependencies(name, version, dependencies, deps_mode)
411 local first_missing_dep = true
412
413 for _, dep in ipairs(dependencies) do
414 if not match_dep(dep, nil, deps_mode) then
415 if first_missing_dep then
416 util.printout(("Missing dependencies for %s %s:"):format(name, version))
417 first_missing_dep = false
418 end
419
420 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode)))
421 end
422 end
423end
424
403--- Check dependencies of a rock and attempt to install any missing ones. 425--- Check dependencies of a rock and attempt to install any missing ones.
404-- Packages are installed using the LuaRocks "install" command. 426-- Packages are installed using the LuaRocks "install" command.
405-- Aborts the program if a dependency could not be fulfilled. 427-- Aborts the program if a dependency could not be fulfilled.
@@ -439,20 +461,9 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
439 end 461 end
440 end 462 end
441 463
442 local first_missing_dep = true 464 deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec.dependencies, deps_mode)
443
444 for _, dep in ipairs(rockspec.dependencies) do
445 if not match_dep(dep, nil, deps_mode) then
446 if first_missing_dep then
447 util.printout(("Missing dependencies for %s %s:"):format(rockspec.name, rockspec.version))
448 first_missing_dep = false
449 end
450
451 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode)))
452 end
453 end
454 465
455 first_missing_dep = true 466 local first_missing_dep = true
456 467
457 for _, dep in ipairs(rockspec.dependencies) do 468 for _, dep in ipairs(rockspec.dependencies) do
458 if not match_dep(dep, nil, deps_mode) then 469 if not match_dep(dep, nil, deps_mode) then
@@ -674,17 +685,15 @@ function deps.check_external_deps(rockspec, mode)
674 return true 685 return true
675end 686end
676 687
677--- Recursively scan dependencies, to build a transitive closure of all 688--- Recursively add satisfied dependencies of a package to a table,
678-- dependent packages. 689-- to build a transitive closure of all dependent packages.
679-- @param results table: The results table being built. 690-- Additionally ensures that `dependencies` table of the manifest is up-to-date.
680-- @param missing table: The table of missing dependencies being recursively built. 691-- @param results table: The results table being built, maps package names to versions.
681-- @param manifest table: The manifest table containing dependencies. 692-- @param manifest table: The manifest table containing dependencies.
682-- @param name string: Package name. 693-- @param name string: Package name.
683-- @param version string: Package version. 694-- @param version string: Package version.
684-- @return (table, table): The results and a table of missing dependencies. 695function deps.scan_deps(results, manifest, name, version, deps_mode)
685function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
686 assert(type(results) == "table") 696 assert(type(results) == "table")
687 assert(type(missing) == "table")
688 assert(type(manifest) == "table") 697 assert(type(manifest) == "table")
689 assert(type(name) == "string") 698 assert(type(name) == "string")
690 assert(type(version) == "string") 699 assert(type(version) == "string")
@@ -692,7 +701,7 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
692 local fetch = require("luarocks.fetch") 701 local fetch = require("luarocks.fetch")
693 702
694 if results[name] then 703 if results[name] then
695 return results, missing 704 return
696 end 705 end
697 if not manifest.dependencies then manifest.dependencies = {} end 706 if not manifest.dependencies then manifest.dependencies = {} end
698 local dependencies = manifest.dependencies 707 local dependencies = manifest.dependencies
@@ -702,26 +711,19 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
702 local rockspec, err 711 local rockspec, err
703 if not deplist then 712 if not deplist then
704 rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false) 713 rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false)
705 if err then 714 if not rockspec then
706 missing[name.." "..version] = err 715 util.printerr("Couldn't load rockspec for "..name.." "..version..": "..err)
707 return results, missing 716 return
708 end 717 end
709 dependencies_name[version] = rockspec.dependencies 718 dependencies_name[version] = rockspec.dependencies
710 else 719 else
711 rockspec = { dependencies = deplist } 720 rockspec = { dependencies = deplist }
712 end 721 end
713 local matched, failures = deps.match_deps(rockspec, nil, deps_mode) 722 local matched = deps.match_deps(rockspec, nil, deps_mode)
714 results[name] = results 723 results[name] = version
715 for _, match in pairs(matched) do 724 for _, match in pairs(matched) do
716 results, missing = deps.scan_deps(results, missing, manifest, match.name, match.version, deps_mode) 725 deps.scan_deps(results, manifest, match.name, match.version, deps_mode)
717 end 726 end
718 if next(failures) then
719 for _, failure in pairs(failures) do
720 missing[deps.show_dep(failure)] = "failed"
721 end
722 end
723 results[name] = version
724 return results, missing
725end 727end
726 728
727local valid_deps_modes = { 729local valid_deps_modes = {