From b65f5304f224ce7f9edd0faa2bbd152dc8f8ddf2 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 23 Feb 2024 20:59:47 -0300 Subject: fix: if --lua-* flags are given, don't use the hardcoded paths Thanks @Frityet for the help with troubleshooting! Fixes #1611 --- src/luarocks/cmd.lua | 11 ++--------- src/luarocks/core/cfg.lua | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 30293d6b..e8f05575 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -192,15 +192,8 @@ local function search_lua(lua_version, verbose, search_at) local path_sep = (package.config:sub(1, 1) == "\\" and ";" or ":") local all_tried = {} for bindir in (os.getenv("PATH") or ""):gmatch("[^"..path_sep.."]+") do - local parentdir = dir.path((bindir:gsub("[\\/][^\\/]+[\\/]?$", ""))) - local detected, tried = util.find_lua(parentdir, lua_version) - if detected then - return detected - else - table.insert(all_tried, tried) - end - bindir = dir.path(bindir) - detected = util.find_lua(bindir, lua_version) + local searchdir = (bindir:gsub("[\\/]+bin[\\/]?$", "")) + local detected, tried = util.find_lua(searchdir, lua_version) if detected then return detected else diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index b991f581..90e52150 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -611,19 +611,37 @@ function cfg.init(detected, warning) -- Use detected values as defaults, overridable via config files or CLI args - cfg.lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) + local hardcoded_lua = hardcoded.LUA + local hardcoded_lua_dir = hardcoded.LUA_DIR + local hardcoded_lua_bindir = hardcoded.LUA_BINDIR + local hardcoded_lua_incdir = hardcoded.LUA_INCDIR + local hardcoded_lua_libdir = hardcoded.LUA_LIBDIR + local hardcoded_lua_version = hardcoded.LUA_VERSION or _VERSION:sub(5) + + -- if --lua-version or --lua-dir are passed from the CLI, + -- don't use the hardcoded paths at all + if detected.given_lua_version or detected.given_lua_dir then + hardcoded_lua = nil + hardcoded_lua_dir = nil + hardcoded_lua_bindir = nil + hardcoded_lua_incdir = nil + hardcoded_lua_libdir = nil + hardcoded_lua_version = nil + end + + cfg.lua_version = detected.lua_version or hardcoded_lua_version cfg.project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir do - local lua = detected.lua or hardcoded.LUA - local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR - local lua_dir = detected.lua_dir or hardcoded.LUA_DIR + local lua = detected.lua or hardcoded_lua + local lua_dir = detected.lua_dir or hardcoded_lua_dir + local lua_bindir = detected.lua_bindir or hardcoded_lua_bindir cfg.variables = { LUA = lua, LUA_DIR = lua_dir, LUA_BINDIR = lua_bindir, - LUA_LIBDIR = hardcoded.LUA_LIBDIR, - LUA_INCDIR = hardcoded.LUA_INCDIR, + LUA_LIBDIR = hardcoded_lua_libdir, + LUA_INCDIR = hardcoded_lua_incdir, } end -- cgit v1.2.3-55-g6feb