From e1dd6375822d800984e1d3d821899a315bc1b222 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 16 Jun 2015 19:31:01 +0200 Subject: added 2 functions to the global environment of the config-file loader sandbox; `os_getenv()` and `__dump_env()` --- src/luarocks/cfg.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 20aa4a21..6d6a911d 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -145,6 +145,14 @@ end cfg.variables = {} cfg.rocks_trees = {} +-- some extras for the global enviornment in the config files; +cfg.os_getenv = os.getenv +cfg.__dump_env = function() + -- debug function, calling it from a config file will show all + -- available globals to that config file + print(util.show_table(cfg, "global environment")) +end + sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" do local err, errcode @@ -159,11 +167,18 @@ do end end -local env_for_config_file = { +local env_for_config_file +env_for_config_file = { home = cfg.home, lua_version = cfg.lua_version, platform = util.make_shallow_copy(detected), processor = proc, + os_getenv = os.getenv, + __dump_env = function() + -- debug function, calling it from a config file will show all + -- available globals to that config file + print(util.show_table(env_for_config_file, "global environment")) + end, } if not site_config.LUAROCKS_FORCE_CONFIG then -- cgit v1.2.3-55-g6feb From 4792618d8882eb36c9e9d05efac8b1ae336f00cb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 17 Jun 2015 11:01:48 +0200 Subject: fixed typo --- src/luarocks/cfg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 6d6a911d..87fb1dda 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -145,7 +145,7 @@ end cfg.variables = {} cfg.rocks_trees = {} --- some extras for the global enviornment in the config files; +-- some extras for the global environment in the config files; cfg.os_getenv = os.getenv cfg.__dump_env = function() -- debug function, calling it from a config file will show all -- cgit v1.2.3-55-g6feb From 998d012a7228099990a88454150e843559074e0c Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 18 Jun 2015 18:01:19 +0200 Subject: fix: use same environment table for the system config file as well. --- src/luarocks/cfg.lua | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 87fb1dda..6ce2ff24 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -145,28 +145,7 @@ end cfg.variables = {} cfg.rocks_trees = {} --- some extras for the global environment in the config files; -cfg.os_getenv = os.getenv -cfg.__dump_env = function() - -- debug function, calling it from a config file will show all - -- available globals to that config file - print(util.show_table(cfg, "global environment")) -end - -sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" -do - local err, errcode - sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) - if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file - sys_config_file = sys_config_dir.."/config.lua" - sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) - end - if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error - io.stderr:write(err.."\n") - os.exit(cfg.errorcodes.CONFIGFILE) - end -end - +-- The global environment in the config files; local env_for_config_file env_for_config_file = { home = cfg.home, @@ -174,13 +153,27 @@ env_for_config_file = { platform = util.make_shallow_copy(detected), processor = proc, os_getenv = os.getenv, - __dump_env = function() + dump_env = function() -- debug function, calling it from a config file will show all -- available globals to that config file print(util.show_table(env_for_config_file, "global environment")) end, } +sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" +do + local err, errcode + sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file) + if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file + sys_config_file = sys_config_dir.."/config.lua" + sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file) + end + if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error + io.stderr:write(err.."\n") + os.exit(cfg.errorcodes.CONFIGFILE) + end +end + if not site_config.LUAROCKS_FORCE_CONFIG then local home_overrides, err, errcode -- cgit v1.2.3-55-g6feb