diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-20 14:20:54 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 15:51:13 -0300 |
| commit | b51e98582dd8b59a15bd0dcbf469c05d01c3e045 (patch) | |
| tree | 6734a1361a9729428b4fc7a8694abfd5a92ad058 /src | |
| parent | 744df0e5bf1ed712478c3df6aa28901f38d7189f (diff) | |
| download | luarocks-b51e98582dd8b59a15bd0dcbf469c05d01c3e045.tar.gz luarocks-b51e98582dd8b59a15bd0dcbf469c05d01c3e045.tar.bz2 luarocks-b51e98582dd8b59a15bd0dcbf469c05d01c3e045.zip | |
cmd: ensure that found Lua matches version requested with --lua-version
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd.lua | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 6ce9a8b5..da78c224 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -35,20 +35,6 @@ local function is_ownership_ok(directory) | |||
| 35 | end | 35 | end |
| 36 | 36 | ||
| 37 | do | 37 | do |
| 38 | local function check_lua_version(lua_exe, luaver) | ||
| 39 | local luajitver | ||
| 40 | if not (luaver and luaver:match("^[0-9]")) then | ||
| 41 | luaver = util.popen_read(lua_exe .. ' -e "io.write(_VERSION:sub(5))"') | ||
| 42 | end | ||
| 43 | if luaver == "5.1" then | ||
| 44 | luajitver = util.popen_read(lua_exe .. ' -e "io.write(tostring(jit and jit.version:sub(8)))"') | ||
| 45 | if luajitver == "nil" then | ||
| 46 | luajitver = nil | ||
| 47 | end | ||
| 48 | end | ||
| 49 | return luaver, luajitver | ||
| 50 | end | ||
| 51 | |||
| 52 | local function exists(file) | 38 | local function exists(file) |
| 53 | local fd = io.open(file, "r") | 39 | local fd = io.open(file, "r") |
| 54 | if fd then | 40 | if fd then |
| @@ -58,6 +44,24 @@ do | |||
| 58 | return false | 44 | return false |
| 59 | end | 45 | end |
| 60 | 46 | ||
| 47 | local function check_lua_version(lua_exe, luaver) | ||
| 48 | if not exists(lua_exe) then | ||
| 49 | return nil | ||
| 50 | end | ||
| 51 | local lv = util.popen_read(lua_exe .. ' -e "io.write(_VERSION:sub(5))"') | ||
| 52 | if luaver and luaver ~= lv then | ||
| 53 | return nil | ||
| 54 | end | ||
| 55 | local ljv | ||
| 56 | if lv == "5.1" then | ||
| 57 | ljv = util.popen_read(lua_exe .. ' -e "io.write(tostring(jit and jit.version:sub(8)))"') | ||
| 58 | if ljv == "nil" then | ||
| 59 | ljv = nil | ||
| 60 | end | ||
| 61 | end | ||
| 62 | return lv, ljv | ||
| 63 | end | ||
| 64 | |||
| 61 | local find_lua_bindir | 65 | local find_lua_bindir |
| 62 | do | 66 | do |
| 63 | local exe_suffix = (package.config:sub(1, 1) == "\\" and ".exe" or "") | 67 | local exe_suffix = (package.config:sub(1, 1) == "\\" and ".exe" or "") |
| @@ -93,8 +97,9 @@ do | |||
| 93 | for _, name in ipairs(names) do | 97 | for _, name in ipairs(names) do |
| 94 | local lua_exe = dir.path(d, name) | 98 | local lua_exe = dir.path(d, name) |
| 95 | table.insert(tried, lua_exe) | 99 | table.insert(tried, lua_exe) |
| 96 | if exists(lua_exe) then | 100 | local lv, ljv = check_lua_version(lua_exe, luaver) |
| 97 | return name, d, luaver | 101 | if lv then |
| 102 | return name, d, lv, ljv | ||
| 98 | end | 103 | end |
| 99 | end | 104 | end |
| 100 | end | 105 | end |
| @@ -115,6 +120,7 @@ do | |||
| 115 | 120 | ||
| 116 | for _, d in ipairs(incdirs) do | 121 | for _, d in ipairs(incdirs) do |
| 117 | local lua_h = dir.path(d, "lua.h") | 122 | local lua_h = dir.path(d, "lua.h") |
| 123 | -- TODO check that LUA_VERSION_MAJOR and LUA_VERSION_MINOR match luaver | ||
| 118 | if exists(lua_h) then | 124 | if exists(lua_h) then |
| 119 | return d | 125 | return d |
| 120 | end | 126 | end |
| @@ -124,17 +130,13 @@ do | |||
| 124 | return incdirs[1] | 130 | return incdirs[1] |
| 125 | end | 131 | end |
| 126 | 132 | ||
| 127 | find_lua = function(prefix, luaver) | 133 | function cmd.find_lua(prefix, luaver) |
| 128 | local lua_interpreter, bindir | 134 | local lua_interpreter, bindir, luajitver |
| 129 | lua_interpreter, bindir, luaver = find_lua_bindir(prefix, luaver) | 135 | lua_interpreter, bindir, luaver, luajitver = find_lua_bindir(prefix, luaver) |
| 130 | if not lua_interpreter then | 136 | if not lua_interpreter then |
| 131 | return nil, bindir | 137 | return nil, bindir |
| 132 | end | 138 | end |
| 133 | 139 | ||
| 134 | local luajitver | ||
| 135 | local lua_exe = dir.path(bindir, lua_interpreter) | ||
| 136 | luaver, luajitver = check_lua_version(lua_exe, luaver) | ||
| 137 | |||
| 138 | return { | 140 | return { |
| 139 | lua_version = luaver, | 141 | lua_version = luaver, |
| 140 | luajit_version = luajitver, | 142 | luajit_version = luajitver, |
| @@ -367,7 +369,7 @@ function cmd.run_command(description, commands, ...) | |||
| 367 | 369 | ||
| 368 | local lua_data | 370 | local lua_data |
| 369 | if flags["lua-dir"] then | 371 | if flags["lua-dir"] then |
| 370 | lua_data = find_lua(flags["lua-dir"], flags["lua-version"]) | 372 | lua_data = cmd.find_lua(flags["lua-dir"], flags["lua-version"]) |
| 371 | end | 373 | end |
| 372 | 374 | ||
| 373 | ----------------------------------------------------------------------------- | 375 | ----------------------------------------------------------------------------- |
