From 130f460fca140b2873d284d0057b326b64621d1d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 12 Apr 2013 23:05:43 -0300 Subject: General improvements for Lua 5.1 and 5.2 coexistance: * Add --versioned-rocks-dir option to Unix installer, which makes it use paths such as /lib/luarocks/rocks-5.X, and /etc/luarocks/config-5.X.lua (where X is 1 or 2). * Make configure script on Unix autodetect the presence of previous LuaRocks installations and adapt accordingly to avoid conflicts. * Support luarocks.site_config_5_X for users who wish to run two versions from the same source tree (may be useful for LR development). * Try to load config-5.X.lua from home directory before trying config.lua. --- Makefile | 14 ++++++++++--- configure | 47 ++++++++++++++++++++++++++++++------------ rockspec | 2 +- src/luarocks/cfg.lua | 56 ++++++++++++++++++++++++++++++++++----------------- src/luarocks/path.lua | 11 +++++----- 5 files changed, 88 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index dc37529b..a102b2be 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua purge.lua -CONFIG_FILE = $(SYSCONFDIR)/config.lua +CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua all: built @@ -51,7 +51,7 @@ src/luarocks/site_config.lua: config.unix fi if [ -n "$(SYSCONFDIR)" ] ;\ then \ - echo "LUAROCKS_SYSCONFIG=[[$(SYSCONFDIR)/config.lua]]" >> src/luarocks/site_config.lua ;\ + echo "LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(ROCKS_TREE)" ] ;\ then \ @@ -61,6 +61,10 @@ src/luarocks/site_config.lua: config.unix then \ echo "LUAROCKS_FORCE_CONFIG=true" >> src/luarocks/site_config.lua ;\ fi + if [ -n "$(LUAROCKS_ROCKS_SUBDIR)" ] ;\ + then \ + echo "LUAROCKS_ROCKS_SUBDIR=[[$(LUAROCKS_ROCKS_SUBDIR)]]" >> src/luarocks/site_config.lua ;\ + fi if [ "$(LUA_DIR_SET)" = "yes" ] ;\ then \ echo "LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\ @@ -121,7 +125,11 @@ clean: cleanup_bins install_bins: built mkdir -p "$(DESTDIR)$(BINDIR)" - cd src/bin && cp $(BIN_FILES) "$(DESTDIR)$(BINDIR)" + cd src/bin && for f in $(BIN_FILES); \ + do \ + cp "$$f" "$(DESTDIR)$(BINDIR)/$$f-$(LUA_VERSION)"; \ + ln -nfs "$(DESTDIR)$(BINDIR)/$$f-$(LUA_VERSION)" "$(DESTDIR)$(BINDIR)/$$f"; \ + done install_luas: built mkdir -p "$(DESTDIR)$(LUADIR)/luarocks" diff --git a/configure b/configure index 2e98a9e5..42ecf03b 100755 --- a/configure +++ b/configure @@ -38,7 +38,7 @@ 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) +--lua-version=VERSION Use specific Lua version: 5.1 or 5.2 Default is "$LUA_VERSION" --lua-suffix=SUFFIX Versioning suffix to use in Lua filenames. Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...) @@ -54,6 +54,9 @@ system's package manager. --with-md5-checker=TOOL Which tool to use as a downloader. Valid options are: md5sum, openssl Default is to auto-detect. +--versioned-rocks-dir Use a versioned rocks dir, such as + \$PREFIX/lib/luarocks/rocks-$LUA_VERSION/. + Default is to auto-detect the necessity. --force-config Use a single config location. Do not use the \$LUAROCKS_CONFIG variable or the user's home directory. Useful to avoid conflicts when LuaRocks @@ -162,6 +165,9 @@ do --force-config) FORCE_CONFIG=yes ;; + --versioned-rocks-dir) + VERSIONED_ROCKS_DIR=yes + ;; --lua-suffix) [ -n "$value" ] || die "Missing value in flag $key." LUA_SUFFIX="$value" @@ -277,18 +283,6 @@ then 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... " @@ -376,6 +370,32 @@ else die "Could not determine processor architecture. 'uname -m' failed." fi +if [ "$LUA_VERSION" = "5.2" ] +then + LUA_OTHER_VERSION=5.1 +else + LUA_OTHER_VERSION=5.2 +fi + +LUAROCKS_ROCKS_SUBDIR=/lib/luarocks/rocks +if [ "$VERSIONED_ROCKS_DIR" = "yes" ] +then + LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR-$LUA_VERSION + echo "Using versioned rocks dir: $PREFIX$LUAROCKS_ROCKS_SUBDIR" +elif [ -e "$PREFIX/share/lua/$LUA_VERSION/luarocks/site_config.lua" ] +then + echo "Existing installation detected." + LUAROCKS_ROCKS_SUBDIR=`grep "LUAROCKS_ROCKS_SUBDIR" "$PREFIX/lib/lua/$LUA_VERSION/luarocks/site_config.lua" | sed 's,.*=\[\[(.*)\]\],\1,'` + echo "Using previously configured rocks dir: $LUAROCKS_ROCKS_DIR" +elif [ -e "$PREFIX/share/lua/$LUA_OTHER_VERSION/luarocks/site_config.lua" ] +then + echo "Existing installation detected for other Lua version ($LUA_OTHER_VERSION)." + LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR-$LUA_VERSION + echo "Using versioned rocks dir: $PREFIX$LUAROCKS_ROCKS_SUBDIR" +else + echo "Using unversioned rocks dir: $PREFIX$LUAROCKS_ROCKS_SUBDIR" +fi + if [ -f config.unix ]; then rm -f config.unix fi @@ -405,6 +425,7 @@ LUAROCKS_UNAME_M=$LUAROCKS_UNAME_M LUAROCKS_UNAME_S=$LUAROCKS_UNAME_S LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER +LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR EOF diff --git a/rockspec b/rockspec index 11cc2c63..1fa7fa8d 100644 --- a/rockspec +++ b/rockspec @@ -1,5 +1,5 @@ package = "LuaRocks" -local VER = "2.0.12" +local VER = "2.0.13" local REV = "1" version = VER.."-"..REV diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 12a477a0..2f2c7a66 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -15,8 +15,14 @@ local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, module("luarocks.cfg") +lua_version = _VERSION:sub(5) +local version_suffix = lua_version:gsub("%.", "_") + -- Load site-local global configurations -local ok, site_config = pcall(require, "luarocks.site_config") +local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix) +if not ok then + ok, site_config = pcall(require, "luarocks.site_config") +end if not ok then io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n") site_config = {} @@ -24,8 +30,7 @@ end _M.site_config = site_config -lua_version = _VERSION:sub(5) -program_version = "2.0.12" +program_version = "2.0.13" local persist = require("luarocks.persist") @@ -97,38 +102,50 @@ end -- Path configuration: -local version_suffix = lua_version:gsub ("%.", "_") local sys_config_file, home_config_file +local sys_config_dir, home_config_dir local sys_config_ok, home_config_ok = false, false -sys_config_file = site_config["LUAROCKS_SYSCONFIG_" .. version_suffix] or site_config.LUAROCKS_SYSCONFIG +sys_config_dir = site_config.LUAROCKS_SYSCONFDIR if detected.windows then home = os.getenv("APPDATA") or "c:" - sys_config_file = sys_config_file or "c:/luarocks/config.lua" - home_config_file = home.."/luarocks/config.lua" + sys_config_dir = sys_config_dir or "c:/luarocks" + home_config_dir = home.."/luarocks" home_tree = home.."/luarocks/" else home = os.getenv("HOME") or "" - sys_config_file = sys_config_file or "/etc/luarocks/config.lua" - home_config_file = home.."/.luarocks/config.lua" + sys_config_dir = sys_config_dir or "/etc/luarocks" + home_config_dir = home.."/.luarocks" home_tree = home.."/.luarocks/" end variables = {} rocks_trees = {} -local ok, err = persist.load_into_table(sys_config_file, _M) -if ok then - sys_config_ok = true -else -- nil or false - sys_config_ok = ok - if err and ok == nil then - io.stderr:write(err.."\n") - end +sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..lua_version..".lua" +local err +sys_config_ok, err = persist.load_into_table(sys_config_file, _M) + +if not sys_config_ok then + sys_config_file = sys_config_dir.."/config.lua" + sys_config_ok, err = persist.load_into_table(sys_config_file, _M) +end +if err and ok == nil then + io.stderr:write(err.."\n") end if not site_config.LUAROCKS_FORCE_CONFIG then - home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") or home_config_file - local home_overrides, err = persist.load_into_table(home_config_file, { home = home }) + local home_overrides, err + home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") + if home_config_file then + home_overrides, err = persist.load_into_table(home_config_file, { home = home }) + else + home_config_file = home_config_dir.."/config-"..lua_version..".lua" + home_overrides, err = persist.load_into_table(home_config_file, { home = home }) + if not home_overrides then + home_config_file = home_config_dir.."/config.lua" + home_overrides, err = persist.load_into_table(home_config_file, { home = home }) + end + end if home_overrides then home_config_ok = true local util = require("luarocks.util") @@ -169,6 +186,7 @@ local defaults = { lua_modules_path = "/share/lua/"..lua_version, lib_modules_path = "/lib/lua/"..lua_version, + rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks", arch = "unknown", lib_extension = "unknown", diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 2ce0e078..5e380992 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -28,17 +28,16 @@ end function rocks_dir(tree) if type(tree) == "string" then - return dir.path(tree, "lib", "luarocks", "rocks") + return dir.path(tree, cfg.rocks_subdir) else assert(type(tree) == "table") - return tree.rocks_dir or dir.path(tree.root, "lib", "luarocks", "rocks") + return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end end function root_dir(rocks_dir) assert(type(rocks_dir) == "string") - local suffix = dir.path("lib", "luarocks") - return rocks_dir:match("(.*)" .. suffix .. ".*$") + return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") end function rocks_tree_to_string(tree) @@ -79,10 +78,10 @@ end function manifest_file(tree) if type(tree) == "string" then - return dir.path(tree, "lib", "luarocks", "rocks", "manifest") + return dir.path(tree, cfg.rocks_subdir, "manifest") else assert(type(tree) == "table") - return (tree.rocks_dir and dir.path(tree.rocks_dir, "manifest")) or dir.path(tree.root, "lib", "luarocks", "rocks", "manifest") + return (tree.rocks_dir and dir.path(tree.rocks_dir, "manifest")) or dir.path(tree.root, cfg.rocks_subdir, "manifest") end end -- cgit v1.2.3-55-g6feb