Mercurial > repo
comparison share/lua/5.2/luarocks/manif_core.lua @ 1132:d137f631bad5
<GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
author | HackBot |
---|---|
date | Fri, 14 Dec 2012 22:24:27 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1131:ff65dfb63263 | 1132:d137f631bad5 |
---|---|
1 | |
2 --- Core functions for querying manifest files. | |
3 -- This module requires no specific 'fs' functionality. | |
4 module("luarocks.manif_core", package.seeall) | |
5 | |
6 local persist = require("luarocks.persist") | |
7 local type_check = require("luarocks.type_check") | |
8 local dir = require("luarocks.dir") | |
9 local util = require("luarocks.util") | |
10 local cfg = require("luarocks.cfg") | |
11 local path = require("luarocks.path") | |
12 | |
13 manifest_cache = {} | |
14 | |
15 --- Back-end function that actually loads the manifest | |
16 -- and stores it in the manifest cache. | |
17 -- @param file string: The local filename of the manifest file. | |
18 -- @param repo_url string: The repository identifier. | |
19 -- @param quick boolean: If given, skips type checking. | |
20 function manifest_loader(file, repo_url, quick) | |
21 local manifest, err = persist.load_into_table(file) | |
22 if not manifest then | |
23 return nil, "Failed loading manifest for "..repo_url..": "..err | |
24 end | |
25 if not quick then | |
26 local ok, err = type_check.type_check_manifest(manifest) | |
27 if not ok then | |
28 return nil, "Error checking manifest: "..err | |
29 end | |
30 end | |
31 | |
32 manifest_cache[repo_url] = manifest | |
33 return manifest | |
34 end | |
35 | |
36 --- Load a local manifest describing a repository. | |
37 -- All functions that use manifest tables assume they were obtained | |
38 -- through either this function or load_manifest. | |
39 -- @param repo_url string: URL or pathname for the repository. | |
40 -- @return table or (nil, string): A table representing the manifest, | |
41 -- or nil followed by an error message. | |
42 function load_local_manifest(repo_url) | |
43 assert(type(repo_url) == "string") | |
44 | |
45 if manifest_cache[repo_url] then | |
46 return manifest_cache[repo_url] | |
47 end | |
48 | |
49 local pathname = dir.path(repo_url, "manifest") | |
50 | |
51 return manifest_loader(pathname, repo_url, true) | |
52 end | |
53 | |
54 --- Get all versions of a package listed in a manifest file. | |
55 -- @param name string: a package name. | |
56 -- @param deps_mode string: "one", to use only the currently | |
57 -- configured tree; "order" to select trees based on order | |
58 -- (use the current tree and all trees below it on the list) | |
59 -- or "all", to use all trees. | |
60 -- @return table: An array of strings listing installed | |
61 -- versions of a package. | |
62 function get_versions(name, deps_mode) | |
63 assert(type(name) == "string") | |
64 assert(type(deps_mode) == "string") | |
65 | |
66 local manifest = {} | |
67 path.map_trees(deps_mode, function(tree) | |
68 local loaded = load_local_manifest(path.rocks_dir(tree)) | |
69 if loaded then | |
70 util.deep_merge(manifest, loaded) | |
71 end | |
72 end) | |
73 | |
74 local item = next(manifest) and manifest.repository[name] | |
75 if item then | |
76 return util.keys(item) | |
77 end | |
78 return {} | |
79 end |