derive PMODULES_ROOT from PMODULES_HOME

This commit is contained in:
2022-05-13 11:32:35 +02:00
parent 1edda11174
commit 0b43ed2280
14 changed files with 204 additions and 287 deletions
-6
View File
@@ -11,10 +11,6 @@ fi
############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_ROOT} ]]; then
echo "Oops: ${PMODULES_ROOT}: Set as Pmodules root, but this is not a directory." 1>&2
return 1
fi
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
@@ -35,8 +31,6 @@ unset MODULE_VERSION_STACK
unset MODULESHOME
unset PMODULES_ENV
declare -x PMODULES_MODULEFILES_DIR='modulefiles'
declare -x PMODULES_CONFIG_DIR='config'
declare -x PMODULES_DIR="${PMODULES_HOME}"
-7
View File
@@ -35,13 +35,6 @@ unset prefix
unset postfix
setenv MODULEPATH
foreach group ( ${DefaultGroups} )
if ( "${MODULEPATH}" == "" ) then
setenv MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
else
setenv MODULEPATH "${MODULEPATH}:${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
endif
end
if (! $?LOADEDMODULES ) then
setenv LOADEDMODULES ""
+3 -3
View File
@@ -314,11 +314,11 @@ proc ModulesHelp { } {
# intialize global vars
# Modulefile is something like
#
# ${PMODULES_ROOT}/group/modulefiles/name/version
# <root_dir>/group/modulefiles/name/version
# or
# ${PMODULES_ROOT}/group/modulefiles/X1/Y1/name/version
# <root_dir>/group/modulefiles/X1/Y1/name/version
# or
# ${PMODULES_ROOT}/group/modulefiles/X1/Y1//X2/Y2/name/version
# <root_dir>/group/modulefiles/X1/Y1//X2/Y2/name/version
#
proc _find_overlay { modulefile_components } {
debug "_find_overlay()"
+23 -3
View File
@@ -941,7 +941,7 @@ pbuild::make_all() {
}
#......................................................................
# Install modulefile in ${PMODULES_ROOT}/${GROUP}/modulefiles/...
# Install modulefile in ${pm_root}/${GROUP}/modulefiles/...
#
# Arguments
# none
@@ -1436,10 +1436,10 @@ pbuild.build_module() {
# :FIXME: this is a hack!!!
# shouldn't this be set in the build-script?
if [[ -e "${PMODULES_ROOT}/Libraries" ]]; then
if [[ -e "${PMODULES_HOME%%/Tools*}/Libraries" ]]; then
eval $( "${MODULECMD}" bash use Libraries )
fi
if [[ -e "${PMODULES_ROOT}/System" ]]; then
if [[ -e "${PMODULES_HOME%%/Tools*}/System" ]]; then
eval $( "${MODULECMD}" bash use System )
fi
unset C_INCLUDE_PATH
@@ -1493,6 +1493,26 @@ pbuild.bootstrap() {
pbuild::make_all
}
#-----------------------------------------------------------------------------
#
read_config_file() {
local fname="$1"
if [[ ! -r "${fname}" ]]; then
std::die 1 "Configuration file '${fname}' does not exist or is not readable!"
fi
eval $(std::parse_yaml "${fname}" '') || std::die 1 "Cannot read configuration file '${fname}'"
PMODULES_ROOT="${Overlays_base_install_root}"
PMODULES_DISTFILESDIR="${DistfilesDir}"
PMODULES_TMPDIR="${TmpDir}"
PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
if [[ -z "${PMODULES_HOME}" ]]; then
std::die 1 "Error in configuration file '${fname}': PMODULE_HOME not defined!"
fi
}
# Local Variables:
# mode: sh
# sh-basic-offset: 8
+15 -14
View File
@@ -9,7 +9,7 @@ declare -A Help=()
# initialize help text of 'module --version'
Help['version']="
Pmodules @PMODULES_VERSION@ using Tcl Environment Modules @MODULES_VERSION@
Pmodules @PMODULES_VERSION@ using Tcl Environment Modules
Copyright GNU GPL v2
"
@@ -78,14 +78,14 @@ get_ol_config_files(){
if [[ -r "${HOME}/.Pmodules/Pmodules.yaml" ]]; then
files+=("${HOME}/.Pmodules/Pmodules.yaml")
fi
test -r "${PMODULES_ROOT}/config/Pmodules.yaml" || \
test -r "${PMODULES_HOME%%/Tools*}/config/Pmodules.yaml" || \
std::die 3 \
"%s %s -- %s" \
"base overlay definition file" \
"does not exist or is not readable" \
"$_"
files+=("${PMODULES_ROOT}/config/Pmodules.yaml")
files+=("${PMODULES_HOME%%/Tools*}/config/Pmodules.yaml")
std::upvar "$1" "${files[@]}"
}
@@ -93,24 +93,24 @@ get_ol_config_files(){
get_ol_install_root(){
# $1 overlay name
# ${@:2} files
yq -Ne e ".overlays.$1.install_root" - < <(cat "${@:2}") 2>/dev/null
yq -Ne e ".Overlays.$1.install_root" - < <(cat "${@:2}") 2>/dev/null
}
get_ol_modulefiles_root(){
# $1 overlay name
# ${@:2} files
yq -Ne e ".overlays.$1.modulefiles_root" - < <(cat "${@:2}") 2>/dev/null
yq -Ne e ".Overlays.$1.modulefiles_root" - < <(cat "${@:2}") 2>/dev/null
}
get_ol_type(){
# $1 overlay name
# ${@:2} files
yq -Ne e ".overlays.$1.type" - < <(cat "${@:2}") 2>/dev/null
yq -Ne e ".Overlays.$1.type" - < <(cat "${@:2}") 2>/dev/null
}
get_ol_names(){
# ${@} files
yq -Ne e ".overlays|keys" - < <(cat "$@") 2>/dev/null | cut -b3-
yq -Ne e ".Overlays|keys" - < <(cat "$@") 2>/dev/null | cut -b3-
}
get_ol_info(){
@@ -154,19 +154,20 @@ get_ol_info(){
"${ol_name}" \
"${files[@]}") || \
ol_type="${ol_normal}"
elif [[ "${name_or_dir}" == 'default' ]]; then
ol_name='default'
elif [[ "${name_or_dir}" == 'base' ]]; then
ol_name='base'
ol_type="${ol_normal}"
ol_modulefiles_root="${PMODULES_ROOT}"
ol_install_root="${PMODULES_ROOT}"
else
ol_modulefiles_root="${PMODULES_HOME%%/Tools*}"
ol_install_root="${PMODULES_HOME%%/Tools*}"
else
return 1
fi
[[ -n "$2" ]] && std::upvar "$2" "${ol_name}"
[[ -n "$3" ]] && std::upvar "$3" "${ol_type}"
[[ -n "$4" ]] && std::upvar "$4" "${ol_install_root}"
[[ -n "$5" ]] && std::upvar "$5" "${ol_modulefiles_root}"
[[ -n "$5" ]] && std::upvar "$5" "$(eval "echo ${ol_modulefiles_root}")"
return 0
}
# Local Variables:
+88 -68
View File
@@ -34,6 +34,7 @@ source libstd.bash || {
# can be set in the configuration file
declare PMODULES_DISTFILESDIR=''
declare PMODULES_TMPDIR=''
declare pm_root="${PMODULES_HOME%%/Tools*}"
source libpbuild.bash || \
std::die 3 "Oops: cannot source library -- '$_'"
@@ -131,7 +132,7 @@ MISCELLANEOUS OPTIONS:
Directory used for building a module.
--overlay
Install in this overlay. Defaults to '${PMODULES_ROOT}'.
Install in this overlay. Defaults to '${PMODULES_HOME%%/Tools*}'.
"
exit 1
}
@@ -147,7 +148,7 @@ MISCELLANEOUS OPTIONS:
# versions to be build, '.*' or none means all
declare -a versions=()
declare opt_bootstrap='no'
declare opt_build_config='modbuild.conf'
declare opt_build_config='Pmodules.yaml'
declare opt_build_target='all'
declare opt_dry_run='no'
declare opt_enable_cleanup_build='yes'
@@ -408,10 +409,10 @@ build_modules_legacy() {
done
std::die 10 "Aborting..."
fi
declare ol_name='default'
declare ol_name='base'
declare ol_type=''
declare ol_dir="${PMODULES_ROOT}"
declare ol_install_dir="${PMODULES_ROOT}"
declare ol_dir="${pm_root}"
declare ol_install_dir="${pm_root}"
local -i i=0
local -i num_variants=${#variants[@]}
for ((i = 0; i < num_variants; i++)); do
@@ -430,27 +431,52 @@ build_modules_yaml(){
local variants_file="${BUILDBLOCK_DIR}/files/"
variants_file+="${BNAME_VARIANTS}.${opt_system}.yaml"
#
# $1 file name
# $2 module name
# $3 index
#
yaml_get_overlay(){
local ol=$(yq e ".overlay" "${variants_file}")
[[ "${ol}" == 'null' ]] && ol='default'
echo "${ol}"
local ol=$(yq e ".$2.variants[$3].overlay" "$1")
if [[ "${ol}" != 'null' ]]; then
echo "${ol}"
return
fi
ol=$(yq e ".$2.overlay" "$1")
if [[ "${ol}" != 'null' ]]; then
echo "${ol}"
return
fi
echo 'base'
}
yaml_get_versions(){
yq e "with_entries(select(.key | test(\"$1\"))) | keys" \
"${variants_file}"|cut -b3-
}
yaml_get_num_variants(){
yq e ".[\"$1\"].variants | length" \
"${variants_file}"
}
yaml_get_dependencies(){
yq e ".[\"$1\"].variants[$2].dependencies[]" \
"${variants_file}"
yq e ".$2.variants[].version" "$1"
}
yaml_get_rel_stage(){
yq e ".[\"$1\"].variants[$2].relstage" \
"${variants_file}"
yaml_get_num_variants(){
yq e ".$2.variants | length" "$1"
}
yaml_get_version(){
yq e ".$2.variants[$3].version" "$1"
}
yaml_get_dependencies(){
yq e ".$2.variants[$2].dependencies[]" "$1"
}
yaml_get_relstage(){
local relstage=$(yq e ".$2.variants[$3].relstage" "$1")
if [[ "${relstage}" != 'null' ]]; then
echo "${relstage}"
return
fi
relstage=$(yq e ".$2.relstage" "$1")
if [[ "${relstage}" != 'null' ]]; then
echo "${relstage}"
return
fi
echo 'unstable'
}
local name="$1"
@@ -464,39 +490,38 @@ build_modules_yaml(){
pattern+=" && /${m//\//\\/}( |$)/"
done
# precidency:
# 1. overlay passed as argument
# 2. overlay defined for the variant
# 3. default in variants file
# 4. default overlay
local ol_name_or_dir=$(yaml_get_overlay)
get_ol_info "${ol_name_or_dir}" \
ol_name \
ol_type \
ol_dir \
ol_install_dir \
|| std::die 3 "${variants_file##*/}: unknown overlay -- ${ol_name_or_dir}"
# loop over all matching versions and all variants
local key=''
local -a keys=( $(yaml_get_versions "${version}") )
for key in "${keys[@]}"; do
local -i n_variants=$(yaml_get_num_variants "${key}")
for ((i=0; i<n_variants; i++)); do
# check dependencies
local with_modules=()
local -a deps=( $(yaml_get_dependencies "${key}" "$i") )
if (( ${#deps[@]} > 0 )); then
with_modules=( $(brace_expand ${deps[@]} | awk "${pattern}") )
(( ${#with_modules[@]} == 0 )) && continue
fi
local name="${key%/*}"
local version="${key#*/}"
local relstage=$(yaml_get_rel_stage "${key}" "$i")
pbuild.build_module \
"${name}" "${version}" \
"${relstage}" "${with_modules[@]}"
done
local -i n_variants=$(yaml_get_num_variants \
"${variants_file}" "${name}")
local i
for (( i=0; i<n_variants; i++ )); do
local vers=$(yaml_get_version "${variants_file}" "${name}" $i)
[[ "${vers}" != "${version}" ]] && continue
# check dependencies
local with_modules=()
local -a deps=( $(yaml_get_dependencies \
"${variants_file}" \
"${name}" "$i") )
if (( ${#deps[@]} > 0 )); then
with_modules=( $(brace_expand ${deps[@]} | awk "${pattern}") )
(( ${#with_modules[@]} == 0 )) && continue
fi
local relstage=$(yaml_get_relstage \
"${variants_file}" \
"${name}" \
"$i")
local ol=$(yaml_get_overlay \
"${variants_file}" \
"${name}" \
"$i")
get_ol_info "${ol}" \
ol_name \
ol_type \
ol_install_dir \
ol_dir \
|| std::die 3 "${variants_file##*/}: unknown overlay -- ${ol_name_or_dir}"
pbuild.build_module \
"${name}" "${version}" \
"${relstage}" "${with_modules[@]}"
done
}
@@ -526,26 +551,21 @@ pbuild.update_modulefiles "${opt_update_modulefiles}"
pbuild.system "${opt_system}"
pbuild.verbose "${opt_verbose}"
#
# read configuration for modbuild
#
if [[ "${opt_bootstrap}" == 'yes' ]]; then
test -d "${BUILDBLOCK_DIR}/../../config" && PATH+=":$_"
else
# Please note: if we trap DEBUG a statement like
# test -d ... && PATH+=$_
# does not work (at least on macOS with bash 4 and 5)
if [[ -d "${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}" ]]; then
PATH+=":${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}"
fi
fi
source "${opt_build_config}" || \
std::die 3 "Oops: Cannot source configuration file -- '$_'"
read_config_file "${pm_root}/${PMODULES_CONFIG_DIR}/${opt_build_config}"
# :FIXME: should go dist files to
# ${PMODULES_ROOT}/var/distfiles
# ${pm_root}/var/distfiles
# or
# ${overlay}/var/distfiles
# ?
: ${PMODULES_DISTFILESDIR:=${PMODULES_ROOT}/var/distfiles}
: ${PMODULES_DISTFILESDIR:=${pm_root}/var/distfiles}
: ${PMODULES_TMPDIR:=/var/tmp/${USER}}
declare -r BUILD_SCRIPT
@@ -559,10 +579,10 @@ module_name=${fname[${#fname[@]}-2]}
# are we bootstrapping? If yes, go for it...
#
if [[ "${opt_bootstrap}" == 'yes' ]]; then
declare ol_name='default'
declare ol_name='base'
declare ol_type=''
declare ol_dir="${PMODULES_ROOT}"
declare ol_install_dir="${PMODULES_ROOT}"
declare ol_dir="${pm_root}"
declare ol_install_dir="${pm_root}"
pbuild.bootstrap "${module_name}" "${versions[0]}" 'stable'
exit $?
fi
+34 -16
View File
@@ -17,8 +17,10 @@ declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libstd.bash"
source "${libdir}/libpmodules.bash"
declare -r os_name="$(uname -s)"
path="/bin:/usr/bin"
[[ $(uname -s) == 'Darwin' ]] && path="${libexecdir}:${path}"
[[ ${os_name} == 'Darwin' ]] && path="${libexecdir}:${path}"
std::def_cmds "${path}" \
'awk' 'base64' 'find' 'getopt' 'logger' 'mktemp' \
'rm' 'sort' 'find'
@@ -38,7 +40,7 @@ declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'}
declare Shell=''
declare -r pmodules_config_file="${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/Pmodules.yaml"
declare -r pmodules_config_file="${PMODULES_HOME%%/Tools*}/${PMODULES_CONFIG_DIR}/Pmodules.yaml"
# the following settings are used if the config file doesn't exist
@@ -92,6 +94,21 @@ export_env() {
#
declare g_env_must_be_saved='no'
encode_base64(){
case "${os_name}" in
Linux )
"${base64}" --wrap=0 <<< "$1"
;;
Darwin )
# does not wrap if running in a script
"${base64}" <<< "$1"
;;
* )
std::die 255 "Oops: Unsupported OS"
;;
esac
}
save_env() {
[[ $1 == 'no' ]] && return 0
local vars=( Version )
@@ -104,7 +121,7 @@ save_env() {
vars+=( OverlayDict Dir2OverlayMap)
local s=$(typeset -p ${vars[@]})
declare -g PMODULES_ENV=$( "${base64}" --wrap=0 <<< "$s" )
declare -g PMODULES_ENV=$( encode_base64 "$s" )
export_env 'PMODULES_ENV'
}
@@ -172,7 +189,7 @@ get_release_stage() {
}
is_release_stage() {
[[ ${ReleaseStages} =~ :$1: ]]
[[ :${ReleaseStages}: =~ :$1: ]]
}
#
@@ -1627,7 +1644,7 @@ subcommand_unuse() {
"is not an overlay directory" \
"${ol_name_or_dir%:*}"
[[ "${ol_dir}" == "${PMODULES_ROOT}" ]] && \
[[ "${ol_dir}" == "${PMODULES_HOME%%/Tools*}" ]] && \
std::die 3 "%s %s: %s -- %s" \
"${CMD}" "${subcommand}" \
"cannot remove root overlay" \
@@ -1862,13 +1879,13 @@ init_manpath() {
}
pmodules_init() {
if [[ -r "${pmodules_config_file}" ]]; then
eval $(yq -Ne e ".defaults" ${pmodules_config_file} | \
awk '/DefaultGroups|ReleaseStages|DefaultReleaseStages/ {
printf "%s=%s\n",substr($1,1,length($1)-1), $2}') || \
std::die 3 "Oops: cannot parse config file -- %s\n" \
"${pmodules_config_file}"
fi
[[ -r "${pmodules_config_file}" ]] || \
std::die 3 "Oops: cannot read config file -- %s\n" \
"${pmodules_config_file}"
eval $(std::parse_yaml "${pmodules_config_file}" '') || \
std::die 3 "Oops: cannot parse config file -- %s\n" \
"${pmodules_config_file}"
declare -gx LOADEDMODULES=''
declare -gx _LMFILES_=''
declare -gx UsedGroups=''
@@ -2445,7 +2462,7 @@ subcommand_search() {
# :FIXME: do we need this?
if (( ${#GroupDepths[@]} == 0 )) || \
[[ ${src_prefix} != ${PMODULES_ROOT} ]]; then
[[ ${src_prefix} != ${PMODULES_HOME%%/Tools*} ]]; then
scan_groups "${src_prefix}"
g_env_must_be_saved='yes'
fi
@@ -2768,9 +2785,10 @@ if [[ -z "${Subcommands[${subcommand}]}" ]]; then
fi
init_overlay_vars() {
declare -ag OverlayList=( "${PMODULES_ROOT}" )
declare -Ag OverlayNames=( [${PMODULES_ROOT}]='base' )
declare -Ag OverlayDict=([${PMODULES_ROOT}]="0:${PMODULES_ROOT}")
local -r pm_root="${PMODULES_HOME%%/Tools*}"
declare -ag OverlayList=( "${pm_root}" )
declare -Ag OverlayNames=( [${pm_root}]='base' )
declare -Ag OverlayDict=([${pm_root}]="0:${pm_root}")
declare -Ag Dir2OverlayMap=()
local overlay
for overlay in "${!OverlayDict[@]}"; do
+1 -1
View File
@@ -10,7 +10,7 @@ Pmodules are a hierarchical module environment based on Environment Modules.
"
#
# It might be that '${PMODULES_ROOT}/Tools/Pmodules/VERSION' is in PATH.
# It might be that '${PMODULES_HOME}' is in PATH.
# Why? With older version the PATH might have been set without loading
# a module.
#
+5 -4
View File
@@ -1,13 +1,14 @@
#!/bin/bash
#
# The following settings are system defaults. They can be (re-)defined
# in a system wide profile or in a user's profile.
# set default version
: ${PMODULES_VERSION:=@PMODULES_VERSION@}
declare -x PMODULES_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
##### no changes below this line ######
declare __pm_root__=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
declare -x PMODULES_HOME="${__pm_root__}/Tools/Pmodules/${PMODULES_VERSION}"
unset __pm_root__
test -r "${PMODULES_HOME}/init/bash" && source "$_"
+1 -21
View File
@@ -9,28 +9,8 @@ if ( ${PMODULES_VERSION} == "" ) then
setenv PMODULES_VERSION "@PMODULES_VERSION@"
endif
#############################################################################
# N O C H A N G E S B E L O W T H I S L I N E ! #
#############################################################################
setenv PMODULES_HOME "@PMODULES_ROOT@/Tools/Pmodules/${PMODULES_VERSION}"
setenv PMODULES_MODULEFILES_DIR 'modulefiles'
setenv ReleaseStages ':unstable:stable:deprecated:'
setenv PMODULES_ROOT "@PMODULES_ROOT@"
setenv PMODULES_CONFIG_DIR 'config'
setenv PMODULES_HOME "${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
setenv PMODULES_DIR "${PMODULES_HOME}"
############################################################################
# some sanity checks
#
# fixme: add some checks
############################################################################
# inititialize Pmodules for csh
#
set _init_csh="${PMODULES_HOME}/init/csh"
if ( ! -r "${_init_csh}" ) then
echo "Oops: cannot initialize Modules!"
+9 -40
View File
@@ -1,50 +1,19 @@
#!/bin/bash
#
# Notes:
# - PMODULES_ROOT is derived from the location of this file.
# - Some for PMODULES_CONFIG_DIR.
# - The Pmodules software must be installed in
# ${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}
#!/bin/zsh
#
declare -xa DefaultGroups
declare -xa DefaultReleaseStages
declare -x PMODULES_VERSION
: ${DefaultGroups:=(Tools Programming)}
: ${DefaultReleaseStages:=(stable)}
# set default version
: ${PMODULES_VERSION:=@PMODULES_VERSION@}
#############################################################################
# N O C H A N G E S B E L O W T H I S L I N E ! #
#############################################################################
##### no changes below this line ######
declare -x PMODULES_MODULEFILES_DIR='modulefiles'
declare -x ReleaseStages=':unstable:stable:deprecated:'
declare __pm_root__=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
declare -x PMODULES_HOME="${__pm_root__}/Tools/Pmodules/${PMODULES_VERSION}"
unset __pm_root__
declare -x PMODULES_ROOT=$(cd $(dirname "${(%):-%N}")/.. && pwd)
declare -x PMODULES_CONFIG_DIR=$(basename $(cd $(dirname "${(%):-%N}") && pwd))
declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
declare -x PMODULES_DIR="${PMODULES_HOME}"
test -r "${PMODULES_HOME}/init/bash" && source "$_"
############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_ROOT} ]]; then
echo "Oops: ${PMODULES_ROOT}: Set as Pmodules root, but this is not a directory." 1>&2
return 1
fi
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
############################################################################
# inititialize Pmodules for zsh
#
test -r "${PMODULES_HOME}/init/zsh" && source "$_"
if (( $? != 0 )); then
echo "Oops: cannot initialize Pmodules environment!"
if [[ $? != 0 ]]; then
echo "Oops: cannot initialize Pmodules!"
return 1
fi
+22 -96
View File
@@ -1,105 +1,19 @@
#!/bin/zsh
#############################################################################
# implement module comand as function
############################################################################
# some sanity checks
#
module() {
local -r modulecmd="${PMODULES_HOME}/bin/modulecmd"
local -a args=()
local -a modulecmd_opts=()
local -a subcmd_opts=()
while (( $# > 0 )); do
case $1 in
-* )
modulecmd_opts+=( $1 )
shift
;;
* )
break
;;
esac
done
local -r subcmd="$1"
shift
while (( $# > 0 )); do
case $1 in
-* )
subcmd_opts+=( $1 )
;;
[/~a-zA-Z]* )
args+=( $1 )
;;
esac
shift
done
[[ -z ${subcmd} ]] && args+=( 'help' )
[[ ${#args[@]} == 0 ]] && args+=( '--' )
# Loop over all modules to load.
# Note: We have to eval here, otherwise we cannot do something like
# $ module load gcc/5.2.0 openmpi/1.8.8 hdf5/1.8.15
local m
for module in ${args[@]}; do
eval $( "${modulecmd}" zsh "${modulecmd_opts[@]}" "${subcmd}" \
"${subcmd_opts[@]}" "${module}" )
done
}
export -f module
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
#############################################################################
# helper functions
# initialize bash completion
#
save_env() {
local s=''
while (( $# > 0 )); do
s+="$( typeset -p $1 );"
shift
done
echo export PMODULES_ENV=$( "${PMODULES_HOME}/sbin/base64" --wrap=0 <<< "$s" )
}
#############################################################################
# setup environment
#
declare -x LOADEDMODULES=''
declare -x _LMFILES_=''
# build initial MODULEPATH
declare -x MODULEPATH=''
typeset -T MODULEPATH modulepath
for group in ${DefaultGroups[@]}; do
dir="${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
modulepath=( "${dir}" ${(m)modulepath:#${dir}} )
done
# build initial list of used releases
declare -x UsedReleases=''
typeset -T UsedReleases usedreleases
for r in ${DefaultReleaseStages[@]}; do
usedreleases=( "${r}" ${(m)usedreleases:#${r}} )
done
eval $(save_env UsedReleases DefaultReleaseStages DefaultGroups ReleaseStages)
unset UsedReleases
unset DefaultReleaseStages
unset DefaultGroups
unset ReleaseStages
# initialize MANPATH with output of `man --path` if not set
[[ -z "${MANPATH}" ]] && manpath=$( man --path )
# add man pages of Pmodules and remove all other Pmodules man pages
manpath=( "${PMODULES_HOME}/share/man" ${(m)manpath:#${dirs_to_remove}} )
# initialize completion
test -r "${PMODULES_HOME}/init/zsh_completion" && source "$_"
# cleanup
unset group dir r dirs_to_remove
if [[ -r "${PMODULES_HOME}/init/bash_completion" ]]; then
source "${PMODULES_HOME}/init/bash_completion"
fi
#############################################################################
# legacy...
@@ -107,6 +21,18 @@ unset group dir r dirs_to_remove
unset MODULE_VERSION
unset MODULE_VERSION_STACK
unset MODULESHOME
unset PMODULES_ENV
declare -x PMODULES_DIR="${PMODULES_HOME}"
#############################################################################
# implement module comand as shell function
#
module() {
eval $("${PMODULES_HOME}/bin/modulecmd" bash "$@")
}
export -f module
# Local Variables:
# mode: sh
+2 -2
View File
@@ -5,7 +5,7 @@ declare -rx CC=gcc
pbuild::set_download_url "https://amas.web.psi.ch/Downloads/$P/$P-$V.tar.bz2"
TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
TCL_DIR="${PMODULES_HOME}"
PATH="${TCL_DIR}/bin:${PATH}"
@@ -21,7 +21,7 @@ pbuild::configure() {
CPPFLAGS="-DUSE_INTERP_ERRORLINE" "${SRC_DIR}"/configure \
--prefix="${PREFIX}" \
--exec-prefix="${PREFIX}" \
--with-module-path="${PMODULES_ROOT}/Tools/${PMODULES_MODULEFILES_DIR}" \
--with-module-path="${PMODULES_HOME%%/Tools*}/Tools/${PMODULES_MODULEFILES_DIR}" \
--with-tcl="${TCL_DIR}/lib" \
--without-x \
--disable-versioning \
+1 -6
View File
@@ -1,16 +1,11 @@
#!/bin/bash
#
: ${PMODULES_ROOT:=@PMODULES_ROOT@}
: ${PMODULES_DISTFILESDIR:=@PMODULES_DISTFILESDIR@}
: ${PMODULES_TMPDIR:=@PMODULES_TMPDIR@}
export PMODULES_ROOT
export PMODULES_DISTFILESDIR
export PMODULES_TMPDIR
declare -x PMODULES_CONFIG_DIR='config'
declare -x PMODULES_MODULEFILES_DIR='modulefiles'
declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
declare -x PMODULES_HOME="@PMODULES_ROOT@/Tools/Pmodules/${PMODULES_VERSION}"
declare -x DefaultGroups='Tools Programming'
declare ReleaseStages=':unstable:stable:deprecated:'