diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-08-21 23:48:23 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-08-22 00:04:55 +0300 |
commit | ecfdd47e1b627e916692affe6ea93ba0ac6d4ac8 (patch) | |
tree | c38f07a535e11545acb4c098a7bfd4a4ae88a5b4 /install.bat | |
parent | 112342feb7f6da3b04251f29fd75bb2eb7c26a97 (diff) | |
download | luarocks-ecfdd47e1b627e916692affe6ea93ba0ac6d4ac8.tar.gz luarocks-ecfdd47e1b627e916692affe6ea93ba0ac6d4ac8.tar.bz2 luarocks-ecfdd47e1b627e916692affe6ea93ba0ac6d4ac8.zip |
Autodetect Lua version in install.bat
Diffstat (limited to 'install.bat')
-rw-r--r-- | install.bat | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/install.bat b/install.bat index 32988022..c95967a6 100644 --- a/install.bat +++ b/install.bat | |||
@@ -42,6 +42,8 @@ local NOADMIN = false | |||
42 | local PROMPT = true | 42 | local PROMPT = true |
43 | local SELFCONTAINED = false | 43 | local SELFCONTAINED = false |
44 | 44 | ||
45 | local lua_version_set = false | ||
46 | |||
45 | --- | 47 | --- |
46 | -- Some helpers | 48 | -- Some helpers |
47 | -- | 49 | -- |
@@ -220,6 +222,7 @@ local function parse_options(args) | |||
220 | vars.TREE_CMODULE = option.value | 222 | vars.TREE_CMODULE = option.value |
221 | elseif name == "/LV" then | 223 | elseif name == "/LV" then |
222 | vars.LUA_VERSION = option.value | 224 | vars.LUA_VERSION = option.value |
225 | lua_version_set = true | ||
223 | elseif name == "/L" then | 226 | elseif name == "/L" then |
224 | INSTALL_LUA = true | 227 | INSTALL_LUA = true |
225 | elseif name == "/MW" then | 228 | elseif name == "/MW" then |
@@ -287,8 +290,31 @@ end | |||
287 | -- *********************************************************** | 290 | -- *********************************************************** |
288 | -- Detect Lua | 291 | -- Detect Lua |
289 | -- *********************************************************** | 292 | -- *********************************************************** |
293 | local function detect_lua_version(interpreter_path) | ||
294 | local handler = io.popen(('type NUL && "%s" -e "io.stdout:write(_VERSION)" 2>NUL'):format(interpreter_path), "r") | ||
295 | if not handler then | ||
296 | return nil, "interpreter does not work" | ||
297 | end | ||
298 | local full_version = handler:read("*a") | ||
299 | handler:close() | ||
300 | |||
301 | local version = full_version:match("^Lua (5%.[123])$") | ||
302 | if not version then | ||
303 | return nil, "unknown interpreter version '" .. full_version .. "'" | ||
304 | end | ||
305 | return version | ||
306 | end | ||
307 | |||
290 | local function look_for_interpreter(directory) | 308 | local function look_for_interpreter(directory) |
291 | local names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe", "lua.exe", "luajit.exe"} | 309 | local names |
310 | if lua_version_set then | ||
311 | names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe"} | ||
312 | else | ||
313 | names = {"lua5.3.exe", "lua53.exe", "lua5.2.exe", "lua52.exe", "lua5.1.exe", "lua51.exe"} | ||
314 | end | ||
315 | table.insert(names, "lua.exe") | ||
316 | table.insert(names, "luajit.exe") | ||
317 | |||
292 | local directories | 318 | local directories |
293 | if vars.LUA_BINDIR then | 319 | if vars.LUA_BINDIR then |
294 | -- If LUA_BINDIR is specified, look only in that directory. | 320 | -- If LUA_BINDIR is specified, look only in that directory. |
@@ -302,16 +328,31 @@ local function look_for_interpreter(directory) | |||
302 | for _, name in ipairs(names) do | 328 | for _, name in ipairs(names) do |
303 | local full_name = dir .. "\\" .. name | 329 | local full_name = dir .. "\\" .. name |
304 | if exists(full_name) then | 330 | if exists(full_name) then |
305 | vars.LUA_INTERPRETER = name | 331 | print(" Found " .. name .. ", testing it...") |
306 | vars.LUA_BINDIR = dir | 332 | local version, err = detect_lua_version(full_name) |
307 | print(" Found " .. full_name) | 333 | if not version then |
308 | return true | 334 | print(" Error: " .. err) |
335 | else | ||
336 | if version ~= vars.LUA_VERSION then | ||
337 | if lua_version_set then | ||
338 | die("Version of interpreter clashes with the value of /LV. Please check your configuration.") | ||
339 | else | ||
340 | vars.LUA_VERSION = version | ||
341 | vars.LUA_SHORTV = version:gsub("%.", "") | ||
342 | vars.LUA_LIB_NAMES = vars.LUA_LIB_NAMES:gsub("5([%.]?)[123]", "5%1" .. version:sub(-1)) | ||
343 | end | ||
344 | end | ||
345 | |||
346 | vars.LUA_INTERPRETER = name | ||
347 | vars.LUA_BINDIR = dir | ||
348 | return true | ||
349 | end | ||
309 | end | 350 | end |
310 | end | 351 | end |
311 | end | 352 | end |
312 | 353 | ||
313 | if vars.LUA_BINDIR then | 354 | if vars.LUA_BINDIR then |
314 | die(S"Lua executable lua.exe, luajit.exe, lua$LUA_SHORTV.exe or lua$LUA_VERSION.exe not found in $LUA_BINDIR") | 355 | die(("Working Lua executable (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_BINDIR)) |
315 | end | 356 | end |
316 | return false | 357 | return false |
317 | end | 358 | end |
@@ -559,12 +600,8 @@ local function look_for_lua_install () | |||
559 | look_for_headers(vars.LUA_INCDIR) | 600 | look_for_headers(vars.LUA_INCDIR) |
560 | then | 601 | then |
561 | if get_runtime() then | 602 | if get_runtime() then |
562 | print("Runtime check completed, now testing interpreter...") | 603 | print("Runtime check completed.") |
563 | if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then | 604 | return true |
564 | print(" Ok") | ||
565 | return true | ||
566 | end | ||
567 | print(" Interpreter returned an error, not ok") | ||
568 | end | 605 | end |
569 | end | 606 | end |
570 | return false | 607 | return false |
@@ -580,12 +617,8 @@ local function look_for_lua_install () | |||
580 | if look_for_headers(directory) then | 617 | if look_for_headers(directory) then |
581 | print("Headers found, checking runtime to use...") | 618 | print("Headers found, checking runtime to use...") |
582 | if get_runtime() then | 619 | if get_runtime() then |
583 | print("Runtime check completed, now testing interpreter...") | 620 | print("Runtime check completed.") |
584 | if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then | 621 | return true |
585 | print(" Ok") | ||
586 | return true | ||
587 | end | ||
588 | print(" Interpreter returned an error, not ok") | ||
589 | end | 622 | end |
590 | end | 623 | end |
591 | end | 624 | end |