From 51ea074d9886995a649f2f2251832c2741e6d4cd Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Mar 2015 17:11:36 -0300 Subject: Expose platform and processor to home config files. platform is a {string:boolean} table, with things such as platform.unix = true and platform.linux = true. processor is the same machine arch string you get when packing a binary rock (eg. "x86", "x86_64", "powerpc"). Closes #296. --- src/luarocks/cfg.lua | 16 ++++++++++++---- src/luarocks/util.lua | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index b4781840..45dbdd1b 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -158,17 +158,25 @@ if (not sys_config_ok) and errcode ~= "open" then os.exit(cfg.errorcodes.CONFIGFILE) end +local env_for_config_file = { + home = cfg.home, + lua_version = cfg.lua_version, + platform = util.make_shallow_copy(detected), + processor = proc, +} + if not site_config.LUAROCKS_FORCE_CONFIG then + local home_overrides, err, errcode home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") if home_config_file then - home_overrides, err, errcode = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) + home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) else home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" - home_overrides, err, errcode = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) + home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) if (not home_overrides) and (not errcode == "run") then home_config_file = home_config_dir.."/config.lua" - home_overrides, err, errcode = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) + home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file) end end if home_overrides then @@ -447,7 +455,7 @@ if detected.macosx then if version >= 10 then version = 8 elseif version >= 5 then - version = 5 + version = 5 else defaults.gcc_rpath = false end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 8772883b..40af35bd 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -177,7 +177,7 @@ local var_format_pattern = "%$%((%a[%a%d_]+)%)" -- the original table (ie, does not copy recursively). -- @param tbl table: the input table -- @return table: a new table with the same contents. -local function make_shallow_copy(tbl) +function util.make_shallow_copy(tbl) local copy = {} for k,v in pairs(tbl) do copy[k] = v @@ -196,7 +196,7 @@ end -- needed variables. -- @param msg string: the warning message to display. function util.warn_if_not_used(var_defs, needed_set, msg) - needed_set = make_shallow_copy(needed_set) + needed_set = util.make_shallow_copy(needed_set) for _, val in pairs(var_defs) do for used in val:gmatch(var_format_pattern) do needed_set[used] = nil -- cgit v1.2.3-55-g6feb