diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fetch.tl | 4 | ||||
| -rw-r--r-- | src/luarocks/manif-original.lua | 225 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 114 | ||||
| -rw-r--r-- | src/luarocks/manif.tl | 8 |
4 files changed, 292 insertions, 59 deletions
diff --git a/src/luarocks/fetch.tl b/src/luarocks/fetch.tl index fa084507..321d4f4e 100644 --- a/src/luarocks/fetch.tl +++ b/src/luarocks/fetch.tl | |||
| @@ -54,7 +54,7 @@ local function download_with_mirrors(url: string, filename: string, cache: boole | |||
| 54 | end | 54 | end |
| 55 | local name, _, _, from_cache = fs.download(try_url, filename, cache) | 55 | local name, _, _, from_cache = fs.download(try_url, filename, cache) |
| 56 | if name then | 56 | if name then |
| 57 | return ok, name, from_cache | 57 | return name, nil, nil, from_cache |
| 58 | else | 58 | else |
| 59 | err = err .. name .. "\n" | 59 | err = err .. name .. "\n" |
| 60 | end | 60 | end |
| @@ -581,7 +581,7 @@ function fetch.fetch_sources(rockspec: Rockspec, extract: boolean, dest_dir?: st | |||
| 581 | if dir.is_basic_protocol(protocol) then | 581 | if dir.is_basic_protocol(protocol) then |
| 582 | proto = fetch as Fetch | 582 | proto = fetch as Fetch |
| 583 | else | 583 | else |
| 584 | ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) as (boolean, Fetch) | 584 | ok, proto = pcall(require, ("luarocks.fetch."..protocol:gsub("[+-]", "_")) as string) as (boolean, Fetch) |
| 585 | if not ok then | 585 | if not ok then |
| 586 | return nil, "Unknown protocol "..protocol | 586 | return nil, "Unknown protocol "..protocol |
| 587 | end | 587 | end |
diff --git a/src/luarocks/manif-original.lua b/src/luarocks/manif-original.lua new file mode 100644 index 00000000..a4ddda11 --- /dev/null +++ b/src/luarocks/manif-original.lua | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | --- Module for handling manifest files and tables. | ||
| 2 | -- Manifest files describe the contents of a LuaRocks tree or server. | ||
| 3 | -- They are loaded into manifest tables, which are then used for | ||
| 4 | -- performing searches, matching dependencies, etc. | ||
| 5 | local manif = {} | ||
| 6 | |||
| 7 | local core = require("luarocks.core.manif") | ||
| 8 | local persist = require("luarocks.persist") | ||
| 9 | local fetch = require("luarocks.fetch") | ||
| 10 | local dir = require("luarocks.dir") | ||
| 11 | local fs = require("luarocks.fs") | ||
| 12 | local cfg = require("luarocks.core.cfg") | ||
| 13 | local path = require("luarocks.path") | ||
| 14 | local util = require("luarocks.util") | ||
| 15 | local queries = require("luarocks.queries") | ||
| 16 | local type_manifest = require("luarocks.type.manifest") | ||
| 17 | |||
| 18 | manif.cache_manifest = core.cache_manifest | ||
| 19 | manif.load_rocks_tree_manifests = core.load_rocks_tree_manifests | ||
| 20 | manif.scan_dependencies = core.scan_dependencies | ||
| 21 | |||
| 22 | manif.rock_manifest_cache = {} | ||
| 23 | |||
| 24 | local function check_manifest(repo_url, manifest, globals) | ||
| 25 | local ok, err = type_manifest.check(manifest, globals) | ||
| 26 | if not ok then | ||
| 27 | core.cache_manifest(repo_url, cfg.lua_version, nil) | ||
| 28 | return nil, "Error checking manifest: "..err, "type" | ||
| 29 | end | ||
| 30 | return manifest | ||
| 31 | end | ||
| 32 | |||
| 33 | local postprocess_dependencies | ||
| 34 | do | ||
| 35 | local postprocess_check = setmetatable({}, { __mode = "k" }) | ||
| 36 | postprocess_dependencies = function(manifest) | ||
| 37 | if postprocess_check[manifest] then | ||
| 38 | return | ||
| 39 | end | ||
| 40 | if manifest.dependencies then | ||
| 41 | for name, versions in pairs(manifest.dependencies) do | ||
| 42 | for version, entries in pairs(versions) do | ||
| 43 | for k, v in pairs(entries) do | ||
| 44 | entries[k] = queries.from_persisted_table(v) | ||
| 45 | end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | end | ||
| 49 | postprocess_check[manifest] = true | ||
| 50 | end | ||
| 51 | end | ||
| 52 | |||
| 53 | function manif.load_rock_manifest(name, version, root) | ||
| 54 | assert(type(name) == "string" and not name:match("/")) | ||
| 55 | assert(type(version) == "string") | ||
| 56 | |||
| 57 | local name_version = name.."/"..version | ||
| 58 | if manif.rock_manifest_cache[name_version] then | ||
| 59 | return manif.rock_manifest_cache[name_version].rock_manifest | ||
| 60 | end | ||
| 61 | local pathname = path.rock_manifest_file(name, version, root) | ||
| 62 | local rock_manifest = persist.load_into_table(pathname) | ||
| 63 | if not rock_manifest then | ||
| 64 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" | ||
| 65 | end | ||
| 66 | manif.rock_manifest_cache[name_version] = rock_manifest | ||
| 67 | return rock_manifest.rock_manifest | ||
| 68 | end | ||
| 69 | |||
| 70 | --- Load a local or remote manifest describing a repository. | ||
| 71 | -- All functions that use manifest tables assume they were obtained | ||
| 72 | -- through this function. | ||
| 73 | -- @param repo_url string: URL or pathname for the repository. | ||
| 74 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
| 75 | -- @param versioned_only boolean: If true, do not fall back to the main manifest | ||
| 76 | -- if a versioned manifest was not found. | ||
| 77 | -- @return table or (nil, string, [string]): A table representing the manifest, | ||
| 78 | -- or nil followed by an error message and an optional error code. | ||
| 79 | function manif.load_manifest(repo_url, lua_version, versioned_only) | ||
| 80 | assert(type(repo_url) == "string") | ||
| 81 | assert(type(lua_version) == "string" or not lua_version) | ||
| 82 | lua_version = lua_version or cfg.lua_version | ||
| 83 | |||
| 84 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) | ||
| 85 | if cached_manifest then | ||
| 86 | postprocess_dependencies(cached_manifest) | ||
| 87 | return cached_manifest | ||
| 88 | end | ||
| 89 | |||
| 90 | local filenames = { | ||
| 91 | "manifest-"..lua_version..".zip", | ||
| 92 | "manifest-"..lua_version, | ||
| 93 | not versioned_only and "manifest" or nil, | ||
| 94 | } | ||
| 95 | |||
| 96 | local protocol, repodir = dir.split_url(repo_url) | ||
| 97 | local pathname, from_cache | ||
| 98 | if protocol == "file" then | ||
| 99 | for _, filename in ipairs(filenames) do | ||
| 100 | pathname = dir.path(repodir, filename) | ||
| 101 | if fs.exists(pathname) then | ||
| 102 | break | ||
| 103 | end | ||
| 104 | end | ||
| 105 | else | ||
| 106 | local err, errcode | ||
| 107 | for _, filename in ipairs(filenames) do | ||
| 108 | pathname, err, errcode, from_cache = fetch.fetch_caching(dir.path(repo_url, filename), "no_mirror") | ||
| 109 | if pathname then | ||
| 110 | break | ||
| 111 | end | ||
| 112 | end | ||
| 113 | if not pathname then | ||
| 114 | return nil, err, errcode | ||
| 115 | end | ||
| 116 | end | ||
| 117 | if pathname:match(".*%.zip$") then | ||
| 118 | pathname = fs.absolute_name(pathname) | ||
| 119 | local nozip = pathname:match("(.*)%.zip$") | ||
| 120 | if not from_cache then | ||
| 121 | local dirname = dir.dir_name(pathname) | ||
| 122 | fs.change_dir(dirname) | ||
| 123 | fs.delete(nozip) | ||
| 124 | local ok, err = fs.unzip(pathname) | ||
| 125 | fs.pop_dir() | ||
| 126 | if not ok then | ||
| 127 | fs.delete(pathname) | ||
| 128 | fs.delete(pathname..".timestamp") | ||
| 129 | return nil, "Failed extracting manifest file: " .. err | ||
| 130 | end | ||
| 131 | end | ||
| 132 | pathname = nozip | ||
| 133 | end | ||
| 134 | local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) | ||
| 135 | if not manifest then | ||
| 136 | return nil, err, errcode | ||
| 137 | end | ||
| 138 | |||
| 139 | postprocess_dependencies(manifest) | ||
| 140 | return check_manifest(repo_url, manifest, err) | ||
| 141 | end | ||
| 142 | |||
| 143 | --- Get type and name of an item (a module or a command) provided by a file. | ||
| 144 | -- @param deploy_type string: rock manifest subtree the file comes from ("bin", "lua", or "lib"). | ||
| 145 | -- @param file_path string: path to the file relatively to deploy_type subdirectory. | ||
| 146 | -- @return (string, string): item type ("module" or "command") and name. | ||
| 147 | function manif.get_provided_item(deploy_type, file_path) | ||
| 148 | assert(type(deploy_type) == "string") | ||
| 149 | assert(type(file_path) == "string") | ||
| 150 | local item_type = deploy_type == "bin" and "command" or "module" | ||
| 151 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) | ||
| 152 | return item_type, item_name | ||
| 153 | end | ||
| 154 | |||
| 155 | local function get_providers(item_type, item_name, repo) | ||
| 156 | assert(type(item_type) == "string") | ||
| 157 | assert(type(item_name) == "string") | ||
| 158 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | ||
| 159 | local manifest = manif.load_manifest(rocks_dir) | ||
| 160 | return manifest and manifest[item_type .. "s"][item_name] | ||
| 161 | end | ||
| 162 | |||
| 163 | --- Given a name of a module or a command, figure out which rock name and version | ||
| 164 | -- correspond to it in the rock tree manifest. | ||
| 165 | -- @param item_type string: "module" or "command". | ||
| 166 | -- @param item_name string: module or command name. | ||
| 167 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | ||
| 168 | -- @return (string, string) or nil: name and version of the provider rock or nil if there | ||
| 169 | -- is no provider. | ||
| 170 | function manif.get_current_provider(item_type, item_name, repo) | ||
| 171 | local providers = get_providers(item_type, item_name, repo) | ||
| 172 | if providers then | ||
| 173 | return providers[1]:match("([^/]*)/([^/]*)") | ||
| 174 | end | ||
| 175 | end | ||
| 176 | |||
| 177 | function manif.get_next_provider(item_type, item_name, repo) | ||
| 178 | local providers = get_providers(item_type, item_name, repo) | ||
| 179 | if providers and providers[2] then | ||
| 180 | return providers[2]:match("([^/]*)/([^/]*)") | ||
| 181 | end | ||
| 182 | end | ||
| 183 | |||
| 184 | --- Get all versions of a package listed in a manifest file. | ||
| 185 | -- @param name string: a package name. | ||
| 186 | -- @param deps_mode string: "one", to use only the currently | ||
| 187 | -- configured tree; "order" to select trees based on order | ||
| 188 | -- (use the current tree and all trees below it on the list) | ||
| 189 | -- or "all", to use all trees. | ||
| 190 | -- @return table: An array of strings listing installed | ||
| 191 | -- versions of a package, and a table indicating where they are found. | ||
| 192 | function manif.get_versions(dep, deps_mode) | ||
| 193 | assert(type(dep) == "table") | ||
| 194 | assert(type(deps_mode) == "string") | ||
| 195 | |||
| 196 | local name = dep.name | ||
| 197 | local namespace = dep.namespace | ||
| 198 | |||
| 199 | local version_set = {} | ||
| 200 | path.map_trees(deps_mode, function(tree) | ||
| 201 | local manifest = manif.load_manifest(path.rocks_dir(tree)) | ||
| 202 | |||
| 203 | if manifest and manifest.repository[name] then | ||
| 204 | for version in pairs(manifest.repository[name]) do | ||
| 205 | if dep.namespace then | ||
| 206 | local ns_file = path.rock_namespace_file(name, version, tree) | ||
| 207 | local fd = io.open(ns_file, "r") | ||
| 208 | if fd then | ||
| 209 | local ns = fd:read("*a") | ||
| 210 | fd:close() | ||
| 211 | if ns == namespace then | ||
| 212 | version_set[version] = tree | ||
| 213 | end | ||
| 214 | end | ||
| 215 | else | ||
| 216 | version_set[version] = tree | ||
| 217 | end | ||
| 218 | end | ||
| 219 | end | ||
| 220 | end) | ||
| 221 | |||
| 222 | return util.keys(version_set), version_set | ||
| 223 | end | ||
| 224 | |||
| 225 | return manif | ||
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index a4ddda11..437ebe3b 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -1,9 +1,18 @@ | |||
| 1 | --- Module for handling manifest files and tables. | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string |
| 2 | -- Manifest files describe the contents of a LuaRocks tree or server. | 2 | |
| 3 | -- They are loaded into manifest tables, which are then used for | 3 | |
| 4 | -- performing searches, matching dependencies, etc. | 4 | |
| 5 | local manif = {} | 5 | local manif = {} |
| 6 | 6 | ||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 7 | local core = require("luarocks.core.manif") | 16 | local core = require("luarocks.core.manif") |
| 8 | local persist = require("luarocks.persist") | 17 | local persist = require("luarocks.persist") |
| 9 | local fetch = require("luarocks.fetch") | 18 | local fetch = require("luarocks.fetch") |
| @@ -15,6 +24,14 @@ local util = require("luarocks.util") | |||
| 15 | local queries = require("luarocks.queries") | 24 | local queries = require("luarocks.queries") |
| 16 | local type_manifest = require("luarocks.type.manifest") | 25 | local type_manifest = require("luarocks.type.manifest") |
| 17 | 26 | ||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 18 | manif.cache_manifest = core.cache_manifest | 35 | manif.cache_manifest = core.cache_manifest |
| 19 | manif.load_rocks_tree_manifests = core.load_rocks_tree_manifests | 36 | manif.load_rocks_tree_manifests = core.load_rocks_tree_manifests |
| 20 | manif.scan_dependencies = core.scan_dependencies | 37 | manif.scan_dependencies = core.scan_dependencies |
| @@ -25,7 +42,7 @@ local function check_manifest(repo_url, manifest, globals) | |||
| 25 | local ok, err = type_manifest.check(manifest, globals) | 42 | local ok, err = type_manifest.check(manifest, globals) |
| 26 | if not ok then | 43 | if not ok then |
| 27 | core.cache_manifest(repo_url, cfg.lua_version, nil) | 44 | core.cache_manifest(repo_url, cfg.lua_version, nil) |
| 28 | return nil, "Error checking manifest: "..err, "type" | 45 | return nil, "Error checking manifest: " .. err, "type" |
| 29 | end | 46 | end |
| 30 | return manifest | 47 | return manifest |
| 31 | end | 48 | end |
| @@ -38,9 +55,9 @@ do | |||
| 38 | return | 55 | return |
| 39 | end | 56 | end |
| 40 | if manifest.dependencies then | 57 | if manifest.dependencies then |
| 41 | for name, versions in pairs(manifest.dependencies) do | 58 | for _, versions in pairs(manifest.dependencies) do |
| 42 | for version, entries in pairs(versions) do | 59 | for _, entries in pairs(versions) do |
| 43 | for k, v in pairs(entries) do | 60 | for k, v in ipairs(entries) do |
| 44 | entries[k] = queries.from_persisted_table(v) | 61 | entries[k] = queries.from_persisted_table(v) |
| 45 | end | 62 | end |
| 46 | end | 63 | end |
| @@ -51,34 +68,31 @@ do | |||
| 51 | end | 68 | end |
| 52 | 69 | ||
| 53 | function manif.load_rock_manifest(name, version, root) | 70 | function manif.load_rock_manifest(name, version, root) |
| 54 | assert(type(name) == "string" and not name:match("/")) | 71 | assert(not name:match("/")) |
| 55 | assert(type(version) == "string") | ||
| 56 | 72 | ||
| 57 | local name_version = name.."/"..version | 73 | local name_version = name .. "/" .. version |
| 58 | if manif.rock_manifest_cache[name_version] then | 74 | if manif.rock_manifest_cache[name_version] then |
| 59 | return manif.rock_manifest_cache[name_version].rock_manifest | 75 | return manif.rock_manifest_cache[name_version].rock_manifest |
| 60 | end | 76 | end |
| 61 | local pathname = path.rock_manifest_file(name, version, root) | 77 | local pathname = path.rock_manifest_file(name, version, root) |
| 62 | local rock_manifest = persist.load_into_table(pathname) | 78 | local rock_manifest = persist.load_into_table(pathname) |
| 63 | if not rock_manifest then | 79 | if not rock_manifest then |
| 64 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" | 80 | return nil, "rock_manifest file not found for " .. name .. " " .. version .. " - not a LuaRocks tree?" |
| 65 | end | 81 | end |
| 66 | manif.rock_manifest_cache[name_version] = rock_manifest | 82 | manif.rock_manifest_cache[name_version] = rock_manifest |
| 67 | return rock_manifest.rock_manifest | 83 | return rock_manifest.rock_manifest |
| 68 | end | 84 | end |
| 69 | 85 | ||
| 70 | --- Load a local or remote manifest describing a repository. | 86 | |
| 71 | -- All functions that use manifest tables assume they were obtained | 87 | |
| 72 | -- through this function. | 88 | |
| 73 | -- @param repo_url string: URL or pathname for the repository. | 89 | |
| 74 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 90 | |
| 75 | -- @param versioned_only boolean: If true, do not fall back to the main manifest | 91 | |
| 76 | -- if a versioned manifest was not found. | 92 | |
| 77 | -- @return table or (nil, string, [string]): A table representing the manifest, | 93 | |
| 78 | -- or nil followed by an error message and an optional error code. | 94 | |
| 79 | function manif.load_manifest(repo_url, lua_version, versioned_only) | 95 | function manif.load_manifest(repo_url, lua_version, versioned_only) |
| 80 | assert(type(repo_url) == "string") | ||
| 81 | assert(type(lua_version) == "string" or not lua_version) | ||
| 82 | lua_version = lua_version or cfg.lua_version | 96 | lua_version = lua_version or cfg.lua_version |
| 83 | 97 | ||
| 84 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) | 98 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) |
| @@ -88,8 +102,8 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
| 88 | end | 102 | end |
| 89 | 103 | ||
| 90 | local filenames = { | 104 | local filenames = { |
| 91 | "manifest-"..lua_version..".zip", | 105 | "manifest-" .. lua_version .. ".zip", |
| 92 | "manifest-"..lua_version, | 106 | "manifest-" .. lua_version, |
| 93 | not versioned_only and "manifest" or nil, | 107 | not versioned_only and "manifest" or nil, |
| 94 | } | 108 | } |
| 95 | 109 | ||
| @@ -125,14 +139,14 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
| 125 | fs.pop_dir() | 139 | fs.pop_dir() |
| 126 | if not ok then | 140 | if not ok then |
| 127 | fs.delete(pathname) | 141 | fs.delete(pathname) |
| 128 | fs.delete(pathname..".timestamp") | 142 | fs.delete(pathname .. ".timestamp") |
| 129 | return nil, "Failed extracting manifest file: " .. err | 143 | return nil, "Failed extracting manifest file: " .. err |
| 130 | end | 144 | end |
| 131 | end | 145 | end |
| 132 | pathname = nozip | 146 | pathname = nozip |
| 133 | end | 147 | end |
| 134 | local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) | 148 | local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) |
| 135 | if not manifest then | 149 | if not manifest and type(err) == "string" then |
| 136 | return nil, err, errcode | 150 | return nil, err, errcode |
| 137 | end | 151 | end |
| 138 | 152 | ||
| @@ -140,33 +154,29 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
| 140 | return check_manifest(repo_url, manifest, err) | 154 | return check_manifest(repo_url, manifest, err) |
| 141 | end | 155 | end |
| 142 | 156 | ||
| 143 | --- Get type and name of an item (a module or a command) provided by a file. | 157 | |
| 144 | -- @param deploy_type string: rock manifest subtree the file comes from ("bin", "lua", or "lib"). | 158 | |
| 145 | -- @param file_path string: path to the file relatively to deploy_type subdirectory. | 159 | |
| 146 | -- @return (string, string): item type ("module" or "command") and name. | 160 | |
| 147 | function manif.get_provided_item(deploy_type, file_path) | 161 | function manif.get_provided_item(deploy_type, file_path) |
| 148 | assert(type(deploy_type) == "string") | ||
| 149 | assert(type(file_path) == "string") | ||
| 150 | local item_type = deploy_type == "bin" and "command" or "module" | 162 | local item_type = deploy_type == "bin" and "command" or "module" |
| 151 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) | 163 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) |
| 152 | return item_type, item_name | 164 | return item_type, item_name |
| 153 | end | 165 | end |
| 154 | 166 | ||
| 155 | local function get_providers(item_type, item_name, repo) | 167 | local function get_providers(item_type, item_name, repo) |
| 156 | assert(type(item_type) == "string") | ||
| 157 | assert(type(item_name) == "string") | ||
| 158 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 168 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 159 | local manifest = manif.load_manifest(rocks_dir) | 169 | local manifest = manif.load_manifest(rocks_dir) |
| 160 | return manifest and manifest[item_type .. "s"][item_name] | 170 | return manifest and (manifest)[item_type .. "s"][item_name] |
| 161 | end | 171 | end |
| 162 | 172 | ||
| 163 | --- Given a name of a module or a command, figure out which rock name and version | 173 | |
| 164 | -- correspond to it in the rock tree manifest. | 174 | |
| 165 | -- @param item_type string: "module" or "command". | 175 | |
| 166 | -- @param item_name string: module or command name. | 176 | |
| 167 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | 177 | |
| 168 | -- @return (string, string) or nil: name and version of the provider rock or nil if there | 178 | |
| 169 | -- is no provider. | 179 | |
| 170 | function manif.get_current_provider(item_type, item_name, repo) | 180 | function manif.get_current_provider(item_type, item_name, repo) |
| 171 | local providers = get_providers(item_type, item_name, repo) | 181 | local providers = get_providers(item_type, item_name, repo) |
| 172 | if providers then | 182 | if providers then |
| @@ -181,17 +191,15 @@ function manif.get_next_provider(item_type, item_name, repo) | |||
| 181 | end | 191 | end |
| 182 | end | 192 | end |
| 183 | 193 | ||
| 184 | --- Get all versions of a package listed in a manifest file. | 194 | |
| 185 | -- @param name string: a package name. | 195 | |
| 186 | -- @param deps_mode string: "one", to use only the currently | 196 | |
| 187 | -- configured tree; "order" to select trees based on order | 197 | |
| 188 | -- (use the current tree and all trees below it on the list) | 198 | |
| 189 | -- or "all", to use all trees. | 199 | |
| 190 | -- @return table: An array of strings listing installed | 200 | |
| 191 | -- versions of a package, and a table indicating where they are found. | 201 | |
| 192 | function manif.get_versions(dep, deps_mode) | 202 | function manif.get_versions(dep, deps_mode) |
| 193 | assert(type(dep) == "table") | ||
| 194 | assert(type(deps_mode) == "string") | ||
| 195 | 203 | ||
| 196 | local name = dep.name | 204 | local name = dep.name |
| 197 | local namespace = dep.namespace | 205 | local namespace = dep.namespace |
diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl index ff725e5f..f1963150 100644 --- a/src/luarocks/manif.tl +++ b/src/luarocks/manif.tl | |||
| @@ -26,9 +26,9 @@ local type_manifest = require("luarocks.type.manifest") | |||
| 26 | 26 | ||
| 27 | local type tree = require("luarocks.core.types.tree") | 27 | local type tree = require("luarocks.core.types.tree") |
| 28 | local type Tree = tree.Tree | 28 | local type Tree = tree.Tree |
| 29 | local type manifest = require("luarocks.core.types.manifest") | 29 | local type m = require("luarocks.core.types.manifest") |
| 30 | local type Manifest = manifest.Manifest | 30 | local type Manifest = m.Manifest |
| 31 | local type Tree_manifest = manifest.Tree_manifest | 31 | local type Tree_manifest = m .Tree_manifest |
| 32 | local type query = require("luarocks.core.types.query") | 32 | local type query = require("luarocks.core.types.query") |
| 33 | local type Query = query.Query | 33 | local type Query = query.Query |
| 34 | 34 | ||
| @@ -167,7 +167,7 @@ end | |||
| 167 | local function get_providers(item_type: string, item_name: string, repo: string | Tree): {string} | 167 | local function get_providers(item_type: string, item_name: string, repo: string | Tree): {string} |
| 168 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 168 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 169 | local manifest = manif.load_manifest(rocks_dir) | 169 | local manifest = manif.load_manifest(rocks_dir) |
| 170 | return manifest and manifest[item_type .. "s"][item_name] | 170 | return manifest and (manifest as {string: {string: {string}}})[item_type .. "s"][item_name] |
| 171 | end | 171 | end |
| 172 | 172 | ||
| 173 | --- Given a name of a module or a command, figure out which rock name and version | 173 | --- Given a name of a module or a command, figure out which rock name and version |
