aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-09-03 16:54:33 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-09-04 14:28:46 -0300
commitdf3072cc88b36815be7ff4890eca6d0f8d4c20da (patch)
tree1e31824a78f521056f0c820ce96b419a226c12f2
parentc300bbf52e9a97248ba57ab8e10b0a5c38c369d4 (diff)
downloadluarocks-df3072cc88b36815be7ff4890eca6d0f8d4c20da.tar.gz
luarocks-df3072cc88b36815be7ff4890eca6d0f8d4c20da.tar.bz2
luarocks-df3072cc88b36815be7ff4890eca6d0f8d4c20da.zip
cfg: only override config file values with detected when giving flags
-rw-r--r--src/luarocks/core/cfg.lua61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 99f609db..4e1b5108 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -527,12 +527,6 @@ function cfg.init(detected, warning)
527 if not hc_ok then 527 if not hc_ok then
528 hardcoded = {} 528 hardcoded = {}
529 end 529 end
530
531 local lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5)
532 local lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg and arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua")
533 local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", ""))
534 local lua_dir = detected.lua_dir or hardcoded.LUA_DIR or (lua_bindir and lua_bindir:gsub("[\\/]bin$", ""))
535 local project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir
536 530
537 local init = cfg.init 531 local init = cfg.init
538 532
@@ -548,15 +542,22 @@ function cfg.init(detected, warning)
548 cfg.program_series = program_series 542 cfg.program_series = program_series
549 cfg.major_version = major_version 543 cfg.major_version = major_version
550 544
551 cfg.lua_version = lua_version 545 -- Use detected values as defaults, overridable via config files or CLI args
552 cfg.lua_interpreter = lua_interpreter
553 546
554 cfg.variables = { 547 cfg.lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5)
555 LUA_DIR = lua_dir, 548 cfg.lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg and arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua")
556 LUA_BINDIR = lua_bindir, 549 cfg.project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir
557 LUA_LIBDIR = hardcoded.LUA_LIBDIR, 550
558 LUA_INCDIR = hardcoded.LUA_INCDIR, 551 do
559 } 552 local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", ""))
553 local lua_dir = detected.lua_dir or hardcoded.LUA_DIR or (lua_bindir and lua_bindir:gsub("[\\/]bin$", ""))
554 cfg.variables = {
555 LUA_DIR = lua_dir,
556 LUA_BINDIR = lua_bindir,
557 LUA_LIBDIR = hardcoded.LUA_LIBDIR,
558 LUA_INCDIR = hardcoded.LUA_INCDIR,
559 }
560 end
560 561
561 cfg.init = init 562 cfg.init = init
562 563
@@ -607,8 +608,8 @@ function cfg.init(detected, warning)
607 local name = "config-"..cfg.lua_version..".lua" 608 local name = "config-"..cfg.lua_version..".lua"
608 sys_config_file = (cfg.sysconfdir .. "/" .. name):gsub("\\", "/") 609 sys_config_file = (cfg.sysconfdir .. "/" .. name):gsub("\\", "/")
609 home_config_file = (cfg.homeconfdir .. "/" .. name):gsub("\\", "/") 610 home_config_file = (cfg.homeconfdir .. "/" .. name):gsub("\\", "/")
610 if project_dir then 611 if cfg.project_dir then
611 project_config_file = project_dir .. "/.luarocks/" .. name 612 project_config_file = cfg.project_dir .. "/.luarocks/" .. name
612 end 613 end
613 end 614 end
614 615
@@ -622,7 +623,7 @@ function cfg.init(detected, warning)
622 local home_config_ok 623 local home_config_ok
623 local project_config_ok 624 local project_config_ok
624 if not hardcoded.FORCE_CONFIG then 625 if not hardcoded.FORCE_CONFIG then
625 local env_var = "LUAROCKS_CONFIG_" .. lua_version:gsub("%.", "_") 626 local env_var = "LUAROCKS_CONFIG_" .. cfg.lua_version:gsub("%.", "_")
626 local env_value = os.getenv(env_var) 627 local env_value = os.getenv(env_var)
627 if not env_value then 628 if not env_value then
628 env_var = "LUAROCKS_CONFIG" 629 env_var = "LUAROCKS_CONFIG"
@@ -651,7 +652,7 @@ function cfg.init(detected, warning)
651 end 652 end
652 653
653 -- finally, use the project-specific config file if any 654 -- finally, use the project-specific config file if any
654 if project_dir then 655 if cfg.project_dir then
655 project_config_ok, err = load_config_file(cfg, platforms, project_config_file) 656 project_config_ok, err = load_config_file(cfg, platforms, project_config_file)
656 if err then 657 if err then
657 return nil, err, "config" 658 return nil, err, "config"
@@ -664,14 +665,16 @@ function cfg.init(detected, warning)
664 -- Let's finish up the cfg table. 665 -- Let's finish up the cfg table.
665 ---------------------------------------- 666 ----------------------------------------
666 667
667 -- Settings given via the CLI (i.e. --lua-dir) take precedence over config files. 668 cfg.variables.LUA_DIR = detected.given_lua_dir or cfg.variables.LUA_DIR
668 cfg.project_dir = detected.given_project_dir or project_dir
669 cfg.lua_version = detected.given_lua_version or lua_version or cfg.lua_version
670 cfg.variables.LUA_DIR = detected.given_lua_dir or cfg.variables.LUA_DIR or lua_dir
671
672 cfg.lua_interpreter = detected.lua_interpreter or cfg.lua_interpreter
673 669
674 cfg.variables.LUA_BINDIR = cfg.variables.LUA_BINDIR or lua_bindir 670 -- Settings given via the CLI (i.e. --lua-dir) take precedence over config files.
671 cfg.project_dir = detected.given_project_dir or cfg.project_dir
672 cfg.lua_version = detected.given_lua_version or cfg.lua_version
673 if detected.given_lua_dir then
674 cfg.variables.LUA_DIR = detected.given_lua_dir
675 cfg.variables.LUA_BINDIR = detected.lua_bindir
676 cfg.lua_interpreter = detected.lua_interpreter
677 end
675 678
676 -- Build a default list of rocks trees if not given 679 -- Build a default list of rocks trees if not given
677 if cfg.rocks_trees == nil then 680 if cfg.rocks_trees == nil then
@@ -684,7 +687,7 @@ function cfg.init(detected, warning)
684 end 687 end
685 end 688 end
686 689
687 local defaults = make_defaults(lua_version, processor, platforms, cfg.home) 690 local defaults = make_defaults(cfg.lua_version, processor, platforms, cfg.home)
688 691
689 if platforms.windows and hardcoded.WIN_TOOLS then 692 if platforms.windows and hardcoded.WIN_TOOLS then
690 local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "WGET", "MKDIR" } 693 local tools = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", "PWD", "RMDIR", "WGET", "MKDIR" }
@@ -701,7 +704,7 @@ function cfg.init(detected, warning)
701 cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch 704 cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch
702 705
703 cfg.config_files = { 706 cfg.config_files = {
704 project = project_dir and { 707 project = cfg.project_dir and {
705 file = project_config_file, 708 file = project_config_file,
706 found = not not project_config_ok, 709 found = not not project_config_ok,
707 }, 710 },
@@ -763,8 +766,8 @@ function cfg.init(detected, warning)
763 766
764 function cfg.init_package_paths() 767 function cfg.init_package_paths()
765 local lr_path, lr_cpath, lr_bin = cfg.package_paths() 768 local lr_path, lr_cpath, lr_bin = cfg.package_paths()
766 package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", lua_version, true) 769 package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", cfg.lua_version, true)
767 package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", lua_version, true) 770 package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", cfg.lua_version, true)
768 end 771 end
769 772
770 --- Check if platform was detected 773 --- Check if platform was detected