From e494bbe5b91bd2ba5c7e1f231ff1d6f58cf6ccdb Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 26 Jun 2013 17:33:50 -0300 Subject: Add flags --lr-path, --lr-cpath, --lr-bin to `luarocks path`, for convenience in scripts. --- src/luarocks/cfg.lua | 28 +++++++++++++++++++--------- src/luarocks/path.lua | 19 +++++++++++++++++-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 259293c3..967d756c 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -443,15 +443,25 @@ local cfg_mt = { } setmetatable(_M, cfg_mt) -for _,tree in ipairs(rocks_trees) do - if type(tree) == "string" then - package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path - package.cpath = tree..lib_modules_path.."/?."..lib_extension..";"..package.cpath - else - package.path = (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;".. - (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua;"..package.path - package.cpath = (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension..";"..package.cpath - end +function package_paths() + local new_path, new_cpath = {}, {} + for _,tree in ipairs(rocks_trees) do + if type(tree) == "string" then + table.insert(new_path, 1, tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua") + table.insert(new_cpath, 1, tree..lib_modules_path.."/?."..lib_extension) + else + table.insert(new_path, 1, (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;".. + (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua") + table.insert(new_cpath, 1, (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension) + end + end + return table.concat(new_path, ";"), table.concat(new_cpath, ";") +end + +do + local new_path, new_cpath = package_paths() + package.path = new_path..";"..package.path + package.cpath = new_cpath..";"..package.cpath end function which_config() diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index cfe06118..7af81c07 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -389,13 +389,28 @@ end function run(...) local flags = util.parse_flags(...) local deps_mode = deps.get_deps_mode(flags) + + local lr_path, lr_cpath = cfg.package_paths() + local bin_dirs = map_trees(deps_mode, deploy_bin_dir) + + if flags["lr-path"] then + util.printout(util.remove_path_dupes(lr_path, ';')) + return true + elseif flags["lr-cpath"] then + util.printout(util.remove_path_dupes(lr_cpath, ';')) + return true + elseif flags["lr-bin"] then + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(util.remove_path_dupes(lr_bin, ';')) + return true + end util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';'))) util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';'))) if flags["bin"] then - local bin_dirs = map_trees(deps_mode, deploy_bin_dir) table.insert(bin_dirs, 1, os.getenv("PATH")) - util.printout(cfg.export_path:format(util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator))) + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(cfg.export_path:format(lr_bin)) end return true end -- cgit v1.2.3-55-g6feb