diff options
-rw-r--r-- | src/luarocks/cfg.lua | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 2d3bb8bd..8321e9b9 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -144,39 +144,44 @@ end | |||
144 | cfg.variables = {} | 144 | cfg.variables = {} |
145 | cfg.rocks_trees = {} | 145 | cfg.rocks_trees = {} |
146 | 146 | ||
147 | -- The global environment in the config files; | 147 | -- Create global environment for the config files; |
148 | local env_for_config_file | 148 | local env_for_config_file = function() |
149 | env_for_config_file = { | 149 | local e |
150 | home = cfg.home, | 150 | e = { |
151 | lua_version = cfg.lua_version, | 151 | home = cfg.home, |
152 | platform = util.make_shallow_copy(detected), | 152 | lua_version = cfg.lua_version, |
153 | processor = cfg.target_cpu, -- remains for compat reasons | 153 | platform = util.make_shallow_copy(detected), |
154 | target_cpu = cfg.target_cpu, -- replaces `processor` | 154 | processor = cfg.target_cpu, -- remains for compat reasons |
155 | os_getenv = os.getenv, | 155 | target_cpu = cfg.target_cpu, -- replaces `processor` |
156 | dump_env = function() | 156 | os_getenv = os.getenv, |
157 | -- debug function, calling it from a config file will show all | 157 | dump_env = function() |
158 | -- available globals to that config file | 158 | -- debug function, calling it from a config file will show all |
159 | print(util.show_table(env_for_config_file, "global environment")) | 159 | -- available globals to that config file |
160 | end, | 160 | print(util.show_table(e, "global environment")) |
161 | } | 161 | end, |
162 | } | ||
163 | return e | ||
164 | end | ||
165 | |||
162 | -- Merge values from config files read into the `cfg` table | 166 | -- Merge values from config files read into the `cfg` table |
163 | local merge_overrides = function(overrides) | 167 | local merge_overrides = function(overrides) |
164 | if overrides.rocks_trees then | 168 | -- remove some stuff we do not want to integrate |
165 | cfg.rocks_trees = nil | 169 | overrides.os_getenv = nil |
166 | end | 170 | overrides.dump_env = nil |
167 | if overrides.rocks_servers then | 171 | -- remove tables to be copied verbatim instead of deeply merged |
168 | cfg.rocks_servers = nil | 172 | if overrides.rocks_trees then cfg.rocks_trees = nil end |
169 | end | 173 | if overrides.rocks_servers then cfg.rocks_servers = nil end |
174 | -- perform actual merge | ||
170 | util.deep_merge(cfg, overrides) | 175 | util.deep_merge(cfg, overrides) |
171 | end | 176 | end |
172 | 177 | ||
173 | sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" | 178 | sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" |
174 | do | 179 | do |
175 | local err, errcode | 180 | local err, errcode |
176 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file) | 181 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file()) |
177 | if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file | 182 | if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file |
178 | sys_config_file = sys_config_dir.."/config.lua" | 183 | sys_config_file = sys_config_dir.."/config.lua" |
179 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file) | 184 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file()) |
180 | end | 185 | end |
181 | if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error | 186 | if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error |
182 | io.stderr:write(err.."\n") | 187 | io.stderr:write(err.."\n") |
@@ -192,13 +197,13 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
192 | local home_overrides, err, errcode | 197 | local home_overrides, err, errcode |
193 | home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") | 198 | home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") |
194 | if home_config_file then | 199 | if home_config_file then |
195 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) | 200 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file()) |
196 | else | 201 | else |
197 | home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" | 202 | home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" |
198 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) | 203 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file()) |
199 | if (not home_overrides) and (not errcode == "run") then | 204 | if (not home_overrides) and (not errcode == "run") then |
200 | home_config_file = home_config_dir.."/config.lua" | 205 | home_config_file = home_config_dir.."/config.lua" |
201 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) | 206 | home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file()) |
202 | end | 207 | end |
203 | end | 208 | end |
204 | if home_overrides then | 209 | if home_overrides then |