Skip to content

Commit

Permalink
Issue #680: added depends_on_any modfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcawood committed Apr 10, 2024
1 parent 0aadd8d commit dbd4d00
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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" }
Expand All @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions src/MC_Access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_CheckSyntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/MC_ComputeHash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_DependencyCk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_Load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_MgrLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_Refresh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/MC_Show.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/MC_Spider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MC_Unload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions src/MainControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
--
Expand Down
8 changes: 8 additions & 0 deletions src/modfuncs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/myGlobals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dbd4d00

Please sign in to comment.