diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-03 13:56:38 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-09 16:49:20 -0300 |
| commit | dc2ecc0488af83066c41eac92e6a8cc80fb47497 (patch) | |
| tree | 53a2a3de8cd59b3add87e11422486bb075932f43 | |
| parent | 06f81d93f3e5f33524c0cb0230a4445378801d76 (diff) | |
| download | luarocks-dc2ecc0488af83066c41eac92e6a8cc80fb47497.tar.gz luarocks-dc2ecc0488af83066c41eac92e6a8cc80fb47497.tar.bz2 luarocks-dc2ecc0488af83066c41eac92e6a8cc80fb47497.zip | |
Improve runtime detection of Lua interpreter
Do not confuse the project ./lua wrapper with a valid interpreter.
| -rw-r--r-- | src/luarocks/cmd.lua | 30 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 18 |
2 files changed, 39 insertions, 9 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 8a07a92a..61e44a6e 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -289,6 +289,8 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 289 | if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then | 289 | if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then |
| 290 | die("Invalid entry for --deps-mode.") | 290 | die("Invalid entry for --deps-mode.") |
| 291 | end | 291 | end |
| 292 | |||
| 293 | local lua_found = false | ||
| 292 | 294 | ||
| 293 | local detected | 295 | local detected |
| 294 | if flags["lua-dir"] then | 296 | if flags["lua-dir"] then |
| @@ -297,6 +299,7 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 297 | if not detected then | 299 | if not detected then |
| 298 | die(err) | 300 | die(err) |
| 299 | end | 301 | end |
| 302 | lua_found = true | ||
| 300 | assert(detected.lua_version) | 303 | assert(detected.lua_version) |
| 301 | assert(detected.lua_dir) | 304 | assert(detected.lua_dir) |
| 302 | elseif lua_version then | 305 | elseif lua_version then |
| @@ -312,12 +315,9 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 312 | break | 315 | break |
| 313 | end | 316 | end |
| 314 | end | 317 | end |
| 315 | if not detected then | 318 | if detected then |
| 316 | util.warning("Could not find a Lua interpreter for version " .. | 319 | lua_found = true |
| 317 | lua_version .. " in your PATH. " .. | 320 | else |
| 318 | "Modules may not install with the correct configurations. " .. | ||
| 319 | "You may want to specify to the path prefix to your build " .. | ||
| 320 | "of Lua " .. lua_version .. " using --lua-dir") | ||
| 321 | detected = { | 321 | detected = { |
| 322 | lua_version = lua_version, | 322 | lua_version = lua_version, |
| 323 | } | 323 | } |
| @@ -371,6 +371,24 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 371 | 371 | ||
| 372 | fs.init() | 372 | fs.init() |
| 373 | 373 | ||
| 374 | if not lua_found then | ||
| 375 | if cfg.variables.LUA_DIR then | ||
| 376 | local found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version) | ||
| 377 | if found then | ||
| 378 | lua_found = true | ||
| 379 | end | ||
| 380 | end | ||
| 381 | end | ||
| 382 | |||
| 383 | if not lua_found then | ||
| 384 | util.warning("Could not find a Lua interpreter for version " .. | ||
| 385 | lua_version .. " in your PATH. " .. | ||
| 386 | "Modules may not install with the correct configurations. " .. | ||
| 387 | "You may want to specify to the path prefix to your build " .. | ||
| 388 | "of Lua " .. lua_version .. " using --lua-dir") | ||
| 389 | end | ||
| 390 | cfg.lua_found = lua_found | ||
| 391 | |||
| 374 | if detected.project_dir then | 392 | if detected.project_dir then |
| 375 | detected.project_dir = fs.absolute_name(detected.project_dir) | 393 | detected.project_dir = fs.absolute_name(detected.project_dir) |
| 376 | end | 394 | end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 1714952e..2592fcdc 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -634,9 +634,11 @@ do | |||
| 634 | for _, name in ipairs(names) do | 634 | for _, name in ipairs(names) do |
| 635 | local lua_exe = d .. "/" .. name | 635 | local lua_exe = d .. "/" .. name |
| 636 | table.insert(tried, lua_exe) | 636 | table.insert(tried, lua_exe) |
| 637 | local lv, ljv = util.check_lua_version(lua_exe, luaver) | 637 | if not util.lua_is_wrapper(lua_exe) then |
| 638 | if lv then | 638 | local lv, ljv = util.check_lua_version(lua_exe, luaver) |
| 639 | return name, d, lv, ljv | 639 | if lv then |
| 640 | return name, d, lv, ljv | ||
| 641 | end | ||
| 640 | end | 642 | end |
| 641 | end | 643 | end |
| 642 | end | 644 | end |
| @@ -665,6 +667,16 @@ do | |||
| 665 | end | 667 | end |
| 666 | end | 668 | end |
| 667 | 669 | ||
| 670 | function util.lua_is_wrapper(interp) | ||
| 671 | local fd, err = io.open(interp, "r") | ||
| 672 | if not fd then | ||
| 673 | return nil, err | ||
| 674 | end | ||
| 675 | local data = fd:read(1000) | ||
| 676 | fd:close() | ||
| 677 | return not not data:match("LUAROCKS_SYSCONFDIR") | ||
| 678 | end | ||
| 679 | |||
| 668 | function util.opts_table(type_name, valid_opts) | 680 | function util.opts_table(type_name, valid_opts) |
| 669 | local opts_mt = {} | 681 | local opts_mt = {} |
| 670 | 682 | ||
