aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-04-17 18:47:30 -0300
committerHisham Muhammad <hisham@gobolinux.org>2020-04-22 17:10:21 -0300
commitd1a32ba6b1fd5a829aa551aeb37a0c558b09660f (patch)
treef0c34c4db56431799d50fc649320f8e1d847459b
parent01a83b9b8377f66c5258892bc85fff5c218fdbb7 (diff)
downloadluarocks-d1a32ba6b1fd5a829aa551aeb37a0c558b09660f.tar.gz
luarocks-d1a32ba6b1fd5a829aa551aeb37a0c558b09660f.tar.bz2
luarocks-d1a32ba6b1fd5a829aa551aeb37a0c558b09660f.zip
Print more info about the location of Lua
-rw-r--r--spec/cmd_spec.lua10
-rw-r--r--src/luarocks/cmd.lua43
-rw-r--r--src/luarocks/cmd/config.lua4
-rw-r--r--src/luarocks/core/cfg.lua2
-rw-r--r--src/luarocks/deps.lua28
5 files changed, 70 insertions, 17 deletions
diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua
index 2c3f9f47..ad6ae7ad 100644
--- a/spec/cmd_spec.lua
+++ b/spec/cmd_spec.lua
@@ -56,7 +56,7 @@ describe("LuaRocks command line #integration", function()
56 it("warns but continues if given an invalid version", function() 56 it("warns but continues if given an invalid version", function()
57 local output = run.luarocks("--lua-version=1.0") 57 local output = run.luarocks("--lua-version=1.0")
58 assert.match("Warning: Lua 1.0 interpreter not found", output, 1, true) 58 assert.match("Warning: Lua 1.0 interpreter not found", output, 1, true)
59 assert.match("Lua version: 1.0", output, 1, true) 59 assert.match("Version%s*:%s*1.0", output)
60 end) 60 end)
61 61
62 it("sets the version independently of project tree", function() 62 it("sets the version independently of project tree", function()
@@ -64,10 +64,10 @@ describe("LuaRocks command line #integration", function()
64 assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version)) 64 assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version))
65 65
66 local output = run.luarocks("--lua-version=1.0") 66 local output = run.luarocks("--lua-version=1.0")
67 assert.match("Lua version: 1.0", output, 1, true) 67 assert.match("Version%s*:%s*1.0", output)
68 68
69 output = run.luarocks("--lua-version=1.0 --project-tree=.") 69 output = run.luarocks("--lua-version=1.0 --project-tree=.")
70 assert.match("Lua version: 1.0", output, 1, true) 70 assert.match("Version%s*:%s*1.0", output)
71 end, finally) 71 end, finally)
72 end) 72 end)
73 end) 73 end)
@@ -83,7 +83,7 @@ describe("LuaRocks command line #integration", function()
83 lfs.chdir("bbb") 83 lfs.chdir("bbb")
84 84
85 local output = run.luarocks("") 85 local output = run.luarocks("")
86 assert.match("Lua version: 1.0", output, 1, true) 86 assert.match("Version%s*:%s*1.0", output)
87 end, finally) 87 end, finally)
88 end) 88 end)
89 89
@@ -101,7 +101,7 @@ describe("LuaRocks command line #integration", function()
101 lfs.chdir("bbb") 101 lfs.chdir("bbb")
102 102
103 local output = run.luarocks("") 103 local output = run.luarocks("")
104 assert.match("Lua version: 5.2", output, 1, true) 104 assert.match("Version%s*:%s*5.2", output)
105 end, finally) 105 end, finally)
106 end) 106 end)
107 107
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index be863cfa..37266b40 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -266,7 +266,10 @@ do
266 if args.lua_dir then 266 if args.lua_dir then
267 local detected, err = util.find_lua(args.lua_dir, lua_version) 267 local detected, err = util.find_lua(args.lua_dir, lua_version)
268 if not detected then 268 if not detected then
269 die(err) 269 local suggestion = (not args.lua_version)
270 and "\nYou may want to specify a different Lua version with --lua-version\n"
271 or ""
272 die(err .. suggestion)
270 end 273 end
271 return detected 274 return detected
272 end 275 end
@@ -324,11 +327,45 @@ local function get_status(status)
324 return status and "ok" or "not found" 327 return status and "ok" or "not found"
325end 328end
326 329
330local function use_to_fix_location(key)
331 local buf = " ****************************************\n"
332 buf = buf .. " Use the command\n\n"
333 buf = buf .. " luarocks config " .. key .. " <dir>\n\n"
334 buf = buf .. " to fix the location\n"
335 buf = buf .. " ****************************************\n"
336 return buf
337end
338
327local function get_config_text(cfg) 339local function get_config_text(cfg)
328 local buf = "Configuration:\n Lua version: "..cfg.lua_version.."\n" 340 local deps = require("luarocks.deps")
341
342 local libdir_ok = deps.check_lua_libdir(cfg.variables)
343 local incdir_ok = deps.check_lua_incdir(cfg.variables)
344 local bindir_ok = fs.exists(cfg.variables.LUA_BINDIR)
345 local luadir_ok = fs.exists(cfg.variables.LUA_DIR)
346 local lua_ok = fs.exists(cfg.variables.LUA)
347
348 local buf = "Configuration:\n"
349 buf = buf.." Lua:\n"
350 buf = buf.." Version : "..cfg.lua_version.."\n"
329 if cfg.luajit_version then 351 if cfg.luajit_version then
330 buf = buf.." LuaJIT version: "..cfg.luajit_version.."\n" 352 buf = buf.." LuaJIT : "..cfg.luajit_version.."\n"
331 end 353 end
354 buf = buf.." Interpreter: "..(cfg.variables.LUA or "").." ("..get_status(lua_ok)..")\n"
355 buf = buf.." LUA_DIR : "..(cfg.variables.LUA_DIR or "").." ("..get_status(luadir_ok)..")\n"
356 if not lua_ok then
357 buf = buf .. use_to_fix_location("lua_dir")
358 end
359 buf = buf.." LUA_BINDIR : "..(cfg.variables.LUA_BINDIR or "").." ("..get_status(bindir_ok)..")\n"
360 buf = buf.." LUA_INCDIR : "..(cfg.variables.LUA_INCDIR or "").." ("..get_status(incdir_ok)..")\n"
361 if lua_ok and not incdir_ok then
362 buf = buf .. use_to_fix_location("variables.LUA_INCDIR")
363 end
364 buf = buf.." LUA_LIBDIR : "..(cfg.variables.LUA_LIBDIR or "").." ("..get_status(libdir_ok)..")\n"
365 if lua_ok and not libdir_ok then
366 buf = buf .. use_to_fix_location("variables.LUA_LIBDIR")
367 end
368
332 buf = buf.."\n Configuration files:\n" 369 buf = buf.."\n Configuration files:\n"
333 local conf = cfg.config_files 370 local conf = cfg.config_files
334 buf = buf.." System : "..fs.absolute_name(conf.system.file).." ("..get_status(conf.system.found)..")\n" 371 buf = buf.." System : "..fs.absolute_name(conf.system.file).." ("..get_status(conf.system.found)..")\n"
diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua
index bdabe960..5e92634a 100644
--- a/src/luarocks/cmd/config.lua
+++ b/src/luarocks/cmd/config.lua
@@ -297,6 +297,10 @@ function config_cmd.command(args)
297 ["variables.LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR, 297 ["variables.LUA_LIBDIR"] = cfg.variables.LUA_LIBDIR,
298 ["lua_interpreter"] = cfg.lua_interpreter, 298 ["lua_interpreter"] = cfg.lua_interpreter,
299 } 299 }
300 if args.lua_version then
301 local prefix = dir.dir_name(cfg.config_files[scope].file)
302 persist.save_default_lua_version(prefix, args.lua_version)
303 end
300 return write_entries(keys, scope, args.unset) 304 return write_entries(keys, scope, args.unset)
301 end 305 end
302 306
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 0c79fc63..3917e2af 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -690,6 +690,8 @@ function cfg.init(detected, warning)
690 if detected.given_lua_dir then 690 if detected.given_lua_dir then
691 cfg.variables.LUA_DIR = detected.given_lua_dir 691 cfg.variables.LUA_DIR = detected.given_lua_dir
692 cfg.variables.LUA_BINDIR = detected.lua_bindir 692 cfg.variables.LUA_BINDIR = detected.lua_bindir
693 cfg.variables.LUA_LIBDIR = nil
694 cfg.variables.LUA_INCDIR = nil
693 cfg.lua_interpreter = detected.lua_interpreter 695 cfg.lua_interpreter = detected.lua_interpreter
694 end 696 end
695 697
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 0eb80193..d935a5c8 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -649,6 +649,16 @@ function deps.scan_deps(results, manifest, name, version, deps_mode)
649 end 649 end
650end 650end
651 651
652local function lua_h_exists(d)
653 local lua_h = dir.path(d, "lua.h")
654 local fd = io.open(lua_h)
655 if fd then
656 -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver
657 fd:close()
658 return d
659 end
660end
661
652local function find_lua_incdir(prefix, luaver, luajitver) 662local function find_lua_incdir(prefix, luaver, luajitver)
653 luajitver = luajitver and luajitver:gsub("%-.*", "") 663 luajitver = luajitver and luajitver:gsub("%-.*", "")
654 local shortv = luaver:gsub("%.", "") 664 local shortv = luaver:gsub("%.", "")
@@ -662,11 +672,7 @@ local function find_lua_incdir(prefix, luaver, luajitver)
662 luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"), 672 luajitver and prefix .. "/include/luajit-" .. luajitver:match("^(%d+%.%d+)"),
663 } 673 }
664 for _, d in ipairs(incdirs) do 674 for _, d in ipairs(incdirs) do
665 local lua_h = dir.path(d, "lua.h") 675 if lua_h_exists(d) then
666 local fd = io.open(lua_h)
667 if fd then
668 -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver
669 fd:close()
670 return d 676 return d
671 end 677 end
672 end 678 end
@@ -678,14 +684,18 @@ end
678function deps.check_lua_incdir(vars) 684function deps.check_lua_incdir(vars)
679 local ljv = util.get_luajit_version() 685 local ljv = util.get_luajit_version()
680 686
681 if (not vars.LUA_INCDIR) and vars.LUA_DIR then 687 if vars.LUA_INCDIR then
688 return lua_h_exists(vars.LUA_INCDIR)
689 end
690
691 if vars.LUA_DIR then
682 vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv) 692 vars.LUA_INCDIR = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv)
683 if vars.LUA_INCDIR == nil then 693 if vars.LUA_INCDIR then
684 return nil, "Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.", "dependency" 694 return true
685 end 695 end
686 end 696 end
687 697
688 return true 698 return nil, "Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.", "dependency"
689end 699end
690 700
691function deps.check_lua_libdir(vars) 701function deps.check_lua_libdir(vars)