From 37aded056fae788088855b36281b1d23b0131fdb Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 9 Mar 2012 21:36:20 -0300 Subject: Further steps for Lua 5.2 support --- Makefile | 2 +- configure | 120 ++++++++++++++++++++++++++++------------ src/luarocks/cfg.lua | 25 +++++---- src/luarocks/deps.lua | 4 +- src/luarocks/fs/lua.lua | 5 +- src/luarocks/fs/unix/tools.lua | 3 +- src/luarocks/fs/win32/tools.lua | 3 +- src/luarocks/persist.lua | 21 +++++-- 8 files changed, 123 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index 7c1cb252..6b1ff98f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PREFIX ?= /usr/local ROCKS_TREE ?= $(PREFIX) SYSCONFDIR ?= $(PREFIX)/etc/luarocks BINDIR ?= $(PREFIX)/bin -LUADIR ?= $(PREFIX)/share/lua/5.1/ +LUADIR ?= $(PREFIX)/share/lua/$(LUA_VERSION)/ LUA_DIR ?= /usr/local LUA_BINDIR ?= $(LUA_DIR)/bin diff --git a/configure b/configure index 2be69a68..041a1dc8 100755 --- a/configure +++ b/configure @@ -13,6 +13,7 @@ LUA_DIR="/usr" LUA_BINDIR="/usr/bin" LUA_INCDIR="/usr/include" LUA_LIBDIR="/usr/lib" +LUA_VERSION="5.1" # ---------------------------------------------------------------------------- # FUNCTION DEFINITIONS @@ -37,6 +38,8 @@ system's package manager. --rocks-tree=FILE Root of the local tree of installed rocks. Default is \$PREFIX +--lua-version=VERSION Use specific Lua version: 5.1 or 5.2 (EXPERIMENTAL) + Default is "$LUA_VERSION" --lua-suffix=SUFFIX Versioning suffix to use in Lua filenames. Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...) --with-lua=PREFIX Use Lua from given prefix. @@ -83,6 +86,14 @@ find_program() { fi } +die() { + echo "$*" + echo + echo "configure failed." + echo + exit 1 +} + find_helper() { explanation="$1" shift @@ -99,8 +110,7 @@ find_helper() { shift done echo "Could not find a $explanation. Tried: $tried." - echo "Make sure one of them is installed and available in your PATH." - exit 1 + die "Make sure one of them is installed and available in your PATH." } case `echo -n x` in @@ -112,11 +122,6 @@ echo_n() { echo $echo_n_flag "$*" } -die() { - echo "$*" - exit 1 -} - # ---------------------------------------------------------------------------- # MAIN PROGRAM # ---------------------------------------------------------------------------- @@ -162,6 +167,12 @@ do LUA_SUFFIX="$value" LUA_SUFFIX_SET=yes ;; + --lua-version) + [ -n "$value" ] || die "Missing value in flag $key." + LUA_VERSION="$value" + [ "$LUA_VERSION" = "5.1" -o "$LUA_VERSION" = "5.2" ] || die "Invalid Lua version in flag $key." + LUA_VERSION_SET=yes + ;; --with-lua) [ -n "$value" ] || die "Missing value in flag $key." LUA_DIR="$value" @@ -181,7 +192,7 @@ do [ -n "$value" ] || die "Missing value in flag $key." case "$value" in wget|curl) LUAROCKS_DOWNLOADER="$value" ;; - *) echo "Invalid option: $value. See --help." ; exit 1 ;; + *) die "Invalid option: $value. See --help." ;; esac LUAROCKS_DOWNLOADER_SET=yes ;; @@ -189,19 +200,17 @@ do [ -n "$value" ] || die "Missing value in flag $key." case "$value" in md5sum|openssl|md5) LUAROCKS_MD5CHECKER="$value" ;; - *) echo "Invalid option: $value. See --help." ; exit 1 ;; + *) die "Invalid option: $value. See --help." ;; esac LUAROCKS_MD5CHECKER_SET=yes ;; *) - echo "Error: Unknown flag: $1" - exit 1 + die "Error: Unknown flag: $1" ;; esac shift done - if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ] then if [ "$PREFIX" = "/usr" ] @@ -216,28 +225,70 @@ then ROCKS_TREE=$PREFIX fi -if [ "$LUA_SUFFIX_SET" != "yes" ] -then - for suffix in "" "5.1" "51" "" - do - LUA_SUFFIX="$suffix" - if [ "$LUA_DIR_SET" = "yes" ] +detect_lua_version() { + detected_lua=`$1 -e 'print(_VERSION:sub(5))' 2> /dev/null` + if [ "$detected_lua" = "5.1" -o "$detected_lua" = "5.2" ] + then + echo "Lua version detected: $detected_lua" + if [ "$LUA_VERSION_SET" != "yes" ] + then + LUA_VERSION=$detected_lua + elif [ "$LUA_VERSION" != "$detected_lua" ] then - if [ -f "$LUA_DIR/bin/lua$suffix" ] - then - find_lua="$LUA_DIR" - fi - else - find_lua=`find_program lua$suffix` + die "This clashes with the value of --with-lua-version. Please check your configuration." fi - if [ -n "$find_lua" ] + fi +} + +search_interpreter() { + LUA_SUFFIX="$1" + if [ "$LUA_DIR_SET" = "yes" ] + then + if [ -f "$LUA_DIR/bin/lua$suffix" ] then - echo "Lua interpreter found: $find_lua/lua$suffix..." - break + find_lua="$LUA_DIR/bin" fi + else + find_lua=`find_program lua$suffix` + fi + if [ -n "$find_lua" ] + then + echo "Lua interpreter found: $find_lua/lua$suffix..." + detect_lua_version "$find_lua/lua$suffix" + return 0 + fi + return 1 +} + +if [ "$LUA_SUFFIX_SET" != "yes" ] +then + if [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.1" ] + then + suffixes="5.1 51" + elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.2" ] + then + suffixes="5.2 52" + else + suffixes="5.2 52 5.1 51" + fi + for suffix in "" `echo $suffixes` "" + do + search_interpreter "$suffix" && break done fi +if [ "$LUA_VERSION" = "5.2" ] +then + echo "******************************" + echo "WARNING: Lua 5.2 support is still experimental." + echo "Bug reports, patches and pull requests are welcome" + echo "at the GitHub project:" + echo "http://github.com/keplerproject/luarocks" + echo "and the mailing list:" + echo "https://lists.sourceforge.net/lists/listinfo/luarocks-developers" + echo "******************************" +fi + if [ "$LUA_DIR_SET" != "yes" ] then echo_n "Looking for Lua... " @@ -253,8 +304,7 @@ then echo "lua$LUA_SUFFIX found in \$PATH: $find_lua" else echo "lua$LUA_SUFFIX not found in \$PATH." - echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help." - exit 1 + die "You may want to use the flags --with-lua and/or --lua-suffix. See --help." fi fi @@ -279,15 +329,14 @@ if [ -f "$lua_h" ] then echo "lua.h found in $lua_h" else - LUA_INCDIR="$LUA_INCDIR/lua5.1" + LUA_INCDIR="$LUA_INCDIR/lua/$LUA_VERSION" d_lua_h="$LUA_INCDIR/lua.h" if [ -f "$d_lua_h" ] then echo "lua.h found in $d_lua_h (Debian/Ubuntu)" else echo "lua.h not found (looked in $lua_h)" - echo "You may want to use the flag --with-lua-include. See --help." - exit 1 + die "You may want to use the flag --with-lua-include. See --help." fi fi @@ -308,16 +357,14 @@ if uname -s then LUAROCKS_UNAME_S=`uname -s` else - echo "Could not determine operating system. 'uname -s' failed." - exit 1 + die "Could not determine operating system. 'uname -s' failed." fi echo_n "Configuring for architecture... " if uname -m then LUAROCKS_UNAME_M=`uname -m` else - echo "Could not determine processor architecture. 'uname -m' failed." - exit 1 + die "Could not determine processor architecture. 'uname -m' failed." fi if [ -f config.unix ]; then @@ -334,6 +381,7 @@ cat < config.unix # This file was automatically generated by the configure script. # Run "./configure --help" for details. +LUA_VERSION=$LUA_VERSION PREFIX=$PREFIX SYSCONFDIR=$SYSCONFDIR ROCKS_TREE=$ROCKS_TREE diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 9628a291..8527ba52 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -11,8 +11,8 @@ -- (~/.luarocks/config.lua on Unix or %APPDATA%/luarocks/config.lua on -- Windows). -local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert = - rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert +local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert, _VERSION = + rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, type, assert, _VERSION module("luarocks.cfg") @@ -25,6 +25,7 @@ end _M.site_config = site_config +lua_version = _VERSION:sub(5) program_version = "2.0.8" user_agent = "LuaRocks/"..program_version @@ -150,8 +151,8 @@ local defaults = { use_extensions = false, accept_unknown_fields = false, - lua_modules_path = "/share/lua/5.1/", - lib_modules_path = "/lib/lua/5.1/", + lua_modules_path = "/share/lua/"..lua_version, + lib_modules_path = "/lib/lua/"..lua_version, arch = "unknown", lib_extension = "unknown", @@ -230,9 +231,9 @@ if detected.windows then defaults.external_lib_extension = "dll" defaults.obj_extension = "obj" defaults.external_deps_dirs = { "c:/external/" } - defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua5.1/bin" - defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua5.1/include" - defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua5.1/lib" + defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin" + defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include" + defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib" defaults.cmake_generator = "MinGW Makefiles" defaults.makefile = "Makefile.win" defaults.variables.MAKE = "nmake" -- TODO: Split Windows flavors between mingw and msvc @@ -241,10 +242,10 @@ if detected.windows then defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.obj" defaults.variables.LD = "link" defaults.variables.MT = "mt" - defaults.variables.LUALIB = "lua5.1.lib" + defaults.variables.LUALIB = "lua"..lua_version..".lib" defaults.variables.CFLAGS = "/MD /O2" defaults.variables.LIBFLAG = "/dll" - defaults.variables.LUALIB = "lua5.1.lib" + defaults.variables.LUALIB = "lua"..lua_version..".lib" defaults.external_deps_patterns = { bin = { "?.exe", "?.bat" }, lib = { "?.lib", "?.dll", "lib?.dll" }, @@ -268,9 +269,9 @@ if detected.mingw32 then defaults.external_lib_extension = "dll" defaults.obj_extension = "o" defaults.external_deps_dirs = { "c:/external/" } - defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua5.1/bin" - defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua5.1/include" - defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua5.1/lib" + defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin" + defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include" + defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib" defaults.cmake_generator = "MinGW Makefiles" defaults.make = "mingw32-make" -- TODO: Split Windows flavors between mingw and msvc defaults.makefile = "Makefile.win" diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 9cc9f2c4..194e0e7e 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -317,7 +317,7 @@ local function match_dep(dep, blacklist) local versions if dep.name == "lua" then - versions = { (_VERSION:gsub("Lua ", "")) } + versions = { cfg.lua_version } else versions = manif_core.get_versions(dep.name) end @@ -470,7 +470,7 @@ function fulfill_dependencies(rockspec) if not match_dep(dep) then local rock = search.find_suitable_rock(dep) if not rock then - return nil, "Could not find a rock to satisfy dependency: "..show_dep(dep) + return nil, "Could not satisfy dependency: "..show_dep(dep) end local ok, err, errcode = install.run(rock) if not ok then diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 1cae25f4..191ef35c 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -59,7 +59,7 @@ function is_writable(file) if fh then fh:close() end os.remove(file2) else - local fh = io.open(file, 'rb+') + local fh = io.open(file, 'r+b') result = fh ~= nil if fh then fh:close() end end @@ -129,7 +129,8 @@ if lfs_ok then -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function execute_string(cmd) - if os.execute(cmd) == 0 then + local code = os.execute(cmd) + if code == 0 or code == true then return true else return false diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index d6d60adc..37efcf66 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -17,7 +17,8 @@ local vars = cfg.variables -- otherwise. function execute_string(cmd) local actual_cmd = "cd " .. fs.Q(fs.current_dir()) .. " && " .. cmd - if os.execute(actual_cmd) == 0 then + local code = os.execute(actual_cmd) + if code == 0 or code == true then return true else return false diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 2ad84371..6115f382 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -110,7 +110,8 @@ end -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function execute_string(cmd) - if os.execute(command_at(fs.current_dir(), cmd)) == 0 then + local code = os.execute(command_at(fs.current_dir(), cmd)) + if code == 0 or code == true then return true else return false diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 6d411e0f..182b3da6 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -18,17 +18,28 @@ function load_into_table(filename, tbl) assert(type(filename) == "string") assert(type(tbl) == "table" or not tbl) - local chunk, err = loadfile(filename) + local result, chunk, ran, err + local result = tbl or {} + if setfenv then -- Lua 5.1 + chunk, err = loadfile(filename) + if chunk then + setfenv(chunk, result) + ran, err = pcall(chunk) + end + else -- Lua 5.2 + chunk, err = loadfile(filename, "t", result) + if chunk then + ran, err = pcall(chunk) + end + end + if not chunk then if err:sub(1,5) ~= filename:sub(1,5) then return false, err end return nil, "Error loading file: "..err end - local result = tbl or {} - setfenv(chunk, result) - local ok, err = pcall(chunk) - if not ok then + if not ran then return nil, "Error running file: "..err end return result -- cgit v1.2.3-55-g6feb