diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-29 19:11:26 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-11 14:38:06 -0300 |
| commit | 4941a48407f08544c5517542ffc11b0c26fd4236 (patch) | |
| tree | 4201643b3ee4fdb3fc3f2c610a9e0bcd964cb365 /src | |
| parent | bfc77ef7989d8a07f53681bde17c0c33b1734404 (diff) | |
| download | luarocks-4941a48407f08544c5517542ffc11b0c26fd4236.tar.gz luarocks-4941a48407f08544c5517542ffc11b0c26fd4236.tar.bz2 luarocks-4941a48407f08544c5517542ffc11b0c26fd4236.zip | |
Beginning support for namespaced queries
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/install.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/cmd/list.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/cmd/purge.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/cmd/remove.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/cmd/search.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/download.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/manif/writer.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/queries.lua | 96 | ||||
| -rw-r--r-- | src/luarocks/remove.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 66 |
11 files changed, 132 insertions, 76 deletions
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index 018e9246..6901a680 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
| @@ -11,6 +11,7 @@ local deps = require("luarocks.deps") | |||
| 11 | local writer = require("luarocks.manif.writer") | 11 | local writer = require("luarocks.manif.writer") |
| 12 | local remove = require("luarocks.remove") | 12 | local remove = require("luarocks.remove") |
| 13 | local search = require("luarocks.search") | 13 | local search = require("luarocks.search") |
| 14 | local queries = require("luarocks.queries") | ||
| 14 | local cfg = require("luarocks.core.cfg") | 15 | local cfg = require("luarocks.core.cfg") |
| 15 | 16 | ||
| 16 | install.help_summary = "Install a rock." | 17 | install.help_summary = "Install a rock." |
| @@ -174,7 +175,7 @@ function install.command(flags, name, version) | |||
| 174 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) | 175 | writer.check_dependencies(nil, deps.get_deps_mode(flags)) |
| 175 | return name, version | 176 | return name, version |
| 176 | else | 177 | else |
| 177 | local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) | 178 | local url, err = search.find_suitable_rock(queries.new(name:lower(), version)) |
| 178 | if not url then | 179 | if not url then |
| 179 | return nil, err | 180 | return nil, err |
| 180 | end | 181 | end |
diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.lua index ed94bc68..e07c4ff3 100644 --- a/src/luarocks/cmd/list.lua +++ b/src/luarocks/cmd/list.lua | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | local list = {} | 4 | local list = {} |
| 5 | 5 | ||
| 6 | local search = require("luarocks.search") | 6 | local search = require("luarocks.search") |
| 7 | local queries = require("luarocks.queries") | ||
| 7 | local vers = require("luarocks.vers") | 8 | local vers = require("luarocks.vers") |
| 8 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
| 9 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
| @@ -31,8 +32,7 @@ local function check_outdated(trees, query) | |||
| 31 | table.sort(versions, vers.compare_versions) | 32 | table.sort(versions, vers.compare_versions) |
| 32 | local latest_installed = versions[1] | 33 | local latest_installed = versions[1] |
| 33 | 34 | ||
| 34 | local query_available = search.make_query(name:lower()) | 35 | local query_available = queries.new(name:lower(), nil, false) |
| 35 | query.exact_name = true | ||
| 36 | local results_available, err = search.search_repos(query_available) | 36 | local results_available, err = search.search_repos(query_available) |
| 37 | 37 | ||
| 38 | if results_available[name] then | 38 | if results_available[name] then |
| @@ -69,8 +69,7 @@ end | |||
| 69 | -- @param version string or nil: a version may also be passed. | 69 | -- @param version string or nil: a version may also be passed. |
| 70 | -- @return boolean: True if succeeded, nil on errors. | 70 | -- @return boolean: True if succeeded, nil on errors. |
| 71 | function list.command(flags, filter, version) | 71 | function list.command(flags, filter, version) |
| 72 | local query = search.make_query(filter and filter:lower() or "", version) | 72 | local query = queries.new(filter and filter:lower() or "", version, true) |
| 73 | query.exact_name = false | ||
| 74 | local trees = cfg.rocks_trees | 73 | local trees = cfg.rocks_trees |
| 75 | if flags["tree"] then | 74 | if flags["tree"] then |
| 76 | trees = { flags["tree"] } | 75 | trees = { flags["tree"] } |
diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua index bbce9f8c..15efb0ef 100644 --- a/src/luarocks/cmd/purge.lua +++ b/src/luarocks/cmd/purge.lua | |||
| @@ -12,6 +12,7 @@ local repos = require("luarocks.repos") | |||
| 12 | local writer = require("luarocks.manif.writer") | 12 | local writer = require("luarocks.manif.writer") |
| 13 | local cfg = require("luarocks.core.cfg") | 13 | local cfg = require("luarocks.core.cfg") |
| 14 | local remove = require("luarocks.remove") | 14 | local remove = require("luarocks.remove") |
| 15 | local queries = require("luarocks.queries") | ||
| 15 | 16 | ||
| 16 | purge.help_summary = "Remove all installed rocks from a tree." | 17 | purge.help_summary = "Remove all installed rocks from a tree." |
| 17 | purge.help_arguments = "--tree=<tree> [--old-versions]" | 18 | purge.help_arguments = "--tree=<tree> [--old-versions]" |
| @@ -37,8 +38,6 @@ function purge.command(flags) | |||
| 37 | end | 38 | end |
| 38 | 39 | ||
| 39 | local results = {} | 40 | local results = {} |
| 40 | local query = search.make_query("") | ||
| 41 | query.exact_name = false | ||
| 42 | if not fs.is_dir(tree) then | 41 | if not fs.is_dir(tree) then |
| 43 | return nil, "Directory not found: "..tree | 42 | return nil, "Directory not found: "..tree |
| 44 | end | 43 | end |
| @@ -46,7 +45,7 @@ function purge.command(flags) | |||
| 46 | local ok, err = fs.check_command_permissions(flags) | 45 | local ok, err = fs.check_command_permissions(flags) |
| 47 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | 46 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end |
| 48 | 47 | ||
| 49 | search.manifest_search(results, path.rocks_dir(tree), query) | 48 | search.manifest_search(results, path.rocks_dir(tree), queries.all()) |
| 50 | 49 | ||
| 51 | local sort = function(a,b) return vers.compare_versions(b,a) end | 50 | local sort = function(a,b) return vers.compare_versions(b,a) end |
| 52 | if flags["old-versions"] then | 51 | if flags["old-versions"] then |
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua index b8148ba7..2624854d 100644 --- a/src/luarocks/cmd/remove.lua +++ b/src/luarocks/cmd/remove.lua | |||
| @@ -11,6 +11,7 @@ local search = require("luarocks.search") | |||
| 11 | local path = require("luarocks.path") | 11 | local path = require("luarocks.path") |
| 12 | local deps = require("luarocks.deps") | 12 | local deps = require("luarocks.deps") |
| 13 | local writer = require("luarocks.manif.writer") | 13 | local writer = require("luarocks.manif.writer") |
| 14 | local queries = require("luarocks.queries") | ||
| 14 | 15 | ||
| 15 | cmd_remove.help_summary = "Uninstall a rock." | 16 | cmd_remove.help_summary = "Uninstall a rock." |
| 16 | cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | 17 | cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" |
| @@ -50,7 +51,7 @@ function cmd_remove.command(flags, name, version) | |||
| 50 | 51 | ||
| 51 | local results = {} | 52 | local results = {} |
| 52 | name = name:lower() | 53 | name = name:lower() |
| 53 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) | 54 | search.manifest_search(results, cfg.rocks_dir, queries.new(name, version)) |
| 54 | if not results[name] then | 55 | if not results[name] then |
| 55 | return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) | 56 | return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) |
| 56 | end | 57 | end |
diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua index d12f5314..ccdbda7b 100644 --- a/src/luarocks/cmd/search.lua +++ b/src/luarocks/cmd/search.lua | |||
| @@ -6,6 +6,7 @@ local cmd_search = {} | |||
| 6 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
| 7 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
| 8 | local search = require("luarocks.search") | 8 | local search = require("luarocks.search") |
| 9 | local queries = require("luarocks.queries") | ||
| 9 | 10 | ||
| 10 | cmd_search.help_summary = "Query the LuaRocks servers." | 11 | cmd_search.help_summary = "Query the LuaRocks servers." |
| 11 | cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" | 12 | cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" |
| @@ -55,8 +56,7 @@ function cmd_search.command(flags, name, version) | |||
| 55 | return nil, "Enter name and version or use --all. "..util.see_help("search") | 56 | return nil, "Enter name and version or use --all. "..util.see_help("search") |
| 56 | end | 57 | end |
| 57 | 58 | ||
| 58 | local query = search.make_query(name:lower(), version) | 59 | local query = queries.new(name:lower(), version, true) |
| 59 | query.exact_name = false | ||
| 60 | local results, err = search.search_repos(query) | 60 | local results, err = search.search_repos(query) |
| 61 | local porcelain = flags["porcelain"] | 61 | local porcelain = flags["porcelain"] |
| 62 | local full_name = name .. (version and " " .. version or "") | 62 | local full_name = name .. (version and " " .. version or "") |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 015e2527..229c3843 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
| @@ -8,6 +8,7 @@ local path = require("luarocks.path") | |||
| 8 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
| 9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
| 10 | local vers = require("luarocks.vers") | 10 | local vers = require("luarocks.vers") |
| 11 | local queries = require("luarocks.queries") | ||
| 11 | 12 | ||
| 12 | --- Attempt to match a dependency to an installed rock. | 13 | --- Attempt to match a dependency to an installed rock. |
| 13 | -- @param dep table: A dependency parsed in table format. | 14 | -- @param dep table: A dependency parsed in table format. |
| @@ -90,8 +91,7 @@ local function values_set(tbl) | |||
| 90 | end | 91 | end |
| 91 | 92 | ||
| 92 | local function rock_status(name, deps_mode, rocks_provided) | 93 | local function rock_status(name, deps_mode, rocks_provided) |
| 93 | local search = require("luarocks.search") | 94 | local installed = match_dep(queries.new(name), nil, deps_mode, rocks_provided) |
| 94 | local installed = match_dep(search.make_query(name), nil, deps_mode, rocks_provided) | ||
| 95 | local installation_type = rocks_provided[name] and "provided by VM" or "installed" | 95 | local installation_type = rocks_provided[name] and "provided by VM" or "installed" |
| 96 | return installed and installed.." "..installation_type or "not installed" | 96 | return installed and installed.." "..installation_type or "not installed" |
| 97 | end | 97 | end |
| @@ -184,7 +184,7 @@ function deps.fulfill_dependencies(rockspec, deps_mode) | |||
| 184 | return nil, "Failed matching dependencies" | 184 | return nil, "Failed matching dependencies" |
| 185 | end | 185 | end |
| 186 | 186 | ||
| 187 | local url, search_err = search.find_suitable_rock(dep) | 187 | local url, search_err = search.find_suitable_rock(queries.from_constraints(dep.name, dep.constraints)) |
| 188 | if not url then | 188 | if not url then |
| 189 | return nil, "Could not satisfy dependency "..vers.show_dep(dep)..": "..search_err | 189 | return nil, "Could not satisfy dependency "..vers.show_dep(dep)..": "..search_err |
| 190 | end | 190 | end |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index ec9996b2..77564b52 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
| @@ -3,6 +3,7 @@ local download = {} | |||
| 3 | local path = require("luarocks.path") | 3 | local path = require("luarocks.path") |
| 4 | local fetch = require("luarocks.fetch") | 4 | local fetch = require("luarocks.fetch") |
| 5 | local search = require("luarocks.search") | 5 | local search = require("luarocks.search") |
| 6 | local queries = require("luarocks.queries") | ||
| 6 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
| 7 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
| 8 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
| @@ -22,12 +23,11 @@ local function get_file(filename) | |||
| 22 | end | 23 | end |
| 23 | 24 | ||
| 24 | function download.download(arch, name, version, all) | 25 | function download.download(arch, name, version, all) |
| 25 | local query = search.make_query(name, version) | 26 | local substring = (all and name == "") |
| 26 | if arch then query.arch = arch end | 27 | local query = queries.new(name, version, substring, arch) |
| 27 | local search_err | 28 | local search_err |
| 28 | 29 | ||
| 29 | if all then | 30 | if all then |
| 30 | if name == "" then query.exact_name = false end | ||
| 31 | local results = search.search_repos(query) | 31 | local results = search.search_repos(query) |
| 32 | local has_result = false | 32 | local has_result = false |
| 33 | local all_ok = true | 33 | local all_ok = true |
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 2d17d328..e6edd27d 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua | |||
| @@ -13,6 +13,7 @@ local fetch = require("luarocks.fetch") | |||
| 13 | local path = require("luarocks.path") | 13 | local path = require("luarocks.path") |
| 14 | local persist = require("luarocks.persist") | 14 | local persist = require("luarocks.persist") |
| 15 | local manif = require("luarocks.manif") | 15 | local manif = require("luarocks.manif") |
| 16 | local queries = require("luarocks.queries") | ||
| 16 | 17 | ||
| 17 | --- Update storage table to account for items provided by a package. | 18 | --- Update storage table to account for items provided by a package. |
| 18 | -- @param storage table: a table storing items in the following format: | 19 | -- @param storage table: a table storing items in the following format: |
| @@ -296,9 +297,7 @@ function writer.make_manifest(repo, deps_mode, remote) | |||
| 296 | return nil, "Cannot access repository at "..repo | 297 | return nil, "Cannot access repository at "..repo |
| 297 | end | 298 | end |
| 298 | 299 | ||
| 299 | local query = search.make_query("") | 300 | local query = queries.all("any") |
| 300 | query.exact_name = false | ||
| 301 | query.arch = "any" | ||
| 302 | local results = search.disk_search(repo, query) | 301 | local results = search.disk_search(repo, query) |
| 303 | local manifest = { repository = {}, modules = {}, commands = {} } | 302 | local manifest = { repository = {}, modules = {}, commands = {} } |
| 304 | 303 | ||
diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua new file mode 100644 index 00000000..5bd7462e --- /dev/null +++ b/src/luarocks/queries.lua | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | |||
| 2 | local queries = {} | ||
| 3 | |||
| 4 | local vers = require("luarocks.vers") | ||
| 5 | local cfg = require("luarocks.core.cfg") | ||
| 6 | |||
| 7 | local safer = require("safer") | ||
| 8 | |||
| 9 | --- Convert the arch field of a query table to table format. | ||
| 10 | -- @param input string, table or nil | ||
| 11 | local function arch_to_table(input) | ||
| 12 | if type(input) == "table" then | ||
| 13 | return input | ||
| 14 | elseif type(input) == "string" then | ||
| 15 | local arch = {} | ||
| 16 | for a in input:gmatch("[%w_-]+") do | ||
| 17 | arch[a] = true | ||
| 18 | end | ||
| 19 | return arch | ||
| 20 | else | ||
| 21 | local arch = {} | ||
| 22 | arch["src"] = true | ||
| 23 | arch["all"] = true | ||
| 24 | arch["rockspec"] = true | ||
| 25 | arch["installed"] = true | ||
| 26 | arch[cfg.arch] = true | ||
| 27 | return arch | ||
| 28 | end | ||
| 29 | end | ||
| 30 | |||
| 31 | -- Split name and namespace of a package name. | ||
| 32 | -- @param name a name that may be in "namespace/name" format | ||
| 33 | -- @return string, string? - name and optionally a namespace | ||
| 34 | local function split_namespace(name) | ||
| 35 | local p1, p2 = name:match("^([^/]+)/([^/]+)$") | ||
| 36 | if p1 then | ||
| 37 | return p2, p1 | ||
| 38 | end | ||
| 39 | return name | ||
| 40 | end | ||
| 41 | |||
| 42 | --- Prepare a query in dependency table format. | ||
| 43 | -- @param name string: The query name. | ||
| 44 | -- @param version string or nil: | ||
| 45 | -- @param substring boolean: match substrings of the name | ||
| 46 | -- (default is false, match full name) | ||
| 47 | -- @param arch string: a string with pipe-separated accepted arch values | ||
| 48 | -- @param operator string: operator for version matching (default is "==") | ||
| 49 | -- @return table: A query in table format | ||
| 50 | function queries.new(name, version, substring, arch, operator) | ||
| 51 | assert(type(name) == "string") | ||
| 52 | assert(type(version) == "string" or not version) | ||
| 53 | assert(type(substring) == "boolean" or not substring) | ||
| 54 | assert(type(arch) == "string" or not arch) | ||
| 55 | assert(type(operator) == "string" or not operator) | ||
| 56 | |||
| 57 | operator = operator or "==" | ||
| 58 | |||
| 59 | local namespace | ||
| 60 | name, namespace = split_namespace(name) | ||
| 61 | |||
| 62 | local query = { | ||
| 63 | name = name, | ||
| 64 | namespace = namespace, | ||
| 65 | constraints = {}, | ||
| 66 | substring = substring, | ||
| 67 | arch = arch_to_table(arch), | ||
| 68 | } | ||
| 69 | if version then | ||
| 70 | table.insert(query.constraints, { op = operator, version = vers.parse_version(version)}) | ||
| 71 | end | ||
| 72 | return safer.readonly(query) | ||
| 73 | end | ||
| 74 | |||
| 75 | -- Query for all packages | ||
| 76 | -- @param arch string (optional) | ||
| 77 | function queries.all(arch) | ||
| 78 | assert(type(arch) == "string" or not arch) | ||
| 79 | |||
| 80 | return queries.new("", nil, true, arch) | ||
| 81 | end | ||
| 82 | |||
| 83 | function queries.from_constraints(name, constraints) | ||
| 84 | local namespace | ||
| 85 | name, namespace = split_namespace(name) | ||
| 86 | local query = { | ||
| 87 | name = name, | ||
| 88 | namespace = namespace, | ||
| 89 | constraints = constraints, | ||
| 90 | substring = false, | ||
| 91 | arch = arch_to_table(nil), | ||
| 92 | } | ||
| 93 | return safer.readonly(query) | ||
| 94 | end | ||
| 95 | |||
| 96 | return queries | ||
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 6cc8334f..a469d149 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
| @@ -7,6 +7,7 @@ local repos = require("luarocks.repos") | |||
| 7 | local path = require("luarocks.path") | 7 | local path = require("luarocks.path") |
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
| 10 | local queries = require("luarocks.queries") | ||
| 10 | 11 | ||
| 11 | --- Obtain a list of packages that depend on the given set of packages | 12 | --- Obtain a list of packages that depend on the given set of packages |
| 12 | -- (where all packages of the set are versions of one program). | 13 | -- (where all packages of the set are versions of one program). |
| @@ -22,8 +23,7 @@ local function check_dependents(name, versions, deps_mode) | |||
| 22 | blacklist[name][version] = true | 23 | blacklist[name][version] = true |
| 23 | end | 24 | end |
| 24 | local local_rocks = {} | 25 | local local_rocks = {} |
| 25 | local query_all = search.make_query("") | 26 | local query_all = queries.all() |
| 26 | query_all.exact_name = false | ||
| 27 | search.manifest_search(local_rocks, cfg.rocks_dir, query_all) | 27 | search.manifest_search(local_rocks, cfg.rocks_dir, query_all) |
| 28 | local_rocks[name] = nil | 28 | local_rocks[name] = nil |
| 29 | for rock_name, rock_versions in pairs(local_rocks) do | 29 | for rock_name, rock_versions in pairs(local_rocks) do |
| @@ -105,7 +105,8 @@ end | |||
| 105 | 105 | ||
| 106 | function remove.remove_other_versions(name, version, force, fast) | 106 | function remove.remove_other_versions(name, version, force, fast) |
| 107 | local results = {} | 107 | local results = {} |
| 108 | search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} }) | 108 | local query = queries.new(name, version, false, nil, "~=") |
| 109 | search.manifest_search(results, cfg.rocks_dir, query) | ||
| 109 | if results[name] then | 110 | if results[name] then |
| 110 | return remove.remove_search_results(results, name, cfg.deps_mode, force, fast) | 111 | return remove.remove_search_results(results, name, cfg.deps_mode, force, fast) |
| 111 | end | 112 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 35010c2b..4e0cb847 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
| @@ -6,29 +6,7 @@ local manif = require("luarocks.manif") | |||
| 6 | local vers = require("luarocks.vers") | 6 | local vers = require("luarocks.vers") |
| 7 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | 9 | local queries = require("luarocks.queries") | |
| 10 | --- Convert the arch field of a query table to table format. | ||
| 11 | -- @param query table: A query table. | ||
| 12 | local function query_arch_as_table(query) | ||
| 13 | local format = type(query.arch) | ||
| 14 | if format == "table" then | ||
| 15 | return | ||
| 16 | elseif format == "nil" then | ||
| 17 | local accept = {} | ||
| 18 | accept["src"] = true | ||
| 19 | accept["all"] = true | ||
| 20 | accept["rockspec"] = true | ||
| 21 | accept["installed"] = true | ||
| 22 | accept[cfg.arch] = true | ||
| 23 | query.arch = accept | ||
| 24 | elseif format == "string" then | ||
| 25 | local accept = {} | ||
| 26 | for a in query.arch:gmatch("[%w_-]+") do | ||
| 27 | accept[a] = true | ||
| 28 | end | ||
| 29 | query.arch = accept | ||
| 30 | end | ||
| 31 | end | ||
| 32 | 10 | ||
| 33 | --- Store a search result (a rock or rockspec) in the results table. | 11 | --- Store a search result (a rock or rockspec) in the results table. |
| 34 | -- @param results table: The results table, where keys are package names and | 12 | -- @param results table: The results table, where keys are package names and |
| @@ -56,7 +34,7 @@ function search.store_result(results, name, version, arch, repo) | |||
| 56 | end | 34 | end |
| 57 | 35 | ||
| 58 | --- Test the name field of a query. | 36 | --- Test the name field of a query. |
| 59 | -- If query has a boolean field exact_name set to false, | 37 | -- If query has a boolean field substring set to true, |
| 60 | -- then substring match is performed; otherwise, exact string | 38 | -- then substring match is performed; otherwise, exact string |
| 61 | -- comparison is done. | 39 | -- comparison is done. |
| 62 | -- @param query table: A query in dependency table format. | 40 | -- @param query table: A query in dependency table format. |
| @@ -65,7 +43,7 @@ end | |||
| 65 | local function match_name(query, name) | 43 | local function match_name(query, name) |
| 66 | assert(type(query) == "table") | 44 | assert(type(query) == "table") |
| 67 | assert(type(name) == "string") | 45 | assert(type(name) == "string") |
| 68 | if query.exact_name == false then | 46 | if query.substring then |
| 69 | return name:find(query.name, 0, true) and true or false | 47 | return name:find(query.name, 0, true) and true or false |
| 70 | else | 48 | else |
| 71 | return name == query.name | 49 | return name == query.name |
| @@ -84,7 +62,7 @@ end | |||
| 84 | -- @param version string: The version of the package being tested. | 62 | -- @param version string: The version of the package being tested. |
| 85 | -- @param arch string: The arch of the package being tested. | 63 | -- @param arch string: The arch of the package being tested. |
| 86 | -- @param query table: A table describing the query in dependency | 64 | -- @param query table: A table describing the query in dependency |
| 87 | -- format (for example, {name = "filesystem", exact_name = false, | 65 | -- format (for example, {name = "filesystem", substring = true, |
| 88 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). | 66 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). |
| 89 | -- If the arch field is omitted, the local architecture (cfg.arch) | 67 | -- If the arch field is omitted, the local architecture (cfg.arch) |
| 90 | -- is used. The special value "any" is also recognized, returning all | 68 | -- is used. The special value "any" is also recognized, returning all |
| @@ -102,7 +80,7 @@ end | |||
| 102 | --- Perform search on a local repository. | 80 | --- Perform search on a local repository. |
| 103 | -- @param repo string: The pathname of the local repository. | 81 | -- @param repo string: The pathname of the local repository. |
| 104 | -- @param query table: A table describing the query in dependency | 82 | -- @param query table: A table describing the query in dependency |
| 105 | -- format (for example, {name = "filesystem", exact_name = false, | 83 | -- format (for example, {name = "filesystem", substring = true, |
| 106 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). | 84 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). |
| 107 | -- If the arch field is omitted, the local architecture (cfg.arch) | 85 | -- If the arch field is omitted, the local architecture (cfg.arch) |
| 108 | -- is used. The special value "any" is also recognized, returning all | 86 | -- is used. The special value "any" is also recognized, returning all |
| @@ -123,7 +101,6 @@ function search.disk_search(repo, query, results) | |||
| 123 | if not results then | 101 | if not results then |
| 124 | results = {} | 102 | results = {} |
| 125 | end | 103 | end |
| 126 | query_arch_as_table(query) | ||
| 127 | 104 | ||
| 128 | for name in fs.dir(repo) do | 105 | for name in fs.dir(repo) do |
| 129 | local pathname = dir.path(repo, name) | 106 | local pathname = dir.path(repo, name) |
| @@ -149,7 +126,7 @@ end | |||
| 149 | -- @param repo string: The URL of a rocks server or | 126 | -- @param repo string: The URL of a rocks server or |
| 150 | -- the pathname of a rocks tree (as returned by path.rocks_dir()). | 127 | -- the pathname of a rocks tree (as returned by path.rocks_dir()). |
| 151 | -- @param query table: A table describing the query in dependency | 128 | -- @param query table: A table describing the query in dependency |
| 152 | -- format (for example, {name = "filesystem", exact_name = false, | 129 | -- format (for example, {name = "filesystem", substring = true, |
| 153 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). | 130 | -- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). |
| 154 | -- If the arch field is omitted, the local architecture (cfg.arch) | 131 | -- If the arch field is omitted, the local architecture (cfg.arch) |
| 155 | -- is used. The special value "any" is also recognized, returning all | 132 | -- is used. The special value "any" is also recognized, returning all |
| @@ -160,8 +137,11 @@ function search.manifest_search(results, repo, query, lua_version) | |||
| 160 | assert(type(results) == "table") | 137 | assert(type(results) == "table") |
| 161 | assert(type(repo) == "string") | 138 | assert(type(repo) == "string") |
| 162 | assert(type(query) == "table") | 139 | assert(type(query) == "table") |
| 163 | 140 | ||
| 164 | query_arch_as_table(query) | 141 | if query.namespace then |
| 142 | repo = repo .. "/manifests/" .. query.namespace | ||
| 143 | end | ||
| 144 | |||
| 165 | local manifest, err, errcode = manif.load_manifest(repo, lua_version) | 145 | local manifest, err, errcode = manif.load_manifest(repo, lua_version) |
| 166 | if not manifest then | 146 | if not manifest then |
| 167 | return nil, err, errcode | 147 | return nil, err, errcode |
| @@ -216,24 +196,6 @@ function search.search_repos(query, lua_version) | |||
| 216 | return results | 196 | return results |
| 217 | end | 197 | end |
| 218 | 198 | ||
| 219 | --- Prepare a query in dependency table format. | ||
| 220 | -- @param name string: The query name. | ||
| 221 | -- @param version string or nil: | ||
| 222 | -- @return table: A query in table format | ||
| 223 | function search.make_query(name, version) | ||
| 224 | assert(type(name) == "string") | ||
| 225 | assert(type(version) == "string" or not version) | ||
| 226 | |||
| 227 | local query = { | ||
| 228 | name = name, | ||
| 229 | constraints = {} | ||
| 230 | } | ||
| 231 | if version then | ||
| 232 | table.insert(query.constraints, { op = "==", version = vers.parse_version(version)}) | ||
| 233 | end | ||
| 234 | return query | ||
| 235 | end | ||
| 236 | |||
| 237 | --- Get the URL for the latest in a set of versions. | 199 | --- Get the URL for the latest in a set of versions. |
| 238 | -- @param name string: The package name to be used in the URL. | 200 | -- @param name string: The package name to be used in the URL. |
| 239 | -- @param versions table: An array of version informations, as stored | 201 | -- @param versions table: An array of version informations, as stored |
| @@ -369,8 +331,7 @@ function search.act_on_src_or_rockspec(action, name, version, ...) | |||
| 369 | assert(type(name) == "string") | 331 | assert(type(name) == "string") |
| 370 | assert(type(version) == "string" or not version) | 332 | assert(type(version) == "string" or not version) |
| 371 | 333 | ||
| 372 | local query = search.make_query(name, version) | 334 | local query = queries.new(name, version, nil, "src|rockspec") |
| 373 | query.arch = "src|rockspec" | ||
| 374 | local url, err = search.find_suitable_rock(query) | 335 | local url, err = search.find_suitable_rock(query) |
| 375 | if not url then | 336 | if not url then |
| 376 | return nil, "Could not find a result named "..name..(version and " "..version or "")..": "..err | 337 | return nil, "Could not find a result named "..name..(version and " "..version or "")..": "..err |
| @@ -380,8 +341,7 @@ end | |||
| 380 | 341 | ||
| 381 | function search.pick_installed_rock(name, version, given_tree) | 342 | function search.pick_installed_rock(name, version, given_tree) |
| 382 | local results = {} | 343 | local results = {} |
| 383 | local query = search.make_query(name, version) | 344 | local query = queries.new(name, version, true) |
| 384 | query.exact_name = true | ||
| 385 | local tree_map = {} | 345 | local tree_map = {} |
| 386 | local trees = cfg.rocks_trees | 346 | local trees = cfg.rocks_trees |
| 387 | if given_tree then | 347 | if given_tree then |
