aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-07-01 14:50:59 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 21:32:40 -0300
commit65c417e0ecda55f44c691df032163a8c08f0b52a (patch)
tree6358f4073055afcc8bf86f2d4e077006e8f631ac /src
parenteec12737d4003f3078134468215d4c16fb36c2be (diff)
downloadluarocks-65c417e0ecda55f44c691df032163a8c08f0b52a.tar.gz
luarocks-65c417e0ecda55f44c691df032163a8c08f0b52a.tar.bz2
luarocks-65c417e0ecda55f44c691df032163a8c08f0b52a.zip
path, loader: handle coexisting foo.bar and foo.bar.init modules
LuaRocks used to conflate in its manifest two modules whose names only differed by ".init" (e.g. "foo.bar" and "foo.bar.init"). With this change, `path.path_to_modules` treats them as distinct modules, and `luarocks.loader` handles them correctly (given `require("foo.bar")`, it looks for `foo.bar` first and then `foo.bar.init` next).
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/core/path.lua6
-rw-r--r--src/luarocks/loader.lua35
2 files changed, 24 insertions, 17 deletions
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua
index adebaa23..179d3aaf 100644
--- a/src/luarocks/core/path.lua
+++ b/src/luarocks/core/path.lua
@@ -36,7 +36,7 @@ end
36 36
37--- Convert a pathname to a module identifier. 37--- Convert a pathname to a module identifier.
38-- In Unix, for example, a path "foo/bar/baz.lua" is converted to 38-- In Unix, for example, a path "foo/bar/baz.lua" is converted to
39-- "foo.bar.baz"; "bla/init.lua" returns "bla"; "foo.so" returns "foo". 39-- "foo.bar.baz"; "bla/init.lua" returns "bla.init"; "foo.so" returns "foo".
40-- @param file string: Pathname of module 40-- @param file string: Pathname of module
41-- @return string: The module identifier, or nil if given path is 41-- @return string: The module identifier, or nil if given path is
42-- not a conformant module path (the function does not check if the 42-- not a conformant module path (the function does not check if the
@@ -47,10 +47,6 @@ function path.path_to_module(file)
47 local name = file:match("(.*)%."..cfg.lua_extension.."$") 47 local name = file:match("(.*)%."..cfg.lua_extension.."$")
48 if name then 48 if name then
49 name = name:gsub("/", ".") 49 name = name:gsub("/", ".")
50 local init = name:match("(.*)%.init$")
51 if init then
52 name = init
53 end
54 else 50 else
55 name = file:match("(.*)%."..cfg.lib_extension.."$") 51 name = file:match("(.*)%."..cfg.lib_extension.."$")
56 if name then 52 if name then
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index 537adf94..a8a9cfdf 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -159,6 +159,22 @@ local function call_other_loaders(module, name, version, module_name)
159 return "Failed loading module "..module.." in LuaRocks rock "..name.." "..version 159 return "Failed loading module "..module.." in LuaRocks rock "..name.." "..version
160end 160end
161 161
162local function add_providers(providers, entries, tree, module, filter_file_name)
163 for i, entry in ipairs(entries) do
164 local name, version = entry:match("^([^/]*)/(.*)$")
165 local file_name = tree.manifest.repository[name][version][1].modules[module]
166 if type(file_name) ~= "string" then
167 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")")
168 end
169 file_name = filter_file_name(file_name, name, version, tree.tree, i)
170 if loader.context[name] == version then
171 return name, version, file_name
172 end
173 version = vers.parse_version(version)
174 table.insert(providers, {name = name, version = version, module_name = file_name, tree = tree})
175 end
176end
177
162--- Search for a module in the rocks trees 178--- Search for a module in the rocks trees
163-- @param module string: module name (eg. "socket.core") 179-- @param module string: module name (eg. "socket.core")
164-- @param filter_file_name function(string, string, string, string, number): 180-- @param filter_file_name function(string, string, string, string, number):
@@ -180,21 +196,16 @@ local function select_module(module, filter_file_name)
180 end 196 end
181 197
182 local providers = {} 198 local providers = {}
199 local initmodule
183 for _, tree in ipairs(loader.rocks_trees) do 200 for _, tree in ipairs(loader.rocks_trees) do
184 local entries = tree.manifest.modules[module] 201 local entries = tree.manifest.modules[module]
185 if entries then 202 if entries then
186 for i, entry in ipairs(entries) do 203 add_providers(providers, entries, tree, module, filter_file_name)
187 local name, version = entry:match("^([^/]*)/(.*)$") 204 else
188 local file_name = tree.manifest.repository[name][version][1].modules[module] 205 initmodule = initmodule or module .. ".init"
189 if type(file_name) ~= "string" then 206 entries = tree.manifest.modules[initmodule]
190 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")") 207 if entries then
191 end 208 add_providers(providers, entries, tree, initmodule, filter_file_name)
192 file_name = filter_file_name(file_name, name, version, tree.tree, i)
193 if loader.context[name] == version then
194 return name, version, file_name
195 end
196 version = vers.parse_version(version)
197 table.insert(providers, {name = name, version = version, module_name = file_name, tree = tree})
198 end 209 end
199 end 210 end
200 end 211 end