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. --- src/luarocks/cfg.lua | 56 ++++++++++++++++++++++++++++++++++----------------- src/luarocks/path.lua | 11 +++++----- 2 files changed, 42 insertions(+), 25 deletions(-) (limited to 'src') 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