aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/cfg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/cfg.lua')
-rw-r--r--src/luarocks/cfg.lua42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 2e86c3ca..8b5984ef 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -17,6 +17,8 @@ local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs,
17local cfg = {} 17local cfg = {}
18package.loaded["luarocks.cfg"] = cfg 18package.loaded["luarocks.cfg"] = cfg
19 19
20local util = require("luarocks.util")
21
20cfg.lua_version = _VERSION:sub(5) 22cfg.lua_version = _VERSION:sub(5)
21local version_suffix = cfg.lua_version:gsub("%.", "_") 23local version_suffix = cfg.lua_version:gsub("%.", "_")
22 24
@@ -167,7 +169,6 @@ if not site_config.LUAROCKS_FORCE_CONFIG then
167 end 169 end
168 if home_overrides then 170 if home_overrides then
169 home_config_ok = true 171 home_config_ok = true
170 local util = require("luarocks.util")
171 if home_overrides.rocks_trees then 172 if home_overrides.rocks_trees then
172 cfg.rocks_trees = nil 173 cfg.rocks_trees = nil
173 end 174 end
@@ -217,12 +218,13 @@ local defaults = {
217 "http://rocks.moonscript.org", 218 "http://rocks.moonscript.org",
218 "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/", 219 "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/",
219 "http://luafr.org/moonrocks/", 220 "http://luafr.org/moonrocks/",
221 "http://luarocks.logiceditor.com/rocks",
220 } 222 }
221 }, 223 },
222 disabled_servers = {}, 224 disabled_servers = {},
223 225
224 upload = { 226 upload = {
225 server = "rocks.moonscript.org", 227 server = "https://rocks.moonscript.org",
226 tool_version = "0.0.1", 228 tool_version = "0.0.1",
227 api_version = "1", 229 api_version = "1",
228 }, 230 },
@@ -527,20 +529,28 @@ local cfg_mt = {
527} 529}
528setmetatable(cfg, cfg_mt) 530setmetatable(cfg, cfg_mt)
529 531
532function cfg.make_paths_from_tree(tree)
533 local lua_path, lib_path, bin_path
534 if type(tree) == "string" then
535 lua_path = tree..cfg.lua_modules_path
536 lib_path = tree..cfg.lib_modules_path
537 bin_path = tree.."/bin"
538 else
539 lua_path = tree.lua_dir or tree.root..cfg.lua_modules_path
540 lib_path = tree.lib_dir or tree.root..cfg.lib_modules_path
541 bin_path = tree.bin_dir or tree.root.."/bin"
542 end
543 return lua_path, lib_path, bin_path
544end
545
530function cfg.package_paths() 546function cfg.package_paths()
531 local new_path, new_cpath, new_bin = {}, {}, {} 547 local new_path, new_cpath, new_bin = {}, {}, {}
532 for _,tree in ipairs(cfg.rocks_trees) do 548 for _,tree in ipairs(cfg.rocks_trees) do
533 if type(tree) == "string" then 549 local lua_path, lib_path, bin_path = cfg.make_paths_from_tree(tree)
534 table.insert(new_path, tree..cfg.lua_modules_path.."/?.lua") 550 table.insert(new_path, lua_path.."/?.lua")
535 table.insert(new_path, tree..cfg.lua_modules_path.."/?/init.lua") 551 table.insert(new_path, lua_path.."/?/init.lua")
536 table.insert(new_cpath, tree..cfg.lib_modules_path.."/?."..cfg.lib_extension) 552 table.insert(new_cpath, lib_path.."/?."..cfg.lib_extension)
537 table.insert(new_bin, tree.."/bin") 553 table.insert(new_bin, bin_path)
538 else
539 table.insert(new_path, (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?.lua")
540 table.insert(new_path, (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?/init.lua")
541 table.insert(new_cpath, (tree.lib_dir or tree.root..cfg.lib_modules_path).."/?."..cfg.lib_extension)
542 table.insert(new_bin, (tree.bin_dir or tree.root.."/bin"))
543 end
544 end 554 end
545 if extra_luarocks_module_dir then 555 if extra_luarocks_module_dir then
546 table.insert(new_path, extra_luarocks_module_dir) 556 table.insert(new_path, extra_luarocks_module_dir)
@@ -548,6 +558,12 @@ function cfg.package_paths()
548 return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator) 558 return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator)
549end 559end
550 560
561function cfg.init_package_paths()
562 local lr_path, lr_cpath, lr_bin = cfg.package_paths()
563 package.path = util.remove_path_dupes(package.path .. ";" .. lr_path, ";")
564 package.cpath = util.remove_path_dupes(package.cpath .. ";" .. lr_cpath, ";")
565end
566
551function cfg.which_config() 567function cfg.which_config()
552 return sys_config_file, sys_config_ok, home_config_file, home_config_ok 568 return sys_config_file, sys_config_ok, home_config_file, home_config_ok
553end 569end