diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2015-06-25 17:03:42 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2015-06-25 17:03:42 +0200 |
| commit | 028b37f2376225aa69c946beb44fd7dd68f32604 (patch) | |
| tree | cd12b72a07d6560a9e6f51127224339981de509c /src | |
| parent | 6cb37a1c73fd9f8b23565725f835b84e9872cf29 (diff) | |
| parent | 3b58640f79c114e651e53858afee94bd7e7eb52d (diff) | |
| download | luarocks-028b37f2376225aa69c946beb44fd7dd68f32604.tar.gz luarocks-028b37f2376225aa69c946beb44fd7dd68f32604.tar.bz2 luarocks-028b37f2376225aa69c946beb44fd7dd68f32604.zip | |
Merge pull request #397 from Tieske/fix_config
Fix config, bug introduced in #385
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cfg.lua | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 2a92c4dd..8321e9b9 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -144,34 +144,52 @@ 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 | |||
| 166 | -- Merge values from config files read into the `cfg` table | ||
| 167 | local merge_overrides = function(overrides) | ||
| 168 | -- remove some stuff we do not want to integrate | ||
| 169 | overrides.os_getenv = nil | ||
| 170 | overrides.dump_env = nil | ||
| 171 | -- remove tables to be copied verbatim instead of deeply merged | ||
| 172 | if overrides.rocks_trees then cfg.rocks_trees = nil end | ||
| 173 | if overrides.rocks_servers then cfg.rocks_servers = nil end | ||
| 174 | -- perform actual merge | ||
| 175 | util.deep_merge(cfg, overrides) | ||
| 176 | end | ||
| 162 | 177 | ||
| 163 | 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" |
| 164 | do | 179 | do |
| 165 | local err, errcode | 180 | local err, errcode |
| 166 | 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()) |
| 167 | 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 |
| 168 | sys_config_file = sys_config_dir.."/config.lua" | 183 | sys_config_file = sys_config_dir.."/config.lua" |
| 169 | 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()) |
| 170 | end | 185 | end |
| 171 | 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 |
| 172 | io.stderr:write(err.."\n") | 187 | io.stderr:write(err.."\n") |
| 173 | os.exit(cfg.errorcodes.CONFIGFILE) | 188 | os.exit(cfg.errorcodes.CONFIGFILE) |
| 174 | end | 189 | end |
| 190 | if sys_config_ok then | ||
| 191 | merge_overrides(sys_config_ok) | ||
| 192 | end | ||
| 175 | end | 193 | end |
| 176 | 194 | ||
| 177 | if not site_config.LUAROCKS_FORCE_CONFIG then | 195 | if not site_config.LUAROCKS_FORCE_CONFIG then |
| @@ -179,24 +197,18 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
| 179 | local home_overrides, err, errcode | 197 | local home_overrides, err, errcode |
| 180 | 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") |
| 181 | if home_config_file then | 199 | if home_config_file then |
| 182 | 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()) |
| 183 | else | 201 | else |
| 184 | home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" | 202 | home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" |
| 185 | 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()) |
| 186 | if (not home_overrides) and (not errcode == "run") then | 204 | if (not home_overrides) and (not errcode == "run") then |
| 187 | home_config_file = home_config_dir.."/config.lua" | 205 | home_config_file = home_config_dir.."/config.lua" |
| 188 | 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()) |
| 189 | end | 207 | end |
| 190 | end | 208 | end |
| 191 | if home_overrides then | 209 | if home_overrides then |
| 192 | home_config_ok = true | 210 | home_config_ok = true |
| 193 | if home_overrides.rocks_trees then | 211 | merge_overrides(home_overrides) |
| 194 | cfg.rocks_trees = nil | ||
| 195 | end | ||
| 196 | if home_overrides.rocks_servers then | ||
| 197 | cfg.rocks_servers = nil | ||
| 198 | end | ||
| 199 | util.deep_merge(cfg, home_overrides) | ||
| 200 | else | 212 | else |
| 201 | home_config_ok = home_overrides | 213 | home_config_ok = home_overrides |
| 202 | if errcode ~= "open" then | 214 | if errcode ~= "open" then |
