diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-04-12 23:05:43 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-04-12 23:05:43 -0300 |
commit | 130f460fca140b2873d284d0057b326b64621d1d (patch) | |
tree | 825a90c51e9fd9b15f98d1c7e9a38eca439862c5 /src | |
parent | 26db61478504c7b13099b942aeebbdd6ffa4472b (diff) | |
download | luarocks-130f460fca140b2873d284d0057b326b64621d1d.tar.gz luarocks-130f460fca140b2873d284d0057b326b64621d1d.tar.bz2 luarocks-130f460fca140b2873d284d0057b326b64621d1d.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cfg.lua | 56 | ||||
-rw-r--r-- | src/luarocks/path.lua | 11 |
2 files changed, 42 insertions, 25 deletions
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, | |||
15 | 15 | ||
16 | module("luarocks.cfg") | 16 | module("luarocks.cfg") |
17 | 17 | ||
18 | lua_version = _VERSION:sub(5) | ||
19 | local version_suffix = lua_version:gsub("%.", "_") | ||
20 | |||
18 | -- Load site-local global configurations | 21 | -- Load site-local global configurations |
19 | local ok, site_config = pcall(require, "luarocks.site_config") | 22 | local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix) |
23 | if not ok then | ||
24 | ok, site_config = pcall(require, "luarocks.site_config") | ||
25 | end | ||
20 | if not ok then | 26 | if not ok then |
21 | io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n") | 27 | io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n") |
22 | site_config = {} | 28 | site_config = {} |
@@ -24,8 +30,7 @@ end | |||
24 | 30 | ||
25 | _M.site_config = site_config | 31 | _M.site_config = site_config |
26 | 32 | ||
27 | lua_version = _VERSION:sub(5) | 33 | program_version = "2.0.13" |
28 | program_version = "2.0.12" | ||
29 | 34 | ||
30 | local persist = require("luarocks.persist") | 35 | local persist = require("luarocks.persist") |
31 | 36 | ||
@@ -97,38 +102,50 @@ end | |||
97 | 102 | ||
98 | -- Path configuration: | 103 | -- Path configuration: |
99 | 104 | ||
100 | local version_suffix = lua_version:gsub ("%.", "_") | ||
101 | local sys_config_file, home_config_file | 105 | local sys_config_file, home_config_file |
106 | local sys_config_dir, home_config_dir | ||
102 | local sys_config_ok, home_config_ok = false, false | 107 | local sys_config_ok, home_config_ok = false, false |
103 | sys_config_file = site_config["LUAROCKS_SYSCONFIG_" .. version_suffix] or site_config.LUAROCKS_SYSCONFIG | 108 | sys_config_dir = site_config.LUAROCKS_SYSCONFDIR |
104 | if detected.windows then | 109 | if detected.windows then |
105 | home = os.getenv("APPDATA") or "c:" | 110 | home = os.getenv("APPDATA") or "c:" |
106 | sys_config_file = sys_config_file or "c:/luarocks/config.lua" | 111 | sys_config_dir = sys_config_dir or "c:/luarocks" |
107 | home_config_file = home.."/luarocks/config.lua" | 112 | home_config_dir = home.."/luarocks" |
108 | home_tree = home.."/luarocks/" | 113 | home_tree = home.."/luarocks/" |
109 | else | 114 | else |
110 | home = os.getenv("HOME") or "" | 115 | home = os.getenv("HOME") or "" |
111 | sys_config_file = sys_config_file or "/etc/luarocks/config.lua" | 116 | sys_config_dir = sys_config_dir or "/etc/luarocks" |
112 | home_config_file = home.."/.luarocks/config.lua" | 117 | home_config_dir = home.."/.luarocks" |
113 | home_tree = home.."/.luarocks/" | 118 | home_tree = home.."/.luarocks/" |
114 | end | 119 | end |
115 | 120 | ||
116 | variables = {} | 121 | variables = {} |
117 | rocks_trees = {} | 122 | rocks_trees = {} |
118 | 123 | ||
119 | local ok, err = persist.load_into_table(sys_config_file, _M) | 124 | sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..lua_version..".lua" |
120 | if ok then | 125 | local err |
121 | sys_config_ok = true | 126 | sys_config_ok, err = persist.load_into_table(sys_config_file, _M) |
122 | else -- nil or false | 127 | |
123 | sys_config_ok = ok | 128 | if not sys_config_ok then |
124 | if err and ok == nil then | 129 | sys_config_file = sys_config_dir.."/config.lua" |
125 | io.stderr:write(err.."\n") | 130 | sys_config_ok, err = persist.load_into_table(sys_config_file, _M) |
126 | end | 131 | end |
132 | if err and ok == nil then | ||
133 | io.stderr:write(err.."\n") | ||
127 | end | 134 | end |
128 | 135 | ||
129 | if not site_config.LUAROCKS_FORCE_CONFIG then | 136 | if not site_config.LUAROCKS_FORCE_CONFIG then |
130 | home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") or home_config_file | 137 | local home_overrides, err |
131 | local home_overrides, err = persist.load_into_table(home_config_file, { home = home }) | 138 | home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") |
139 | if home_config_file then | ||
140 | home_overrides, err = persist.load_into_table(home_config_file, { home = home }) | ||
141 | else | ||
142 | home_config_file = home_config_dir.."/config-"..lua_version..".lua" | ||
143 | home_overrides, err = persist.load_into_table(home_config_file, { home = home }) | ||
144 | if not home_overrides then | ||
145 | home_config_file = home_config_dir.."/config.lua" | ||
146 | home_overrides, err = persist.load_into_table(home_config_file, { home = home }) | ||
147 | end | ||
148 | end | ||
132 | if home_overrides then | 149 | if home_overrides then |
133 | home_config_ok = true | 150 | home_config_ok = true |
134 | local util = require("luarocks.util") | 151 | local util = require("luarocks.util") |
@@ -169,6 +186,7 @@ local defaults = { | |||
169 | 186 | ||
170 | lua_modules_path = "/share/lua/"..lua_version, | 187 | lua_modules_path = "/share/lua/"..lua_version, |
171 | lib_modules_path = "/lib/lua/"..lua_version, | 188 | lib_modules_path = "/lib/lua/"..lua_version, |
189 | rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks", | ||
172 | 190 | ||
173 | arch = "unknown", | 191 | arch = "unknown", |
174 | lib_extension = "unknown", | 192 | 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 | |||
28 | 28 | ||
29 | function rocks_dir(tree) | 29 | function rocks_dir(tree) |
30 | if type(tree) == "string" then | 30 | if type(tree) == "string" then |
31 | return dir.path(tree, "lib", "luarocks", "rocks") | 31 | return dir.path(tree, cfg.rocks_subdir) |
32 | else | 32 | else |
33 | assert(type(tree) == "table") | 33 | assert(type(tree) == "table") |
34 | return tree.rocks_dir or dir.path(tree.root, "lib", "luarocks", "rocks") | 34 | return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) |
35 | end | 35 | end |
36 | end | 36 | end |
37 | 37 | ||
38 | function root_dir(rocks_dir) | 38 | function root_dir(rocks_dir) |
39 | assert(type(rocks_dir) == "string") | 39 | assert(type(rocks_dir) == "string") |
40 | local suffix = dir.path("lib", "luarocks") | 40 | return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") |
41 | return rocks_dir:match("(.*)" .. suffix .. ".*$") | ||
42 | end | 41 | end |
43 | 42 | ||
44 | function rocks_tree_to_string(tree) | 43 | function rocks_tree_to_string(tree) |
@@ -79,10 +78,10 @@ end | |||
79 | 78 | ||
80 | function manifest_file(tree) | 79 | function manifest_file(tree) |
81 | if type(tree) == "string" then | 80 | if type(tree) == "string" then |
82 | return dir.path(tree, "lib", "luarocks", "rocks", "manifest") | 81 | return dir.path(tree, cfg.rocks_subdir, "manifest") |
83 | else | 82 | else |
84 | assert(type(tree) == "table") | 83 | assert(type(tree) == "table") |
85 | return (tree.rocks_dir and dir.path(tree.rocks_dir, "manifest")) or dir.path(tree.root, "lib", "luarocks", "rocks", "manifest") | 84 | return (tree.rocks_dir and dir.path(tree.rocks_dir, "manifest")) or dir.path(tree.root, cfg.rocks_subdir, "manifest") |
86 | end | 85 | end |
87 | end | 86 | end |
88 | 87 | ||