diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-13 12:30:21 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-13 17:11:12 -0300 |
| commit | 8bbf9ea3e4a6ce56708df556f2909349a0c93c9e (patch) | |
| tree | 8355e184858b340d64e14ef0218379f47a3074be /src | |
| parent | d33b56cd60d623500c88b8bd2924e6674fc22776 (diff) | |
| download | luarocks-8bbf9ea3e4a6ce56708df556f2909349a0c93c9e.tar.gz luarocks-8bbf9ea3e4a6ce56708df556f2909349a0c93c9e.tar.bz2 luarocks-8bbf9ea3e4a6ce56708df556f2909349a0c93c9e.zip | |
Use a single load_manifest function throughout the program
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/core/manif.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/loader.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 37 | ||||
| -rw-r--r-- | src/luarocks/manif/writer.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/queries.lua | 4 |
5 files changed, 35 insertions, 19 deletions
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index cd8d7a06..7a561f8a 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
| @@ -48,12 +48,11 @@ function manif.manifest_loader(file, repo_url, lua_version) | |||
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | --- Load a local manifest describing a repository. | 50 | --- Load a local manifest describing a repository. |
| 51 | -- All functions that use manifest tables assume they were obtained | 51 | -- This is used by the luarocks.loader only. |
| 52 | -- through either this function or load_manifest. | ||
| 53 | -- @param repo_url string: URL or pathname for the repository. | 52 | -- @param repo_url string: URL or pathname for the repository. |
| 54 | -- @return table or (nil, string, string): A table representing the manifest, | 53 | -- @return table or (nil, string, string): A table representing the manifest, |
| 55 | -- or nil followed by an error message and an error code, see manifest_loader. | 54 | -- or nil followed by an error message and an error code, see manifest_loader. |
| 56 | function manif.load_local_manifest(repo_url) | 55 | function manif.fast_load_local_manifest(repo_url) |
| 57 | assert(type(repo_url) == "string") | 56 | assert(type(repo_url) == "string") |
| 58 | 57 | ||
| 59 | local cached_manifest = manif.get_cached_manifest(repo_url) | 58 | local cached_manifest = manif.get_cached_manifest(repo_url) |
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 84cdd696..078e4068 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua | |||
| @@ -58,7 +58,7 @@ local function load_rocks_trees() | |||
| 58 | local any_ok = false | 58 | local any_ok = false |
| 59 | local trees = {} | 59 | local trees = {} |
| 60 | for _, tree in ipairs(cfg.rocks_trees) do | 60 | for _, tree in ipairs(cfg.rocks_trees) do |
| 61 | local manifest, err = manif.load_local_manifest(path.rocks_dir(tree)) | 61 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
| 62 | if manifest then | 62 | if manifest then |
| 63 | any_ok = true | 63 | any_ok = true |
| 64 | table.insert(trees, {tree=tree, manifest=manifest}) | 64 | table.insert(trees, {tree=tree, manifest=manifest}) |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 146d5d73..a982c6f7 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -12,6 +12,7 @@ local fs = require("luarocks.fs") | |||
| 12 | local cfg = require("luarocks.core.cfg") | 12 | local cfg = require("luarocks.core.cfg") |
| 13 | local path = require("luarocks.path") | 13 | local path = require("luarocks.path") |
| 14 | local util = require("luarocks.util") | 14 | local util = require("luarocks.util") |
| 15 | local queries = require("luarocks.queries") | ||
| 15 | local type_manifest = require("luarocks.type.manifest") | 16 | local type_manifest = require("luarocks.type.manifest") |
| 16 | 17 | ||
| 17 | manif.cache_manifest = core.cache_manifest | 18 | manif.cache_manifest = core.cache_manifest |
| @@ -27,15 +28,24 @@ local function check_manifest(repo_url, manifest, globals) | |||
| 27 | return manifest | 28 | return manifest |
| 28 | end | 29 | end |
| 29 | 30 | ||
| 30 | function manif.load_local_manifest(repo_url) | 31 | local postprocess_dependencies |
| 31 | local manifest, err, errcode = core.load_local_manifest(repo_url) | 32 | do |
| 32 | if not manifest then | 33 | local postprocess_check = setmetatable({}, { __mode = "k" }) |
| 33 | return nil, err, errcode | 34 | postprocess_dependencies = function(manifest) |
| 34 | end | 35 | if postprocess_check[manifest] then |
| 35 | if err then | 36 | return |
| 36 | return check_manifest(repo_url, manifest, err) | 37 | end |
| 38 | if manifest.dependencies then | ||
| 39 | for name, versions in pairs(manifest.dependencies) do | ||
| 40 | for version, entries in pairs(versions) do | ||
| 41 | for k, v in pairs(entries) do | ||
| 42 | entries[k] = queries.from_persisted_table(v) | ||
| 43 | end | ||
| 44 | end | ||
| 45 | end | ||
| 46 | end | ||
| 47 | postprocess_check[manifest] = true | ||
| 37 | end | 48 | end |
| 38 | return manifest | ||
| 39 | end | 49 | end |
| 40 | 50 | ||
| 41 | function manif.load_rock_manifest(name, version, root) | 51 | function manif.load_rock_manifest(name, version, root) |
| @@ -73,7 +83,7 @@ end | |||
| 73 | 83 | ||
| 74 | --- Load a local or remote manifest describing a repository. | 84 | --- Load a local or remote manifest describing a repository. |
| 75 | -- All functions that use manifest tables assume they were obtained | 85 | -- All functions that use manifest tables assume they were obtained |
| 76 | -- through either this function or load_local_manifest. | 86 | -- through this function. |
| 77 | -- @param repo_url string: URL or pathname for the repository. | 87 | -- @param repo_url string: URL or pathname for the repository. |
| 78 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 88 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. |
| 79 | -- @return table or (nil, string, [string]): A table representing the manifest, | 89 | -- @return table or (nil, string, [string]): A table representing the manifest, |
| @@ -85,6 +95,7 @@ function manif.load_manifest(repo_url, lua_version) | |||
| 85 | 95 | ||
| 86 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) | 96 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) |
| 87 | if cached_manifest then | 97 | if cached_manifest then |
| 98 | postprocess_dependencies(cached_manifest) | ||
| 88 | return cached_manifest | 99 | return cached_manifest |
| 89 | end | 100 | end |
| 90 | 101 | ||
| @@ -134,6 +145,8 @@ function manif.load_manifest(repo_url, lua_version) | |||
| 134 | if not manifest then | 145 | if not manifest then |
| 135 | return nil, err, errcode | 146 | return nil, err, errcode |
| 136 | end | 147 | end |
| 148 | |||
| 149 | postprocess_dependencies(manifest) | ||
| 137 | return check_manifest(repo_url, manifest, err) | 150 | return check_manifest(repo_url, manifest, err) |
| 138 | end | 151 | end |
| 139 | 152 | ||
| @@ -153,7 +166,7 @@ local function get_providers(item_type, item_name, repo) | |||
| 153 | assert(type(item_type) == "string") | 166 | assert(type(item_type) == "string") |
| 154 | assert(type(item_name) == "string") | 167 | assert(type(item_name) == "string") |
| 155 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 168 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 156 | local manifest = manif.load_local_manifest(rocks_dir) | 169 | local manifest = manif.load_manifest(rocks_dir) |
| 157 | return manifest and manifest[item_type .. "s"][item_name] | 170 | return manifest and manifest[item_type .. "s"][item_name] |
| 158 | end | 171 | end |
| 159 | 172 | ||
| @@ -189,7 +202,7 @@ end | |||
| 189 | -- and path to the providing file relatively to that subtree. | 202 | -- and path to the providing file relatively to that subtree. |
| 190 | function manif.get_providing_file(name, version, item_type, item_name, repo) | 203 | function manif.get_providing_file(name, version, item_type, item_name, repo) |
| 191 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 204 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 192 | local manifest = manif.load_local_manifest(rocks_dir) | 205 | local manifest = manif.load_manifest(rocks_dir) |
| 193 | 206 | ||
| 194 | local entry_table = manifest.repository[name][version][1] | 207 | local entry_table = manifest.repository[name][version][1] |
| 195 | local file_path = entry_table[item_type .. "s"][item_name] | 208 | local file_path = entry_table[item_type .. "s"][item_name] |
| @@ -239,7 +252,7 @@ function manif.get_versions(dep, deps_mode) | |||
| 239 | 252 | ||
| 240 | local version_set = {} | 253 | local version_set = {} |
| 241 | path.map_trees(deps_mode, function(tree) | 254 | path.map_trees(deps_mode, function(tree) |
| 242 | local manifest = manif.load_local_manifest(path.rocks_dir(tree)) | 255 | local manifest = manif.load_manifest(path.rocks_dir(tree)) |
| 243 | 256 | ||
| 244 | if manifest and manifest.repository[name] then | 257 | if manifest and manifest.repository[name] then |
| 245 | for version in pairs(manifest.repository[name]) do | 258 | for version in pairs(manifest.repository[name]) do |
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 07628ea2..8e8d5525 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua | |||
| @@ -367,7 +367,7 @@ function writer.add_to_manifest(name, version, repo, deps_mode) | |||
| 367 | 367 | ||
| 368 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 368 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
| 369 | 369 | ||
| 370 | local manifest, err = manif.load_local_manifest(rocks_dir) | 370 | local manifest, err = manif.load_manifest(rocks_dir) |
| 371 | if not manifest then | 371 | if not manifest then |
| 372 | util.printerr("No existing manifest. Attempting to rebuild...") | 372 | util.printerr("No existing manifest. Attempting to rebuild...") |
| 373 | -- Manifest built by `writer.make_manifest` should already | 373 | -- Manifest built by `writer.make_manifest` should already |
| @@ -404,7 +404,7 @@ function writer.remove_from_manifest(name, version, repo, deps_mode) | |||
| 404 | 404 | ||
| 405 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 405 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
| 406 | 406 | ||
| 407 | local manifest, err = manif.load_local_manifest(rocks_dir) | 407 | local manifest, err = manif.load_manifest(rocks_dir) |
| 408 | if not manifest then | 408 | if not manifest then |
| 409 | util.printerr("No existing manifest. Attempting to rebuild...") | 409 | util.printerr("No existing manifest. Attempting to rebuild...") |
| 410 | -- Manifest built by `writer.make_manifest` should already | 410 | -- Manifest built by `writer.make_manifest` should already |
| @@ -442,7 +442,7 @@ function writer.check_dependencies(repo, deps_mode) | |||
| 442 | assert(type(deps_mode) == "string") | 442 | assert(type(deps_mode) == "string") |
| 443 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 443 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
| 444 | 444 | ||
| 445 | local manifest = manif.load_local_manifest(rocks_dir) | 445 | local manifest = manif.load_manifest(rocks_dir) |
| 446 | if not manifest then | 446 | if not manifest then |
| 447 | return | 447 | return |
| 448 | end | 448 | end |
diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 6a9166ba..2699aa8c 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua | |||
| @@ -172,6 +172,10 @@ do | |||
| 172 | end | 172 | end |
| 173 | end | 173 | end |
| 174 | 174 | ||
| 175 | function queries.from_persisted_table(tbl) | ||
| 176 | return setmetatable(tbl, query_mt) | ||
| 177 | end | ||
| 178 | |||
| 175 | --- Build a string representation of a query package name. | 179 | --- Build a string representation of a query package name. |
| 176 | -- Includes namespace, name and version, but not arch or constraints. | 180 | -- Includes namespace, name and version, but not arch or constraints. |
| 177 | -- @param query table: a query table | 181 | -- @param query table: a query table |
