aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-20 14:23:06 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 15:51:13 -0300
commit65b1722c12d1ffe99093a2d8ed80d9493ec079a1 (patch)
treed0f1086e837e50ed334dcedf10e3e1d697a7829f /src
parent73bb24caafa90b03744451590eebf24d357f9a2e (diff)
downloadluarocks-65b1722c12d1ffe99093a2d8ed80d9493ec079a1.tar.gz
luarocks-65b1722c12d1ffe99093a2d8ed80d9493ec079a1.tar.bz2
luarocks-65b1722c12d1ffe99093a2d8ed80d9493ec079a1.zip
cmd, cfg: read project-dir configuration
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cmd.lua7
-rw-r--r--src/luarocks/cmd/help.lua9
-rw-r--r--src/luarocks/core/cfg.lua33
3 files changed, 40 insertions, 9 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index 813587e0..d4ee5bc0 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -372,8 +372,13 @@ function cmd.run_command(description, commands, ...)
372 lua_data = cmd.find_lua(flags["lua-dir"], flags["lua-version"]) 372 lua_data = cmd.find_lua(flags["lua-dir"], flags["lua-version"])
373 end 373 end
374 374
375 local project_dir
376 if flags["project-tree"] then
377 project_dir = flags["project-tree"]:gsub("[/\\][^/\\]+$", "")
378 end
379
375 ----------------------------------------------------------------------------- 380 -----------------------------------------------------------------------------
376 local ok, err = cfg.init(lua_data, util.warning) 381 local ok, err = cfg.init(lua_data, project_dir, util.warning)
377 if not ok then 382 if not ok then
378 die(err) 383 die(err)
379 end 384 end
diff --git a/src/luarocks/cmd/help.lua b/src/luarocks/cmd/help.lua
index 3b13acc2..77e73254 100644
--- a/src/luarocks/cmd/help.lua
+++ b/src/luarocks/cmd/help.lua
@@ -85,11 +85,14 @@ function help.command(description, commands, command)
85 util.printout("\tLua version: " .. cfg.lua_version) 85 util.printout("\tLua version: " .. cfg.lua_version)
86 util.printout() 86 util.printout()
87 util.printout("\tConfiguration files:") 87 util.printout("\tConfiguration files:")
88 util.printout("\t\tSystem: ".. dir.normalize(conf.system.file) .. " (" .. get_status(conf.system.ok) ..")") 88 util.printout("\t\tSystem : ".. dir.normalize(conf.system.file) .. " (" .. get_status(conf.system.ok) ..")")
89 if conf.user.file then 89 if conf.user.file then
90 util.printout("\t\tUser : ".. dir.normalize(conf.user.file) .. " (" .. get_status(conf.user.ok) ..")") 90 util.printout("\t\tUser : ".. dir.normalize(conf.user.file) .. " (" .. get_status(conf.user.ok) ..")")
91 else 91 else
92 util.printout("\t\tUser : disabled in this LuaRocks installation.") 92 util.printout("\t\tUser : disabled in this LuaRocks installation.")
93 end
94 if conf.project then
95 util.printout("\t\tProject : ".. dir.normalize(conf.project.file) .. " (" .. get_status(conf.project.ok) ..")")
93 end 96 end
94 util.printout() 97 util.printout()
95 util.printout("\tRocks trees in use: ") 98 util.printout("\tRocks trees in use: ")
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index cd3aadbc..2508fa1d 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -500,7 +500,7 @@ end
500 500
501local cfg = {} 501local cfg = {}
502 502
503function cfg.init(lua_data, warning) 503function cfg.init(lua_data, project_dir, warning)
504 lua_data = lua_data or {} 504 lua_data = lua_data or {}
505 505
506 local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded") 506 local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded")
@@ -581,9 +581,11 @@ function cfg.init(lua_data, warning)
581 581
582 local sys_config_file 582 local sys_config_file
583 local home_config_file 583 local home_config_file
584 local project_config_file
584 do 585 do
585 local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR 586 local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR
586 local sdir, hdir 587 local sdir, hdir
588 local name = "config-"..cfg.lua_version..".lua"
587 if platforms.windows then 589 if platforms.windows then
588 cfg.home = os.getenv("APPDATA") or "c:" 590 cfg.home = os.getenv("APPDATA") or "c:"
589 sdir = sysconfdir or (os.getenv("PROGRAMFILES") or "c:") .. "/luarocks" 591 sdir = sysconfdir or (os.getenv("PROGRAMFILES") or "c:") .. "/luarocks"
@@ -595,11 +597,15 @@ function cfg.init(lua_data, warning)
595 hdir = cfg.home.."/.luarocks" 597 hdir = cfg.home.."/.luarocks"
596 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" 598 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/"
597 end 599 end
598 sys_config_file = sdir .. "/config-"..cfg.lua_version..".lua" 600 sys_config_file = sdir .. "/" .. name
599 home_config_file = hdir .. "/config-"..cfg.lua_version..".lua" 601 home_config_file = hdir .. "/" .. name
600 602
601 sys_config_file = sys_config_file:gsub("\\", "/") 603 sys_config_file = sys_config_file:gsub("\\", "/")
602 home_config_file = home_config_file:gsub("\\", "/") 604 home_config_file = home_config_file:gsub("\\", "/")
605
606 if project_dir then
607 project_config_file = project_dir .. "/.luarocks/" .. name
608 end
603 end 609 end
604 610
605 -- Load system configuration file 611 -- Load system configuration file
@@ -610,6 +616,7 @@ function cfg.init(lua_data, warning)
610 616
611 -- Load user configuration file (if allowed) 617 -- Load user configuration file (if allowed)
612 local home_config_ok 618 local home_config_ok
619 local project_config_ok
613 if not hardcoded.FORCE_CONFIG then 620 if not hardcoded.FORCE_CONFIG then
614 local env_var = "LUAROCKS_CONFIG_" .. lua_version:gsub("%.", "_") 621 local env_var = "LUAROCKS_CONFIG_" .. lua_version:gsub("%.", "_")
615 local env_value = os.getenv(env_var) 622 local env_value = os.getenv(env_var)
@@ -633,7 +640,15 @@ function cfg.init(lua_data, warning)
633 640
634 -- try the alternative defaults if there was no environment specified file or it didn't work 641 -- try the alternative defaults if there was no environment specified file or it didn't work
635 if not home_config_ok then 642 if not home_config_ok then
636 home_config_ok = load_config_file(cfg, platforms, home_config_file) 643 home_config_ok, err = load_config_file(cfg, platforms, home_config_file)
644 if err then
645 return nil, err, "config"
646 end
647 end
648
649 -- finally, use the project-specific config file if any
650 if project_dir then
651 project_config_ok, err = load_config_file(cfg, platforms, project_config_file)
637 if err then 652 if err then
638 return nil, err, "config" 653 return nil, err, "config"
639 end 654 end
@@ -677,6 +692,10 @@ function cfg.init(lua_data, warning)
677 692
678 function cfg.which_config() 693 function cfg.which_config()
679 return { 694 return {
695 project = project_dir and {
696 file = project_config_file,
697 ok = project_config_ok,
698 },
680 system = { 699 system = {
681 file = sys_config_file, 700 file = sys_config_file,
682 ok = sys_config_ok, 701 ok = sys_config_ok,
@@ -685,7 +704,11 @@ function cfg.init(lua_data, warning)
685 file = home_config_file, 704 file = home_config_file,
686 ok = home_config_ok, 705 ok = home_config_ok,
687 }, 706 },
688 nearest = home_config_ok and home_config_file or sys_config_file, 707 nearest = project_config_ok
708 and project_config_file
709 or (home_config_ok
710 and home_config_file
711 or sys_config_file),
689 } 712 }
690 end 713 end
691 714