From 1d3bb56b309ce0463249852f901147157f34adfa Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 26 Jul 2019 19:11:21 -0300 Subject: cfg: avoid setting LUA_LIBDIR and LUA_INCDIR too early --- spec/build_spec.lua | 3 ++- src/luarocks/build.lua | 9 ++++++++- src/luarocks/cmd.lua | 15 +++++++++++--- src/luarocks/cmd/config.lua | 3 ++- src/luarocks/cmd/init.lua | 2 +- src/luarocks/core/cfg.lua | 22 +++++++++------------ src/luarocks/deps.lua | 48 +++++++++++++++++++++++---------------------- 7 files changed, 59 insertions(+), 43 deletions(-) diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 2cfdeace..41c169d9 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -507,7 +507,8 @@ describe("LuaRocks build tests #unit", function() runner.tick = true cfg.init() fs.init() - deps.check_lua(cfg.variables) + deps.check_lua_incdir(cfg.variables) + deps.check_lua_libdir(cfg.variables) end) teardown(function() diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index c2dd4439..2ac7dd3a 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -109,11 +109,18 @@ local function process_dependencies(rockspec, opts) end end - local ok, err, errcode = deps.check_lua(rockspec.variables) + local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) if not ok then return nil, err, errcode end + if cfg.link_lua_explicitly then + local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) + if not ok then + return nil, err, errcode + end + end + if opts.deps_mode == "none" then util.warning("skipping dependency checks.") return true diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 4397ffbd..1ead6c4b 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -178,12 +178,12 @@ do do local function find_project_dir(project_tree) if project_tree then - return project_tree:gsub("[/\\][^/\\]+$", "") + return project_tree:gsub("[/\\][^/\\]+$", ""), true else local try = "." for _ = 1, 10 do -- FIXME detect when root dir was hit instead if util.exists(try .. "/.luarocks") and util.exists(try .. "/lua_modules") then - return try + return try, false elseif util.exists(try .. "/.luarocks-no-project") then break end @@ -265,8 +265,17 @@ do end detect_config_via_flags = function(flags) - local project_dir = find_project_dir(flags["project-tree"]) + local project_dir, given = find_project_dir(flags["project-tree"]) local detected = detect_lua_via_flags(flags, project_dir) + if flags["lua-version"] then + detected.given_lua_version = flags["lua-version"] + end + if flags["lua-dir"] then + detected.given_lua_dir = flags["lua-dir"] + end + if given then + detected.given_project_dir = project_dir + end detected.project_dir = project_dir return detected end diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index e9b2fef4..b3cb5e07 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -234,7 +234,8 @@ end --- Driver function for "config" command. -- @return boolean: True if succeeded, nil on errors. function config_cmd.command(flags, var, val) - deps.check_lua(cfg.variables) + deps.check_lua_incdir(cfg.variables) + deps.check_lua_libdir(cfg.variables) -- deprecated flags if flags["lua-incdir"] then diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 88de283b..60aa4f82 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua @@ -70,7 +70,7 @@ function init.command(flags, name, version) if not cfg.lua_found then return nil, "Lua installation is not found." end - local ok, err = deps.check_lua(cfg.variables) + local ok, err = deps.check_lua_incdir(cfg.variables) if not ok then return nil, err end diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 8edd5f63..008ae7dc 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -514,8 +514,6 @@ local cfg = {} -- environment. All fields below are optional: -- * lua_version (in x.y format, e.g. "5.3") -- * lua_bindir (e.g. "/usr/local/bin") --- * lua_incdir (e.g. "/usr/local/include/lua5.3/") --- * lua_libdir(e.g. "/usr/local/lib") -- * lua_dir (e.g. "/usr/local") -- * lua_interpreter (e.g. "lua-5.3") -- * project_dir (a string with the path of the project directory @@ -533,8 +531,6 @@ function cfg.init(detected, warning) local lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) 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") local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", "")) - local lua_incdir = detected.lua_incdir or hardcoded.LUA_INCDIR - local lua_libdir = detected.lua_libdir or hardcoded.LUA_LIBDIR local lua_dir = detected.lua_dir or hardcoded.LUA_DIR or (lua_bindir and lua_bindir:gsub("[\\/]bin$", "")) local project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir @@ -558,8 +554,8 @@ function cfg.init(detected, warning) cfg.variables = { LUA_DIR = lua_dir, LUA_BINDIR = lua_bindir, - LUA_INCDIR = lua_incdir, - LUA_LIBDIR = lua_libdir, + LUA_LIBDIR = hardcoded.LUA_LIBDIR, + LUA_INCDIR = hardcoded.LUA_INCDIR, } cfg.init = init @@ -668,14 +664,14 @@ function cfg.init(detected, warning) -- Let's finish up the cfg table. ---------------------------------------- - -- Settings detected or given via the CLI (i.e. --lua-dir) take precedence over config files: - cfg.project_dir = project_dir - cfg.lua_version = detected.lua_version or cfg.lua_version + -- Settings given via the CLI (i.e. --lua-dir) take precedence over config files. + cfg.project_dir = detected.given_project_dir or project_dir + cfg.lua_version = detected.given_lua_version or lua_version or cfg.lua_version + cfg.variables.LUA_DIR = detected.given_lua_dir or cfg.variables.LUA_DIR or lua_dir + cfg.lua_interpreter = detected.lua_interpreter or cfg.lua_interpreter - cfg.variables.LUA_BINDIR = detected.lua_bindir or cfg.variables.LUA_BINDIR or lua_bindir - cfg.variables.LUA_INCDIR = detected.lua_incdir or cfg.variables.LUA_INCDIR or lua_incdir - cfg.variables.LUA_LIBDIR = detected.lua_libdir or cfg.variables.LUA_LIBDIR or lua_libdir - cfg.variables.LUA_DIR = detected.lua_dir or cfg.variables.LUA_DIR or lua_dir + + cfg.variables.LUA_BINDIR = cfg.variables.LUA_BINDIR or lua_bindir -- Build a default list of rocks trees if not given if cfg.rocks_trees == nil then diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 9ea14881..9ee21772 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -531,7 +531,7 @@ local function find_lua_incdir(prefix, luaver, luajitver) return nil end -function deps.check_lua(vars) +function deps.check_lua_incdir(vars) local ljv = util.get_luajit_version() if (not vars.LUA_INCDIR) and vars.LUA_DIR then @@ -541,30 +541,32 @@ function deps.check_lua(vars) end end - if cfg.link_lua_explicitly then - local shortv = cfg.lua_version:gsub("%.", "") - local libnames = { - "lua" .. cfg.lua_version, - "lua" .. shortv, - "lua-" .. cfg.lua_version, - "lua-" .. shortv, - "lua", - } - if ljv then - table.insert(libnames, 1, "luajit-" .. cfg.lua_version) - end - local cache = {} - for _, libname in ipairs(libnames) do - local ok = check_external_dependency("LUA", { library = libname }, vars, "build", cache) - if ok then - vars.LUALIB = vars.LUA_LIBDIR_FILE - return true - end + return true +end + +function deps.check_lua_libdir(vars) + local ljv = util.get_luajit_version() + + local shortv = cfg.lua_version:gsub("%.", "") + local libnames = { + "lua" .. cfg.lua_version, + "lua" .. shortv, + "lua-" .. cfg.lua_version, + "lua-" .. shortv, + "lua", + } + if ljv then + table.insert(libnames, 1, "luajit-" .. cfg.lua_version) + end + local cache = {} + for _, libname in ipairs(libnames) do + local ok = check_external_dependency("LUA", { library = libname }, vars, "build", cache) + if ok then + vars.LUALIB = vars.LUA_LIBDIR_FILE + return true end - return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency" end - - return true + return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency" end local valid_deps_modes = { -- cgit v1.2.3-55-g6feb