diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-03 13:58:47 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-09 16:49:20 -0300 |
commit | 208c5528289b2f69f03b70a1ea6f979d675882a9 (patch) | |
tree | 128342046f7abe88b85b4352b136c3c252d7a308 /src | |
parent | 29513caaca2bfdf197e3bbdc27c24f0081639fbd (diff) | |
download | luarocks-208c5528289b2f69f03b70a1ea6f979d675882a9.tar.gz luarocks-208c5528289b2f69f03b70a1ea6f979d675882a9.tar.bz2 luarocks-208c5528289b2f69f03b70a1ea6f979d675882a9.zip |
search: add report and opt-out for checking other Lua versions
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/build.lua | 2 | ||||
-rw-r--r-- | src/luarocks/cmd/install.lua | 2 | ||||
-rw-r--r-- | src/luarocks/cmd/unpack.lua | 2 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 1 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 2 | ||||
-rw-r--r-- | src/luarocks/download.lua | 3 | ||||
-rw-r--r-- | src/luarocks/search.lua | 44 |
7 files changed, 35 insertions, 21 deletions
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index e6dc8a88..23a94fa7 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
@@ -96,7 +96,7 @@ local function do_build(ns_name, version, opts) | |||
96 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then | 96 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then |
97 | url = ns_name | 97 | url = ns_name |
98 | else | 98 | else |
99 | url, err = search.find_src_or_rockspec(ns_name, version) | 99 | url, err = search.find_src_or_rockspec(ns_name, version, true) |
100 | if not url then | 100 | if not url then |
101 | return nil, err | 101 | return nil, err |
102 | end | 102 | end |
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index 647dbdfd..d1d7bf6c 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
@@ -247,7 +247,7 @@ function install.command(flags, name, version) | |||
247 | return install_rock_file(name, opts) | 247 | return install_rock_file(name, opts) |
248 | end | 248 | end |
249 | else | 249 | else |
250 | local url, err = search.find_suitable_rock(queries.new(name:lower(), version)) | 250 | local url, err = search.find_suitable_rock(queries.new(name:lower(), version), true) |
251 | if not url then | 251 | if not url then |
252 | return nil, err | 252 | return nil, err |
253 | end | 253 | end |
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index 7d3b7ca4..99263f49 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua | |||
@@ -159,7 +159,7 @@ function unpack.command(flags, ns_name, version) | |||
159 | if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then | 159 | if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then |
160 | url = ns_name | 160 | url = ns_name |
161 | else | 161 | else |
162 | url, err = search.find_src_or_rockspec(ns_name, version) | 162 | url, err = search.find_src_or_rockspec(ns_name, version, true) |
163 | if not url then | 163 | if not url then |
164 | return nil, err | 164 | return nil, err |
165 | end | 165 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index af4327c6..c420c5bd 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -190,6 +190,7 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
190 | check_certificates = false, | 190 | check_certificates = false, |
191 | 191 | ||
192 | cache_timeout = 10, | 192 | cache_timeout = 10, |
193 | version_check_on_fail = true, | ||
193 | 194 | ||
194 | lua_modules_path = "/share/lua/"..lua_version, | 195 | lua_modules_path = "/share/lua/"..lua_version, |
195 | lib_modules_path = "/lib/lua/"..lua_version, | 196 | lib_modules_path = "/lib/lua/"..lua_version, |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index c2f6ab96..a2b7f0ea 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -165,7 +165,7 @@ function deps.fulfill_dependency(dep, deps_mode, name, version, rocks_provided, | |||
165 | return nil, "Failed matching dependencies" | 165 | return nil, "Failed matching dependencies" |
166 | end | 166 | end |
167 | 167 | ||
168 | local url, search_err = search.find_suitable_rock(dep) | 168 | local url, search_err = search.find_suitable_rock(dep, true) |
169 | if not url then | 169 | if not url then |
170 | return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err | 170 | return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err |
171 | end | 171 | end |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index ac401f33..0620be68 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -6,7 +6,6 @@ local search = require("luarocks.search") | |||
6 | local queries = require("luarocks.queries") | 6 | local queries = require("luarocks.queries") |
7 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
8 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
9 | local cfg = require("luarocks.core.cfg") | ||
10 | 9 | ||
11 | local function get_file(filename) | 10 | local function get_file(filename) |
12 | local protocol, pathname = dir.split_url(filename) | 11 | local protocol, pathname = dir.split_url(filename) |
@@ -54,7 +53,7 @@ function download.download(arch, name, version, all) | |||
54 | end | 53 | end |
55 | else | 54 | else |
56 | local url | 55 | local url |
57 | url, search_err = search.find_suitable_rock(query) | 56 | url, search_err = search.find_suitable_rock(query, true) |
58 | if url then | 57 | if url then |
59 | return get_file(url) | 58 | return get_file(url) |
60 | end | 59 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index da527bc6..a11d959c 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -205,13 +205,17 @@ end | |||
205 | 205 | ||
206 | -- Find out which other Lua versions provide rock versions matching a query, | 206 | -- Find out which other Lua versions provide rock versions matching a query, |
207 | -- @param query table: a query object. | 207 | -- @param query table: a query object. |
208 | -- @param cli boolean: print status messages as it works | ||
208 | -- @return table: array of Lua versions supported, in "5.x" format. | 209 | -- @return table: array of Lua versions supported, in "5.x" format. |
209 | local function supported_lua_versions(query) | 210 | local function supported_lua_versions(query, cli) |
210 | assert(query:type() == "query") | 211 | assert(query:type() == "query") |
211 | local result_tree = {} | 212 | local result_tree = {} |
212 | 213 | ||
213 | for lua_version in util.lua_versions() do | 214 | for lua_version in util.lua_versions() do |
214 | if lua_version ~= cfg.lua_version then | 215 | if lua_version ~= cfg.lua_version then |
216 | if cli then | ||
217 | util.printout("Checking for Lua " .. lua_version .. "...") | ||
218 | end | ||
215 | if search.search_repos(query, lua_version)[query.name] then | 219 | if search.search_repos(query, lua_version)[query.name] then |
216 | table.insert(result_tree, lua_version) | 220 | table.insert(result_tree, lua_version) |
217 | end | 221 | end |
@@ -221,9 +225,9 @@ local function supported_lua_versions(query) | |||
221 | return result_tree | 225 | return result_tree |
222 | end | 226 | end |
223 | 227 | ||
224 | function search.find_src_or_rockspec(ns_name, version) | 228 | function search.find_src_or_rockspec(ns_name, version, cli) |
225 | local query = queries.new(ns_name, version, false, "src|rockspec") | 229 | local query = queries.new(ns_name, version, false, "src|rockspec") |
226 | local url, err = search.find_suitable_rock(query) | 230 | local url, err = search.find_suitable_rock(query, cli) |
227 | if not url then | 231 | if not url then |
228 | return nil, "Could not find a result named "..tostring(query)..": "..err | 232 | return nil, "Could not find a result named "..tostring(query)..": "..err |
229 | end | 233 | end |
@@ -232,27 +236,41 @@ end | |||
232 | 236 | ||
233 | --- Attempt to get a single URL for a given search for a rock. | 237 | --- Attempt to get a single URL for a given search for a rock. |
234 | -- @param query table: a query object. | 238 | -- @param query table: a query object. |
239 | -- @param cli boolean: print status messages as it works | ||
235 | -- @return string or (nil, string): URL for latest matching version | 240 | -- @return string or (nil, string): URL for latest matching version |
236 | -- of the rock if it was found, or nil followed by an error message. | 241 | -- of the rock if it was found, or nil followed by an error message. |
237 | function search.find_suitable_rock(query) | 242 | function search.find_suitable_rock(query, cli) |
238 | assert(query:type() == "query") | 243 | assert(query:type() == "query") |
244 | |||
245 | if cfg.rocks_provided[query.name] ~= nil then | ||
246 | -- Do not install versions listed in cfg.rocks_provided. | ||
247 | return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. | ||
248 | " is already provided by VM or via 'rocks_provided' in the config file." | ||
249 | end | ||
239 | 250 | ||
240 | local result_tree = search.search_repos(query) | 251 | local result_tree = search.search_repos(query) |
241 | local first_rock = next(result_tree) | 252 | local first_rock = next(result_tree) |
242 | if not first_rock then | 253 | if not first_rock then |
243 | if cfg.rocks_provided[query.name] == nil then | 254 | if cfg.version_check_on_fail then |
255 | if cli then | ||
256 | util.printout(query.name .. " not found for Lua " .. cfg.lua_version .. ".") | ||
257 | util.printout("Checking if available for other Lua versions...") | ||
258 | end | ||
259 | |||
244 | -- Check if constraints are satisfiable with other Lua versions. | 260 | -- Check if constraints are satisfiable with other Lua versions. |
245 | local lua_versions = supported_lua_versions(query) | 261 | local lua_versions = supported_lua_versions(query, cli) |
246 | 262 | ||
247 | if #lua_versions ~= 0 then | 263 | if #lua_versions ~= 0 then |
248 | -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format | 264 | -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format |
249 | for i, lua_version in ipairs(lua_versions) do | 265 | for i, lua_version in ipairs(lua_versions) do |
250 | lua_versions[i] = "Lua "..lua_version | 266 | lua_versions[i] = "Lua "..lua_version |
251 | end | 267 | end |
252 | 268 | ||
253 | local versions_message = "only "..table.concat(lua_versions, " and ").. | 269 | local versions_message = "only "..table.concat(lua_versions, " and ").. |
254 | " but not Lua "..cfg.lua_version.."." | 270 | " but not Lua "..cfg.lua_version..".\n".. |
255 | 271 | "(To suppress these checks run '".. | |
272 | "luarocks --lua-version="..cfg.lua_version.." config version_check_on_fail false')" | ||
273 | |||
256 | if #query.constraints == 0 then | 274 | if #query.constraints == 0 then |
257 | return nil, query.name.." supports "..versions_message | 275 | return nil, query.name.." supports "..versions_message |
258 | elseif #query.constraints == 1 and query.constraints[1].op == "==" then | 276 | elseif #query.constraints == 1 and query.constraints[1].op == "==" then |
@@ -263,14 +281,10 @@ function search.find_suitable_rock(query) | |||
263 | end | 281 | end |
264 | end | 282 | end |
265 | 283 | ||
266 | return nil, "No results matching query were found." | 284 | return nil, "No results matching query were found for Lua " .. cfg.lua_version .. "." |
267 | elseif next(result_tree, first_rock) then | 285 | elseif next(result_tree, first_rock) then |
268 | -- Shouldn't happen as query must match only one package. | 286 | -- Shouldn't happen as query must match only one package. |
269 | return nil, "Several rocks matched query." | 287 | return nil, "Several rocks matched query." |
270 | elseif cfg.rocks_provided[query.name] ~= nil then | ||
271 | -- Do not install versions listed in cfg.rocks_provided. | ||
272 | return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. | ||
273 | " was found but it is provided by VM or 'rocks_provided' in the config file." | ||
274 | else | 288 | else |
275 | return pick_latest_version(query.name, result_tree[first_rock]) | 289 | return pick_latest_version(query.name, result_tree[first_rock]) |
276 | end | 290 | end |