diff --git a/src/Configuration.lua b/src/Configuration.lua index e1cfecb54..ef8a686e2 100644 --- a/src/Configuration.lua +++ b/src/Configuration.lua @@ -156,6 +156,7 @@ local function l_new(self) local mpath_avail = cosmic:value("LMOD_MPATH_AVAIL") local mpath_init = cosmic:value("LMOD_MODULEPATH_INIT") local mpath_root = cosmic:value("MODULEPATH_ROOT") + local mAutoHanding = cosmic:value("MODULES_AUTO_HANDLING") local nag = cosmic:value("LMOD_ADMIN_FILE") local pager = cosmic:value("LMOD_PAGER") local pager_opts = cosmic:value("LMOD_PAGER_OPTS") @@ -237,6 +238,7 @@ local function l_new(self) tbl.luaV = { k = "Lua Version" , v = _VERSION, n = false } tbl.lua_term = { k = "System lua-term" , v = have_term, n = "LMOD_HAVE_LUA_TERM" } tbl.lua_term_A = { k = "Active lua-term" , v = activeTerm, n = false } + tbl.mAutoHndl = { k = "Modules Auto Handling" , v = mAutoHanding, n = "MODULES_AUTO_HANDLING" } tbl.mpath_av = { k = "avail: Include modulepath dir" , v = mpath_avail, n = "LMOD_MPATH_AVAIL" } tbl.mpath_init = { k = "MODULEPATH_INIT" , v = mpath_init, n = "LMOD_MODULEPATH_INIT" } tbl.mpath_root = { k = "MODULEPATH_ROOT" , v = mpath_root, n = "MODULEPATH_ROOT" } @@ -248,7 +250,7 @@ local function l_new(self) tbl.pager_opts = { k = "Pager Options" , v = pager_opts, n = "LMOD_PAGER_OPTS" } tbl.path_hash = { k = "Path to HashSum" , v = hashsum_path, n = "LMOD_HASHSUM_PATH" } tbl.path_lua = { k = "Path to Lua" , v = lua_path, n = false } - tbl.dsConflicts = { k = "Downstream Module Conflicts" , v = dsConflicts, n = "LMOD_DOWNSTREAM_CONFLICTS" } + tbl.dsConflicts = { k = "Downstream Module Conflicts" , v = dsConflicts, n = "LMOD_DOWNSTREAM_CONFLICTS" } tbl.pin_v = { k = "Pin Versions in restore" , v = pin_versions, n = "LMOD_PIN_VERSIONS" } tbl.pkg = { k = "Pkg Class name" , v = pkgName, n = false } tbl.prefix = { k = "Lmod prefix" , v = "@PREFIX@", n = false } diff --git a/src/MC_Access.lua b/src/MC_Access.lua index 9b94a4bec..8f8ed837b 100644 --- a/src/MC_Access.lua +++ b/src/MC_Access.lua @@ -111,6 +111,7 @@ M.complete = MainControl.quiet M.uncomplete = MainControl.quiet M.conflict = MainControl.quiet M.depends_on = MainControl.quiet +M.depends_on_any = MainControl.quiet M.error = MainControl.quiet M.execute = MainControl.execute M.extensions = MainControl.quiet diff --git a/src/MC_CheckSyntax.lua b/src/MC_CheckSyntax.lua index aafca3670..992f4dc7e 100644 --- a/src/MC_CheckSyntax.lua +++ b/src/MC_CheckSyntax.lua @@ -56,6 +56,7 @@ M.color_banner = MainControl.quiet M.complete = MainControl.quiet M.conflict = MainControl.quiet M.depends_on = MainControl.quiet +M.depends_on_any = MainControl.quiet M.error = MainControl.error M.execute = MainControl.quiet M.extensions = MainControl.quiet diff --git a/src/MC_ComputeHash.lua b/src/MC_ComputeHash.lua index 01e50151a..aebea067e 100644 --- a/src/MC_ComputeHash.lua +++ b/src/MC_ComputeHash.lua @@ -174,6 +174,14 @@ function M.depends_on(self, mA) A[#A+1] = ShowCmdA("depends_on", mA) end +-------------------------------------------------------------------------- +---- Print depends_on command. +---- @param self A MainControl object +---- @param mA An array of module names (MName objects) +function M.depends_on_any(self, mA) + A[#A+1] = ShowCmdA("depends_on_any", mA) +end + -------------------------------------------------------------------------- -- Print load command. -- @param self A MainControl object diff --git a/src/MC_DependencyCk.lua b/src/MC_DependencyCk.lua index b9e6a3a66..bae25a38f 100644 --- a/src/MC_DependencyCk.lua +++ b/src/MC_DependencyCk.lua @@ -56,6 +56,7 @@ M.color_banner = MainControl.quiet M.complete = MainControl.quiet M.conflict = MainControl.quiet M.depends_on = MainControl.dependencyCk +M.depends_on_any = MainControl.dependencyCk_any M.execute = MainControl.quiet M.extensions = MainControl.quiet M.family = MainControl.quiet diff --git a/src/MC_Load.lua b/src/MC_Load.lua index 70f3772e8..f2b04dc06 100644 --- a/src/MC_Load.lua +++ b/src/MC_Load.lua @@ -54,6 +54,7 @@ M.color_banner = MainControl.color_banner M.complete = MainControl.complete M.conflict = MainControl.conflict M.depends_on = MainControl.depends_on +M.depends_on_any = MainControl.depends_on_any M.execute = MainControl.execute M.extensions = MainControl.quiet M.family = MainControl.family diff --git a/src/MC_MgrLoad.lua b/src/MC_MgrLoad.lua index a3f3fafc4..98356258c 100644 --- a/src/MC_MgrLoad.lua +++ b/src/MC_MgrLoad.lua @@ -55,6 +55,7 @@ M.color_banner = MainControl.color_banner M.complete = MainControl.complete M.conflict = MainControl.conflict M.depends_on = MainControl.fake_load +M.depends_on_any = MainControl.fake_load M.execute = MainControl.execute M.extensions = MainControl.quiet M.family = MainControl.family diff --git a/src/MC_Refresh.lua b/src/MC_Refresh.lua index e70b0d07a..a28005936 100644 --- a/src/MC_Refresh.lua +++ b/src/MC_Refresh.lua @@ -58,6 +58,7 @@ M.color_banner = MainControl.quiet M.complete = MainControl.complete M.conflict = MainControl.quiet M.depends_on = MainControl.quiet +M.depends_on_any = MainControl.quiet M.execute = MainControl.execute M.extensions = MainControl.quiet M.family = MainControl.quiet diff --git a/src/MC_Show.lua b/src/MC_Show.lua index f69d5b19b..0a1508620 100644 --- a/src/MC_Show.lua +++ b/src/MC_Show.lua @@ -255,6 +255,16 @@ function M.depends_on(self, mA) A[#A+1] = ShowCmdA("depends_on",mA) end +-------------------------------------------------------------------------- +-- Print depends_on_any command. +-- @param self A MainControl object +-- @param mA An array of module names (MName objects) +function M.depends_on_any(self, mA) + A[#A+1] = ShowCmdA("depends_on_any",mA) +end + +-------------------------------------------------------------------------- + M.load_usr = M.load -------------------------------------------------------------------------- diff --git a/src/MC_Spider.lua b/src/MC_Spider.lua index 6d6a135f5..1226dcff3 100644 --- a/src/MC_Spider.lua +++ b/src/MC_Spider.lua @@ -66,6 +66,7 @@ M.color_banner = MainControl.quiet M.complete = MainControl.quiet M.conflict = MainControl.quiet M.depends_on = MainControl.quiet +M.depends_on_any = MainControl.quiet M.error = MainControl.quiet M.execute = MainControl.execute M.inherit = MainControl.quiet diff --git a/src/MC_Unload.lua b/src/MC_Unload.lua index 4ea4186a4..7379df8c2 100644 --- a/src/MC_Unload.lua +++ b/src/MC_Unload.lua @@ -58,6 +58,7 @@ M.color_banner = MainControl.color_banner M.complete = MainControl.uncomplete M.conflict = MainControl.removeConflict M.depends_on = MainControl.forgo +M.depends_on_any = MainControl.forgo_any M.error = MainControl.warning M.execute = MainControl.execute M.extensions = MainControl.quiet diff --git a/src/MainControl.lua b/src/MainControl.lua index b8817dc31..eabc2c35b 100644 --- a/src/MainControl.lua +++ b/src/MainControl.lua @@ -975,6 +975,52 @@ function M.depends_on(self, mA) return a end +------------------------------------------------------------------- +-- depends_on_any() a list of modules. This is short hand for: +-- +-- if (isloaded(any("mod1, mod2, modN"))) then done end +-- if no module loadable error. +-- + +function M.depends_on_any(self, mA) + if (dbg.active()) then + local s = mAList(mA) + dbg.start{"MainControl:depends_on_any(mA={"..s.."})"} + end + + local mt = FrameStk:singleton():mt() + local mB = {} + + for i = 1,#mA do + local mname = mA[i] + if (mname:isloaded()) then + mt:safely_incr_ref_count(mname) + dbg.fini("MainControl:depends_on_any") + return {} + elseif (mname:sn()) then + mB[#mB + 1] = mname + end + end + + if (next(mB) == nil) then + local s = mAList(mA) + LmodError{msg="e_Failed_depends_any", module_list=s} + end + + + local mC = {mB[1]} + local mname = mC[1] + mname:set_depends_on_flag(true) + + l_registerUserLoads(mC) + local a = self:load(mC) + + self:registerDependencyCk() + + dbg.fini("MainControl:depends_on_any") + return a +end + ------------------------------------------------------------------- -- forgo a list of modules. This is the reverse of depends_on() -- diff --git a/src/modfuncs.lua b/src/modfuncs.lua index 08014b62a..9a5827d87 100644 --- a/src/modfuncs.lua +++ b/src/modfuncs.lua @@ -851,6 +851,14 @@ function depends_on(...) dbg.fini("depends_on") end +function depends_on_any(...) + dbg.start{"depends_on_any(",l_concatTbl({...},", "),")"} + if (not l_validateModules("depends_on_any",...)) then return {} end + + local b = mcp:depends_on_any(MName:buildA(mcp:MNameType(),...)) + dbg.fini("depends_on_any") +end + function extensions(...) dbg.start{"extensions(",l_concatTbl({...},", "),")"} if (not l_validateStringArgs("extensions",...)) then return {} end diff --git a/src/myGlobals.lua b/src/myGlobals.lua index 716745369..6eb0e7212 100644 --- a/src/myGlobals.lua +++ b/src/myGlobals.lua @@ -731,6 +731,15 @@ cosmic:init{name = "LMOD_HASHSUM_PATH", sedV = "@hashsum@", default = HashSum} +------------------------------------------------------------------------ +-- MODULES_AUTO_HANDLING: If true the make prereq -> depends_on +-- prereq_any -> depends_on_any +------------------------------------------------------------------------ + +cosmic:init{name = "MODULES_AUTO_HANDLING", + sedV = "@modules_auto_handling@", + default = "no"} + ------------------------------------------------------------------------ -- PATH_TO_LUA ------------------------------------------------------------------------ diff --git a/src/sandbox.lua b/src/sandbox.lua index 91d133341..671f09d2d 100644 --- a/src/sandbox.lua +++ b/src/sandbox.lua @@ -109,7 +109,7 @@ local sandbox_env = { unload = unload, always_load = always_load, depends_on = depends_on, - + depends_on_any = depends_on_any, --- Load Modify functions --- atleast = atleast,