From 208c5528289b2f69f03b70a1ea6f979d675882a9 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 3 Apr 2019 13:58:47 -0300 Subject: search: add report and opt-out for checking other Lua versions --- src/luarocks/cmd/build.lua | 2 +- src/luarocks/cmd/install.lua | 2 +- src/luarocks/cmd/unpack.lua | 2 +- src/luarocks/core/cfg.lua | 1 + src/luarocks/deps.lua | 2 +- src/luarocks/download.lua | 3 +-- src/luarocks/search.lua | 44 +++++++++++++++++++++++++++++--------------- 7 files changed, 35 insertions(+), 21 deletions(-) (limited to 'src') 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) if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then url = ns_name else - url, err = search.find_src_or_rockspec(ns_name, version) + url, err = search.find_src_or_rockspec(ns_name, version, true) if not url then return nil, err 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) return install_rock_file(name, opts) end else - local url, err = search.find_suitable_rock(queries.new(name:lower(), version)) + local url, err = search.find_suitable_rock(queries.new(name:lower(), version), true) if not url then return nil, err 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) if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then url = ns_name else - url, err = search.find_src_or_rockspec(ns_name, version) + url, err = search.find_src_or_rockspec(ns_name, version, true) if not url then return nil, err 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) check_certificates = false, cache_timeout = 10, + version_check_on_fail = true, lua_modules_path = "/share/lua/"..lua_version, 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, return nil, "Failed matching dependencies" end - local url, search_err = search.find_suitable_rock(dep) + local url, search_err = search.find_suitable_rock(dep, true) if not url then return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err 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") local queries = require("luarocks.queries") local fs = require("luarocks.fs") local dir = require("luarocks.dir") -local cfg = require("luarocks.core.cfg") local function get_file(filename) local protocol, pathname = dir.split_url(filename) @@ -54,7 +53,7 @@ function download.download(arch, name, version, all) end else local url - url, search_err = search.find_suitable_rock(query) + url, search_err = search.find_suitable_rock(query, true) if url then return get_file(url) 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 -- Find out which other Lua versions provide rock versions matching a query, -- @param query table: a query object. +-- @param cli boolean: print status messages as it works -- @return table: array of Lua versions supported, in "5.x" format. -local function supported_lua_versions(query) +local function supported_lua_versions(query, cli) assert(query:type() == "query") local result_tree = {} for lua_version in util.lua_versions() do if lua_version ~= cfg.lua_version then + if cli then + util.printout("Checking for Lua " .. lua_version .. "...") + end if search.search_repos(query, lua_version)[query.name] then table.insert(result_tree, lua_version) end @@ -221,9 +225,9 @@ local function supported_lua_versions(query) return result_tree end -function search.find_src_or_rockspec(ns_name, version) +function search.find_src_or_rockspec(ns_name, version, cli) local query = queries.new(ns_name, version, false, "src|rockspec") - local url, err = search.find_suitable_rock(query) + local url, err = search.find_suitable_rock(query, cli) if not url then return nil, "Could not find a result named "..tostring(query)..": "..err end @@ -232,27 +236,41 @@ end --- Attempt to get a single URL for a given search for a rock. -- @param query table: a query object. +-- @param cli boolean: print status messages as it works -- @return string or (nil, string): URL for latest matching version -- of the rock if it was found, or nil followed by an error message. -function search.find_suitable_rock(query) +function search.find_suitable_rock(query, cli) assert(query:type() == "query") + + if cfg.rocks_provided[query.name] ~= nil then + -- Do not install versions listed in cfg.rocks_provided. + return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. + " is already provided by VM or via 'rocks_provided' in the config file." + end local result_tree = search.search_repos(query) local first_rock = next(result_tree) if not first_rock then - if cfg.rocks_provided[query.name] == nil then + if cfg.version_check_on_fail then + if cli then + util.printout(query.name .. " not found for Lua " .. cfg.lua_version .. ".") + util.printout("Checking if available for other Lua versions...") + end + -- Check if constraints are satisfiable with other Lua versions. - local lua_versions = supported_lua_versions(query) - + local lua_versions = supported_lua_versions(query, cli) + if #lua_versions ~= 0 then -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format for i, lua_version in ipairs(lua_versions) do lua_versions[i] = "Lua "..lua_version end - + local versions_message = "only "..table.concat(lua_versions, " and ").. - " but not Lua "..cfg.lua_version.."." - + " but not Lua "..cfg.lua_version..".\n".. + "(To suppress these checks run '".. + "luarocks --lua-version="..cfg.lua_version.." config version_check_on_fail false')" + if #query.constraints == 0 then return nil, query.name.." supports "..versions_message elseif #query.constraints == 1 and query.constraints[1].op == "==" then @@ -263,14 +281,10 @@ function search.find_suitable_rock(query) end end - return nil, "No results matching query were found." + return nil, "No results matching query were found for Lua " .. cfg.lua_version .. "." elseif next(result_tree, first_rock) then -- Shouldn't happen as query must match only one package. return nil, "Several rocks matched query." - elseif cfg.rocks_provided[query.name] ~= nil then - -- Do not install versions listed in cfg.rocks_provided. - return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. - " was found but it is provided by VM or 'rocks_provided' in the config file." else return pick_latest_version(query.name, result_tree[first_rock]) end -- cgit v1.2.3-55-g6feb