diff options
Diffstat (limited to 'src/luarocks/deps.lua')
-rw-r--r-- | src/luarocks/deps.lua | 78 |
1 files changed, 41 insertions, 37 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 567a576b..3f75f9be 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -11,7 +11,9 @@ | |||
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) | 14 | --module("luarocks.deps", package.seeall) |
15 | local deps = {} | ||
16 | package.loaded["luarocks.deps"] = deps | ||
15 | 17 | ||
16 | local cfg = require("luarocks.cfg") | 18 | local cfg = require("luarocks.cfg") |
17 | local manif_core = require("luarocks.manif_core") | 19 | local manif_core = require("luarocks.manif_core") |
@@ -101,7 +103,7 @@ setmetatable(version_cache, { | |||
101 | -- @param vstring string: A version number in string format. | 103 | -- @param vstring string: A version number in string format. |
102 | -- @return table or nil: A version table or nil | 104 | -- @return table or nil: A version table or nil |
103 | -- if the input string contains invalid characters. | 105 | -- if the input string contains invalid characters. |
104 | function parse_version(vstring) | 106 | function deps.parse_version(vstring) |
105 | if not vstring then return nil end | 107 | if not vstring then return nil end |
106 | assert(type(vstring) == "string") | 108 | assert(type(vstring) == "string") |
107 | 109 | ||
@@ -153,8 +155,8 @@ end | |||
153 | -- @param a string: one version. | 155 | -- @param a string: one version. |
154 | -- @param b string: another version. | 156 | -- @param b string: another version. |
155 | -- @return boolean: True if a > b. | 157 | -- @return boolean: True if a > b. |
156 | function compare_versions(a, b) | 158 | function deps.compare_versions(a, b) |
157 | return parse_version(a) > parse_version(b) | 159 | return deps.parse_version(a) > deps.parse_version(b) |
158 | end | 160 | end |
159 | 161 | ||
160 | --- Consumes a constraint from a string, converting it to table format. | 162 | --- Consumes a constraint from a string, converting it to table format. |
@@ -170,7 +172,7 @@ local function parse_constraint(input) | |||
170 | 172 | ||
171 | local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)") | 173 | local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)") |
172 | local _op = operators[op] | 174 | local _op = operators[op] |
173 | version = parse_version(version) | 175 | version = deps.parse_version(version) |
174 | if not _op then | 176 | if not _op then |
175 | return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'" | 177 | return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'" |
176 | end | 178 | end |
@@ -188,7 +190,7 @@ end | |||
188 | -- @param input string: A list of constraints in string format. | 190 | -- @param input string: A list of constraints in string format. |
189 | -- @return table or nil: A table representing the same constraints, | 191 | -- @return table or nil: A table representing the same constraints, |
190 | -- or nil if the input string is invalid. | 192 | -- or nil if the input string is invalid. |
191 | function parse_constraints(input) | 193 | function deps.parse_constraints(input) |
192 | assert(type(input) == "string") | 194 | assert(type(input) == "string") |
193 | 195 | ||
194 | local constraints, constraint, oinput = {}, nil, input | 196 | local constraints, constraint, oinput = {}, nil, input |
@@ -213,12 +215,12 @@ end | |||
213 | -- as entered in rockspec files. | 215 | -- as entered in rockspec files. |
214 | -- @return table or nil: A table representing the same dependency relation, | 216 | -- @return table or nil: A table representing the same dependency relation, |
215 | -- or nil if the input string is invalid. | 217 | -- or nil if the input string is invalid. |
216 | function parse_dep(dep) | 218 | function deps.parse_dep(dep) |
217 | assert(type(dep) == "string") | 219 | assert(type(dep) == "string") |
218 | 220 | ||
219 | local name, rest = dep:match("^%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*(.*)") | 221 | local name, rest = dep:match("^%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*(.*)") |
220 | if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end | 222 | if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end |
221 | local constraints, err = parse_constraints(rest) | 223 | local constraints, err = deps.parse_constraints(rest) |
222 | if not constraints then return nil, err end | 224 | if not constraints then return nil, err end |
223 | return { name = name, constraints = constraints } | 225 | return { name = name, constraints = constraints } |
224 | end | 226 | end |
@@ -228,7 +230,7 @@ end | |||
228 | -- @param internal boolean or nil: Whether to display versions in their | 230 | -- @param internal boolean or nil: Whether to display versions in their |
229 | -- internal representation format or how they were specified. | 231 | -- internal representation format or how they were specified. |
230 | -- @return string: The dependency information pretty-printed as a string. | 232 | -- @return string: The dependency information pretty-printed as a string. |
231 | function show_version(v, internal) | 233 | function deps.show_version(v, internal) |
232 | assert(type(v) == "table") | 234 | assert(type(v) == "table") |
233 | assert(type(internal) == "boolean" or not internal) | 235 | assert(type(internal) == "boolean" or not internal) |
234 | 236 | ||
@@ -242,13 +244,13 @@ end | |||
242 | -- @param internal boolean or nil: Whether to display versions in their | 244 | -- @param internal boolean or nil: Whether to display versions in their |
243 | -- internal representation format or how they were specified. | 245 | -- internal representation format or how they were specified. |
244 | -- @return string: The dependency information pretty-printed as a string. | 246 | -- @return string: The dependency information pretty-printed as a string. |
245 | function show_dep(dep, internal) | 247 | function deps.show_dep(dep, internal) |
246 | assert(type(dep) == "table") | 248 | assert(type(dep) == "table") |
247 | assert(type(internal) == "boolean" or not internal) | 249 | assert(type(internal) == "boolean" or not internal) |
248 | 250 | ||
249 | local pretty = {} | 251 | local pretty = {} |
250 | for _, c in ipairs(dep.constraints) do | 252 | for _, c in ipairs(dep.constraints) do |
251 | table.insert(pretty, c.op .. " " .. show_version(c.version, internal)) | 253 | table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal)) |
252 | end | 254 | end |
253 | return dep.name.." "..table.concat(pretty, ", ") | 255 | return dep.name.." "..table.concat(pretty, ", ") |
254 | end | 256 | end |
@@ -269,8 +271,8 @@ local function partial_match(version, requested) | |||
269 | assert(type(version) == "string" or type(version) == "table") | 271 | assert(type(version) == "string" or type(version) == "table") |
270 | assert(type(requested) == "string" or type(version) == "table") | 272 | assert(type(requested) == "string" or type(version) == "table") |
271 | 273 | ||
272 | if type(version) ~= "table" then version = parse_version(version) end | 274 | if type(version) ~= "table" then version = deps.parse_version(version) end |
273 | if type(requested) ~= "table" then requested = parse_version(requested) end | 275 | if type(requested) ~= "table" then requested = deps.parse_version(requested) end |
274 | if not version or not requested then return false end | 276 | if not version or not requested then return false end |
275 | 277 | ||
276 | for i, ri in ipairs(requested) do | 278 | for i, ri in ipairs(requested) do |
@@ -288,14 +290,14 @@ end | |||
288 | -- @param constraints table: An array of constraints in table format. | 290 | -- @param constraints table: An array of constraints in table format. |
289 | -- @return boolean: True if version satisfies all constraints, | 291 | -- @return boolean: True if version satisfies all constraints, |
290 | -- false otherwise. | 292 | -- false otherwise. |
291 | function match_constraints(version, constraints) | 293 | function deps.match_constraints(version, constraints) |
292 | assert(type(version) == "table") | 294 | assert(type(version) == "table") |
293 | assert(type(constraints) == "table") | 295 | assert(type(constraints) == "table") |
294 | local ok = true | 296 | local ok = true |
295 | setmetatable(version, version_mt) | 297 | setmetatable(version, version_mt) |
296 | for _, constr in pairs(constraints) do | 298 | for _, constr in pairs(constraints) do |
297 | if type(constr.version) == "string" then | 299 | if type(constr.version) == "string" then |
298 | constr.version = parse_version(constr.version) | 300 | constr.version = deps.parse_version(constr.version) |
299 | end | 301 | end |
300 | local constr_version, constr_op = constr.version, constr.op | 302 | local constr_version, constr_op = constr.version, constr.op |
301 | setmetatable(constr_version, version_mt) | 303 | setmetatable(constr_version, version_mt) |
@@ -344,8 +346,8 @@ local function match_dep(dep, blacklist, deps_mode) | |||
344 | end | 346 | end |
345 | local candidates = {} | 347 | local candidates = {} |
346 | for _, vstring in ipairs(versions) do | 348 | for _, vstring in ipairs(versions) do |
347 | local version = parse_version(vstring) | 349 | local version = deps.parse_version(vstring) |
348 | if match_constraints(version, dep.constraints) then | 350 | if deps.match_constraints(version, dep.constraints) then |
349 | table.insert(candidates, version) | 351 | table.insert(candidates, version) |
350 | end | 352 | end |
351 | end | 353 | end |
@@ -371,7 +373,7 @@ end | |||
371 | -- parsed as tables; and a table of "no-upgrade" missing dependencies | 373 | -- parsed as tables; and a table of "no-upgrade" missing dependencies |
372 | -- (to be used in plugin modules so that a plugin does not force upgrade of | 374 | -- (to be used in plugin modules so that a plugin does not force upgrade of |
373 | -- its parent application). | 375 | -- its parent application). |
374 | function match_deps(rockspec, blacklist, deps_mode) | 376 | function deps.match_deps(rockspec, blacklist, deps_mode) |
375 | assert(type(rockspec) == "table") | 377 | assert(type(rockspec) == "table") |
376 | assert(type(blacklist) == "table" or not blacklist) | 378 | assert(type(blacklist) == "table" or not blacklist) |
377 | local matched, missing, no_upgrade = {}, {}, {} | 379 | local matched, missing, no_upgrade = {}, {}, {} |
@@ -411,24 +413,24 @@ end | |||
411 | -- @return boolean or (nil, string, [string]): True if no errors occurred, or | 413 | -- @return boolean or (nil, string, [string]): True if no errors occurred, or |
412 | -- nil and an error message if any test failed, followed by an optional | 414 | -- nil and an error message if any test failed, followed by an optional |
413 | -- error code. | 415 | -- error code. |
414 | function fulfill_dependencies(rockspec, deps_mode) | 416 | function deps.fulfill_dependencies(rockspec, deps_mode) |
415 | 417 | ||
416 | local search = require("luarocks.search") | 418 | local search = require("luarocks.search") |
417 | local install = require("luarocks.install") | 419 | local install = require("luarocks.install") |
418 | 420 | ||
419 | if rockspec.supported_platforms then | 421 | if rockspec.supported_platforms then |
420 | if not platforms_set then | 422 | if not deps.platforms_set then |
421 | platforms_set = values_set(cfg.platforms) | 423 | deps.platforms_set = values_set(cfg.platforms) |
422 | end | 424 | end |
423 | local supported = nil | 425 | local supported = nil |
424 | for _, plat in pairs(rockspec.supported_platforms) do | 426 | for _, plat in pairs(rockspec.supported_platforms) do |
425 | local neg, plat = plat:match("^(!?)(.*)") | 427 | local neg, plat = plat:match("^(!?)(.*)") |
426 | if neg == "!" then | 428 | if neg == "!" then |
427 | if platforms_set[plat] then | 429 | if deps.platforms_set[plat] then |
428 | return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms." | 430 | return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms." |
429 | end | 431 | end |
430 | else | 432 | else |
431 | if platforms_set[plat] then | 433 | if deps.platforms_set[plat] then |
432 | supported = true | 434 | supported = true |
433 | else | 435 | else |
434 | if supported == nil then | 436 | if supported == nil then |
@@ -443,22 +445,22 @@ function fulfill_dependencies(rockspec, deps_mode) | |||
443 | end | 445 | end |
444 | end | 446 | end |
445 | 447 | ||
446 | local _, missing, no_upgrade = match_deps(rockspec, nil, deps_mode) | 448 | local _, missing, no_upgrade = deps.match_deps(rockspec, nil, deps_mode) |
447 | 449 | ||
448 | if next(no_upgrade) then | 450 | if next(no_upgrade) then |
449 | util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") | 451 | util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") |
450 | for _, dep in pairs(no_upgrade) do | 452 | for _, dep in pairs(no_upgrade) do |
451 | util.printerr(show_dep(dep)) | 453 | util.printerr(deps.show_dep(dep)) |
452 | end | 454 | end |
453 | if next(missing) then | 455 | if next(missing) then |
454 | for _, dep in pairs(missing) do | 456 | for _, dep in pairs(missing) do |
455 | util.printerr(show_dep(dep)) | 457 | util.printerr(deps.show_dep(dep)) |
456 | end | 458 | end |
457 | end | 459 | end |
458 | util.printerr() | 460 | util.printerr() |
459 | for _, dep in pairs(no_upgrade) do | 461 | for _, dep in pairs(no_upgrade) do |
460 | util.printerr("This version of "..rockspec.name.." is designed for use with") | 462 | util.printerr("This version of "..rockspec.name.." is designed for use with") |
461 | util.printerr(show_dep(dep)..", but is configured to avoid upgrading it") | 463 | util.printerr(deps.show_dep(dep)..", but is configured to avoid upgrading it") |
462 | util.printerr("automatically. Please upgrade "..dep.name.." with") | 464 | util.printerr("automatically. Please upgrade "..dep.name.." with") |
463 | util.printerr(" luarocks install "..dep.name) | 465 | util.printerr(" luarocks install "..dep.name) |
464 | util.printerr("or choose an older version of "..rockspec.name.." with") | 466 | util.printerr("or choose an older version of "..rockspec.name.." with") |
@@ -471,7 +473,7 @@ function fulfill_dependencies(rockspec, deps_mode) | |||
471 | util.printerr() | 473 | util.printerr() |
472 | util.printerr("Missing dependencies for "..rockspec.name..":") | 474 | util.printerr("Missing dependencies for "..rockspec.name..":") |
473 | for _, dep in pairs(missing) do | 475 | for _, dep in pairs(missing) do |
474 | util.printerr(show_dep(dep)) | 476 | util.printerr(deps.show_dep(dep)) |
475 | end | 477 | end |
476 | util.printerr() | 478 | util.printerr() |
477 | 479 | ||
@@ -480,7 +482,7 @@ function fulfill_dependencies(rockspec, deps_mode) | |||
480 | if not match_dep(dep, nil, deps_mode) then | 482 | if not match_dep(dep, nil, deps_mode) then |
481 | local rock = search.find_suitable_rock(dep) | 483 | local rock = search.find_suitable_rock(dep) |
482 | if not rock then | 484 | if not rock then |
483 | return nil, "Could not satisfy dependency: "..show_dep(dep) | 485 | return nil, "Could not satisfy dependency: "..deps.show_dep(dep) |
484 | end | 486 | end |
485 | local ok, err, errcode = install.run(rock) | 487 | local ok, err, errcode = install.run(rock) |
486 | if not ok then | 488 | if not ok then |
@@ -530,7 +532,7 @@ end | |||
530 | -- if "install" is given, do not scan for headers. | 532 | -- if "install" is given, do not scan for headers. |
531 | -- @return boolean or (nil, string): True if no errors occurred, or | 533 | -- @return boolean or (nil, string): True if no errors occurred, or |
532 | -- nil and an error message if any test failed. | 534 | -- nil and an error message if any test failed. |
533 | function check_external_deps(rockspec, mode) | 535 | function deps.check_external_deps(rockspec, mode) |
534 | assert(type(rockspec) == "table") | 536 | assert(type(rockspec) == "table") |
535 | 537 | ||
536 | local fs = require("luarocks.fs") | 538 | local fs = require("luarocks.fs") |
@@ -668,7 +670,7 @@ end | |||
668 | -- @param name string: Package name. | 670 | -- @param name string: Package name. |
669 | -- @param version string: Package version. | 671 | -- @param version string: Package version. |
670 | -- @return (table, table): The results and a table of missing dependencies. | 672 | -- @return (table, table): The results and a table of missing dependencies. |
671 | function scan_deps(results, missing, manifest, name, version, deps_mode) | 673 | function deps.scan_deps(results, missing, manifest, name, version, deps_mode) |
672 | assert(type(results) == "table") | 674 | assert(type(results) == "table") |
673 | assert(type(missing) == "table") | 675 | assert(type(missing) == "table") |
674 | assert(type(manifest) == "table") | 676 | assert(type(manifest) == "table") |
@@ -697,14 +699,14 @@ function scan_deps(results, missing, manifest, name, version, deps_mode) | |||
697 | else | 699 | else |
698 | rockspec = { dependencies = deplist } | 700 | rockspec = { dependencies = deplist } |
699 | end | 701 | end |
700 | local matched, failures = match_deps(rockspec, nil, deps_mode) | 702 | local matched, failures = deps.match_deps(rockspec, nil, deps_mode) |
701 | results[name] = results | 703 | results[name] = results |
702 | for _, match in pairs(matched) do | 704 | for _, match in pairs(matched) do |
703 | results, missing = scan_deps(results, missing, manifest, match.name, match.version, deps_mode) | 705 | results, missing = deps.scan_deps(results, missing, manifest, match.name, match.version, deps_mode) |
704 | end | 706 | end |
705 | if next(failures) then | 707 | if next(failures) then |
706 | for _, failure in pairs(failures) do | 708 | for _, failure in pairs(failures) do |
707 | missing[show_dep(failure)] = "failed" | 709 | missing[deps.show_dep(failure)] = "failed" |
708 | end | 710 | end |
709 | end | 711 | end |
710 | results[name] = version | 712 | results[name] = version |
@@ -718,11 +720,11 @@ local valid_deps_modes = { | |||
718 | none = true, | 720 | none = true, |
719 | } | 721 | } |
720 | 722 | ||
721 | function check_deps_mode_flag(flag) | 723 | function deps.check_deps_mode_flag(flag) |
722 | return valid_deps_modes[flag] | 724 | return valid_deps_modes[flag] |
723 | end | 725 | end |
724 | 726 | ||
725 | function get_deps_mode(flags) | 727 | function deps.get_deps_mode(flags) |
726 | if flags["deps-mode"] then | 728 | if flags["deps-mode"] then |
727 | return flags["deps-mode"] | 729 | return flags["deps-mode"] |
728 | else | 730 | else |
@@ -730,6 +732,8 @@ function get_deps_mode(flags) | |||
730 | end | 732 | end |
731 | end | 733 | end |
732 | 734 | ||
733 | function deps_mode_to_flag(deps_mode) | 735 | function deps.deps_mode_to_flag(deps_mode) |
734 | return "--deps-mode="..deps_mode | 736 | return "--deps-mode="..deps_mode |
735 | end | 737 | end |
738 | |||
739 | return deps | ||