diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2017-09-29 15:53:51 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-09-29 15:54:55 -0300 |
| commit | 6f9cc282207af83ad8692ac64b37d2549a0dcfec (patch) | |
| tree | 79f2c8dc24ee6643e378d5d8c6be30ffb2e4c078 /src | |
| parent | e64f83bc3723d28a3b83ff08bccfe332b1e7fc0b (diff) | |
| download | luarocks-6f9cc282207af83ad8692ac64b37d2549a0dcfec.tar.gz luarocks-6f9cc282207af83ad8692ac64b37d2549a0dcfec.tar.bz2 luarocks-6f9cc282207af83ad8692ac64b37d2549a0dcfec.zip | |
Make sure package paths only reference current Lua version
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/path.lua | 12 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/core/util.lua | 10 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 4 |
4 files changed, 18 insertions, 12 deletions
diff --git a/src/luarocks/cmd/path.lua b/src/luarocks/cmd/path.lua index 516a0c47..3cf43091 100644 --- a/src/luarocks/cmd/path.lua +++ b/src/luarocks/cmd/path.lua | |||
| @@ -37,13 +37,13 @@ function path_cmd.command(flags) | |||
| 37 | local path_sep = cfg.export_path_separator | 37 | local path_sep = cfg.export_path_separator |
| 38 | 38 | ||
| 39 | if flags["lr-path"] then | 39 | if flags["lr-path"] then |
| 40 | util.printout(util.remove_path_dupes(lr_path, ';')) | 40 | util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version)) |
| 41 | return true | 41 | return true |
| 42 | elseif flags["lr-cpath"] then | 42 | elseif flags["lr-cpath"] then |
| 43 | util.printout(util.remove_path_dupes(lr_cpath, ';')) | 43 | util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version)) |
| 44 | return true | 44 | return true |
| 45 | elseif flags["lr-bin"] then | 45 | elseif flags["lr-bin"] then |
| 46 | util.printout(util.remove_path_dupes(lr_bin, path_sep)) | 46 | util.printout(util.cleanup_path(lr_bin, path_sep)) |
| 47 | return true | 47 | return true |
| 48 | end | 48 | end |
| 49 | 49 | ||
| @@ -57,10 +57,10 @@ function path_cmd.command(flags) | |||
| 57 | lr_bin = lr_bin .. path_sep .. os.getenv("PATH") | 57 | lr_bin = lr_bin .. path_sep .. os.getenv("PATH") |
| 58 | end | 58 | end |
| 59 | 59 | ||
| 60 | util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) | 60 | util.printout(cfg.export_lua_path:format(util.cleanup_path(lr_path, ';', cfg.lua_version))) |
| 61 | util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) | 61 | util.printout(cfg.export_lua_cpath:format(util.cleanup_path(lr_cpath, ';', cfg.lua_version))) |
| 62 | if flags["bin"] then | 62 | if flags["bin"] then |
| 63 | util.printout(cfg.export_path:format(util.remove_path_dupes(lr_bin, path_sep))) | 63 | util.printout(cfg.export_path:format(util.cleanup_path(lr_bin, path_sep))) |
| 64 | end | 64 | end |
| 65 | return true | 65 | return true |
| 66 | end | 66 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 250f503e..8c005aaa 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -731,8 +731,8 @@ end | |||
| 731 | 731 | ||
| 732 | function cfg.init_package_paths() | 732 | function cfg.init_package_paths() |
| 733 | local lr_path, lr_cpath, lr_bin = cfg.package_paths() | 733 | local lr_path, lr_cpath, lr_bin = cfg.package_paths() |
| 734 | package.path = util.remove_path_dupes(package.path .. ";" .. lr_path, ";") | 734 | package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", cfg.lua_version) |
| 735 | package.cpath = util.remove_path_dupes(package.cpath .. ";" .. lr_cpath, ";") | 735 | package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", cfg.lua_version) |
| 736 | end | 736 | end |
| 737 | 737 | ||
| 738 | function cfg.which_config() | 738 | function cfg.which_config() |
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 85b59af6..a025da7d 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
| @@ -135,17 +135,23 @@ function util.deep_merge(dst, src) | |||
| 135 | end | 135 | end |
| 136 | end | 136 | end |
| 137 | 137 | ||
| 138 | --- Remove repeated entries from a path-style string. | 138 | --- Clean up a path-style string ($PATH, $LUA_PATH/package.path, etc.), |
| 139 | -- removing repeated entries and making sure only the relevant | ||
| 140 | -- Lua version is used. | ||
| 139 | -- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d". | 141 | -- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d". |
| 140 | -- @param list string: A path string (from $PATH or package.path) | 142 | -- @param list string: A path string (from $PATH or package.path) |
| 141 | -- @param sep string: The separator | 143 | -- @param sep string: The separator |
| 142 | function util.remove_path_dupes(list, sep) | 144 | -- @param lua_version (optional) string: The Lua version to use. |
| 145 | function util.cleanup_path(list, sep, lua_version) | ||
| 143 | assert(type(list) == "string") | 146 | assert(type(list) == "string") |
| 144 | assert(type(sep) == "string") | 147 | assert(type(sep) == "string") |
| 145 | local parts = util.split_string(list, sep) | 148 | local parts = util.split_string(list, sep) |
| 146 | local final, entries = {}, {} | 149 | local final, entries = {}, {} |
| 147 | for _, part in ipairs(parts) do | 150 | for _, part in ipairs(parts) do |
| 148 | part = part:gsub("//", "/") | 151 | part = part:gsub("//", "/") |
| 152 | if lua_version then | ||
| 153 | part = part:gsub("/lua/[%d.]+/", "/lua/"..lua_version) | ||
| 154 | end | ||
| 149 | if not entries[part] then | 155 | if not entries[part] then |
| 150 | table.insert(final, part) | 156 | table.insert(final, part) |
| 151 | entries[part] = true | 157 | entries[part] = true |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 19c603dc..bd504fa7 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -141,8 +141,8 @@ function win32.wrap_script(file, dest, name, version) | |||
| 141 | local wrapname = fs.is_dir(dest) and dest.."/"..base or dest | 141 | local wrapname = fs.is_dir(dest) and dest.."/"..base or dest |
| 142 | wrapname = wrapname..".bat" | 142 | wrapname = wrapname..".bat" |
| 143 | local lpath, lcpath = cfg.package_paths() | 143 | local lpath, lcpath = cfg.package_paths() |
| 144 | lpath = util.remove_path_dupes(lpath, ";") | 144 | lpath = util.cleanup_path(lpath, ";", cfg.lua_version) |
| 145 | lcpath = util.remove_path_dupes(lcpath, ";") | 145 | lcpath = util.cleanup_path(lcpath, ";", cfg.lua_version) |
| 146 | local wrapper = io.open(wrapname, "w") | 146 | local wrapper = io.open(wrapname, "w") |
| 147 | if not wrapper then | 147 | if not wrapper then |
| 148 | return nil, "Could not open "..wrapname.." for writing." | 148 | return nil, "Could not open "..wrapname.." for writing." |
