aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/deps.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/deps.lua')
-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 acbf1dd6..d9419ec3 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -230,6 +230,28 @@ local function rock_status(name, deps_mode, rocks_provided)
230 return installed and installed.." "..installation_type or "not installed" 230 return installed and installed.." "..installation_type or "not installed"
231end 231end
232 232
233--- Check depenendencies of a package and report any missing ones.
234-- @param name string: package name.
235-- @param version string: package version.
236-- @param dependencies table: array of dependencies.
237-- @param deps_mode string: Which trees to check dependencies for:
238-- "one" for the current default tree, "all" for all trees,
239-- "order" for all trees with priority >= the current default, "none" for no trees.
240function deps.report_missing_dependencies(name, version, dependencies, deps_mode)
241 local first_missing_dep = true
242
243 for _, dep in ipairs(dependencies) do
244 if not match_dep(dep, nil, deps_mode) then
245 if first_missing_dep then
246 util.printout(("Missing dependencies for %s %s:"):format(name, version))
247 first_missing_dep = false
248 end
249
250 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode)))
251 end
252 end
253end
254
233--- Check dependencies of a rock and attempt to install any missing ones. 255--- Check dependencies of a rock and attempt to install any missing ones.
234-- Packages are installed using the LuaRocks "install" command. 256-- Packages are installed using the LuaRocks "install" command.
235-- Aborts the program if a dependency could not be fulfilled. 257-- Aborts the program if a dependency could not be fulfilled.
@@ -270,20 +292,9 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
270 end 292 end
271 end 293 end
272 294
273 local first_missing_dep = true 295 deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec.dependencies, deps_mode)
274 296
275 for _, dep in ipairs(rockspec.dependencies) do 297 local first_missing_dep = true
276 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then
277 if first_missing_dep then
278 util.printout(("Missing dependencies for %s %s:"):format(rockspec.name, rockspec.version))
279 first_missing_dep = false
280 end
281
282 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided)))
283 end
284 end
285
286 first_missing_dep = true
287 298
288 for _, dep in ipairs(rockspec.dependencies) do 299 for _, dep in ipairs(rockspec.dependencies) do
289 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then 300 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then
@@ -505,17 +516,15 @@ function deps.check_external_deps(rockspec, mode)
505 return true 516 return true
506end 517end
507 518
508--- Recursively scan dependencies, to build a transitive closure of all 519--- Recursively add satisfied dependencies of a package to a table,
509-- dependent packages. 520-- to build a transitive closure of all dependent packages.
510-- @param results table: The results table being built. 521-- Additionally ensures that `dependencies` table of the manifest is up-to-date.
511-- @param missing table: The table of missing dependencies being recursively built. 522-- @param results table: The results table being built, maps package names to versions.
512-- @param manifest table: The manifest table containing dependencies. 523-- @param manifest table: The manifest table containing dependencies.
513-- @param name string: Package name. 524-- @param name string: Package name.
514-- @param version string: Package version. 525-- @param version string: Package version.
515-- @return (table, table): The results and a table of missing dependencies. 526function deps.scan_deps(results, manifest, name, version, deps_mode)
516function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
517 assert(type(results) == "table") 527 assert(type(results) == "table")
518 assert(type(missing) == "table")
519 assert(type(manifest) == "table") 528 assert(type(manifest) == "table")
520 assert(type(name) == "string") 529 assert(type(name) == "string")
521 assert(type(version) == "string") 530 assert(type(version) == "string")
@@ -523,7 +532,7 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
523 local fetch = require("luarocks.fetch") 532 local fetch = require("luarocks.fetch")
524 533
525 if results[name] then 534 if results[name] then
526 return results, missing 535 return
527 end 536 end
528 if not manifest.dependencies then manifest.dependencies = {} end 537 if not manifest.dependencies then manifest.dependencies = {} end
529 local dependencies = manifest.dependencies 538 local dependencies = manifest.dependencies
@@ -533,9 +542,9 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
533 local rockspec, err 542 local rockspec, err
534 if not deplist then 543 if not deplist then
535 rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false) 544 rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false)
536 if err then 545 if not rockspec then
537 missing[name.." "..version] = err 546 util.printerr("Couldn't load rockspec for "..name.." "..version..": "..err)
538 return results, missing 547 return
539 end 548 end
540 dependencies_name[version] = rockspec.dependencies 549 dependencies_name[version] = rockspec.dependencies
541 else 550 else
@@ -544,18 +553,11 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
544 rocks_provided = setmetatable({}, { __index = cfg.rocks_provided_3_0 }) 553 rocks_provided = setmetatable({}, { __index = cfg.rocks_provided_3_0 })
545 } 554 }
546 end 555 end
547 local matched, failures = deps.match_deps(rockspec, nil, deps_mode) 556 local matched = deps.match_deps(rockspec, nil, deps_mode)
548 results[name] = results 557 results[name] = version
549 for _, match in pairs(matched) do 558 for _, match in pairs(matched) do
550 results, missing = deps.scan_deps(results, missing, manifest, match.name, match.version, deps_mode) 559 deps.scan_deps(results, manifest, match.name, match.version, deps_mode)
551 end 560 end
552 if next(failures) then
553 for _, failure in pairs(failures) do
554 missing[deps.show_dep(failure)] = "failed"
555 end
556 end
557 results[name] = version
558 return results, missing
559end 561end
560 562
561local valid_deps_modes = { 563local valid_deps_modes = {