diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-09-07 01:06:53 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-09-07 02:42:15 +0300 |
commit | ea49b058fb0a2f48ab8b3e3aa2879bbd01a412c9 (patch) | |
tree | 84de07f880d83b3468b8b94b5f7780922d1dc8b4 | |
parent | 5b0d8ff87f53c368861a8913df1861c3940df1ea (diff) | |
download | luarocks-ea49b058fb0a2f48ab8b3e3aa2879bbd01a412c9.tar.gz luarocks-ea49b058fb0a2f48ab8b3e3aa2879bbd01a412c9.tar.bz2 luarocks-ea49b058fb0a2f48ab8b3e3aa2879bbd01a412c9.zip |
cmd: look for proper Lua version in $PATH when --lua-version is given
-rw-r--r-- | src/luarocks/cmd.lua | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index f85821a5..fc98e45f 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -35,16 +35,16 @@ local function is_ownership_ok(directory) | |||
35 | return false | 35 | return false |
36 | end | 36 | end |
37 | 37 | ||
38 | do | 38 | local function exists(file) |
39 | local function exists(file) | 39 | local fd = io.open(file, "r") |
40 | local fd = io.open(file, "r") | 40 | if fd then |
41 | if fd then | 41 | fd:close() |
42 | fd:close() | 42 | return true |
43 | return true | ||
44 | end | ||
45 | return false | ||
46 | end | 43 | end |
47 | 44 | return false | |
45 | end | ||
46 | |||
47 | do | ||
48 | local function Q(pathname) | 48 | local function Q(pathname) |
49 | if pathname:match("^.:") then | 49 | if pathname:match("^.:") then |
50 | return pathname:sub(1, 2) .. '"' .. pathname:sub(3) .. '"' | 50 | return pathname:sub(1, 2) .. '"' .. pathname:sub(3) .. '"' |
@@ -363,6 +363,11 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
363 | die("Invalid entry for --deps-mode.") | 363 | die("Invalid entry for --deps-mode.") |
364 | end | 364 | end |
365 | 365 | ||
366 | local project_dir | ||
367 | if flags["project-tree"] then | ||
368 | project_dir = flags["project-tree"]:gsub("[/\\][^/\\]+$", "") | ||
369 | end | ||
370 | |||
366 | local lua_data | 371 | local lua_data |
367 | if flags["lua-dir"] then | 372 | if flags["lua-dir"] then |
368 | local err | 373 | local err |
@@ -371,16 +376,34 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
371 | die(err) | 376 | die(err) |
372 | end | 377 | end |
373 | elseif flags["lua-version"] then | 378 | elseif flags["lua-version"] then |
379 | local path_sep = (package.config:sub(1, 1) == "\\" and ";" or ":") | ||
380 | for bindir in os.getenv("PATH"):gmatch("[^"..path_sep.."]+") do | ||
381 | local parentdir = bindir:gsub("[\\/][^\\/]+[\\/]?$", "") | ||
382 | lua_data = cmd.find_lua(dir.path(parentdir), flags["lua-version"]) | ||
383 | if lua_data then | ||
384 | break | ||
385 | end | ||
386 | lua_data = cmd.find_lua(bindir, flags["lua-version"]) | ||
387 | if lua_data then | ||
388 | break | ||
389 | end | ||
390 | end | ||
391 | if not lua_data then | ||
392 | die("Could not find a Lua interpreter for version " .. flags["lua-version"] .. " in your PATH") | ||
393 | end | ||
394 | elseif project_dir then | ||
395 | local lua_version | ||
396 | for v in util.lua_versions("descending") do | ||
397 | if exists(dir.path(project_dir, ".luarocks", "config-"..v..".lua")) then | ||
398 | lua_version = v | ||
399 | break | ||
400 | end | ||
401 | end | ||
374 | lua_data = { | 402 | lua_data = { |
375 | lua_version = flags["lua-version"] | 403 | lua_version = lua_version |
376 | } | 404 | } |
377 | end | 405 | end |
378 | 406 | ||
379 | local project_dir | ||
380 | if flags["project-tree"] then | ||
381 | project_dir = flags["project-tree"]:gsub("[/\\][^/\\]+$", "") | ||
382 | end | ||
383 | |||
384 | -- FIXME A quick hack for the experimental Windows build | 407 | -- FIXME A quick hack for the experimental Windows build |
385 | if os.getenv("LUAROCKS_CROSS_COMPILING") then | 408 | if os.getenv("LUAROCKS_CROSS_COMPILING") then |
386 | cfg.each_platform = function() | 409 | cfg.each_platform = function() |