diff options
| -rw-r--r-- | src/luarocks/core/manif-original.lua (renamed from src/luarocks/core/manif-incomplete.lua) | 99 | ||||
| -rw-r--r-- | src/luarocks/core/manif.lua | 99 |
2 files changed, 99 insertions, 99 deletions
diff --git a/src/luarocks/core/manif-incomplete.lua b/src/luarocks/core/manif-original.lua index c64795dc..3925f636 100644 --- a/src/luarocks/core/manif-incomplete.lua +++ b/src/luarocks/core/manif-original.lua | |||
| @@ -1,4 +1,6 @@ | |||
| 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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table | 1 | |
| 2 | --- Core functions for querying manifest files. | ||
| 3 | local manif = {} | ||
| 2 | 4 | ||
| 3 | local persist = require("luarocks.core.persist") | 5 | local persist = require("luarocks.core.persist") |
| 4 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
| @@ -6,84 +8,53 @@ local dir = require("luarocks.core.dir") | |||
| 6 | local util = require("luarocks.core.util") | 8 | local util = require("luarocks.core.util") |
| 7 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
| 8 | local path = require("luarocks.core.path") | 10 | local path = require("luarocks.core.path") |
| 11 | local require = nil | ||
| 12 | -------------------------------------------------------------------------------- | ||
| 9 | 13 | ||
| 10 | 14 | -- Table with repository identifiers as keys and tables mapping | |
| 11 | 15 | -- Lua versions to cached loaded manifests as values. | |
| 12 | |||
| 13 | local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | local manifest_cache = {} | 16 | local manifest_cache = {} |
| 45 | 17 | ||
| 46 | 18 | --- Cache a loaded manifest. | |
| 47 | 19 | -- @param repo_url string: The repository identifier. | |
| 48 | 20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
| 49 | 21 | -- @param manifest table: the manifest to be cached. | |
| 50 | function manif.cache_manifest(repo_url, lua_version, manifest) | 22 | function manif.cache_manifest(repo_url, lua_version, manifest) |
| 51 | lua_version = lua_version or cfg.lua_version | 23 | lua_version = lua_version or cfg.lua_version |
| 52 | manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} | 24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} |
| 53 | manifest_cache.repository[repo_url][lua_version] = manifest | 25 | manifest_cache[repo_url][lua_version] = manifest |
| 54 | end | 26 | end |
| 55 | 27 | ||
| 56 | 28 | --- Attempt to get cached loaded manifest. | |
| 57 | 29 | -- @param repo_url string: The repository identifier. | |
| 58 | 30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
| 59 | 31 | -- @return table or nil: loaded manifest or nil if cache is empty. | |
| 60 | function manif.get_cached_manifest(repo_url, lua_version) | 32 | function manif.get_cached_manifest(repo_url, lua_version) |
| 61 | lua_version = lua_version or cfg.lua_version | 33 | lua_version = lua_version or cfg.lua_version |
| 62 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] | 34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] |
| 63 | end | 35 | end |
| 64 | 36 | ||
| 65 | 37 | --- Back-end function that actually loads the manifest | |
| 66 | 38 | -- and stores it in the manifest cache. | |
| 67 | 39 | -- @param file string: The local filename of the manifest file. | |
| 68 | 40 | -- @param repo_url string: The repository identifier. | |
| 69 | 41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
| 70 | 42 | -- @return table or (nil, string, string): the manifest or nil, | |
| 71 | 43 | -- error message and error code ("open", "load", "run"). | |
| 72 | function manif.manifest_loader(file, repo_url, lua_version) | 44 | function manif.manifest_loader(file, repo_url, lua_version) |
| 73 | local manifest, err, errcode = persist.load_into_table(file) | 45 | local manifest, err, errcode = persist.load_into_table(file) |
| 74 | if not manifest and type(err) == "string" then | 46 | if not manifest then |
| 75 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode | 47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode |
| 76 | end | 48 | end |
| 77 | |||
| 78 | manif.cache_manifest(repo_url, lua_version, manifest) | 49 | manif.cache_manifest(repo_url, lua_version, manifest) |
| 79 | return manifest, err, errcode | 50 | return manifest, err, errcode |
| 80 | end | 51 | end |
| 81 | 52 | ||
| 82 | 53 | --- Load a local manifest describing a repository. | |
| 83 | 54 | -- This is used by the luarocks.loader only. | |
| 84 | 55 | -- @param repo_url string: URL or pathname for the repository. | |
| 85 | 56 | -- @return table or (nil, string, string): A table representing the manifest, | |
| 86 | 57 | -- or nil followed by an error message and an error code, see manifest_loader. | |
| 87 | function manif.fast_load_local_manifest(repo_url) | 58 | function manif.fast_load_local_manifest(repo_url) |
| 88 | assert(type(repo_url) == "string") | 59 | assert(type(repo_url) == "string") |
| 89 | 60 | ||
| @@ -93,15 +64,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
| 93 | end | 64 | end |
| 94 | 65 | ||
| 95 | local pathname = dir.path(repo_url, "manifest") | 66 | local pathname = dir.path(repo_url, "manifest") |
| 96 | return manif.manifest_loader(pathname, repo_url, nil) | 67 | return manif.manifest_loader(pathname, repo_url, nil, true) |
| 97 | end | 68 | end |
| 98 | 69 | ||
| 99 | function manif.load_rocks_tree_manifests(deps_mode) | 70 | function manif.load_rocks_tree_manifests(deps_mode) |
| 100 | local trees = {} | 71 | local trees = {} |
| 101 | path.map_trees(deps_mode, function(tree) | 72 | path.map_trees(deps_mode, function(tree) |
| 102 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
| 103 | if manifest then | 74 | if manifest then |
| 104 | table.insert(trees, { tree = tree, manifest = manifest }) | 75 | table.insert(trees, {tree=tree, manifest=manifest}) |
| 105 | end | 76 | end |
| 106 | end) | 77 | end) |
| 107 | return trees | 78 | return trees |
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 3925f636..c64795dc 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
| @@ -1,6 +1,4 @@ | |||
| 1 | 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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table | |
| 2 | --- Core functions for querying manifest files. | ||
| 3 | local manif = {} | ||
| 4 | 2 | ||
| 5 | local persist = require("luarocks.core.persist") | 3 | local persist = require("luarocks.core.persist") |
| 6 | local cfg = require("luarocks.core.cfg") | 4 | local cfg = require("luarocks.core.cfg") |
| @@ -8,53 +6,84 @@ local dir = require("luarocks.core.dir") | |||
| 8 | local util = require("luarocks.core.util") | 6 | local util = require("luarocks.core.util") |
| 9 | local vers = require("luarocks.core.vers") | 7 | local vers = require("luarocks.core.vers") |
| 10 | local path = require("luarocks.core.path") | 8 | local path = require("luarocks.core.path") |
| 11 | local require = nil | ||
| 12 | -------------------------------------------------------------------------------- | ||
| 13 | 9 | ||
| 14 | -- Table with repository identifiers as keys and tables mapping | 10 | |
| 15 | -- Lua versions to cached loaded manifests as values. | 11 | |
| 12 | |||
| 13 | local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 16 | local manifest_cache = {} | 44 | local manifest_cache = {} |
| 17 | 45 | ||
| 18 | --- Cache a loaded manifest. | 46 | |
| 19 | -- @param repo_url string: The repository identifier. | 47 | |
| 20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 48 | |
| 21 | -- @param manifest table: the manifest to be cached. | 49 | |
| 22 | function manif.cache_manifest(repo_url, lua_version, manifest) | 50 | function manif.cache_manifest(repo_url, lua_version, manifest) |
| 23 | lua_version = lua_version or cfg.lua_version | 51 | lua_version = lua_version or cfg.lua_version |
| 24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | 52 | manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} |
| 25 | manifest_cache[repo_url][lua_version] = manifest | 53 | manifest_cache.repository[repo_url][lua_version] = manifest |
| 26 | end | 54 | end |
| 27 | 55 | ||
| 28 | --- Attempt to get cached loaded manifest. | 56 | |
| 29 | -- @param repo_url string: The repository identifier. | 57 | |
| 30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 58 | |
| 31 | -- @return table or nil: loaded manifest or nil if cache is empty. | 59 | |
| 32 | function manif.get_cached_manifest(repo_url, lua_version) | 60 | function manif.get_cached_manifest(repo_url, lua_version) |
| 33 | lua_version = lua_version or cfg.lua_version | 61 | lua_version = lua_version or cfg.lua_version |
| 34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | 62 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] |
| 35 | end | 63 | end |
| 36 | 64 | ||
| 37 | --- Back-end function that actually loads the manifest | 65 | |
| 38 | -- and stores it in the manifest cache. | 66 | |
| 39 | -- @param file string: The local filename of the manifest file. | 67 | |
| 40 | -- @param repo_url string: The repository identifier. | 68 | |
| 41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 69 | |
| 42 | -- @return table or (nil, string, string): the manifest or nil, | 70 | |
| 43 | -- error message and error code ("open", "load", "run"). | 71 | |
| 44 | function manif.manifest_loader(file, repo_url, lua_version) | 72 | function manif.manifest_loader(file, repo_url, lua_version) |
| 45 | local manifest, err, errcode = persist.load_into_table(file) | 73 | local manifest, err, errcode = persist.load_into_table(file) |
| 46 | if not manifest then | 74 | if not manifest and type(err) == "string" then |
| 47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | 75 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode |
| 48 | end | 76 | end |
| 77 | |||
| 49 | manif.cache_manifest(repo_url, lua_version, manifest) | 78 | manif.cache_manifest(repo_url, lua_version, manifest) |
| 50 | return manifest, err, errcode | 79 | return manifest, err, errcode |
| 51 | end | 80 | end |
| 52 | 81 | ||
| 53 | --- Load a local manifest describing a repository. | 82 | |
| 54 | -- This is used by the luarocks.loader only. | 83 | |
| 55 | -- @param repo_url string: URL or pathname for the repository. | 84 | |
| 56 | -- @return table or (nil, string, string): A table representing the manifest, | 85 | |
| 57 | -- or nil followed by an error message and an error code, see manifest_loader. | 86 | |
| 58 | function manif.fast_load_local_manifest(repo_url) | 87 | function manif.fast_load_local_manifest(repo_url) |
| 59 | assert(type(repo_url) == "string") | 88 | assert(type(repo_url) == "string") |
| 60 | 89 | ||
| @@ -64,15 +93,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
| 64 | end | 93 | end |
| 65 | 94 | ||
| 66 | local pathname = dir.path(repo_url, "manifest") | 95 | local pathname = dir.path(repo_url, "manifest") |
| 67 | return manif.manifest_loader(pathname, repo_url, nil, true) | 96 | return manif.manifest_loader(pathname, repo_url, nil) |
| 68 | end | 97 | end |
| 69 | 98 | ||
| 70 | function manif.load_rocks_tree_manifests(deps_mode) | 99 | function manif.load_rocks_tree_manifests(deps_mode) |
| 71 | local trees = {} | 100 | local trees = {} |
| 72 | path.map_trees(deps_mode, function(tree) | 101 | path.map_trees(deps_mode, function(tree) |
| 73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 102 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
| 74 | if manifest then | 103 | if manifest then |
| 75 | table.insert(trees, {tree=tree, manifest=manifest}) | 104 | table.insert(trees, { tree = tree, manifest = manifest }) |
| 76 | end | 105 | end |
| 77 | end) | 106 | end) |
| 78 | return trees | 107 | return trees |
