From 3f0f3028321154cbacecd6690833d0e8c805ccd8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 28 Feb 2024 11:49:34 -0300 Subject: feat: more informative reports no bad LUA_{INC,LIB}DIR configs --- src/luarocks/cmd.lua | 10 +++--- src/luarocks/cmd/config.lua | 86 ++++++++++++++++++++++++++++++++++++++++++--- src/luarocks/deps.lua | 12 +++---- 3 files changed, 93 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 643023b8..452237d2 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -337,8 +337,8 @@ local lua_example = package.config:sub(1, 1) == "\\" and "" or "" -local function show_status(file, status) - return (file and file .. " " or "") .. (status and "(ok)" or "(not found)") +local function show_status(file, status, err) + return (file and file .. " " or "") .. (status and "(ok)" or ("(" .. (err or "not found") ..")")) end local function use_to_fix_location(key, what) @@ -363,15 +363,15 @@ local function get_config_text(cfg) -- luacheck: ignore 431 if cfg.luajit_version then buf = buf.." LuaJIT : "..cfg.luajit_version.."\n" end - buf = buf.." LUA : "..show_status(cfg.variables.LUA, lua_ok).."\n" + buf = buf.." LUA : "..show_status(cfg.variables.LUA, lua_ok, "interpreter not found").."\n" if not lua_ok then buf = buf .. use_to_fix_location("variables.LUA", lua_example) end - buf = buf.." LUA_INCDIR : "..show_status(cfg.variables.LUA_INCDIR, incdir_ok).."\n" + buf = buf.." LUA_INCDIR : "..show_status(cfg.variables.LUA_INCDIR, incdir_ok, "lua.h not found").."\n" if lua_ok and not incdir_ok then buf = buf .. use_to_fix_location("variables.LUA_INCDIR") end - buf = buf.." LUA_LIBDIR : "..show_status(cfg.variables.LUA_LIBDIR, libdir_ok).."\n" + buf = buf.." LUA_LIBDIR : "..show_status(cfg.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found").."\n" if lua_ok and not libdir_ok then buf = buf .. use_to_fix_location("variables.LUA_LIBDIR") end diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index a01d33a9..26d60f09 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -243,11 +243,59 @@ local function get_scope(args) or "user" end +local function report_on_lua_incdir_config(value, lua_version) + local variables = { + ["LUA_DIR"] = cfg.variables.LUA_DIR, + ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, + ["LUA_INCDIR"] = value, + ["LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR, + ["LUA"] = cfg.variables.LUA, + } + + local ok, err = deps.check_lua_incdir(variables, lua_version) + if not ok then + util.printerr() + util.warning((err:gsub(" You can use.*", ""))) + end + return ok +end + +local function report_on_lua_libdir_config(value, lua_version) + local variables = { + ["LUA_DIR"] = cfg.variables.LUA_DIR, + ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, + ["LUA_INCDIR"] = cfg.variables.LUA_INCDIR, + ["LUA_LIBDIR"] = value, + ["LUA"] = cfg.variables.LUA, + } + + local ok, err, _, err_files = deps.check_lua_libdir(variables, lua_version) + if not ok then + util.printerr() + util.warning((err:gsub(" You can use.*", ""))) + util.printerr("Tried:") + for _, l in pairs(err_files) do + for _, d in ipairs(l) do + util.printerr("\t" .. d) + end + end + end + return ok +end + +local function warn_bad_c_config() + util.printerr() + util.printerr("LuaRocks may not work correctly when building C modules using this configuration.") + util.printerr() +end + --- Driver function for "config" command. -- @return boolean: True if succeeded, nil on errors. function config_cmd.command(args) - deps.check_lua_incdir(cfg.variables, args.lua_version or cfg.lua_version) - deps.check_lua_libdir(cfg.variables, args.lua_version or cfg.lua_version) + local lua_version = args.lua_version or cfg.lua_version + + deps.check_lua_incdir(cfg.variables, lua_version) + deps.check_lua_libdir(cfg.variables, lua_version) -- deprecated flags if args.lua_incdir then @@ -312,13 +360,43 @@ function config_cmd.command(args) local prefix = dir.dir_name(cfg.config_files[scope].file) persist.save_default_lua_version(prefix, args.lua_version) end - return write_entries(keys, scope, args.unset) + local ok, err = write_entries(keys, scope, args.unset) + if ok then + local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR, lua_version) + local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR, lua_version) + if not (inc_ok and lib_ok) then + warn_bad_c_config() + end + end + + return ok, err end if args.key then + if args.key:match("^[A-Z]") then + args.key = "variables." .. args.key + end + if args.value or args.unset then local scope = get_scope(args) - return write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) + + local ok, err = write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) + + if ok then + if args.key == "variables.LUA_INCDIR" then + local ok = report_on_lua_incdir_config(args.value, lua_version) + if not ok then + warn_bad_c_config() + end + elseif args.key == "variables.LUA_LIBDIR" then + local ok = report_on_lua_libdir_config(args.value, lua_version) + if not ok then + warn_bad_c_config() + end + end + end + + return ok, err else return print_entry(args.key, cfg, args.json) end diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 16631c58..1cd500ca 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -703,10 +703,10 @@ local function lua_h_exists(d, luaver) if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then return d end - return nil, "Lua header found at " .. d .. " does not match Lua version " .. luaver .. ". You may want to override this by configuring LUA_INCDIR.", "dependency", 2 + return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR ` to set the correct location.", "dependency", 2 end - return nil, "Failed finding Lua header files (searched at " .. d .. "). You may need to install them or configure LUA_INCDIR.", "dependency", 1 + return nil, "Failed finding Lua header lua.h (searched at " .. d .. "). You may need to install Lua development headers. You can use `luarocks config variables.LUA_INCDIR ` to set the correct location.", "dependency", 1 end local function find_lua_incdir(prefix, luaver, luajitver) @@ -793,7 +793,7 @@ function deps.check_lua_libdir(vars) end local cache = {} local save_LUA_INCDIR = vars.LUA_INCDIR - local ok = check_external_dependency("LUA", { library = libnames }, vars, "build", cache) + local ok, _, _, errfiles = check_external_dependency("LUA", { library = libnames }, vars, "build", cache) vars.LUA_INCDIR = save_LUA_INCDIR local err if ok then @@ -806,7 +806,7 @@ function deps.check_lua_libdir(vars) ok = txt:match("Lua " .. cfg.lua_version, 1, true) or txt:match("lua" .. (cfg.lua_version:gsub("%.", "")), 1, true) if not ok then - err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You may want to override this by configuring LUA_LIBDIR." + err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You can use `luarocks config variables.LUA_LIBDIR ` to set the correct location." end end @@ -819,8 +819,8 @@ function deps.check_lua_libdir(vars) vars.LUA_LIBDIR_OK = true return true else - err = err or "Failed finding Lua library. You may need to configure LUA_LIBDIR." - return nil, err, "dependency" + err = err or "Failed finding the Lua library. You can use `luarocks config variables.LUA_LIBDIR ` to set the correct location." + return nil, err, "dependency", errfiles end end -- cgit v1.2.3-55-g6feb