diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-07-12 15:27:21 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-07-26 23:58:19 -0300 |
commit | ffab9f32698431bb901b786460e4695806ebcf30 (patch) | |
tree | c79e87fa2511803da0c70874bc66be53176858e8 /src | |
parent | 8bbfa80cdb248254c323abc8627a9e63bc0469f1 (diff) | |
download | luarocks-ffab9f32698431bb901b786460e4695806ebcf30.tar.gz luarocks-ffab9f32698431bb901b786460e4695806ebcf30.tar.bz2 luarocks-ffab9f32698431bb901b786460e4695806ebcf30.zip |
detect LuaJIT dynamically
This reduces the complexity of the interaction between
build-time configuration, run-time auto-detection, and overrides via
CLI flags. The LuaJIT version is now always auto-detected at run-time
based on the Lua interpreter currently configured, based on the values
of configuration options `variables.LUA_BINDIR` and `lua_interpreter`.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/help.lua | 5 | ||||
-rw-r--r-- | src/luarocks/cmd/init.lua | 1 | ||||
-rw-r--r-- | src/luarocks/cmd/show.lua | 5 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 46 | ||||
-rw-r--r-- | src/luarocks/core/util.lua | 10 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 7 | ||||
-rw-r--r-- | src/luarocks/manif/writer.lua | 2 | ||||
-rw-r--r-- | src/luarocks/rockspecs.lua | 6 | ||||
-rw-r--r-- | src/luarocks/search.lua | 12 | ||||
-rw-r--r-- | src/luarocks/util.lua | 76 |
10 files changed, 103 insertions, 67 deletions
diff --git a/src/luarocks/cmd/help.lua b/src/luarocks/cmd/help.lua index a508953a..b3d937e1 100644 --- a/src/luarocks/cmd/help.lua +++ b/src/luarocks/cmd/help.lua | |||
@@ -85,8 +85,9 @@ function help.command(description, commands, command) | |||
85 | end | 85 | end |
86 | print_section("CONFIGURATION") | 86 | print_section("CONFIGURATION") |
87 | util.printout("\tLua version: " .. cfg.lua_version) | 87 | util.printout("\tLua version: " .. cfg.lua_version) |
88 | if cfg.luajit_version then | 88 | local ljv = util.get_luajit_version() |
89 | util.printout("\tLuaJIT version: " .. cfg.luajit_version) | 89 | if ljv then |
90 | util.printout("\tLuaJIT version: " .. ljv) | ||
90 | end | 91 | end |
91 | util.printout() | 92 | util.printout() |
92 | util.printout("\tConfiguration files:") | 93 | util.printout("\tConfiguration files:") |
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 0da9c88f..88de283b 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua | |||
@@ -110,7 +110,6 @@ function init.command(flags, name, version) | |||
110 | if config_tbl then | 110 | if config_tbl then |
111 | local globals = { | 111 | local globals = { |
112 | "lua_interpreter", | 112 | "lua_interpreter", |
113 | "luajit_version", | ||
114 | } | 113 | } |
115 | for _, v in ipairs(globals) do | 114 | for _, v in ipairs(globals) do |
116 | if cfg[v] then | 115 | if cfg[v] then |
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index bb0fdfd7..37c2c55e 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua | |||
@@ -116,8 +116,9 @@ end | |||
116 | 116 | ||
117 | local function installed_rock_label(dep, tree) | 117 | local function installed_rock_label(dep, tree) |
118 | local installed, version | 118 | local installed, version |
119 | if cfg.rocks_provided[dep.name] then | 119 | local rocks_provided = util.get_rocks_provided() |
120 | installed, version = true, cfg.rocks_provided[dep.name] | 120 | if rocks_provided[dep.name] then |
121 | installed, version = true, rocks_provided[dep.name] | ||
121 | else | 122 | else |
122 | installed, version = search.pick_installed_rock(dep, tree) | 123 | installed, version = search.pick_installed_rock(dep, tree) |
123 | end | 124 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index a1ebe4e4..c50e0a44 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -481,43 +481,18 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
481 | return defaults | 481 | return defaults |
482 | end | 482 | end |
483 | 483 | ||
484 | local function make_rocks_provided(lua_version, luajit_version) | ||
485 | local rocks_provided = {} | ||
486 | local rocks_provided_3_0 = {} | ||
487 | |||
488 | rocks_provided["lua"] = lua_version.."-1" | ||
489 | |||
490 | if lua_version == "5.2" or lua_version == "5.3" then | ||
491 | rocks_provided["bit32"] = lua_version.."-1" | ||
492 | end | ||
493 | |||
494 | if lua_version == "5.3" or lua_version == "5.4" then | ||
495 | rocks_provided["utf8"] = lua_version.."-1" | ||
496 | end | ||
497 | |||
498 | if luajit_version then | ||
499 | rocks_provided["luabitop"] = luajit_version.."-1" | ||
500 | rocks_provided_3_0["luajit"] = luajit_version.."-1" | ||
501 | end | ||
502 | |||
503 | return rocks_provided, rocks_provided_3_0 | ||
504 | end | ||
505 | |||
506 | local function use_defaults(cfg, defaults) | 484 | local function use_defaults(cfg, defaults) |
507 | 485 | ||
508 | -- Populate some arrays with values from their 'defaults' counterparts | 486 | -- Populate variables with values from their 'defaults' counterparts |
509 | -- if they were not already set by user. | 487 | -- if they were not already set by user. |
510 | for _, entry in ipairs({"variables", "rocks_provided"}) do | 488 | if not cfg.variables then |
511 | if not cfg[entry] then | 489 | cfg.variables = {} |
512 | cfg[entry] = {} | 490 | end |
513 | end | 491 | for k,v in pairs(defaults.variables) do |
514 | for k,v in pairs(defaults[entry]) do | 492 | if not cfg.variables[k] then |
515 | if not cfg[entry][k] then | 493 | cfg.variables[k] = v |
516 | cfg[entry][k] = v | ||
517 | end | ||
518 | end | 494 | end |
519 | end | 495 | end |
520 | util.deep_merge_under(defaults.rocks_provided_3_0, cfg.rocks_provided) | ||
521 | 496 | ||
522 | util.deep_merge_under(cfg, defaults) | 497 | util.deep_merge_under(cfg, defaults) |
523 | 498 | ||
@@ -537,7 +512,6 @@ local cfg = {} | |||
537 | -- @param detected table containing information detected about the | 512 | -- @param detected table containing information detected about the |
538 | -- environment. All fields below are optional: | 513 | -- environment. All fields below are optional: |
539 | -- * lua_version (in x.y format, e.g. "5.3") | 514 | -- * lua_version (in x.y format, e.g. "5.3") |
540 | -- * luajit_version (complete, e.g. "2.1.0-beta3") | ||
541 | -- * lua_bindir (e.g. "/usr/local/bin") | 515 | -- * lua_bindir (e.g. "/usr/local/bin") |
542 | -- * lua_incdir (e.g. "/usr/local/include/lua5.3/") | 516 | -- * lua_incdir (e.g. "/usr/local/include/lua5.3/") |
543 | -- * lua_libdir(e.g. "/usr/local/lib") | 517 | -- * lua_libdir(e.g. "/usr/local/lib") |
@@ -556,7 +530,6 @@ function cfg.init(detected, warning) | |||
556 | end | 530 | end |
557 | 531 | ||
558 | local lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) | 532 | local lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) |
559 | local luajit_version = detected.luajit_version or hardcoded.LUAJIT_VERSION or (jit and jit.version:sub(8)) | ||
560 | local lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg and arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua") | 533 | local lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg and arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua") |
561 | local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", "")) | 534 | local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", "")) |
562 | local lua_incdir = detected.lua_incdir or hardcoded.LUA_INCDIR | 535 | local lua_incdir = detected.lua_incdir or hardcoded.LUA_INCDIR |
@@ -579,7 +552,6 @@ function cfg.init(detected, warning) | |||
579 | cfg.major_version = major_version | 552 | cfg.major_version = major_version |
580 | 553 | ||
581 | cfg.lua_version = lua_version | 554 | cfg.lua_version = lua_version |
582 | cfg.luajit_version = luajit_version | ||
583 | cfg.lua_interpreter = lua_interpreter | 555 | cfg.lua_interpreter = lua_interpreter |
584 | 556 | ||
585 | cfg.variables = { | 557 | cfg.variables = { |
@@ -698,7 +670,6 @@ function cfg.init(detected, warning) | |||
698 | -- Settings detected or given via the CLI (i.e. --lua-dir) take precedence over config files: | 670 | -- Settings detected or given via the CLI (i.e. --lua-dir) take precedence over config files: |
699 | cfg.project_dir = project_dir | 671 | cfg.project_dir = project_dir |
700 | cfg.lua_version = detected.lua_version or cfg.lua_version | 672 | cfg.lua_version = detected.lua_version or cfg.lua_version |
701 | cfg.luajit_version = detected.luajit_version or cfg.luajit_version | ||
702 | cfg.lua_interpreter = detected.lua_interpreter or cfg.lua_interpreter | 673 | cfg.lua_interpreter = detected.lua_interpreter or cfg.lua_interpreter |
703 | cfg.variables.LUA_BINDIR = detected.lua_bindir or cfg.variables.LUA_BINDIR or lua_bindir | 674 | cfg.variables.LUA_BINDIR = detected.lua_bindir or cfg.variables.LUA_BINDIR or lua_bindir |
704 | cfg.variables.LUA_INCDIR = detected.lua_incdir or cfg.variables.LUA_INCDIR or lua_incdir | 675 | cfg.variables.LUA_INCDIR = detected.lua_incdir or cfg.variables.LUA_INCDIR or lua_incdir |
@@ -727,7 +698,6 @@ function cfg.init(detected, warning) | |||
727 | defaults.fs_use_modules = true | 698 | defaults.fs_use_modules = true |
728 | end | 699 | end |
729 | 700 | ||
730 | defaults.rocks_provided, defaults.rocks_provided_3_0 = make_rocks_provided(lua_version, luajit_version) | ||
731 | use_defaults(cfg, defaults) | 701 | use_defaults(cfg, defaults) |
732 | 702 | ||
733 | cfg.variables.LUA = cfg.variables.LUA or (cfg.variables.LUA_BINDIR and (cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter):gsub("//", "/")) | 703 | cfg.variables.LUA = cfg.variables.LUA or (cfg.variables.LUA_BINDIR and (cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter):gsub("//", "/")) |
@@ -752,6 +722,8 @@ function cfg.init(detected, warning) | |||
752 | and home_config_file | 722 | and home_config_file |
753 | or sys_config_file), | 723 | or sys_config_file), |
754 | } | 724 | } |
725 | |||
726 | cfg.cache = {} | ||
755 | 727 | ||
756 | ---------------------------------------- | 728 | ---------------------------------------- |
757 | -- Attributes of cfg are set. | 729 | -- Attributes of cfg are set. |
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 6a306026..d8f75d76 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
@@ -120,13 +120,14 @@ function util.show_table(t, tname, top_indent) | |||
120 | return cart .. autoref | 120 | return cart .. autoref |
121 | end | 121 | end |
122 | 122 | ||
123 | --- Merges contents of src on top of dst's contents. | 123 | --- Merges contents of src on top of dst's contents |
124 | -- (i.e. if an key from src already exists in dst, replace it). | ||
124 | -- @param dst Destination table, which will receive src's contents. | 125 | -- @param dst Destination table, which will receive src's contents. |
125 | -- @param src Table which provides new contents to dst. | 126 | -- @param src Table which provides new contents to dst. |
126 | function util.deep_merge(dst, src) | 127 | function util.deep_merge(dst, src) |
127 | for k, v in pairs(src) do | 128 | for k, v in pairs(src) do |
128 | if type(v) == "table" then | 129 | if type(v) == "table" then |
129 | if not dst[k] then | 130 | if dst[k] == nil then |
130 | dst[k] = {} | 131 | dst[k] = {} |
131 | end | 132 | end |
132 | if type(dst[k]) == "table" then | 133 | if type(dst[k]) == "table" then |
@@ -140,13 +141,14 @@ function util.deep_merge(dst, src) | |||
140 | end | 141 | end |
141 | end | 142 | end |
142 | 143 | ||
143 | --- Merges contents of src below those of dst's contents. | 144 | --- Merges contents of src below those of dst's contents |
145 | -- (i.e. if an key from src already exists in dst, do not replace it). | ||
144 | -- @param dst Destination table, which will receive src's contents. | 146 | -- @param dst Destination table, which will receive src's contents. |
145 | -- @param src Table which provides new contents to dst. | 147 | -- @param src Table which provides new contents to dst. |
146 | function util.deep_merge_under(dst, src) | 148 | function util.deep_merge_under(dst, src) |
147 | for k, v in pairs(src) do | 149 | for k, v in pairs(src) do |
148 | if type(v) == "table" then | 150 | if type(v) == "table" then |
149 | if not dst[k] then | 151 | if dst[k] == nil then |
150 | dst[k] = {} | 152 | dst[k] = {} |
151 | end | 153 | end |
152 | if type(dst[k]) == "table" then | 154 | if type(dst[k]) == "table" then |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 6eb19aba..874787da 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -497,7 +497,7 @@ function deps.scan_deps(results, manifest, name, version, deps_mode) | |||
497 | rocks_provided = rockspec.rocks_provided | 497 | rocks_provided = rockspec.rocks_provided |
498 | mdn[version] = dependencies | 498 | mdn[version] = dependencies |
499 | else | 499 | else |
500 | rocks_provided = setmetatable({}, { __index = cfg.rocks_provided_3_0 }) | 500 | rocks_provided = util.get_rocks_provided() |
501 | end | 501 | end |
502 | local matched = deps.match_deps(dependencies, rocks_provided, nil, deps_mode) | 502 | local matched = deps.match_deps(dependencies, rocks_provided, nil, deps_mode) |
503 | results[name] = version | 503 | results[name] = version |
@@ -533,8 +533,9 @@ end | |||
533 | 533 | ||
534 | function deps.check_lua(vars) | 534 | function deps.check_lua(vars) |
535 | local incdir_found = true | 535 | local incdir_found = true |
536 | local ljv = util.get_luajit_version() | ||
536 | if (not vars.LUA_INCDIR) and vars.LUA_DIR then | 537 | if (not vars.LUA_INCDIR) and vars.LUA_DIR then |
537 | vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, cfg.luajit_version) | 538 | vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv) |
538 | incdir_found = (vars.LUA_INCDIR ~= nil) | 539 | incdir_found = (vars.LUA_INCDIR ~= nil) |
539 | end | 540 | end |
540 | local shortv = cfg.lua_version:gsub("%.", "") | 541 | local shortv = cfg.lua_version:gsub("%.", "") |
@@ -545,7 +546,7 @@ function deps.check_lua(vars) | |||
545 | "lua-" .. shortv, | 546 | "lua-" .. shortv, |
546 | "lua", | 547 | "lua", |
547 | } | 548 | } |
548 | if cfg.luajit_version then | 549 | if ljv then |
549 | table.insert(libnames, 1, "luajit-" .. cfg.lua_version) | 550 | table.insert(libnames, 1, "luajit-" .. cfg.lua_version) |
550 | end | 551 | end |
551 | local cache = {} | 552 | local cache = {} |
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 6f70338b..23ba2532 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua | |||
@@ -453,7 +453,7 @@ function writer.check_dependencies(repo, deps_mode) | |||
453 | for _, entry in ipairs(version_entries) do | 453 | for _, entry in ipairs(version_entries) do |
454 | if entry.arch == "installed" then | 454 | if entry.arch == "installed" then |
455 | if manifest.dependencies[name] and manifest.dependencies[name][version] then | 455 | if manifest.dependencies[name] and manifest.dependencies[name][version] then |
456 | deps.report_missing_dependencies(name, version, manifest.dependencies[name][version], deps_mode, cfg.rocks_provided_3_0) | 456 | deps.report_missing_dependencies(name, version, manifest.dependencies[name][version], deps_mode, util.get_rocks_provided()) |
457 | end | 457 | end |
458 | end | 458 | end |
459 | end | 459 | end |
diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua index fe4a6d74..f1bb6d6a 100644 --- a/src/luarocks/rockspecs.lua +++ b/src/luarocks/rockspecs.lua | |||
@@ -5,7 +5,7 @@ local dir = require("luarocks.dir") | |||
5 | local path = require("luarocks.path") | 5 | local path = require("luarocks.path") |
6 | local queries = require("luarocks.queries") | 6 | local queries = require("luarocks.queries") |
7 | local type_rockspec = require("luarocks.type.rockspec") | 7 | local type_rockspec = require("luarocks.type.rockspec") |
8 | local util = require("luarocks.core.util") | 8 | local util = require("luarocks.util") |
9 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
10 | 10 | ||
11 | local rockspec_mt = {} | 11 | local rockspec_mt = {} |
@@ -142,9 +142,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) | |||
142 | or ".") ) | 142 | or ".") ) |
143 | or base | 143 | or base |
144 | 144 | ||
145 | rockspec.rocks_provided = (rockspec:format_is_at_least("3.0") | 145 | rockspec.rocks_provided = util.get_rocks_provided(rockspec) |
146 | and cfg.rocks_provided_3_0 | ||
147 | or cfg.rocks_provided) | ||
148 | 146 | ||
149 | for _, key in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do | 147 | for _, key in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do |
150 | local ok, err = convert_dependencies(rockspec, key) | 148 | local ok, err = convert_dependencies(rockspec, key) |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index a11d959c..e5ee9b47 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -164,9 +164,9 @@ function search.search_repos(query, lua_version) | |||
164 | end | 164 | end |
165 | end | 165 | end |
166 | end | 166 | end |
167 | -- search through rocks in cfg.rocks_provided | 167 | -- search through rocks in rocks_provided |
168 | local provided_repo = "provided by VM or rocks_provided" | 168 | local provided_repo = "provided by VM or rocks_provided" |
169 | for name, version in pairs(cfg.rocks_provided) do | 169 | for name, version in pairs(util.get_rocks_provided()) do |
170 | local result = results.new(name, version, provided_repo, "installed") | 170 | local result = results.new(name, version, provided_repo, "installed") |
171 | store_if_match(result_tree, result, query) | 171 | store_if_match(result_tree, result, query) |
172 | end | 172 | end |
@@ -242,9 +242,11 @@ end | |||
242 | function search.find_suitable_rock(query, cli) | 242 | function search.find_suitable_rock(query, cli) |
243 | assert(query:type() == "query") | 243 | assert(query:type() == "query") |
244 | 244 | ||
245 | if cfg.rocks_provided[query.name] ~= nil then | 245 | local rocks_provided = util.get_rocks_provided() |
246 | -- Do not install versions listed in cfg.rocks_provided. | 246 | |
247 | return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. | 247 | if rocks_provided[query.name] ~= nil then |
248 | -- Do not install versions listed in rocks_provided. | ||
249 | return nil, "Rock "..query.name.." "..rocks_provided[query.name].. | ||
248 | " is already provided by VM or via 'rocks_provided' in the config file." | 250 | " is already provided by VM or via 'rocks_provided' in the config file." |
249 | end | 251 | end |
250 | 252 | ||
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 57cefc61..6caba8cd 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -588,14 +588,25 @@ do | |||
588 | if luaver and luaver ~= lv then | 588 | if luaver and luaver ~= lv then |
589 | return nil | 589 | return nil |
590 | end | 590 | end |
591 | return lv | ||
592 | end | ||
593 | |||
594 | function util.get_luajit_version() | ||
595 | local cfg = require("luarocks.core.cfg") | ||
596 | if cfg.cache.luajit_version_checked then | ||
597 | return cfg.cache.luajit_version | ||
598 | end | ||
599 | cfg.cache.luajit_version_checked = true | ||
600 | |||
591 | local ljv | 601 | local ljv |
592 | if lv == "5.1" then | 602 | if cfg.lua_version == "5.1" then |
593 | ljv = util.popen_read(Q(lua_exe) .. ' -e "io.write(tostring(jit and jit.version:sub(8)))"') | 603 | ljv = util.popen_read(Q(cfg.variables["LUA_BINDIR"] .. "/" .. cfg.lua_interpreter) .. ' -e "io.write(tostring(jit and jit.version:sub(8)))"') |
594 | if ljv == "nil" then | 604 | if ljv == "nil" then |
595 | ljv = nil | 605 | ljv = nil |
596 | end | 606 | end |
597 | end | 607 | end |
598 | return lv, ljv | 608 | cfg.cache.luajit_version = ljv |
609 | return ljv | ||
599 | end | 610 | end |
600 | 611 | ||
601 | local find_lua_bindir | 612 | local find_lua_bindir |
@@ -636,9 +647,9 @@ do | |||
636 | local lua_exe = d .. "/" .. name | 647 | local lua_exe = d .. "/" .. name |
637 | local is_wrapper, err = util.lua_is_wrapper(lua_exe) | 648 | local is_wrapper, err = util.lua_is_wrapper(lua_exe) |
638 | if is_wrapper == false then | 649 | if is_wrapper == false then |
639 | local lv, ljv = util.check_lua_version(lua_exe, luaver) | 650 | local lv = util.check_lua_version(lua_exe, luaver) |
640 | if lv then | 651 | if lv then |
641 | return name, d, lv, ljv | 652 | return name, d, lv |
642 | end | 653 | end |
643 | elseif is_wrapper == true or err == nil then | 654 | elseif is_wrapper == true or err == nil then |
644 | table.insert(tried, lua_exe) | 655 | table.insert(tried, lua_exe) |
@@ -656,15 +667,14 @@ do | |||
656 | end | 667 | end |
657 | 668 | ||
658 | function util.find_lua(prefix, luaver) | 669 | function util.find_lua(prefix, luaver) |
659 | local lua_interpreter, bindir, luajitver | 670 | local lua_interpreter, bindir |
660 | lua_interpreter, bindir, luaver, luajitver = find_lua_bindir(prefix, luaver) | 671 | lua_interpreter, bindir, luaver = find_lua_bindir(prefix, luaver) |
661 | if not lua_interpreter then | 672 | if not lua_interpreter then |
662 | return nil, bindir | 673 | return nil, bindir |
663 | end | 674 | end |
664 | 675 | ||
665 | return { | 676 | return { |
666 | lua_version = luaver, | 677 | lua_version = luaver, |
667 | luajit_version = luajitver, | ||
668 | lua_interpreter = lua_interpreter, | 678 | lua_interpreter = lua_interpreter, |
669 | lua_dir = prefix, | 679 | lua_dir = prefix, |
670 | lua_bindir = bindir, | 680 | lua_bindir = bindir, |
@@ -714,5 +724,55 @@ function util.opts_table(type_name, valid_opts) | |||
714 | end | 724 | end |
715 | end | 725 | end |
716 | 726 | ||
727 | --- Return a table of modules that are already provided by the VM, which | ||
728 | -- can be specified as dependencies without having to install an actual rock. | ||
729 | -- @param rockspec (optional) a rockspec table, so that rockspec format | ||
730 | -- version compatibility can be checked. If not given, maximum compatibility | ||
731 | -- is assumed. | ||
732 | -- @return a table with rock names as keys and versions and values, | ||
733 | -- specifying modules that are already provided by the VM (including | ||
734 | -- "lua" for the Lua version and, for format 3.0+, "luajit" if detected). | ||
735 | function util.get_rocks_provided(rockspec) | ||
736 | local cfg = require("luarocks.core.cfg") | ||
737 | |||
738 | if not rockspec and cfg.cache.rocks_provided then | ||
739 | return cfg.cache.rocks_provided | ||
740 | end | ||
741 | |||
742 | local rocks_provided = {} | ||
743 | |||
744 | local lv = cfg.lua_version | ||
745 | |||
746 | rocks_provided["lua"] = lv.."-1" | ||
747 | |||
748 | if lv == "5.2" or lv == "5.3" then | ||
749 | rocks_provided["bit32"] = lv.."-1" | ||
750 | end | ||
751 | |||
752 | if lv == "5.3" or lv == "5.4" then | ||
753 | rocks_provided["utf8"] = lv.."-1" | ||
754 | end | ||
755 | |||
756 | if lv == "5.1" then | ||
757 | local ljv = util.get_luajit_version() | ||
758 | if ljv then | ||
759 | rocks_provided["luabitop"] = ljv.."-1" | ||
760 | if (not rockspec) or rockspec:format_is_at_least("3.0") then | ||
761 | rocks_provided["luajit"] = ljv.."-1" | ||
762 | end | ||
763 | end | ||
764 | end | ||
765 | |||
766 | if cfg.rocks_provided then | ||
767 | util.deep_merge_under(rocks_provided, cfg.rocks_provided) | ||
768 | end | ||
769 | |||
770 | if not rockspec then | ||
771 | cfg.cache.rocks_provided = rocks_provided | ||
772 | end | ||
773 | |||
774 | return rocks_provided | ||
775 | end | ||
776 | |||
717 | return util | 777 | return util |
718 | 778 | ||