diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-01-05 15:38:37 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-01-05 15:38:37 -0200 |
commit | 98a0bd9a97190be8ba10f14a3d67e42de827b04a (patch) | |
tree | 079b71a6416b62a5d9ab61a5a4f47e340d353831 | |
parent | 291c34696daa496d4ceb1e58b282fa935d90a3f5 (diff) | |
download | luarocks-98a0bd9a97190be8ba10f14a3d67e42de827b04a.tar.gz luarocks-98a0bd9a97190be8ba10f14a3d67e42de827b04a.tar.bz2 luarocks-98a0bd9a97190be8ba10f14a3d67e42de827b04a.zip |
path: use versioned LUA_xPATH_5_x variables
`luarocks path` now exports versioned variables `LUA_PATH_5_x` and
`LUA_CPATH_5_x` instead of `LUA_PATH` and `LUA_CPATH`
when those are in use in your system.
Fixes #760.
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | spec/path_spec.lua | 34 | ||||
-rw-r--r-- | src/luarocks/cmd/path.lua | 20 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 6 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 4 |
6 files changed, 62 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d028713..0bd8c0c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -2,6 +2,9 @@ | |||
2 | What's new in LuaRocks 3.0 | 2 | What's new in LuaRocks 3.0 |
3 | ========================== | 3 | ========================== |
4 | 4 | ||
5 | * `luarocks path` now exports versioned variables `LUA_PATH_5_x` and | ||
6 | `LUA_CPATH_5_x` instead of `LUA_PATH` and `LUA_CPATH` | ||
7 | when those are in use in your system. | ||
5 | * Package paths are sanitized to only reference the current Lua version. | 8 | * Package paths are sanitized to only reference the current Lua version. |
6 | For example, if you have `/some/dir/lua/5.1/` in your `$LUA_PATH` and | 9 | For example, if you have `/some/dir/lua/5.1/` in your `$LUA_PATH` and |
7 | you are running Lua 5.2, `luarocks.loader` and the `luarocks` command-line | 10 | you are running Lua 5.2, `luarocks.loader` and the `luarocks` command-line |
diff --git a/spec/path_spec.lua b/spec/path_spec.lua index 22f07591..536233b1 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua | |||
@@ -8,6 +8,40 @@ describe("LuaRocks path tests #blackbox #b_path", function() | |||
8 | test_env.setup_specs() | 8 | test_env.setup_specs() |
9 | end) | 9 | end) |
10 | 10 | ||
11 | it("LuaRocks path", function() | ||
12 | local output = run.luarocks("path") | ||
13 | assert.match("LUA_PATH=", output) | ||
14 | assert.match("LUA_CPATH=", output) | ||
15 | end) | ||
16 | |||
17 | if _VERSION:match("[23]") then | ||
18 | local v = _VERSION:gsub("Lua (%d+)%.(%d+)", "%1_%2") | ||
19 | |||
20 | it("LuaRocks path with LUA_PATH_"..v, function() | ||
21 | local output = run.luarocks("path", { | ||
22 | ["LUA_PATH_"..v] = package.path, | ||
23 | }) | ||
24 | assert.match("LUA_PATH_"..v.."=", output) | ||
25 | end) | ||
26 | |||
27 | it("LuaRocks path with LUA_CPATH_"..v, function() | ||
28 | local output = run.luarocks("path", { | ||
29 | ["LUA_CPATH_"..v] = package.cpath, | ||
30 | }) | ||
31 | assert.match("LUA_CPATH_"..v.."=", output) | ||
32 | end) | ||
33 | |||
34 | it("LuaRocks path with LUA_PATH_"..v.." and LUA_CPATH_"..v, function() | ||
35 | local output = run.luarocks("path", { | ||
36 | ["LUA_PATH_"..v] = package.path, | ||
37 | ["LUA_CPATH_"..v] = package.cpath, | ||
38 | }) | ||
39 | assert.match("LUA_PATH_"..v.."=", output) | ||
40 | assert.match("LUA_CPATH_"..v.."=", output) | ||
41 | end) | ||
42 | |||
43 | end | ||
44 | |||
11 | it("LuaRocks path bin", function() | 45 | it("LuaRocks path bin", function() |
12 | assert.is_true(run.luarocks_bool("path --bin")) | 46 | assert.is_true(run.luarocks_bool("path --bin")) |
13 | end) | 47 | end) |
diff --git a/src/luarocks/cmd/path.lua b/src/luarocks/cmd/path.lua index 3cf43091..9bcd1c81 100644 --- a/src/luarocks/cmd/path.lua +++ b/src/luarocks/cmd/path.lua | |||
@@ -5,6 +5,7 @@ local path_cmd = {} | |||
5 | 5 | ||
6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
7 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
8 | local fs = require("luarocks.fs") | ||
8 | 9 | ||
9 | path_cmd.help_summary = "Return the currently configured package path." | 10 | path_cmd.help_summary = "Return the currently configured package path." |
10 | path_cmd.help_arguments = "" | 11 | path_cmd.help_arguments = "" |
@@ -56,11 +57,24 @@ function path_cmd.command(flags) | |||
56 | lr_cpath = lr_cpath .. ";" .. package.cpath | 57 | lr_cpath = lr_cpath .. ";" .. package.cpath |
57 | lr_bin = lr_bin .. path_sep .. os.getenv("PATH") | 58 | lr_bin = lr_bin .. path_sep .. os.getenv("PATH") |
58 | end | 59 | end |
60 | |||
61 | local lpath_var = "LUA_PATH" | ||
62 | local lcpath_var = "LUA_CPATH" | ||
63 | |||
64 | local lv = cfg.lua_version:gsub("%.", "_") | ||
65 | if lv ~= "5_1" then | ||
66 | if os.getenv("LUA_PATH_" .. lv) then | ||
67 | lpath_var = "LUA_PATH_" .. lv | ||
68 | end | ||
69 | if os.getenv("LUA_CPATH_" .. lv) then | ||
70 | lcpath_var = "LUA_CPATH_" .. lv | ||
71 | end | ||
72 | end | ||
59 | 73 | ||
60 | util.printout(cfg.export_lua_path:format(util.cleanup_path(lr_path, ';', cfg.lua_version))) | 74 | util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version))) |
61 | util.printout(cfg.export_lua_cpath:format(util.cleanup_path(lr_cpath, ';', cfg.lua_version))) | 75 | util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version))) |
62 | if flags["bin"] then | 76 | if flags["bin"] then |
63 | util.printout(cfg.export_path:format(util.cleanup_path(lr_bin, path_sep))) | 77 | util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep))) |
64 | end | 78 | end |
65 | return true | 79 | return true |
66 | end | 80 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index e6351add..3326375f 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -473,10 +473,7 @@ if cfg.platforms.windows then | |||
473 | lib = { "?.dll", "lib?.dll" }, | 473 | lib = { "?.dll", "lib?.dll" }, |
474 | include = { "?.h" } | 474 | include = { "?.h" } |
475 | } | 475 | } |
476 | defaults.export_path = "SET PATH=%s" | ||
477 | defaults.export_path_separator = ";" | 476 | defaults.export_path_separator = ";" |
478 | defaults.export_lua_path = "SET LUA_PATH=%s" | ||
479 | defaults.export_lua_cpath = "SET LUA_CPATH=%s" | ||
480 | defaults.wrapper_suffix = ".bat" | 477 | defaults.wrapper_suffix = ".bat" |
481 | 478 | ||
482 | local localappdata = os.getenv("LOCALAPPDATA") | 479 | local localappdata = os.getenv("LOCALAPPDATA") |
@@ -541,10 +538,7 @@ if cfg.platforms.unix then | |||
541 | lib = { "lib?.so", "lib?.so.*" }, | 538 | lib = { "lib?.so", "lib?.so.*" }, |
542 | include = { "?.h" } | 539 | include = { "?.h" } |
543 | } | 540 | } |
544 | defaults.export_path = "export PATH='%s'" | ||
545 | defaults.export_path_separator = ":" | 541 | defaults.export_path_separator = ":" |
546 | defaults.export_lua_path = "export LUA_PATH='%s'" | ||
547 | defaults.export_lua_cpath = "export LUA_CPATH='%s'" | ||
548 | defaults.wrapper_suffix = "" | 542 | defaults.wrapper_suffix = "" |
549 | defaults.local_cache = cfg.home.."/.cache/luarocks" | 543 | defaults.local_cache = cfg.home.."/.cache/luarocks" |
550 | if not defaults.variables.CFLAGS:match("-fPIC") then | 544 | if not defaults.variables.CFLAGS:match("-fPIC") then |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 52634246..c99e1566 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -136,4 +136,8 @@ function unix.current_user() | |||
136 | return os.getenv("USER") | 136 | return os.getenv("USER") |
137 | end | 137 | end |
138 | 138 | ||
139 | function unix.export_cmd(var, val) | ||
140 | return ("export %s='%s'"):format(var, val) | ||
141 | end | ||
142 | |||
139 | return unix | 143 | return unix |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 92068e39..6fd24fa5 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -272,4 +272,8 @@ function win32.current_user() | |||
272 | return os.getenv("USERNAME") | 272 | return os.getenv("USERNAME") |
273 | end | 273 | end |
274 | 274 | ||
275 | function win32.export_cmd(var, val) | ||
276 | return ("SET %s=%s"):format(var, val) | ||
277 | end | ||
278 | |||
275 | return win32 | 279 | return win32 |