From 0aadd8d51077888316395326d88903dccc00fb42 Mon Sep 17 00:00:00 2001 From: Robert McLay Date: Fri, 29 Mar 2024 09:15:11 -0500 Subject: [PATCH] Issue #701: Cleanup paths for PATH, LD_LIBRARY_PATH and MODULEPATH --- rt/spider/mf/Core/intel/intel.lua | 2 +- rt/spider/spider.tdesc | 4 ++-- src/modfuncs.lua | 27 +++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/rt/spider/mf/Core/intel/intel.lua b/rt/spider/mf/Core/intel/intel.lua index 830797fd8..a280d0d80 100644 --- a/rt/spider/mf/Core/intel/intel.lua +++ b/rt/spider/mf/Core/intel/intel.lua @@ -28,7 +28,7 @@ prepend_path('MANPATH', '/vol/local/intel/idb/idb/man') prepend_path('MANPATH', '/vol/local/intel/mkl/mkl/man') setenv( 'MKL_DIR', '/vol/local/intel/mkl/mkl/lib/lib') setenv( 'MKL_INCLUDE', '/vol/local/intel/mkl/mkl/include') -prepend_path('LD_LIBRARY_PATH','/vol/local/intel/mkl/mkl/lib/lib') +prepend_path('LD_LIBRARY_PATH','/vol/local/intel/mkl/mkl/lib/lib:') family("compiler") diff --git a/rt/spider/spider.tdesc b/rt/spider/spider.tdesc index e028202f3..766dcde81 100644 --- a/rt/spider/spider.tdesc +++ b/rt/spider/spider.tdesc @@ -132,7 +132,7 @@ testdescript = { unsetMT - rm $HOME/.cache/lmod/spiderT.lua + rm -f $HOME/.cache/lmod/spiderT.lua export MODULEPATH_ROOT2=$testDir/mf2 export MODULEPATH=$MODULEPATH_ROOT2/Core @@ -145,7 +145,7 @@ testdescript = { # Test writing of user cache export LMOD_SHORT_TIME=0 - rm $HOME/.cache/lmod/* + rm -f $HOME/.cache/lmod/* runLmod spider #71 diff --git a/src/modfuncs.lua b/src/modfuncs.lua index 8c52b6859..08014b62a 100644 --- a/src/modfuncs.lua +++ b/src/modfuncs.lua @@ -215,6 +215,8 @@ function load_any(...) return b end +local s_cleanupDirT = { PATH = true, LD_LIBRARY_PATH = true, MODULEPATH = true } + --- PATH functions --- -------------------------------------------------------------------------- -- convert arguments into a table if necessary. @@ -224,22 +226,39 @@ local function l_convert2table(...) if (argA.n == 1 and type(argA[1]) == "table" ) then t = argA[1] - t[1] = t[1]:trim() + t[1] = t[1] else - t[1] = argA[1]:trim() + t[1] = argA[1] t[2] = argA[2] t.delim = argA[3] end + t.priority = tonumber(t.priority or "0") return t end +local function l_cleanupPathArgs(t) + local name = t[1]:trim() + local path = t[2]:trim() + + if (s_cleanupDirT[name]) then + path = path:gsub(":+$",""):gsub("^:+","") + t[2] = path + end + + return t +end + + -------------------------------------------------------------------------- -- Prepend a value to a path like variable. function prepend_path(...) local t = l_convert2table(...) dbg.start{"prepend_path(",l_concatTbl(t,", "),")"} if (not l_validateStringTable(2, "prepend_path",t)) then return end + l_cleanupPathArgs(t) + + mcp:prepend_path(t) dbg.fini("prepend_path") @@ -251,7 +270,7 @@ function append_path(...) local t = l_convert2table(...) dbg.start{"append_path(",l_concatTbl(t,", "),")"} if (not l_validateStringTable(2, "append_path",t)) then return end - + l_cleanupPathArgs(t) mcp:append_path(t) dbg.fini("append_path") end @@ -262,7 +281,7 @@ function remove_path(...) local t = l_convert2table(...) dbg.start{"remove_path(",l_concatTbl(t,", "),")"} if (not l_validateStringTable(2, "remove_path",t)) then return end - + l_cleanupPathArgs(t) mcp:remove_path(t) dbg.fini("remove_path") end