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 83449f223ce59695bbd628abb0fb6c418a713c0f Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Wed, 17 Jun 2015 13:00:29 -0300 Subject: Checks if git is installed When sources are to be fetched using git, check beforehand it is available in the path instead of causing an error. It will show the message: `Error: 'git' program not found. Is git installed? You may want to edit variables.GIT` and exit. refs #381 --- src/luarocks/fetch/git.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 53fd4445..bea53fc8 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -40,6 +40,10 @@ function git.get_sources(rockspec, extract, dest_dir, depth) -- Strip off .git from base name if present module = module:gsub("%.git$", "") + if not fs.execute_quiet(git_cmd, "--version") then + return nil, "'"..git_cmd.."' program not found. Is git installed? You may want to edit variables.GIT" + end + local store_dir if not dest_dir then store_dir = fs.make_temp_dir(name_version) -- cgit v1.2.3-55-g6feb From 8d030a06ed62aef4cf0b4648b54b712069a0d3ad Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Thu, 18 Jun 2015 12:26:38 -0300 Subject: Checks if tool is installed (svn, cvs, hg) --- src/luarocks/fetch/cvs.lua | 7 ++++++- src/luarocks/fetch/hg.lua | 6 +++++- src/luarocks/fetch/svn.lua | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index cc9fd655..fad1ca0d 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -20,9 +20,14 @@ function cvs.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) + local cvs_cmd = rockspec.variables.CVS + if not fs.execute_quiet(cvs_cmd, "--version") then + return nil, "'"..cvs_cmd.."' program not found. Is CVS installed? You may want to edit variables.CVS" + end + local name_version = rockspec.name .. "-" .. rockspec.version local module = rockspec.source.module or dir.base_name(rockspec.source.url) - local command = {rockspec.variables.CVS, "-d"..rockspec.source.pathname, "export", module} + local command = {cvs_cmd, "-d"..rockspec.source.pathname, "export", module} if rockspec.source.tag then table.insert(command, 4, "-r") table.insert(command, 5, rockspec.source.tag) diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index e736a071..055e3bbe 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -21,9 +21,13 @@ function hg.get_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local hg_cmd = rockspec.variables.HG + if not fs.execute_quiet(hg_cmd, "--version") then + return nil, "'"..hg_cmd.."' program not found. Is Mercurial installed? You may want to edit variables.HG" + end + local name_version = rockspec.name .. "-" .. rockspec.version -- Strip off special hg:// protocol type - local url = rockspec.source.url:gsub("^hg://", "") + local url = rockspec.source.url:gsub("^hg://", "") local module = dir.base_name(url) diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua index abeacf9a..8fe582f6 100644 --- a/src/luarocks/fetch/svn.lua +++ b/src/luarocks/fetch/svn.lua @@ -21,6 +21,10 @@ function svn.get_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local svn_cmd = rockspec.variables.SVN + if not fs.execute_quiet(svn_cmd, "--version") then + return nil, "'"..svn_cmd.."' program not found. Is Subversion installed? You may want to edit variables.SVN" + end + local name_version = rockspec.name .. "-" .. rockspec.version local module = rockspec.source.module or dir.base_name(rockspec.source.url) local url = rockspec.source.url:gsub("^svn://", "") -- 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 From c9b7f0bc5453251730c73040904a17a8fd32eef3 Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Thu, 18 Jun 2015 16:29:25 -0300 Subject: Factors the code to check for a tool. Changes 'not found' message wording. Adds the function fs.is_tool_available to check if a given tool (git, hg, cmake, etc) is available. --- src/luarocks/build/cmake.lua | 5 +++-- src/luarocks/fetch/cvs.lua | 5 +++-- src/luarocks/fetch/git.lua | 5 +++-- src/luarocks/fetch/hg.lua | 5 +++-- src/luarocks/fetch/svn.lua | 5 +++-- src/luarocks/fs/lua.lua | 21 +++++++++++++++++++++ 6 files changed, 36 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index e5b29147..c8f5a669 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua @@ -23,8 +23,9 @@ function cmake.run(rockspec) util.variable_substitutions(variables, rockspec.variables) - if not fs.execute_quiet(rockspec.variables.CMAKE, "--help") then - return nil, "'"..rockspec.variables.CMAKE.."' program not found. Is cmake installed? You may want to edit variables.CMAKE" + local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake") + if not ok then + return nil, err_msg end -- If inline cmake is present create CMakeLists.txt from it. diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index fad1ca0d..ccf928c4 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -21,8 +21,9 @@ function cvs.get_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local cvs_cmd = rockspec.variables.CVS - if not fs.execute_quiet(cvs_cmd, "--version") then - return nil, "'"..cvs_cmd.."' program not found. Is CVS installed? You may want to edit variables.CVS" + local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") + if not ok then + return nil, err_msg end local name_version = rockspec.name .. "-" .. rockspec.version diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index bea53fc8..e540d696 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -40,8 +40,9 @@ function git.get_sources(rockspec, extract, dest_dir, depth) -- Strip off .git from base name if present module = module:gsub("%.git$", "") - if not fs.execute_quiet(git_cmd, "--version") then - return nil, "'"..git_cmd.."' program not found. Is git installed? You may want to edit variables.GIT" + local ok, err_msg = fs.is_tool_available(git_cmd, "Git") + if not ok then + return nil, err_msg end local store_dir diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 055e3bbe..518130b4 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -21,8 +21,9 @@ function hg.get_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local hg_cmd = rockspec.variables.HG - if not fs.execute_quiet(hg_cmd, "--version") then - return nil, "'"..hg_cmd.."' program not found. Is Mercurial installed? You may want to edit variables.HG" + local ok, err_msg = fs.is_tool_available(hg_cmd, "Mercurial") + if not ok then + return nil, err_msg end local name_version = rockspec.name .. "-" .. rockspec.version diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua index 8fe582f6..755e5e32 100644 --- a/src/luarocks/fetch/svn.lua +++ b/src/luarocks/fetch/svn.lua @@ -21,8 +21,9 @@ function svn.get_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local svn_cmd = rockspec.variables.SVN - if not fs.execute_quiet(svn_cmd, "--version") then - return nil, "'"..svn_cmd.."' program not found. Is Subversion installed? You may want to edit variables.SVN" + local ok, err_msg = fs.is_tool_available(svn_cmd, "--version", "Subversion") + if not ok then + return nil, err_msg end local name_version = rockspec.name .. "-" .. rockspec.version diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index c0f6c1c6..73ae2698 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -122,6 +122,27 @@ function fs_lua.execute_quiet(command, ...) end end +--- Checks if the given tool is available. +-- The tool is executed using a flag, usually just to ask its version. +-- @param tool_cmd string: The command to be used to check the tool's presence (e.g. hg in case of Mercurial) +-- @param tool_name string: The actual name of the tool (e.g. Mercurial) +-- @param arg string: The flag to pass to the tool. '--version' by default. +function fs_lua.is_tool_available(tool_cmd, tool_name, arg) + assert(type(tool_cmd) == "string") + assert(type(tool_name) == "string") + + arg = arg or "--version" + assert(type(arg) == "string") + + if not fs.execute_quiet(tool_cmd, arg) then + local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " .. + "(or you may want to edit the 'variables.%s' value in file 'config.lua')" + return nil, msg:format(tool_cmd, tool_name, tool_cmd:upper()) + else + return true + end +end + --- Check the MD5 checksum for a file. -- @param file string: The file to be checked. -- @param md5sum string: The string with the expected MD5 checksum. -- cgit v1.2.3-55-g6feb From fdcecd17fc27eb6c2fab9192b66bb03c3b55bf11 Mon Sep 17 00:00:00 2001 From: Ignacio Burgueño Date: Fri, 19 Jun 2015 15:33:11 -0300 Subject: Allows luarocks.cfg to be used without being installed. This allows to address the issue #386 --- 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 20aa4a21..a02caaee 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -310,7 +310,7 @@ local defaults = { } if detected.windows then - local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..cfg.major_version + local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])).."\\"..cfg.major_version extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" home_config_file = home_config_file and home_config_file:gsub("\\","/") -- cgit v1.2.3-55-g6feb