From dc2ecc0488af83066c41eac92e6a8cc80fb47497 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 3 Apr 2019 13:56:38 -0300 Subject: Improve runtime detection of Lua interpreter Do not confuse the project ./lua wrapper with a valid interpreter. --- src/luarocks/cmd.lua | 30 ++++++++++++++++++++++++------ src/luarocks/util.lua | 18 +++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src') 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, ...) if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then die("Invalid entry for --deps-mode.") end + + local lua_found = false local detected if flags["lua-dir"] then @@ -297,6 +299,7 @@ function cmd.run_command(description, commands, external_namespace, ...) if not detected then die(err) end + lua_found = true assert(detected.lua_version) assert(detected.lua_dir) elseif lua_version then @@ -312,12 +315,9 @@ function cmd.run_command(description, commands, external_namespace, ...) break end end - if not detected then - util.warning("Could not find a Lua interpreter for version " .. - lua_version .. " in your PATH. " .. - "Modules may not install with the correct configurations. " .. - "You may want to specify to the path prefix to your build " .. - "of Lua " .. lua_version .. " using --lua-dir") + if detected then + lua_found = true + else detected = { lua_version = lua_version, } @@ -371,6 +371,24 @@ function cmd.run_command(description, commands, external_namespace, ...) fs.init() + if not lua_found then + if cfg.variables.LUA_DIR then + local found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version) + if found then + lua_found = true + end + end + end + + if not lua_found then + util.warning("Could not find a Lua interpreter for version " .. + lua_version .. " in your PATH. " .. + "Modules may not install with the correct configurations. " .. + "You may want to specify to the path prefix to your build " .. + "of Lua " .. lua_version .. " using --lua-dir") + end + cfg.lua_found = lua_found + if detected.project_dir then detected.project_dir = fs.absolute_name(detected.project_dir) 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 for _, name in ipairs(names) do local lua_exe = d .. "/" .. name table.insert(tried, lua_exe) - local lv, ljv = util.check_lua_version(lua_exe, luaver) - if lv then - return name, d, lv, ljv + if not util.lua_is_wrapper(lua_exe) then + local lv, ljv = util.check_lua_version(lua_exe, luaver) + if lv then + return name, d, lv, ljv + end end end end @@ -665,6 +667,16 @@ do end end +function util.lua_is_wrapper(interp) + local fd, err = io.open(interp, "r") + if not fd then + return nil, err + end + local data = fd:read(1000) + fd:close() + return not not data:match("LUAROCKS_SYSCONFDIR") +end + function util.opts_table(type_name, valid_opts) local opts_mt = {} -- cgit v1.2.3-55-g6feb