diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-28 11:49:34 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-29 15:31:46 +0000 |
| commit | 3f0f3028321154cbacecd6690833d0e8c805ccd8 (patch) | |
| tree | 76150d9b8cc50f89fa32d5716a26b6261f4e087e /src | |
| parent | 6f07395f37459d7e0c2732888a1f7312fea0c67c (diff) | |
| download | luarocks-3f0f3028321154cbacecd6690833d0e8c805ccd8.tar.gz luarocks-3f0f3028321154cbacecd6690833d0e8c805ccd8.tar.bz2 luarocks-3f0f3028321154cbacecd6690833d0e8c805ccd8.zip | |
feat: more informative reports no bad LUA_{INC,LIB}DIR configs
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd.lua | 10 | ||||
| -rw-r--r-- | src/luarocks/cmd/config.lua | 86 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 12 |
3 files changed, 93 insertions, 15 deletions
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) == "\\" | |||
| 337 | and "<d:\\path\\lua.exe>" | 337 | and "<d:\\path\\lua.exe>" |
| 338 | or "</path/lua>" | 338 | or "</path/lua>" |
| 339 | 339 | ||
| 340 | local function show_status(file, status) | 340 | local function show_status(file, status, err) |
| 341 | return (file and file .. " " or "") .. (status and "(ok)" or "(not found)") | 341 | return (file and file .. " " or "") .. (status and "(ok)" or ("(" .. (err or "not found") ..")")) |
| 342 | end | 342 | end |
| 343 | 343 | ||
| 344 | local function use_to_fix_location(key, what) | 344 | local function use_to_fix_location(key, what) |
| @@ -363,15 +363,15 @@ local function get_config_text(cfg) -- luacheck: ignore 431 | |||
| 363 | if cfg.luajit_version then | 363 | if cfg.luajit_version then |
| 364 | buf = buf.." LuaJIT : "..cfg.luajit_version.."\n" | 364 | buf = buf.." LuaJIT : "..cfg.luajit_version.."\n" |
| 365 | end | 365 | end |
| 366 | buf = buf.." LUA : "..show_status(cfg.variables.LUA, lua_ok).."\n" | 366 | buf = buf.." LUA : "..show_status(cfg.variables.LUA, lua_ok, "interpreter not found").."\n" |
| 367 | if not lua_ok then | 367 | if not lua_ok then |
| 368 | buf = buf .. use_to_fix_location("variables.LUA", lua_example) | 368 | buf = buf .. use_to_fix_location("variables.LUA", lua_example) |
| 369 | end | 369 | end |
| 370 | buf = buf.." LUA_INCDIR : "..show_status(cfg.variables.LUA_INCDIR, incdir_ok).."\n" | 370 | buf = buf.." LUA_INCDIR : "..show_status(cfg.variables.LUA_INCDIR, incdir_ok, "lua.h not found").."\n" |
| 371 | if lua_ok and not incdir_ok then | 371 | if lua_ok and not incdir_ok then |
| 372 | buf = buf .. use_to_fix_location("variables.LUA_INCDIR") | 372 | buf = buf .. use_to_fix_location("variables.LUA_INCDIR") |
| 373 | end | 373 | end |
| 374 | buf = buf.." LUA_LIBDIR : "..show_status(cfg.variables.LUA_LIBDIR, libdir_ok).."\n" | 374 | buf = buf.." LUA_LIBDIR : "..show_status(cfg.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found").."\n" |
| 375 | if lua_ok and not libdir_ok then | 375 | if lua_ok and not libdir_ok then |
| 376 | buf = buf .. use_to_fix_location("variables.LUA_LIBDIR") | 376 | buf = buf .. use_to_fix_location("variables.LUA_LIBDIR") |
| 377 | end | 377 | 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) | |||
| 243 | or "user" | 243 | or "user" |
| 244 | end | 244 | end |
| 245 | 245 | ||
| 246 | local function report_on_lua_incdir_config(value, lua_version) | ||
| 247 | local variables = { | ||
| 248 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | ||
| 249 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | ||
| 250 | ["LUA_INCDIR"] = value, | ||
| 251 | ["LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR, | ||
| 252 | ["LUA"] = cfg.variables.LUA, | ||
| 253 | } | ||
| 254 | |||
| 255 | local ok, err = deps.check_lua_incdir(variables, lua_version) | ||
| 256 | if not ok then | ||
| 257 | util.printerr() | ||
| 258 | util.warning((err:gsub(" You can use.*", ""))) | ||
| 259 | end | ||
| 260 | return ok | ||
| 261 | end | ||
| 262 | |||
| 263 | local function report_on_lua_libdir_config(value, lua_version) | ||
| 264 | local variables = { | ||
| 265 | ["LUA_DIR"] = cfg.variables.LUA_DIR, | ||
| 266 | ["LUA_BINDIR"] = cfg.variables.LUA_BINDIR, | ||
| 267 | ["LUA_INCDIR"] = cfg.variables.LUA_INCDIR, | ||
| 268 | ["LUA_LIBDIR"] = value, | ||
| 269 | ["LUA"] = cfg.variables.LUA, | ||
| 270 | } | ||
| 271 | |||
| 272 | local ok, err, _, err_files = deps.check_lua_libdir(variables, lua_version) | ||
| 273 | if not ok then | ||
| 274 | util.printerr() | ||
| 275 | util.warning((err:gsub(" You can use.*", ""))) | ||
| 276 | util.printerr("Tried:") | ||
| 277 | for _, l in pairs(err_files) do | ||
| 278 | for _, d in ipairs(l) do | ||
| 279 | util.printerr("\t" .. d) | ||
| 280 | end | ||
| 281 | end | ||
| 282 | end | ||
| 283 | return ok | ||
| 284 | end | ||
| 285 | |||
| 286 | local function warn_bad_c_config() | ||
| 287 | util.printerr() | ||
| 288 | util.printerr("LuaRocks may not work correctly when building C modules using this configuration.") | ||
| 289 | util.printerr() | ||
| 290 | end | ||
| 291 | |||
| 246 | --- Driver function for "config" command. | 292 | --- Driver function for "config" command. |
| 247 | -- @return boolean: True if succeeded, nil on errors. | 293 | -- @return boolean: True if succeeded, nil on errors. |
| 248 | function config_cmd.command(args) | 294 | function config_cmd.command(args) |
| 249 | deps.check_lua_incdir(cfg.variables, args.lua_version or cfg.lua_version) | 295 | local lua_version = args.lua_version or cfg.lua_version |
| 250 | deps.check_lua_libdir(cfg.variables, args.lua_version or cfg.lua_version) | 296 | |
| 297 | deps.check_lua_incdir(cfg.variables, lua_version) | ||
| 298 | deps.check_lua_libdir(cfg.variables, lua_version) | ||
| 251 | 299 | ||
| 252 | -- deprecated flags | 300 | -- deprecated flags |
| 253 | if args.lua_incdir then | 301 | if args.lua_incdir then |
| @@ -312,13 +360,43 @@ function config_cmd.command(args) | |||
| 312 | local prefix = dir.dir_name(cfg.config_files[scope].file) | 360 | local prefix = dir.dir_name(cfg.config_files[scope].file) |
| 313 | persist.save_default_lua_version(prefix, args.lua_version) | 361 | persist.save_default_lua_version(prefix, args.lua_version) |
| 314 | end | 362 | end |
| 315 | return write_entries(keys, scope, args.unset) | 363 | local ok, err = write_entries(keys, scope, args.unset) |
| 364 | if ok then | ||
| 365 | local inc_ok = report_on_lua_incdir_config(cfg.variables.LUA_INCDIR, lua_version) | ||
| 366 | local lib_ok = ok and report_on_lua_libdir_config(cfg.variables.LUA_LIBDIR, lua_version) | ||
| 367 | if not (inc_ok and lib_ok) then | ||
| 368 | warn_bad_c_config() | ||
| 369 | end | ||
| 370 | end | ||
| 371 | |||
| 372 | return ok, err | ||
| 316 | end | 373 | end |
| 317 | 374 | ||
| 318 | if args.key then | 375 | if args.key then |
| 376 | if args.key:match("^[A-Z]") then | ||
| 377 | args.key = "variables." .. args.key | ||
| 378 | end | ||
| 379 | |||
| 319 | if args.value or args.unset then | 380 | if args.value or args.unset then |
| 320 | local scope = get_scope(args) | 381 | local scope = get_scope(args) |
| 321 | return write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) | 382 | |
| 383 | local ok, err = write_entries({ [args.key] = args.value or args.unset }, scope, args.unset) | ||
| 384 | |||
| 385 | if ok then | ||
| 386 | if args.key == "variables.LUA_INCDIR" then | ||
| 387 | local ok = report_on_lua_incdir_config(args.value, lua_version) | ||
| 388 | if not ok then | ||
| 389 | warn_bad_c_config() | ||
| 390 | end | ||
| 391 | elseif args.key == "variables.LUA_LIBDIR" then | ||
| 392 | local ok = report_on_lua_libdir_config(args.value, lua_version) | ||
| 393 | if not ok then | ||
| 394 | warn_bad_c_config() | ||
| 395 | end | ||
| 396 | end | ||
| 397 | end | ||
| 398 | |||
| 399 | return ok, err | ||
| 322 | else | 400 | else |
| 323 | return print_entry(args.key, cfg, args.json) | 401 | return print_entry(args.key, cfg, args.json) |
| 324 | end | 402 | 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) | |||
| 703 | if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then | 703 | if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then |
| 704 | return d | 704 | return d |
| 705 | end | 705 | end |
| 706 | 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 | 706 | return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR <path>` to set the correct location.", "dependency", 2 |
| 707 | end | 707 | end |
| 708 | 708 | ||
| 709 | return nil, "Failed finding Lua header files (searched at " .. d .. "). You may need to install them or configure LUA_INCDIR.", "dependency", 1 | 709 | 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 <path>` to set the correct location.", "dependency", 1 |
| 710 | end | 710 | end |
| 711 | 711 | ||
| 712 | local function find_lua_incdir(prefix, luaver, luajitver) | 712 | local function find_lua_incdir(prefix, luaver, luajitver) |
| @@ -793,7 +793,7 @@ function deps.check_lua_libdir(vars) | |||
| 793 | end | 793 | end |
| 794 | local cache = {} | 794 | local cache = {} |
| 795 | local save_LUA_INCDIR = vars.LUA_INCDIR | 795 | local save_LUA_INCDIR = vars.LUA_INCDIR |
| 796 | local ok = check_external_dependency("LUA", { library = libnames }, vars, "build", cache) | 796 | local ok, _, _, errfiles = check_external_dependency("LUA", { library = libnames }, vars, "build", cache) |
| 797 | vars.LUA_INCDIR = save_LUA_INCDIR | 797 | vars.LUA_INCDIR = save_LUA_INCDIR |
| 798 | local err | 798 | local err |
| 799 | if ok then | 799 | if ok then |
| @@ -806,7 +806,7 @@ function deps.check_lua_libdir(vars) | |||
| 806 | ok = txt:match("Lua " .. cfg.lua_version, 1, true) | 806 | ok = txt:match("Lua " .. cfg.lua_version, 1, true) |
| 807 | or txt:match("lua" .. (cfg.lua_version:gsub("%.", "")), 1, true) | 807 | or txt:match("lua" .. (cfg.lua_version:gsub("%.", "")), 1, true) |
| 808 | if not ok then | 808 | if not ok then |
| 809 | err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You may want to override this by configuring LUA_LIBDIR." | 809 | err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You can use `luarocks config variables.LUA_LIBDIR <path>` to set the correct location." |
| 810 | end | 810 | end |
| 811 | end | 811 | end |
| 812 | 812 | ||
| @@ -819,8 +819,8 @@ function deps.check_lua_libdir(vars) | |||
| 819 | vars.LUA_LIBDIR_OK = true | 819 | vars.LUA_LIBDIR_OK = true |
| 820 | return true | 820 | return true |
| 821 | else | 821 | else |
| 822 | err = err or "Failed finding Lua library. You may need to configure LUA_LIBDIR." | 822 | err = err or "Failed finding the Lua library. You can use `luarocks config variables.LUA_LIBDIR <path>` to set the correct location." |
| 823 | return nil, err, "dependency" | 823 | return nil, err, "dependency", errfiles |
| 824 | end | 824 | end |
| 825 | end | 825 | end |
| 826 | 826 | ||
