diff options
-rw-r--r-- | spec/cmd_spec.lua | 6 | ||||
-rw-r--r-- | spec/quick/cmd.q | 36 | ||||
-rw-r--r-- | spec/quick/config.q | 90 | ||||
-rw-r--r-- | spec/util/quick.lua | 2 | ||||
-rw-r--r-- | spec/util/test_env.lua | 17 | ||||
-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 |
8 files changed, 225 insertions, 34 deletions
diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua index 9067a160..20248af7 100644 --- a/spec/cmd_spec.lua +++ b/spec/cmd_spec.lua | |||
@@ -56,12 +56,6 @@ describe("LuaRocks command line #integration", function() | |||
56 | assert.match("malformed", output, 1, true) | 56 | assert.match("malformed", output, 1, true) |
57 | end) | 57 | end) |
58 | 58 | ||
59 | it("warns but continues if given an invalid version", function() | ||
60 | local output = run.luarocks("--lua-version=1.0") | ||
61 | assert.match("LUA *: %(not found%)", output) | ||
62 | assert.match("Version%s*:%s*1.0", output) | ||
63 | end) | ||
64 | |||
65 | it("sets the version independently of project tree", function() | 59 | it("sets the version independently of project tree", function() |
66 | test_env.run_in_tmp(function(tmpdir) | 60 | test_env.run_in_tmp(function(tmpdir) |
67 | assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version)) | 61 | assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version)) |
diff --git a/spec/quick/cmd.q b/spec/quick/cmd.q new file mode 100644 index 00000000..acde92b4 --- /dev/null +++ b/spec/quick/cmd.q | |||
@@ -0,0 +1,36 @@ | |||
1 | SUITE: luarocks CLI | ||
2 | |||
3 | ================================================================================ | ||
4 | TEST: warns but continues if given an invalid version | ||
5 | |||
6 | RUN: luarocks --lua-version 1.0 | ||
7 | |||
8 | STDOUT: | ||
9 | -------------------------------------------------------------------------------- | ||
10 | Version : 1.0 | ||
11 | LUA : (interpreter not found) | ||
12 | -------------------------------------------------------------------------------- | ||
13 | |||
14 | |||
15 | |||
16 | ================================================================================ | ||
17 | TEST: reports if lua.h header is not found | ||
18 | |||
19 | RUN: luarocks LUA_INCDIR=/bad/dir | ||
20 | |||
21 | STDOUT: | ||
22 | -------------------------------------------------------------------------------- | ||
23 | LUA_INCDIR : /bad/dir (lua.h not found) | ||
24 | -------------------------------------------------------------------------------- | ||
25 | |||
26 | |||
27 | |||
28 | ================================================================================ | ||
29 | TEST: reports if Lua library is not found | ||
30 | |||
31 | RUN: luarocks LUA_LIBDIR=/bad/dir | ||
32 | |||
33 | STDOUT: | ||
34 | -------------------------------------------------------------------------------- | ||
35 | LUA_LIBDIR : /bad/dir (Lua library itself not found) | ||
36 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/config.q b/spec/quick/config.q index 3150a9ce..d6230567 100644 --- a/spec/quick/config.q +++ b/spec/quick/config.q | |||
@@ -1,13 +1,11 @@ | |||
1 | ================================================================================ | 1 | SUITE: luarocks config |
2 | TEST: luarocks config --system-config shows the path of the system config | ||
3 | 2 | ||
4 | MKDIR: %{testing_lrprefix}/etc/luarocks | 3 | ================================================================================ |
4 | TEST: --system-config shows the path of the system config | ||
5 | 5 | ||
6 | FILE: %{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua | 6 | FILE: %{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua |
7 | -------------------------------------------------------------------------------- | 7 | -------------------------------------------------------------------------------- |
8 | |||
9 | -------------------------------------------------------------------------------- | 8 | -------------------------------------------------------------------------------- |
10 | |||
11 | RUN: luarocks config --system-config | 9 | RUN: luarocks config --system-config |
12 | 10 | ||
13 | STDOUT: | 11 | STDOUT: |
@@ -15,3 +13,85 @@ STDOUT: | |||
15 | %{path(%{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua)} | 13 | %{path(%{testing_lrprefix}/etc/luarocks/config-%{LUA_VERSION}.lua)} |
16 | -------------------------------------------------------------------------------- | 14 | -------------------------------------------------------------------------------- |
17 | 15 | ||
16 | |||
17 | |||
18 | ================================================================================ | ||
19 | TEST: reports when setting a bad LUA_LIBDIR | ||
20 | |||
21 | RUN: luarocks config variables.LUA_LIBDIR /some/bad/path | ||
22 | |||
23 | LuaRocks writes configuration values as they are given, without auto-conversion | ||
24 | of slashes for Windows: | ||
25 | |||
26 | STDOUT: | ||
27 | -------------------------------------------------------------------------------- | ||
28 | Wrote | ||
29 | variables.LUA_LIBDIR = "/some/bad/path" | ||
30 | -------------------------------------------------------------------------------- | ||
31 | |||
32 | STDERR: | ||
33 | -------------------------------------------------------------------------------- | ||
34 | Warning: Failed finding the Lua library. | ||
35 | Tried: | ||
36 | |||
37 | LuaRocks may not work correctly when building C modules using this configuration. | ||
38 | -------------------------------------------------------------------------------- | ||
39 | |||
40 | |||
41 | |||
42 | ================================================================================ | ||
43 | TEST: reports when setting a bad LUA_INCDIR | ||
44 | |||
45 | RUN: luarocks config variables.LUA_INCDIR /some/bad/path | ||
46 | |||
47 | STDOUT: | ||
48 | -------------------------------------------------------------------------------- | ||
49 | Wrote | ||
50 | variables.LUA_INCDIR = "/some/bad/path" | ||
51 | -------------------------------------------------------------------------------- | ||
52 | |||
53 | LuaRocks uses configuration values as they are given, without auto-conversion | ||
54 | of slashes for Windows: | ||
55 | |||
56 | STDERR: | ||
57 | -------------------------------------------------------------------------------- | ||
58 | Warning: Failed finding Lua header lua.h (searched at /some/bad/path). You may need to install Lua development headers. | ||
59 | |||
60 | LuaRocks may not work correctly when building C modules using this configuration. | ||
61 | -------------------------------------------------------------------------------- | ||
62 | |||
63 | |||
64 | |||
65 | ================================================================================ | ||
66 | TEST: rejects setting bad lua_dir | ||
67 | |||
68 | RUN: luarocks config lua_dir /some/bad/dir | ||
69 | EXIT: 1 | ||
70 | |||
71 | STDERR: | ||
72 | -------------------------------------------------------------------------------- | ||
73 | Lua interpreter not found | ||
74 | -------------------------------------------------------------------------------- | ||
75 | |||
76 | |||
77 | |||
78 | ================================================================================ | ||
79 | TEST: reports when setting a bad LUA_INCDIR | ||
80 | |||
81 | RUN: luarocks config variables.LUA_INCDIR /some/bad/path | ||
82 | |||
83 | STDOUT: | ||
84 | -------------------------------------------------------------------------------- | ||
85 | Wrote | ||
86 | variables.LUA_INCDIR = "/some/bad/path" | ||
87 | -------------------------------------------------------------------------------- | ||
88 | |||
89 | LuaRocks uses configuration values as they are given, without auto-conversion | ||
90 | of slashes for Windows: | ||
91 | |||
92 | STDERR: | ||
93 | -------------------------------------------------------------------------------- | ||
94 | Warning: Failed finding Lua header lua.h (searched at /some/bad/path). You may need to install Lua development headers. | ||
95 | |||
96 | LuaRocks may not work correctly when building C modules using this configuration. | ||
97 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index cb4bb4cf..c313f575 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -347,7 +347,7 @@ function quick.compile(filename, env) | |||
347 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) | 347 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) |
348 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | 348 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) |
349 | elseif op.op == "RUN" then | 349 | elseif op.op == "RUN" then |
350 | local cmd_helper = cmd_helpers[op.program] or op.program | 350 | local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) |
351 | local redirs = " 1>stdout.txt 2>stderr.txt " | 351 | local redirs = " 1>stdout.txt 2>stderr.txt " |
352 | write(([=[ local ok, _, code = os.execute(%s .. " " .. %q .. %q) ]=]):format(cmd_helper, op.args, redirs)) | 352 | write(([=[ local ok, _, code = os.execute(%s .. " " .. %q .. %q) ]=]):format(cmd_helper, op.args, redirs)) |
353 | write([=[ if type(ok) == "number" then code = (ok >= 256 and ok / 256 or ok) end ]=]) | 353 | write([=[ if type(ok) == "number" then code = (ok >= 256 and ok / 256 or ok) end ]=]) |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 24a1de9e..8ccb494b 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -207,13 +207,16 @@ function test_env.run_in_tmp(f, finally) | |||
207 | end | 207 | end |
208 | fs.change_dir(tmpdir) | 208 | fs.change_dir(tmpdir) |
209 | 209 | ||
210 | if finally then | 210 | local lr_config = test_env.env_variables.LUAROCKS_CONFIG |
211 | finally(function() | 211 | |
212 | lfs.chdir(olddir) | 212 | test_env.copy(lr_config, lr_config .. ".bak") |
213 | lfs.rmdir(tmpdir) | 213 | |
214 | fs.change_dir(olddir) | 214 | finally(function() |
215 | end) | 215 | test_env.copy(lr_config .. ".bak", lr_config) |
216 | end | 216 | lfs.chdir(olddir) |
217 | lfs.rmdir(tmpdir) | ||
218 | fs.change_dir(olddir) | ||
219 | end) | ||
217 | 220 | ||
218 | f(tmpdir) | 221 | f(tmpdir) |
219 | end | 222 | end |
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 | ||