diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-11-23 01:18:25 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-23 01:18:25 -0300 |
| commit | f3bb9d5e34a178a2d40e409970c0f60aa13fe657 (patch) | |
| tree | 312af42e1a8eb578c6cac725d43580b66657e003 | |
| parent | bd98e53f02c76755c17235f1c38151816460f108 (diff) | |
| download | luarocks-f3bb9d5e34a178a2d40e409970c0f60aa13fe657.tar.gz luarocks-f3bb9d5e34a178a2d40e409970c0f60aa13fe657.tar.bz2 luarocks-f3bb9d5e34a178a2d40e409970c0f60aa13fe657.zip | |
Add --check-lua-versions flag (#1115)
Only check for availability of a rock for other Lua versions
if the user explicitly requests so.
| -rw-r--r-- | src/luarocks/build.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/cmd/build.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/cmd/download.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/cmd/install.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/cmd/make.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/cmd/unpack.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/download.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 92 |
10 files changed, 71 insertions, 49 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 948c5f53..fe8a815e 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -20,6 +20,7 @@ build.opts = util.opts_table("build.opts", { | |||
| 20 | namespace = "string?", | 20 | namespace = "string?", |
| 21 | branch = "string?", | 21 | branch = "string?", |
| 22 | verify = "boolean", | 22 | verify = "boolean", |
| 23 | check_lua_versions = "boolean", | ||
| 23 | }) | 24 | }) |
| 24 | 25 | ||
| 25 | do | 26 | do |
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 1819d0da..6b30666b 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
| @@ -79,7 +79,7 @@ local function do_build(ns_name, version, opts) | |||
| 79 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then | 79 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then |
| 80 | url = ns_name | 80 | url = ns_name |
| 81 | else | 81 | else |
| 82 | url, err = search.find_src_or_rockspec(ns_name, version, true) | 82 | url, err = search.find_src_or_rockspec(ns_name, version, opts.check_lua_versions) |
| 83 | if not url then | 83 | if not url then |
| 84 | return nil, err | 84 | return nil, err |
| 85 | end | 85 | end |
| @@ -123,6 +123,7 @@ function cmd_build.command(args) | |||
| 123 | namespace = args.namespace, | 123 | namespace = args.namespace, |
| 124 | branch = args.branch, | 124 | branch = args.branch, |
| 125 | verify = not not args.verify, | 125 | verify = not not args.verify, |
| 126 | check_lua_versions = not not args.check_lua_versions, | ||
| 126 | }) | 127 | }) |
| 127 | 128 | ||
| 128 | if args.sign and not args.pack_binary_rock then | 129 | if args.sign and not args.pack_binary_rock then |
diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua index 5032d580..4beecdc3 100644 --- a/src/luarocks/cmd/download.lua +++ b/src/luarocks/cmd/download.lua | |||
| @@ -19,6 +19,8 @@ function cmd_download.add_to_parser(parser) | |||
| 19 | cmd:flag("--source", "Download .src.rock if available."), | 19 | cmd:flag("--source", "Download .src.rock if available."), |
| 20 | cmd:flag("--rockspec", "Download .rockspec if available."), | 20 | cmd:flag("--rockspec", "Download .rockspec if available."), |
| 21 | cmd:option("--arch", "Download rock for a specific architecture.")) | 21 | cmd:option("--arch", "Download rock for a specific architecture.")) |
| 22 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 23 | "and report if it is available for another Lua version.") | ||
| 22 | end | 24 | end |
| 23 | 25 | ||
| 24 | --- Driver function for the "download" command. | 26 | --- Driver function for the "download" command. |
| @@ -43,7 +45,7 @@ function cmd_download.command(args) | |||
| 43 | arch = args.arch | 45 | arch = args.arch |
| 44 | end | 46 | end |
| 45 | 47 | ||
| 46 | local dl, err = download.download(arch, name:lower(), args.version, args.all) | 48 | local dl, err = download.download(arch, name:lower(), args.version, args.all, args.check_lua_versions) |
| 47 | return dl and true, err | 49 | return dl and true, err |
| 48 | end | 50 | end |
| 49 | 51 | ||
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index b4c87f7c..0fcec4ad 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
| @@ -39,6 +39,8 @@ function install.add_to_parser(parser) | |||
| 39 | "file should be already available locally in the same directory.\n".. | 39 | "file should be already available locally in the same directory.\n".. |
| 40 | "You need the signer’s public key in your local keyring for this ".. | 40 | "You need the signer’s public key in your local keyring for this ".. |
| 41 | "option to work properly.") | 41 | "option to work properly.") |
| 42 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 43 | "and report if it is available for another Lua version.") | ||
| 42 | util.deps_mode_option(cmd) | 44 | util.deps_mode_option(cmd) |
| 43 | -- luarocks build options | 45 | -- luarocks build options |
| 44 | parser:flag("--pack-binary-rock"):hidden(true) | 46 | parser:flag("--pack-binary-rock"):hidden(true) |
| @@ -236,7 +238,9 @@ function install.command(args) | |||
| 236 | return install_rock_file(args.rock, opts) | 238 | return install_rock_file(args.rock, opts) |
| 237 | end | 239 | end |
| 238 | else | 240 | else |
| 239 | local url, err = search.find_suitable_rock(queries.new(args.rock:lower(), args.version), true) | 241 | local url, err = search.find_rock_checking_lua_versions( |
| 242 | queries.new(args.rock:lower(), args.version), | ||
| 243 | args.check_lua_versions) | ||
| 240 | if not url then | 244 | if not url then |
| 241 | return nil, err | 245 | return nil, err |
| 242 | end | 246 | end |
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 0a1f99f0..74de6f26 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua | |||
| @@ -35,6 +35,8 @@ function make.cmd_options(parser) | |||
| 35 | "option to work properly.") | 35 | "option to work properly.") |
| 36 | parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. | 36 | parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. |
| 37 | "signature file for the generated .rock file.") | 37 | "signature file for the generated .rock file.") |
| 38 | parser:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 39 | "and report if it is available for another Lua version.") | ||
| 38 | util.deps_mode_option(parser) | 40 | util.deps_mode_option(parser) |
| 39 | end | 41 | end |
| 40 | 42 | ||
| @@ -94,6 +96,7 @@ function make.command(args) | |||
| 94 | namespace = args.namespace, | 96 | namespace = args.namespace, |
| 95 | branch = args.branch, | 97 | branch = args.branch, |
| 96 | verify = not not args.verify, | 98 | verify = not not args.verify, |
| 99 | check_lua_versions = not not args.check_lua_versions, | ||
| 97 | }) | 100 | }) |
| 98 | 101 | ||
| 99 | if args.sign and not args.pack_binary_rock then | 102 | if args.sign and not args.pack_binary_rock then |
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index fe0535e4..c2b5b983 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua | |||
| @@ -23,6 +23,8 @@ In the latter case, the rock version may be given as a second argument.]], | |||
| 23 | :args("?") | 23 | :args("?") |
| 24 | 24 | ||
| 25 | cmd:flag("--force", "Unpack files even if the output directory already exists.") | 25 | cmd:flag("--force", "Unpack files even if the output directory already exists.") |
| 26 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | ||
| 27 | "and report if it is available for another Lua version.") | ||
| 26 | end | 28 | end |
| 27 | 29 | ||
| 28 | --- Load a rockspec file to the given directory, fetches the source | 30 | --- Load a rockspec file to the given directory, fetches the source |
| @@ -155,7 +157,7 @@ function unpack.command(args) | |||
| 155 | if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then | 157 | if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then |
| 156 | url = ns_name | 158 | url = ns_name |
| 157 | else | 159 | else |
| 158 | url, err = search.find_src_or_rockspec(ns_name, args.version, true) | 160 | url, err = search.find_src_or_rockspec(ns_name, args.version, args.check_lua_versions) |
| 159 | if not url then | 161 | if not url then |
| 160 | return nil, err | 162 | return nil, err |
| 161 | end | 163 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 4e1b5108..e26c263c 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -191,7 +191,6 @@ local function make_defaults(lua_version, target_cpu, platforms, home) | |||
| 191 | 191 | ||
| 192 | cache_timeout = 60, | 192 | cache_timeout = 60, |
| 193 | cache_fail_timeout = 86400, | 193 | cache_fail_timeout = 86400, |
| 194 | version_check_on_fail = true, | ||
| 195 | 194 | ||
| 196 | lua_modules_path = "/share/lua/"..lua_version, | 195 | lua_modules_path = "/share/lua/"..lua_version, |
| 197 | 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 cb85764e..7f695d9c 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, true) | 168 | local url, search_err = search.find_suitable_rock(dep) |
| 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 0620be68..145fefed 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
| @@ -21,7 +21,7 @@ local function get_file(filename) | |||
| 21 | end | 21 | end |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | function download.download(arch, name, version, all) | 24 | function download.download(arch, name, version, all, check_lua_versions) |
| 25 | local substring = (all and name == "") | 25 | local substring = (all and name == "") |
| 26 | local query = queries.new(name, version, substring, arch) | 26 | local query = queries.new(name, version, substring, arch) |
| 27 | local search_err | 27 | local search_err |
| @@ -53,7 +53,7 @@ function download.download(arch, name, version, all) | |||
| 53 | end | 53 | end |
| 54 | else | 54 | else |
| 55 | local url | 55 | local url |
| 56 | url, search_err = search.find_suitable_rock(query, true) | 56 | url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) |
| 57 | if url then | 57 | if url then |
| 58 | return get_file(url) | 58 | return get_file(url) |
| 59 | end | 59 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 9b13b7cc..efe3b9c9 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
| @@ -205,17 +205,14 @@ 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 | ||
| 209 | -- @return table: array of Lua versions supported, in "5.x" format. | 208 | -- @return table: array of Lua versions supported, in "5.x" format. |
| 210 | local function supported_lua_versions(query, cli) | 209 | local function supported_lua_versions(query) |
| 211 | assert(query:type() == "query") | 210 | assert(query:type() == "query") |
| 212 | local result_tree = {} | 211 | local result_tree = {} |
| 213 | 212 | ||
| 214 | for lua_version in util.lua_versions() do | 213 | for lua_version in util.lua_versions() do |
| 215 | if lua_version ~= cfg.lua_version then | 214 | if lua_version ~= cfg.lua_version then |
| 216 | if cli then | 215 | util.printout("Checking for Lua " .. lua_version .. "...") |
| 217 | util.printout("Checking for Lua " .. lua_version .. "...") | ||
| 218 | end | ||
| 219 | if search.search_repos(query, lua_version)[query.name] then | 216 | if search.search_repos(query, lua_version)[query.name] then |
| 220 | table.insert(result_tree, lua_version) | 217 | table.insert(result_tree, lua_version) |
| 221 | end | 218 | end |
| @@ -225,21 +222,12 @@ local function supported_lua_versions(query, cli) | |||
| 225 | return result_tree | 222 | return result_tree |
| 226 | end | 223 | end |
| 227 | 224 | ||
| 228 | function search.find_src_or_rockspec(ns_name, version, cli) | ||
| 229 | local query = queries.new(ns_name, version, false, "src|rockspec") | ||
| 230 | local url, err = search.find_suitable_rock(query, cli) | ||
| 231 | if not url then | ||
| 232 | return nil, "Could not find a result named "..tostring(query)..": "..err | ||
| 233 | end | ||
| 234 | return url | ||
| 235 | end | ||
| 236 | |||
| 237 | --- Attempt to get a single URL for a given search for a rock. | 225 | --- Attempt to get a single URL for a given search for a rock. |
| 238 | -- @param query table: a query object. | 226 | -- @param query table: a query object. |
| 239 | -- @param cli boolean: print status messages as it works | 227 | -- @return string or (nil, string, string): URL for latest matching version |
| 240 | -- @return string or (nil, string): URL for latest matching version | 228 | -- 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. | 229 | -- and an error code. |
| 242 | function search.find_suitable_rock(query, cli) | 230 | function search.find_suitable_rock(query) |
| 243 | assert(query:type() == "query") | 231 | assert(query:type() == "query") |
| 244 | 232 | ||
| 245 | local rocks_provided = util.get_rocks_provided() | 233 | local rocks_provided = util.get_rocks_provided() |
| @@ -247,49 +235,71 @@ function search.find_suitable_rock(query, cli) | |||
| 247 | if rocks_provided[query.name] ~= nil then | 235 | if rocks_provided[query.name] ~= nil then |
| 248 | -- Do not install versions listed in rocks_provided. | 236 | -- Do not install versions listed in rocks_provided. |
| 249 | return nil, "Rock "..query.name.." "..rocks_provided[query.name].. | 237 | return nil, "Rock "..query.name.." "..rocks_provided[query.name].. |
| 250 | " is already provided by VM or via 'rocks_provided' in the config file." | 238 | " is already provided by VM or via 'rocks_provided' in the config file.", "provided" |
| 251 | end | 239 | end |
| 252 | 240 | ||
| 253 | local result_tree = search.search_repos(query) | 241 | local result_tree = search.search_repos(query) |
| 254 | local first_rock = next(result_tree) | 242 | local first_rock = next(result_tree) |
| 255 | if not first_rock then | 243 | if not first_rock then |
| 256 | if cfg.version_check_on_fail then | 244 | return nil, "No results matching query were found for Lua " .. cfg.lua_version .. ".", "notfound" |
| 257 | if cli then | 245 | elseif next(result_tree, first_rock) then |
| 258 | util.printout(query.name .. " not found for Lua " .. cfg.lua_version .. ".") | 246 | -- Shouldn't happen as query must match only one package. |
| 259 | util.printout("Checking if available for other Lua versions...") | 247 | return nil, "Several rocks matched query.", "manyfound" |
| 260 | end | 248 | else |
| 249 | return pick_latest_version(query.name, result_tree[first_rock]) | ||
| 250 | end | ||
| 251 | end | ||
| 252 | |||
| 253 | function search.find_src_or_rockspec(ns_name, version, check_lua_versions) | ||
| 254 | local query = queries.new(ns_name, version, false, "src|rockspec") | ||
| 255 | local url, err = search.find_rock_checking_lua_versions(query, check_lua_versions) | ||
| 256 | if not url then | ||
| 257 | return nil, "Could not find a result named "..tostring(query)..": "..err | ||
| 258 | end | ||
| 259 | return url | ||
| 260 | end | ||
| 261 | |||
| 262 | function search.find_rock_checking_lua_versions(query, check_lua_versions) | ||
| 263 | local url, err, errcode = search.find_suitable_rock(query) | ||
| 264 | if url then | ||
| 265 | return url | ||
| 266 | end | ||
| 267 | |||
| 268 | if errcode == "notfound" then | ||
| 269 | local add | ||
| 270 | if check_lua_versions then | ||
| 271 | util.printout(query.name .. " not found for Lua " .. cfg.lua_version .. ".") | ||
| 272 | util.printout("Checking if available for other Lua versions...") | ||
| 261 | 273 | ||
| 262 | -- Check if constraints are satisfiable with other Lua versions. | 274 | -- Check if constraints are satisfiable with other Lua versions. |
| 263 | local lua_versions = supported_lua_versions(query, cli) | 275 | local lua_versions = supported_lua_versions(query) |
| 264 | 276 | ||
| 265 | if #lua_versions ~= 0 then | 277 | if #lua_versions ~= 0 then |
| 266 | -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format | 278 | -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format |
| 267 | for i, lua_version in ipairs(lua_versions) do | 279 | for i, lua_version in ipairs(lua_versions) do |
| 268 | lua_versions[i] = "Lua "..lua_version | 280 | lua_versions[i] = "Lua "..lua_version |
| 269 | end | 281 | end |
| 270 | 282 | ||
| 271 | local versions_message = "only "..table.concat(lua_versions, " and ").. | 283 | local versions_message = "only "..table.concat(lua_versions, " and ").. |
| 272 | " but not Lua "..cfg.lua_version..".\n".. | 284 | " but not Lua "..cfg.lua_version.."." |
| 273 | "(To suppress these checks run '".. | 285 | |
| 274 | "luarocks --lua-version="..cfg.lua_version.." config version_check_on_fail false')" | ||
| 275 | |||
| 276 | if #query.constraints == 0 then | 286 | if #query.constraints == 0 then |
| 277 | return nil, query.name.." supports "..versions_message | 287 | add = query.name.." supports "..versions_message |
| 278 | elseif #query.constraints == 1 and query.constraints[1].op == "==" then | 288 | elseif #query.constraints == 1 and query.constraints[1].op == "==" then |
| 279 | return nil, query.name.." "..query.constraints[1].version.string.." supports "..versions_message | 289 | add = query.name.." "..query.constraints[1].version.string.." supports "..versions_message |
| 280 | else | 290 | else |
| 281 | return nil, "Matching "..query.name.." versions support "..versions_message | 291 | add = "Matching "..query.name.." versions support "..versions_message |
| 282 | end | 292 | end |
| 293 | else | ||
| 294 | add = query.name.." is not available for any Lua versions." | ||
| 283 | end | 295 | end |
| 296 | else | ||
| 297 | add = "To check if it is available for other Lua versions, use --check-lua-versions." | ||
| 284 | end | 298 | end |
| 285 | 299 | err = err .. "\n" .. add | |
| 286 | return nil, "No results matching query were found for Lua " .. cfg.lua_version .. "." | ||
| 287 | elseif next(result_tree, first_rock) then | ||
| 288 | -- Shouldn't happen as query must match only one package. | ||
| 289 | return nil, "Several rocks matched query." | ||
| 290 | else | ||
| 291 | return pick_latest_version(query.name, result_tree[first_rock]) | ||
| 292 | end | 300 | end |
| 301 | |||
| 302 | return nil, err | ||
| 293 | end | 303 | end |
| 294 | 304 | ||
| 295 | --- Print a list of rocks/rockspecs on standard output. | 305 | --- Print a list of rocks/rockspecs on standard output. |
