diff options
author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-13 22:50:37 +0000 |
---|---|---|
committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-13 22:50:37 +0000 |
commit | 73eb0c1f54e17f28155cf43a3ff092f97b51ba0f (patch) | |
tree | 083c3c7f7f89aedc3aadeb1c2e44af63143fb867 | |
parent | e89cde014d381bcac4d0bdd76f385b67122e0489 (diff) | |
download | luarocks-73eb0c1f54e17f28155cf43a3ff092f97b51ba0f.tar.gz luarocks-73eb0c1f54e17f28155cf43a3ff092f97b51ba0f.tar.bz2 luarocks-73eb0c1f54e17f28155cf43a3ff092f97b51ba0f.zip |
add a which() function, as requested by Fabio Mascarenhas :)
git-svn-id: http://luarocks.org/svn/luarocks/trunk@100 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
-rw-r--r-- | src/luarocks/loader.lua | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index f8880a58..74f8c426 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua | |||
@@ -21,11 +21,10 @@ local function load_rocks_trees() | |||
21 | local any_ok = false | 21 | local any_ok = false |
22 | local trees = {} | 22 | local trees = {} |
23 | for _, tree in pairs(cfg.rocks_trees) do | 23 | for _, tree in pairs(cfg.rocks_trees) do |
24 | local rocks_dir = path.rocks_dir(tree) | 24 | local manifest, err = manif_core.load_local_manifest(path.rocks_dir(tree)) |
25 | local manifest, err = manif_core.load_local_manifest(rocks_dir) | ||
26 | if manifest then | 25 | if manifest then |
27 | any_ok = true | 26 | any_ok = true |
28 | table.insert(trees, {rocks_dir=rocks_dir, manifest=manifest}) | 27 | table.insert(trees, {tree=tree, manifest=manifest}) |
29 | end | 28 | end |
30 | end | 29 | end |
31 | if not any_ok then | 30 | if not any_ok then |
@@ -40,12 +39,9 @@ end | |||
40 | -- chain for loading modules. | 39 | -- chain for loading modules. |
41 | -- @parse name string: The name of an installed rock. | 40 | -- @parse name string: The name of an installed rock. |
42 | -- @parse version string: The version of the rock, in string format | 41 | -- @parse version string: The version of the rock, in string format |
43 | -- @parse manifest table: The local manifest table where this rock | ||
44 | -- is installed. | ||
45 | function add_context(name, version) | 42 | function add_context(name, version) |
46 | -- assert(type(name) == "string") | 43 | -- assert(type(name) == "string") |
47 | -- assert(type(version) == "string") | 44 | -- assert(type(version) == "string") |
48 | -- assert(type(manifest) == "table") | ||
49 | 45 | ||
50 | if context[name] then | 46 | if context[name] then |
51 | return | 47 | return |
@@ -72,7 +68,7 @@ function add_context(name, version) | |||
72 | if entries then | 68 | if entries then |
73 | for version, packages in pairs(entries) do | 69 | for version, packages in pairs(entries) do |
74 | if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then | 70 | if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then |
75 | add_context(package, version, tree.manifest) | 71 | add_context(package, version) |
76 | end | 72 | end |
77 | end | 73 | end |
78 | end | 74 | end |
@@ -102,8 +98,9 @@ local function call_other_loaders(module, name, version, module_name) | |||
102 | return nil, "Failed loading module "..module.." in LuaRocks rock "..name.." "..version | 98 | return nil, "Failed loading module "..module.." in LuaRocks rock "..name.." "..version |
103 | end | 99 | end |
104 | 100 | ||
105 | local function pick_module(module) | 101 | local function select_module(module, filter_module_name) |
106 | --assert(type(module) == "string") | 102 | --assert(type(module) == "string") |
103 | --assert(type(filter_module_name) == "function") | ||
107 | 104 | ||
108 | if not rocks_trees and not load_rocks_trees() then | 105 | if not rocks_trees and not load_rocks_trees() then |
109 | return nil | 106 | return nil |
@@ -116,10 +113,7 @@ local function pick_module(module) | |||
116 | for i, entry in ipairs(entries) do | 113 | for i, entry in ipairs(entries) do |
117 | local name, version = entry:match("^([^/]*)/(.*)$") | 114 | local name, version = entry:match("^([^/]*)/(.*)$") |
118 | local module_name = tree.manifest.repository[name][version][1].modules[module] | 115 | local module_name = tree.manifest.repository[name][version][1].modules[module] |
119 | if i > 1 then | 116 | module_name = filter_module_name(module_name, name, version, tree.tree, i) |
120 | module_name = path.versioned_name(module_name, "", name, version) | ||
121 | end | ||
122 | module_name = path.path_to_module(module_name) | ||
123 | if context[name] == version then | 117 | if context[name] == version then |
124 | return name, version, module_name | 118 | return name, version, module_name |
125 | end | 119 | end |
@@ -136,6 +130,33 @@ local function pick_module(module) | |||
136 | end | 130 | end |
137 | end | 131 | end |
138 | 132 | ||
133 | local function pick_module(module) | ||
134 | return | ||
135 | select_module(module, function(module_name, name, version, tree, i) | ||
136 | if i > 1 then | ||
137 | module_name = path.versioned_name(module_name, "", name, version) | ||
138 | end | ||
139 | module_name = path.path_to_module(module_name) | ||
140 | return module_name | ||
141 | end) | ||
142 | end | ||
143 | |||
144 | function which(module) | ||
145 | local name, version, module_name = | ||
146 | select_module(module, function(module_name, name, version, tree, i) | ||
147 | if module_name:match("%.lua$") then | ||
148 | module_name = path.deploy_lua_dir(tree).."/"..module_name | ||
149 | else | ||
150 | module_name = path.deploy_lib_dir(tree).."/"..module_name | ||
151 | end | ||
152 | if i > 1 then | ||
153 | module_name = path.versioned_name(module_name, tree, name, version) | ||
154 | end | ||
155 | return module_name | ||
156 | end) | ||
157 | return module_name | ||
158 | end | ||
159 | |||
139 | --- Package loader for LuaRocks support. | 160 | --- Package loader for LuaRocks support. |
140 | -- A module is searched in installed rocks that match the | 161 | -- A module is searched in installed rocks that match the |
141 | -- current LuaRocks context. If module is not part of the | 162 | -- current LuaRocks context. If module is not part of the |