upstream merged

This commit is contained in:
2022-07-25 13:53:51 +02:00
32 changed files with 2549 additions and 2045 deletions
+5 -2
View File
@@ -29,11 +29,9 @@ fi
unset MODULE_VERSION
unset MODULE_VERSION_STACK
unset MODULESHOME
unset PMODULES_ENV
declare -x PMODULES_DIR="${PMODULES_HOME}"
#############################################################################
# implement module comand as shell function
#
@@ -43,6 +41,11 @@ module() {
}
export -f module
modbuild(){
"${PMODULES_HOME}/bin/modbuild" "$@"
}
export -f modbuild
# Local Variables:
# mode: sh
# sh-basic-offset: 8
+25 -23
View File
@@ -43,15 +43,15 @@ proc _pmodules_parse_pmodules_env { } {
Dir2OverlayMap {
array set ::Dir2OverlayMap [regsub -all {[]=[]} $value " "]
}
OverlayDict {
array set ::OverlayDict [regsub -all {[]=[]} $value " "]
OverlayInfo {
array set ::OverlayInfo [regsub -all {[]=[]} $value " "]
}
OverlayList {
UsedOverlays {
array set tmp [regsub -all {[]=[]} $value " "]
set ::OverlayList {}
set ::UsedOverlays {}
set l [lsort [array names tmp]]
foreach k $l {
lappend ::OverlayList $tmp($k)
lappend ::UsedOverlays $tmp($k)
}
}
UsedGroups {
@@ -79,9 +79,10 @@ proc module-addgroup { group } {
if { [module-info mode load] } {
set overlays_to_add {}
foreach overlay $::OverlayList {
foreach overlay $::UsedOverlays {
lappend overlays_to_add $overlay
set ol_type [lindex [split $::OverlayDict($overlay) ":"] 0]
set ol_type $::OverlayInfo($overlay:type)
debug "ol_type=$ol_type"
if { [string compare $ol_type $::ol_replacing] == 0 } {
break
}
@@ -91,10 +92,11 @@ proc module-addgroup { group } {
debug "group=$group"
debug "::variant=$::variant"
set dir [file join \
$overlay \
$::OverlayInfo($overlay:mod_root) \
$group \
$::MODULEFILES_DIR \
{*}$::variant]
debug "dir=$dir"
if { [file isdirectory $dir] } {
debug "prepend $dir to MODULEPATH "
prepend-path MODULEPATH $dir
@@ -122,7 +124,7 @@ proc module-addgroup { group } {
debug "mode=remove: no orphan modules to unload"
}
debug "mode=remove: $env(MODULEPATH)"
foreach overlay $::OverlayList {
foreach overlay $::UsedOverlays {
set dir [file join \
$overlay \
$group \
@@ -325,22 +327,22 @@ proc ModulesHelp { } {
#
proc _find_overlay { modulefile_components } {
debug "_find_overlay()"
foreach ol $::OverlayList {
foreach ol $::UsedOverlays {
debug "$ol"
set ol_dir $::OverlayDict(${ol}:mod_root)
if { [string range $ol_dir end end] == "/" } {
set ol_dir [string range $ol_dir 0 end-1]
set ol_mod_root $::OverlayInfo(${ol}:mod_root)
if { [string range $ol_mod_root end end] == "/" } {
set ol_mod_root [string range $ol_mod_root 0 end-1]
}
debug "$ol_dir"
set ol_dir_splitted [file split $ol_dir]
debug "$ol_mod_root"
set ol_mod_root_splitted [file split $ol_mod_root]
set modulefile_root [file join \
{*}[lrange \
$modulefile_components \
0 [expr [llength $ol_dir_splitted] - 1]]]
0 [expr [llength $ol_mod_root_splitted] - 1]]]
debug "$modulefile_root"
if { [string compare $ol_dir $modulefile_root] == 0 } {
debug "$ol_dir_splitted"
return $ol_dir_splitted
if { [string compare $ol_mod_root $modulefile_root] == 0 } {
debug "$ol_mod_root_splitted"
return $ol_mod_root_splitted
}
}
debug "not found"
@@ -372,8 +374,8 @@ proc _pmodules_init_global_vars { } {
set modulefile_splitted [file split $::ModulesCurrentModulefile]
set ol_dir_splitted [_find_overlay ${modulefile_splitted}]
set rel_modulefile [lrange $modulefile_splitted [llength $ol_dir_splitted] end]
set ol_mod_root_splitted [_find_overlay ${modulefile_splitted}]
set rel_modulefile [lrange $modulefile_splitted [llength $ol_mod_root_splitted] end]
set group [lindex $rel_modulefile 0]
set GROUP "${group}"
set name [lindex $modulefile_splitted end-1]
@@ -384,11 +386,11 @@ proc _pmodules_init_global_vars { } {
set V_RELEASE [lindex [split $tmp _] 0]
lassign [split $V_PKG .] V_MAJOR V_MINOR V_PATCHLVL
set variant [lrange $rel_modulefile 2 end]
set mod_root [file join {*}$ol_dir_splitted]
set mod_root [file join {*}$ol_mod_root_splitted]
debug "mod_root=$mod_root"
set ol $::Dir2OverlayMap($mod_root)
debug "ol=$ol"
set install_prefix [file split $::OverlayDict(${ol}:inst_root)]
set install_prefix [file split $::OverlayInfo(${ol}:inst_root)]
set prefix "$install_prefix $group [lreverse_n $variant 2]"
set PREFIX [file join {*}$prefix]
debug "PREFIX=$PREFIX"
+1088 -1016
View File
File diff suppressed because it is too large Load Diff
-24
View File
@@ -1,24 +0,0 @@
#!/bin/bash
eval "pbuild::pre_prep_${system}() { :; }"
eval "pbuild::pre_prep_${OS}() { :; }"
eval "pbuild::post_prep_${system}() { :; }"
eval "pbuild::post_prep_${OS}() { :; }"
eval "pbuild::add_patch_${system}() { pbuild::add_patch \"\$@\"; }"
eval "pbuild::add_patch_${OD}() { pbuild::add_patch \"\$@\"; }"
eval "pbuild::pre_configure_${system}() { :; }"
eval "pbuild::pre_configure_${OS}() { :; }"
eval "pbuild::post_configure_${system}() { :; }"
eval "pbuild::post_configure_${OS}() { :; }"
eval "pbuild::pre_compile_${system}() { :; }"
eval "pbuild::pre_compile_${OS}() { :; }"
eval "pbuild::post_compile_${system}() { :; }"
eval "pbuild::post_compile_${OS}() { :; }"
eval "pbuild::pre_install_${system}() { :; }"
eval "pbuild::pre_install_${OS}() { :; }"
eval "pbuild::post_install_${system}() { :; }"
eval "pbuild::post_install_${OS}() { :; }"
+73 -38
View File
@@ -8,9 +8,14 @@ declare -A Options=()
declare -A Help=()
declare -a Overlays=()
declare -A OverlayDict
declare -a OverlayList
declare -Ag Dir2OverlayMap
declare -A OverlayInfo
declare -a UsedOverlays
declare -A Dir2OverlayMap
declare -r ol_normal='n'
declare -r ol_hiding='h'
declare -r ol_replacing='r'
# initialize help text of 'module --version'
Help['version']="
@@ -33,33 +38,42 @@ print_help() {
# $1: absolute path of a modulefile directory
#
compute_group_depth () {
local -r dir=$1
test -d "${dir}" || return 1
local -n result="$1"
local -r dir="$2"
if [[ ! -d "${dir}" ]]; then
${mkdir} -p "${dir}" || \
std::die 1 "Cannot create directory -- ${dir}"
fi
local group=${dir%/*}
local group=${group##*/}
[[ -n "${GroupDepths[${group}]}" ]] && return 0
local -i depth=$(${find} "${dir}" -depth \( -type f -o -type l \) \
result=$(${find} "${dir}" -depth \( -type f -o -type l \) \
-printf "%d" -quit 2>/dev/null)
(( depth-=2 ))
(( result-=2 ))
# if a group doesn't contain a modulefile, depth is negativ
# :FIXME: better solution?
(( depth < 0 )) && (( depth = 0 ))
GroupDepths[$group]=${depth}
(( result < 0 )) && (( result = 0 ))
}
#
# (Re-)Scan available groups in given overlays and compute group depth's
#
# Args:
# $1: array of overlays
# $@: overlay names
#
scan_groups () {
local ol
local depth
for ol in "$@"; do
local mod_root="${OverlayDict[${ol}:mod_root]}"
local moduledir
for moduledir in ${mod_root}/*/${PMODULES_MODULEFILES_DIR}; do
compute_group_depth "${moduledir}"
local mod_root="${OverlayInfo[${ol}:mod_root]}"
local dir
for dir in ${mod_root}/*/${PMODULES_MODULEFILES_DIR}; do
local group="${dir%/*}"
group="${group##*/}"
if [[ ! -v GroupDepths[${group}] ]]; then
compute_group_depth depth "${dir}"
GroupDepths[$group]=${depth}
fi
Dir2OverlayMap[${dir%/${PMODULES_MODULEFILES_DIR}*}]="${ol}"
done
done
}
@@ -73,17 +87,24 @@ pm::read_config(){
#
# Args:
# $1 [upvar] result
local -n fnames="$1"
# user defined via environment variable
if [[ -v PMODULES_OVERLAYS_DEF ]]; then
test -r "${PMODULES_OVERLAYS_DEF}" || \
std::die 3 \
"%s -- %s" \
"overlay definition file is not readable" \
"$_"
config_files+=("${PMODULES_OVERLAYS_DEF}")
fnames+=("${PMODULES_OVERLAYS_DEF}")
fi
# user defined
if [[ -r "${HOME}/.Pmodules/Pmodules.yaml" ]]; then
config_files+=("${HOME}/.Pmodules/Pmodules.yaml")
fnames+=("${HOME}/.Pmodules/Pmodules.yaml")
fi
# system config file
test -r "${PMODULES_HOME%%/Tools*}/config/Pmodules.yaml" || \
std::die 3 \
"%s %s -- %s" \
@@ -91,14 +112,19 @@ pm::read_config(){
"does not exist or is not readable" \
"$_"
config_files+=("${PMODULES_HOME%%/Tools*}/config/Pmodules.yaml")
fnames+=("${PMODULES_HOME%%/Tools*}/config/Pmodules.yaml")
}
_get_ol_names(){
${yq} -Ne eval-all '. as $item ireduce ({}; . *+ $item) |.Overlays|keys()' "${config_files[@]}" | awk '{print $2}'
#
# get the names of all overlays
#
local -n fnames="$1"
${yq} -Ne eval-all '. as $item ireduce ({}; . *+ $item) |.Overlays|keys()' \
"${fnames[@]}" | awk '{print $2}'
}
_get_config_files
_get_config_files config_files
eval $(std::parse_yaml "${config_files[-1]}" 'cfg_')
[[ -v cfg_DefaultGroups ]] && DefaultGroups="${cfg_DefaultGroups}"
@@ -106,14 +132,37 @@ pm::read_config(){
[[ -v cfg_ReleaseStages ]] && ReleaseStages="${cfg_ReleaseStages}"
unset ${!cfg_*}
Overlays=( $(_get_ol_names) )
#
# loop over all overlays and save config in OverlayInfo and Dir2OverlayMap
#
# - at least install_root must be specified
# - modulefiles_root default so install_root
# - the type defaults to ${ol_normal}
#
Overlays=( $(_get_ol_names config_files) )
local ol=''
for ol in "${Overlays[@]}"; do
eval $(${yq} -Ne eval-all \
". as \$item ireduce ({}; . *+ \$item) |.Overlays.${ol}" \
"${config_files[@]}" | \
sed 's/: /=/; s/\(.*\)/local \1/')
: ${type:=n}
[[ -n ${install_root} ]] || \
std::die 3 \
"install_root missing for overlay -- ${ol}"
[[ -d ${install_root} ]] || \
std::die 3 \
"Invalid installation root directory for overlay '${ol}' -- ${install_root}"
OverlayInfo[${ol}:inst_root]="${install_root}"
: ${modulefiles_root:=${install_root}}
[[ -d ${modulefiles_root} ]] || \
std::die 3 \
"Invalid modulefiles root directory for overlay '${ol}' -- ${modulefiles_root}"
OverlayInfo[${ol}:mod_root]="${modulefiles_root}"
Dir2OverlayMap[${modulefiles_root}]="${ol}"
: ${type:=${ol_normal}}
case ${type} in
${ol_normal} | ${ol_replacing} | ${ol_hiding} )
:
@@ -122,23 +171,9 @@ pm::read_config(){
std::die 3 "Invalid type for overlay '${ol}' -- ${type}"
;;
esac
OverlayDict[${ol}:type]="${type}"
OverlayInfo[${ol}:type]="${type}"
: ${modulefiles_root:=${PMODULES_HOME%%/Tools*}}
[[ -d ${modulefiles_root} ]] || \
std::die 3 \
"Invalid modulefiles root directory for overlay '${ol}' -- ${modulefiles_root}"
: ${modulefiles_root:=${PMODULES_HOME%%/Tools*}}
OverlayDict[${ol}:mod_root]="${modulefiles_root}"
Dir2OverlayMap[${modulefiles_root}]="${ol}"
: ${install_root:=${PMODULES_HOME%%/Tools*}}
[[ -d ${install_root} ]] || \
std::die 3 \
"Invalid installation root directory for overlay '${ol}' -- ${install_root}"
OverlayDict[${ol}:inst_root]="${install_root:-${PMODULES_HOME%%/Tools*}}"
OverlayDict[${ol}:used]='no'
OverlayInfo[${ol}:used]='no'
unset type modulefiles_root install_root
done
}
+46 -44
View File
@@ -20,7 +20,7 @@ std::error() {
}
std::debug() {
[[ ${PMODULES_DEBUG} ]] || return 0
[[ -v PMODULES_DEBUG ]] || return 0
std::log 2 "$@"
}
@@ -39,7 +39,7 @@ std::def_cmds(){
local path="$1"
shift
for cmd in "$@"; do
eval declare -g ${cmd}=$(PATH="${path}" which $cmd 2>/dev/null)
eval declare -gr ${cmd}=$(PATH="${path}" /usr/bin/which $cmd 2>/dev/null)
if [[ -z "${!cmd}" ]]; then
std::die 255 "${cmd} not found"
fi
@@ -78,42 +78,42 @@ std::get_abspath() {
}
std::append_path () {
local -r P=$1
local -r d=$2
local -nr P="$1"
shift 1
local dir
local dirs=''
for dir in "$@"; do
[[ "${P}" == @(|*:)${dir}@(|:*) ]] && continue
dirs+=":${dir}"
done
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
export "$P=${d}"
else
export "$P=${!P}:${d}"
fi
fi
if [[ -z ${P} ]]; then
P="${dirs:1}" # remove leading ':'
else
P="${P}${dirs}"
fi
}
std::prepend_path () {
local -r P="$1"
local -nr P="$1"
shift 1
local new_path="$1"
shift 1
local dir
if [[ -z ${!P} ]]; then
for dir in "$@"; do
new_path+=":${dir}"
done
export "$P=${new_path}"
local dir
local dirs=''
for dir in "$@"; do
[[ "${P}" == @(|*:)${dir}@(|:*) ]] && continue
dirs+="${dir}:"
done
if [[ -z ${P} ]]; then
P="${dirs:0:-1}" # remove trailing ':'
else
for dir in "$@"; do
[[ "${!P}" == @(|*:)${dir}@(|:*) ]] && continue
new_path+=":${dir}"
done
new_path+=":${!P}"
P="${dirs}${P}"
fi
std::upvar "$P" "${new_path}"
}
std::remove_path() {
local -r P=$1
local -nr P="$1"
shift 1
local -ar dirs="$@"
local new_path=''
@@ -125,8 +125,7 @@ std::remove_path() {
[[ "${entry}" != "${dir}" ]] && new_path+=":${entry}"
done
done
# remove leading ':'
std::upvar "$P" "${new_path:1}"
P="${new_path:1}" # remove leading ':'
}
#
@@ -176,22 +175,23 @@ std::replace_path () {
# analog to std::split_abspath() with a relative path.
#
std::split_path() {
local parts="$1"
local -r path="$2"
local -n parts="$1"
local -r path="$2"
IFS='/'
local std__split_path_result=( ${std__split_path_tmp} )
unset IFS
std::upvar ${parts} "${std__split_path_result[@]}"
parts="${std__split_path_result[@]}"
if (( $# >= 3 )); then
# return number of parts
std::upvar "$3" ${#std__split_path_result[@]}
local -n num="$3"
num="${#std__split_path_result[@]}"
fi
}
std::split_abspath() {
local parts="$1"
local -r path="$2"
local -n parts="$1"
local -r path="$2"
if [[ "${path:0:1}" == '/' ]]; then
local -r std__split_path_tmp="${path:1}"
else
@@ -201,16 +201,17 @@ std::split_abspath() {
IFS='/'
local std__split_path_result=( ${std__split_path_tmp} )
unset IFS
std::upvar ${parts} "${std__split_path_result[@]}"
parts="${std__split_path_result[@]}"
if (( $# >= 3 )); then
# return number of parts
std::upvar "$3" ${#std__split_path_result[@]}
local -n num="$3"
num="${#std__split_path_result[@]}"
fi
}
std::split_relpath() {
local parts="$1"
local -r path="$2"
local -n parts="$1"
local -r path="$2"
if [[ "${path:0:1}" == '/' ]]; then
std::die 255 "Oops: Internal error in '${FUNCNAME[0]}' called by '${FUNCNAME[1]}' }"
else
@@ -220,10 +221,11 @@ std::split_relpath() {
IFS='/'
local std__split_path_result=( ${std__split_path_tmp} )
unset IFS
std::upvar ${parts} "${std__split_path_result[@]}"
parts="${std__split_path_result[@]}"
if (( $# >= 3 )); then
# return number of parts
std::upvar "$3" ${#std__split_path_result[@]}
local -n num="$3"
num="${#std__split_path_result[@]}"
fi
}
@@ -287,11 +289,11 @@ std::upvar() {
}
std.get_os_release_linux() {
local lsb_release=$(which lsb_release)
#local lsb_release=$(which lsb_release)
local ID=''
local VERSION_ID=''
if [[ -n $(which lsb_release) ]]; then
if [[ -n $(which lsb_release 2>/dev/null) ]]; then
ID=$(lsb_release -is)
VERSION_ID=$(lsb_release -rs)
elif [[ -r '/etc/os-release' ]]; then
@@ -322,7 +324,7 @@ std::get_os_release() {
local -A func_map;
func_map['Linux']=std.get_os_release_linux
func_map['Darwin']=std.get_os_release_macos
${func_map[${OS}]}
${func_map[$(uname -s)]}
}
std::get_type() {
+265 -183
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!@BASH@
#
# The following build specific variables are set and used in libpbuild.bash:
# ARGS
@@ -7,45 +7,59 @@
#
#.............................................................................
set -x
declare VERSION='@PMODULES_VERSION@'
# get absolute path of script
declare mydir=$(dirname "$0")
declare -r mydir=$(cd ${mydir} && pwd -P)
# initialize PATH,
# add library installation directories to the PATH,
# so 'source' is able find them
if [[ $(uname -s) == 'Darwin' ]]; then
PATH='/opt/local/bin:'
else
PATH=''
fi
PATH+='/usr/bin:/bin:/usr/sbin:/sbin'
PATH+=":${mydir}"
PATH+=":${mydir}/../lib:${mydir}/../config"
PATH+=":${PMODULES_DIR}/libexec"
source libstd.bash || {
source "${mydir}/../lib/libstd.bash" || {
echo "Oops: cannot source library -- '$_'" 1>&2; exit 3;
}
# can be set in the configuration file
declare PMODULES_DISTFILESDIR=''
declare PMODULES_TMPDIR=''
declare pm_root="${PMODULES_HOME%%/Tools*}"
##############################################################################
#
# check availability of used commands and set environment variables
# cmd=$(which cmd)
# in the following we use these environment variable to call binaries.
#
declare -r MODULECMD="${PMODULES_HOME}/bin/modulecmd"
[[ -x ${MODULECMD} ]] || \
std::die 1 "Oops: modulecmd binary not available!"
source libpbuild.bash || \
std::def_cmds "${mydir}/../libexec" \
'yq'
std::def_cmds '/usr/bin:/bin:/usr/sbin:/sbin' \
'awk' 'base64' 'cat' 'cp' 'find' 'getopt' 'grep' \
'install' 'logger' 'make' 'mkdir' 'mktemp' 'patch' 'pwd' \
'rm' 'rmdir' 'sort' 'tar' 'tee' 'uname'
declare -r OS="$(${uname} -s)"
if [[ ${OS} == 'Darwin' ]]; then
std::def_cmds '/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin' \
'curl' 'otool' 'shasum' 'sysctl'
declare -r sha256sum="${shasum -a 256}"
else
std::def_cmds '/usr/bin:/bin:/usr/sbin:/sbin' \
'ldd' 'curl' 'sha256sum'
fi
# for the time being, we still set PATH. Just in case we forgot a binary
PATH='/usr/bin:/bin:/usr/sbin:/sbin'
##############################################################################
source "${mydir}/../lib/libpbuild.bash" || \
std::die 3 "Oops: cannot source library -- '$_'"
source libpmodules.bash || \
source "${mydir}/../lib/libpmodules.bash" || \
std::die 3 "Oops: cannot source library -- '$_'"
# save arguments, (still) required for building dependencies
declare -r ARGS="$@"
shopt -s nocaseglob
shopt -s extglob
##############################################################################
set -o nounset
shopt -s nocaseglob
shopt -s extglob
shopt -s nullglob
##############################################################################
#
@@ -145,10 +159,13 @@ MISCELLANEOUS OPTIONS:
# then configuration file
# last default
# save arguments, required for building dependencies
declare -r ARGS="$@"
declare PMODULES_DISTFILESDIR=''
declare PMODULES_TMPDIR=''
# versions to be build, '.*' or none means all
declare -a versions=()
declare opt_bootstrap='no'
declare opt_build_config='Pmodules.yaml'
declare opt_build_target='all'
declare opt_dry_run='no'
declare opt_enable_cleanup_build='yes'
@@ -157,12 +174,12 @@ declare opt_force_rebuild='no'
declare -i opt_jobs=0
declare opt_update_modulefiles='no'
declare opt_system=''
declare opt_overlay=''
declare opt_verbose='no'
# array collecting all modules specified on the command line via '--with=module'
declare -a opt_with_modules=()
declare opt_ol_name_or_dir=''
declare BUILD_SCRIPT=''
parse_args() {
while (( $# > 0 )); do
@@ -193,13 +210,6 @@ parse_args() {
--dry-run )
opt_dry_run='yes'
;;
--config )
opt_build_config="$2"
shift 1
;;
--config=* )
opt_build_config="${1#*=}"
;;
--enable-cleanup )
opt_enable_cleanup_build='yes'
opt_enable_cleanup_src='yes'
@@ -220,19 +230,21 @@ parse_args() {
--disable-cleanup-src )
opt_enable_cleanup_src='no'
;;
--distdir )
PMODULES_DISTFILESDIR="$2"
shift
--distdir | --distdir=* )
if [[ $1 == *=* ]]; then
PMODULES_DISTFILESDIR="${1/--distdir=}"
else
PMODULES_DISTFILESDIR="$2"
shift
fi
;;
--distdir=* )
PMODULES_DISTFILESDIR="${1/--distdir=}"
;;
--tmpdir )
PMODULES_TMPDIR="$2"
shift
;;
--tmpdir=* )
PMODULES_TMPDIR="${1/--tmpdir=}"
--tmpdir | --tmpdir=* )
if [[ $1 == *=* ]]; then
PMODULES_TMPDIR="${1#--*=}"
else
PMODULES_TMPDIR="$2"
shift
fi
;;
--system | --system=* )
if [[ $1 == *=* ]]; then
@@ -250,27 +262,25 @@ parse_args() {
shift
fi
;;
--use-flags )
USE_FLAGS="y:$2:"
shift
--use-flags | --use-flags=* )
if [[ $1 == *=* ]]; then
USE_FLAGS=":${1#--*=}:"
else
USE_FLAGS=":$2:"
shift
fi
;;
--use-flags=* )
USE_FLAGS=":${1/--use-flags=}:"
;;
--with )
opt_with_modules+=( "$2" )
shift
;;
--with=*/* )
m="${1/--with=}"
opt_with_modules+=( ${m} )
--with | --with=*/* )
if [[ $1 == *=* ]]; then
opt_with_modules+=( "${1#--*=}" )
else
opt_with_modules+=( "$2" )
shift
fi
;;
--prep | --configure | --compile | --install | --all )
opt_build_target=${1:2}
;;
--bootstrap )
opt_bootstrap='yes'
;;
--update-modulefiles )
opt_update_modulefiles='yes'
;;
@@ -301,7 +311,17 @@ parse_args() {
esac
shift
done
[[ -n ${BUILD_SCRIPT} ]] || std::die 1 "No build-block specified!"
if [[ -z ${BUILD_SCRIPT} ]]; then
if [[ -r "${PWD}/build" ]]; then
if grep -q '#!.* modbuild' "${PWD}/build"; then
BUILD_SCRIPT="${PWD}/build"
BUILDBLOCK_DIR=$(dirname "${BUILD_SCRIPT}")
fi
fi
if [[ -z ${BUILD_SCRIPT} ]]; then
std::die 1 "Don't know what to build!"
fi
fi
(( ${#versions[@]} > 0)) || versions+=( '.*' )
}
@@ -317,7 +337,7 @@ parse_args() {
# "text gcc/10.3.0 openmpi/4.0.5"
# "text gcc/10.3.0 openmpi/4.1.0"
#
brace_expand_with_prefix(){
bash_expand(){
local text="$1"
shift
local to_expand=( "${@}" )
@@ -328,20 +348,13 @@ brace_expand_with_prefix(){
eval list=( ${to_expand[0]} )
local s
for s in ${list[*]}; do
brace_expand_with_prefix "${text} ${s}" "${to_expand[@]:1}"
bash_expand "${text} ${s}" "${to_expand[@]:1}"
done;
fi;
}
brace_expand(){
brace_expand_with_prefix "" "$@"
}
build_modules_legacy() {
find_variants_files(){
shopt -q nullglob || :
local -i nullglob_set=$?
shopt -s nullglob
local files=( "${BUILDBLOCK_DIR}"/*/"${BNAME_VARIANTS}"\.${opt_system} )
files+=( "${BUILDBLOCK_DIR}"/*/"${BNAME_VARIANTS}.$(uname -s)" )
local f
@@ -350,7 +363,6 @@ build_modules_legacy() {
|| [[ -e "${f}.$(uname -s)" ]] \
|| files+=( "$f" )
done
(( nullglob_set == 1 )) && shopt -u nullglob
std::upvar "$1" "${files[@]}"
}
@@ -361,7 +373,7 @@ build_modules_legacy() {
[[ -z ${toks} ]] && continue
[[ ${toke:0:1} == '#' ]] && continue
local -a deps=( ${toks[*]:2} )
brace_expand_with_prefix "${toks[0]} ${toks[1]}" "${deps[@]}"
bash_expand "${toks[0]} ${toks[1]}" "${deps[@]}"
done < "${input}"
}
@@ -384,7 +396,7 @@ build_modules_legacy() {
local m
local pattern="/^${name}\/${version}[[:blank:]]/"
for m in "${with_modules[@]}"; do
if [[ -n $(awk "/${m%/*}[\/ ]/" "${files[@]}") ]]; then
if [[ -n $(${awk} "/${m%/*}[\/ ]/" "${files[@]}") ]]; then
pattern+=" && /${m//\//\\/}/"
fi
done
@@ -394,7 +406,7 @@ build_modules_legacy() {
local line=''
while read line; do
variants+=( "${line}" )
done < <(expand_variants_file "${f}" | awk "${pattern}")
done < <(expand_variants_file "${f}" | ${awk} "${pattern}")
done
if (( ${#variants[@]} == 0 )); then
std::info "%s " \
@@ -410,9 +422,9 @@ build_modules_legacy() {
std::die 10 "Aborting..."
fi
declare ol_name='base'
declare ol_type=''
declare ol_dir="${pm_root}"
declare ol_install_dir="${pm_root}"
declare ol_type='n'
declare ol_mod_root="${PMODULES_HOME%%/Tools*}"
declare ol_inst_root="${PMODULES_HOME%%/Tools*}"
local -i i=0
local -i num_variants=${#variants[@]}
for ((i = 0; i < num_variants; i++)); do
@@ -428,106 +440,195 @@ build_modules_legacy() {
}
build_modules_yaml(){
local variants_file="${BUILDBLOCK_DIR}/files/"
variants_file+="${BNAME_VARIANTS}.${opt_system}.yaml"
local -a fnames=()
local -A mod_overlays=()
#
# $1 file name
# $2 module name
# $3 index
#
yaml_get_overlay(){
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'
}
fnames+=( "${BUILDBLOCK_DIR}/files/${BNAME_VARIANTS}.${opt_system}.yaml" )
fnames+=( "${BUILDBLOCK_DIR}/files/${BNAME_VARIANTS}.yaml" )
fnames+=( '__zzzzz__' )
for fname in "${fnames[@]}"; do
[[ -r "${fname}" ]] && break
done
[[ ${fname} == '__zzzzz__' ]] && \
std::die 3 "No suitable YAML variants file found"
echo "Using ${fname}..."
yaml_get_versions(){
yq e ".$2.variants[].version" "$1"
local -n _result="$1"
local fname="$2"
local version="$3"
_result=( $(${yq} -Ne e \
"with_entries(select(.key | test(\"^${version}\$\")))|keys" \
"${fname}" 2>/dev/null | ${awk} '{print $2}') )
}
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"
local -n _result="$1"
local fname="$2"
local version="$3"
_result=$(${yq} -Ne e ".\"${version}\"|length" \
"${fname}" 2>/dev/null)
if (( $? != 0 )); then
_result=0
fi
}
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 -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=$(${yq} -Ne e ".\"${version}\"[${idx}].relstage" \
"${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result=$(${yq} -Ne e ".relstage" "${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result='unstable'
}
local name="$1"
yaml_get_overlay(){
local -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=$(${yq} -Ne e ".\"${version}\"[${idx}].overlay" \
"${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result=$(${yq} -Ne e ".overlay" "${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result='base'
}
yaml_get_systems(){
local -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=$(${yq} -Ne e ".\"${version}\"[${idx}].systems" \
"${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result=$(${yq} -Ne e ".systems" "${fname}" 2>/dev/null)
(( $? == 0 )) && return
_result='any'
}
yaml_get_dependencies(){
local -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=( $(${yq} -Ne e ".\"${version}\"[${idx}]|(.with, .dependencies)" \
"${fname}" 2>/dev/null) )
if (( $? != 0 )); then
# neither .with nor .dependencies are set
_result=()
return
fi
# if one of .with, .dependencies is not set, the vaulue is
# returned as 'null'.
local -i i
for i in "${!_result[@]}"; do
[[ ${_result[$i]} == 'null' ]] && unset -v '_result[$i]'
done
_result=("${_result[@]}")
}
yaml_get_build_requirements(){
local -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=( $(${yq} -Ne e ".\"${version}\"[${idx}].build_requires" \
"${fname}" 2>/dev/null) )
if (( $? != 0 )); then
_result=()
return
fi
}
local name="$1"
local version="$2"
shift 2
local with_modules=( $* )
# pattern used in the for-loop to filter dependencies via awk
local m
local pattern="//"
for m in "${with_modules[@]}"; do
pattern+=" && /${m//\//\\/}( |$)/"
pattern+=" && /${m//\//\\/}/"
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[@]}"
local -a versions
yaml_get_versions versions "${fname}" "${name}/${version}"
for v in "${versions[@]}"; do
local -i n_variants
yaml_get_num_variants n_variants "${fname}" "${v}"
(( n_variants == 0 )) && (( n_variants = 1 ))
local -i i
local -a deps=()
local -a build_requires=()
local relstage
local ol_name
for (( i=0; i<n_variants; i++)); do
if [[ -z ${opt_overlay} ]]; then
yaml_get_overlay ol_name "${fname}" "${v}" $i
else
ol_name="${opt_overlay}"
fi
if [[ ! -v OverlayInfo[${ol_name}:inst_root] ]]; then
std::die 3 "Overlay is not defined -- ${ol_name}"
fi
mod_overlays[$i]="${ol_name}"
done
for (( i=0; i<n_variants; i++)); do
ol_name="${mod_overlays[$i]}"
yaml_get_relstage relstage "${fname}" "${v}" $i
yaml_get_dependencies deps "${fname}" "${v}" $i
yaml_get_build_requirements build_requires "${fname}" "${v}" $i
# :FIXME:
# for the time being we prefix the build requirements
# with 'b:' and append them to the other dependencies.
# With this solution we don't have to change anything
# else in the code but have better readable variant
# files.
deps+=("${build_requires[@]/#/b:}")
declare ol_inst_root="${OverlayInfo[${ol_name}:inst_root]}"
declare ol_mod_root="${OverlayInfo[${ol_name}:mod_root]}"
local systems
yaml_get_systems systems "${fname}" "${v}" $i
# build module if
# - systems is any
# - opt_system is listed in systems
local build_it='no'
if [[ "${systems}" == 'any' ]]; then
build_it='yes'
fi
if [[ ,${systems}, == *,${opt_system},* ]]; then
build_it='yes'
fi
if [[ ${build_it} == 'no' ]]; then
# we don't build, but we remember the overlay for
# cleaning up the modulefiles later.
continue
fi
if (( ${#deps[@]} > 0 )); then
while read -a with_modules; do
pbuild.build_module \
"${name}" "${v##*/}" \
"${relstage}" "${with_modules[@]}"
done < <(bash_expand "" ${deps[@]}|${awk} "${pattern}")
else
pbuild.build_module \
"${name}" "${v##*/}" \
"${relstage}"
fi
done
done
}
build_modules() {
local variants_file="${BUILDBLOCK_DIR}/files/${BNAME_VARIANTS}.${opt_system}"
if [[ -e "${variants_file}.yaml" ]]; then
if [[ -n $(ls "${BUILDBLOCK_DIR}/files/${BNAME_VARIANTS}"*.yaml 2>/dev/null) ]]; then
build_modules_yaml "$@"
else
build_modules_legacy "$@"
@@ -554,18 +655,14 @@ pbuild.verbose "${opt_verbose}"
#
# read configuration for modbuild
#
if [[ "${opt_bootstrap}" == 'yes' ]]; then
test -d "${BUILDBLOCK_DIR}/../../config" && PATH+=":$_"
fi
pm::read_config
read_config_file "${pm_root}/${PMODULES_CONFIG_DIR}/${opt_build_config}"
# :FIXME: should go dist files to
# :FIXME: should dist files go to
# ${pm_root}/var/distfiles
# or
# ${overlay}/var/distfiles
# ?
: ${PMODULES_DISTFILESDIR:=${pm_root}/var/distfiles}
: ${PMODULES_DISTFILESDIR:="${PMODULES_HOME%%/Tools*}/var/distfiles"}
: ${PMODULES_TMPDIR:=/var/tmp/${USER}}
declare -r BUILD_SCRIPT
@@ -575,21 +672,6 @@ declare -r BUILDBLOCK_DIR
IFS=/ read -r -a fname <<< "${BUILD_SCRIPT:1}"
module_name=${fname[${#fname[@]}-2]}
#
# are we bootstrapping? If yes, go for it...
#
if [[ "${opt_bootstrap}" == 'yes' ]]; then
declare ol_name='base'
declare ol_type=''
declare ol_dir="${pm_root}"
declare ol_install_dir="${pm_root}"
pbuild.bootstrap "${module_name}" "${versions[0]}" 'stable'
exit $?
fi
#
# else
#
for version in "${versions[@]}"; do
build_modules "${module_name}" "${version}" "${opt_with_modules[@]}"
done
+139 -182
View File
@@ -27,11 +27,10 @@ source "${libdir}/libpmodules.bash"
declare -r os_name="$(uname -s)"
path="/bin:/usr/bin"
[[ ${os_name} == 'Darwin' ]] && path="${libexecdir}:${path}"
path="${libexecdir}:/bin:/usr/bin"
std::def_cmds "${path}" \
'awk' 'base64' 'find' 'getopt' 'logger' 'mktemp' \
'rm' 'sort' 'find' 'yq'
'rm' 'sort' 'yq'
if [[ ${PMODULES_PURETCL} == yes ]]; then
declare -r modulecmd="${libexecdir}/modulecmd.tcl"
@@ -44,10 +43,6 @@ else
declare -r modulecmd="${libexecdir}/modulecmd.bin"
fi
declare -r ol_normal='n'
declare -r ol_hiding='h'
declare -r ol_replacing='r'
declare verbosity_lvl=${PMODULES_VERBOSITY:-'verbose'}
declare Shell=''
@@ -131,16 +126,16 @@ save_env() {
vars+=( ReleaseStages )
vars+=( GroupDepths )
vars+=( Overlays )
vars+=( OverlayList )
vars+=( OverlayDict Dir2OverlayMap)
vars+=( UsedOverlays )
vars+=( OverlayInfo Dir2OverlayMap)
local s=$(typeset -p ${vars[@]})
declare -g PMODULES_ENV=$( encode_base64 "$s" )
export_env 'PMODULES_ENV'
declare -gx PMODULES_ENV=$( encode_base64 "$s" )
}
_exit() {
save_env "${g_env_must_be_saved}"
export_env 'PMODULES_ENV'
if [[ -n "${tmpfile}" ]] && [[ -e "${tmpfile}" ]]; then
${rm} -f "${tmpfile}" || :
fi
@@ -148,34 +143,11 @@ _exit() {
trap '_exit' EXIT
#
# map a moduledir to an overlay
#
# Args:
# $1 upvar for overlay
# $2 moduledir
#
map_moduledir2ol_name() {
local "$1"
local moduledir="${2//+(\/)/\/}" # replace multpile '/' with one
moduledir="${moduledir/%\/}" # remove trailing slash if exist
if [[ ! -v Dir2OverlayMap[${moduledir}] ]]; then
local ol
for ol in "${OverlayList[@]}" 'other'; do
local mod_root="${OverlayDict[${ol}:mod_root]}"
[[ ${moduledir} == ${mod_root}/* ]] && break
done
Dir2OverlayMap[${moduledir}]="${ol}"
fi
std::upvar $1 "${Dir2OverlayMap[${moduledir}]}"
}
#
# get release stage of module
# Note:
# - the release stage of a module outside ${OverlayDict[@]} is always 'stable'
# - the release stage of a module inside ${OverlayDict[@]} without a
# - the release stage of a module outside ${OverlayInfo[@]} is always 'stable'
# - the release stage of a module inside ${OverlayInfo[@]} without a
# coresponding file is always 'unstable'
#
# Args:
@@ -185,13 +157,10 @@ map_moduledir2ol_name() {
#
get_release_stage() {
local "$1"
local -r moduledir=$2
local -r modulefile="$2/$3"
local -r dir="$2"
local -r modulefile="${dir}/$3"
local ol_name
map_moduledir2ol_name ol_name "${moduledir}"
if [[ "${ol_name}" == 'other' ]]; then
if [[ ! -v Dir2OverlayMap[${dir%/${PMODULES_MODULEFILES_DIR}*}] ]]; then
std::upvar $1 'stable'
return
fi
@@ -228,15 +197,14 @@ find_overlay () {
local "$2"
local path="${3//+(\/)/\/}" # replace multpile '/' with one
path="${path/%\/}" # remove trailing slash if exist
path="${path%/${PMODULES_MODULEFILES_DIR}*}"
[[ -v Dir2OverlayMap[${path}] ]] || return 1
local ol="${Dir2OverlayMap[${path}]}"
map_moduledir2ol_name ol "${path}"
std::upvar $1 "${ol}"
[[ "${ol}" == 'other' ]] && return 1
local group="${path#${OverlayDict[${ol}:mod_root]}/}"
group=${group%%/*}
local group="${path#${OverlayInfo[${ol}:mod_root]}/}"
std::upvar $2 "${group}"
return 0
}
@@ -501,8 +469,8 @@ subcommand_load() {
local "$1"
local -r group="$2/${PMODULES_MODULEFILES_DIR}"
local ol
for ol in "${OverlayList[@]}"; do
local inst_root="${OverlayDict[${ol}:inst_root]}"
for ol in "${UsedOverlays[@]}"; do
local inst_root="${OverlayInfo[${ol}:inst_root]}"
if [[ -d "${inst_root}/${group}" ]]; then
std::upvar $1 "${ol}"
return 0
@@ -515,8 +483,10 @@ subcommand_load() {
[[ -n ${group} ]] && [[ -n ${GroupDepths[${group}]} ]] && return 0
local ol=''
find_overlay_with_group ol "${group}" || return 1
local moduledir="${OverlayDict[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
compute_group_depth "${moduledir}" || return 1
local moduledir="${OverlayInfo[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
local -i depth
compute_group_depth depth "${moduledir}" || return 1
GroupDepths[${group}]=${depth}
g_env_must_be_saved='yes'
}
@@ -613,13 +583,11 @@ subcommand_load() {
"${CMD}" "${subcommand}" \
"illegal group name" \
"${group}"
MODULEPATH=""
modulepath=()
group+="${PMODULES_MODULEFILES_DIR}"
for overlay in "${OverlayList[@]}"; do
local mod_root="${OverlayDict[${overlay}:mod_root]}"
MODULEPATH="${mod_root}/${group}/:${MODULEPATH}"
modulepath=( "${mod_root}/${group}/" "${modulepath[@]}" )
group+="/${PMODULES_MODULEFILES_DIR}"
for overlay in "${UsedOverlays[@]}"; do
local mod_root="${OverlayInfo[${overlay}:mod_root]}"
modulepath=( "${mod_root}/${group}" "${modulepath[@]}" )
done
fi
if [[ -n ${rel_stage} ]]; then
@@ -720,9 +688,11 @@ subcommand_load() {
LOADEDMODULES="${_LMFILES_}"
local dir
while read dir; do
# if the first or last character of MODULEPATH is ':',
# we read an empty string.
[[ -z ${dir} ]] && continue
[[ "${dir: -1}" == "/" ]] || dir+="/"
LOADEDMODULES="${LOADEDMODULES//${dir}}"
map_moduledir2ol_name overlay "${dir}"
done <<< "${MODULEPATH//:/$'\n'}"
g_env_must_be_saved='yes'
export_env 'LOADEDMODULES'
@@ -909,6 +879,12 @@ subcommand_show() {
# Find all modules in a given modulepath matching a specific string.
# The search can be restricted to certain release stages.
#
# Args:
# $1 upvar for results
# $2 search pattern
# $3 release stages
# $4... module directories
#
# return list like
# modulename_1 rel_stage_1 modulefile_1 ...
#
@@ -931,8 +907,8 @@ get_available_modules() {
# - after loading the parent of a hierarchical group
# - if we do a search
# - if we create a new hierarchical group
local ol
local group
local ol=''
local group=''
find_overlay ol group "${dir}"
# if no modules are installed in ${dir}, '*' expands to
@@ -941,6 +917,7 @@ get_available_modules() {
# implementations.
local entries=$(echo *)
[[ -n ${entries} ]] || continue
local mod='' # module_name/module_version
while read mod; do
local add='no'
if [[ -n "${ol}" ]]; then
@@ -953,7 +930,7 @@ get_available_modules() {
local name="${mod%/*}"
local key="${dir##/${PMODULES_MODULEFILES_DIR}}/${name}"
if [[ -z "${modulenames[${key}]}" ]]; then
if [[ "${OverlayDict[${ol}:type]}" == "${ol_hiding}" ]]; then
if [[ "${OverlayInfo[${ol}:type]}" == "${ol_hiding}" ]]; then
modulenames[${key}]="${ol}"
else
modulenames[${key}]='0'
@@ -976,7 +953,7 @@ get_available_modules() {
"${mod}"
[[ :${used_rel_stages}: =~ :${rel_stage}: ]] || continue
mods+=( "${mod}" ${rel_stage} "${dir}/${mod}" )
mods+=( "${mod}" ${rel_stage} "${dir}/${mod}" "${ol}" )
dict[${mod}]=1
done < <(${find} -L ${entries} \
\( -type f -o -type l \) \
@@ -1044,12 +1021,18 @@ find_module() {
# no version has been specified. This makes it more
# difficult. We have to load the newest version taking
# the used release stages and flags into account.
# get list of reverse sorted version numbers
(( col += ${#module} + 1 ))
modules=( $(${find} -L "${dir}" -type f -not -name ".*" \
-ipath "${dir}/${module}/*" \
| cut -b${col}- \
| sort -rV ) )
# prepend module name
modules=( "${modules[@]/#/${module}/}" )
# now modules contains a reverse sorted list of
# available modules in the form name/version
for mod in "${modules[@]}"; do
#
# loop over all used flags. If a module with
@@ -1063,7 +1046,7 @@ find_module() {
"${dir}" \
"${mod}"
std::upvar $2 "${rel_stage}"
[[ :${release}: =~ :${UsedReleaseStages}: ]] && \
[[ :${rel_stage}: =~ :${UsedReleaseStages}: ]] && \
return 0
done
done
@@ -1134,7 +1117,7 @@ subcommand_avail() {
terse_output() {
output_header "$1"
local -i i=0
for (( i=0; i<${#mods[@]}; i+=3 )); do
for (( i=0; i<${#mods[@]}; i+=4 )); do
local mod=${mods[i]}
local rel_stage=${mods[i+1]}
case ${rel_stage} in
@@ -1152,7 +1135,7 @@ subcommand_avail() {
#......................................................................
machine_output() {
for (( i=0; i<${#mods[@]}; i+=3 )); do
for (( i=0; i<${#mods[@]}; i+=4 )); do
printf "%-20s\t%s\n" "${mods[i]}" "${mods[i+1]}" 1>&2
done
}
@@ -1161,7 +1144,7 @@ subcommand_avail() {
# :FIXME: for the time being, this is the same as terse_output!
long_output() {
output_header "$1"
for (( i=0; i<${#mods[@]}; i+=3 )); do
for (( i=0; i<${#mods[@]}; i+=4 )); do
local mod=${mods[i]}
local rel_stage=${mods[i+1]}
case ${rel_stage} in
@@ -1184,7 +1167,7 @@ subcommand_avail() {
local -a available_modules=()
local mod=''
local -i max_length=1
for ((i=0; i<${#mods[@]}; i+=3)); do
for ((i=0; i<${#mods[@]}; i+=4)); do
if [[ ${verbosity_lvl} == 'verbose' ]]; then
local rel_stage=${mods[i+1]}
case ${rel_stage} in
@@ -1355,10 +1338,10 @@ subcommand_use() {
print_ol_info(){
local only_used="$1"
local ol=''
for ol in "${OverlayList[@]}"; do
[[ ${OverlayDict[${ol}:used]} == ${only_used} ]] || continue
local inst_root="${OverlayDict[${ol}:inst_root]}"
local mod_root="${OverlayDict[${ol}:mod_root]}"
for ol in "${Overlays[@]}"; do
[[ ${OverlayInfo[${ol}:used]} == ${only_used} ]] || continue
local inst_root="${OverlayInfo[${ol}:inst_root]}"
local mod_root="${OverlayInfo[${ol}:mod_root]}"
local txt="\t${ol}"
if [[ ${inst_root} == ${mod_root} ]]; then
txt+="\n\t\t${inst_root}"
@@ -1366,7 +1349,7 @@ subcommand_use() {
txt+="\n\t\t${inst_root} (install root)"
txt+="\n\t\t${mod_root} (modulefiles root)"
fi
case "${OverlayDict[${ol}:type]}" in
case "${OverlayInfo[${ol}:type]}" in
"${ol_hiding}" )
txt+='\n\t\t(hiding modules with same name)'
;;
@@ -1445,7 +1428,7 @@ subcommand_use() {
"modules are already loaded!"
fi
if [[ ${OverlayDict[${ol_name}:used]} == 'yes' ]]; then
if [[ ${OverlayInfo[${ol_name}:used]} == 'yes' ]]; then
std::die 3 "%s %s: %s -- %s" \
"${CMD}" "${subcommand}" \
"overlay already in use" \
@@ -1453,39 +1436,38 @@ subcommand_use() {
return 0
fi
if [[ "${OverlayDict[${ol_name}:type]}" == "${ol_replacing}" ]]; then
if [[ "${OverlayInfo[${ol_name}:type]}" == "${ol_replacing}" ]]; then
# if this overlay replaces groups, we have
# to remove the modules made available by
# other overlays in these groups
for group in ${UsedGroups//:/ }; do
# is this group in the to be added overlay?
local dir="${OverlayDict[${ol_name}:mod_root]}/"
local dir="${OverlayInfo[${ol_name}:mod_root]}/"
dir+="${group}/${PMODULES_MODULEFILES_DIR}"
[[ -d "${dir}" ]] || continue # no
dir="/${group}/${PMODULES_MODULEFILES_DIR}"
local -a dirs=()
for ol in "${OverlayList[@]}"; do
dirs+=( ${OverlayDict[${ol}:mod_root]}${dir} )
for ol in "${UsedOverlays[@]}"; do
dirs+=( ${OverlayInfo[${ol}:mod_root]}${dir} )
done
std::remove_path MODULEPATH "${dirs[@]}"
done
fi
scan_groups "${ol_name}"
for group in ${UsedGroups//:/ }; do
local dir="${OverlayDict[${ol_name}:mod_root]}/"
local dir="${OverlayInfo[${ol_name}:mod_root]}/"
dir+="${group}/${PMODULES_MODULEFILES_DIR}"
if [[ -d "${dir}" ]]; then
std::prepend_path MODULEPATH "${dir}"
Dir2OverlayMap[${dir}]="${ol_name}"
fi
done
OverlayList=( "${ol_name}" "${OverlayList[@]}" )
OverlayDict[${ol_name}:used]='yes'
export_env OverlayList
UsedOverlays=( "${ol_name}" "${UsedOverlays[@]}" )
OverlayInfo[${ol_name}:used]='yes'
export_env UsedOverlays
g_env_must_be_saved='yes'
scan_groups "${OverlayList[@]}"
scan_groups "${UsedOverlays[@]}"
}
#..............................................................
@@ -1499,13 +1481,12 @@ subcommand_use() {
fi
std::append_path UsedGroups "$1"
local ol_name
for ol_name in "${OverlayList[@]}"; do
local dir="${OverlayDict[${ol_name}:mod_root]}/$1/${PMODULES_MODULEFILES_DIR}"
for ol_name in "${UsedOverlays[@]}"; do
local dir="${OverlayInfo[${ol_name}:mod_root]}/$1/${PMODULES_MODULEFILES_DIR}"
[[ -d "${dir}" ]] || continue
std::prepend_path MODULEPATH "${dir}"
Dir2OverlayMap[${dir}]=${ol_name}
[[ "${OverlayDict[${ol_name}:type]}" == "${ol_replacing}" ]] && break
[[ "${OverlayInfo[${ol_name}:type]}" == "${ol_replacing}" ]] && break
done
}
@@ -1522,7 +1503,7 @@ subcommand_use() {
UsedFlags+=( "${arg/flag=}" )
return
fi
if [[ -v OverlayDict[${arg}:type] ]]; then
if [[ -v OverlayInfo[${arg}:type] ]]; then
use_overlay "${arg}"
return 0
fi
@@ -1533,7 +1514,7 @@ subcommand_use() {
if [[ ! -v GroupDepths[${arg}] ]]; then
# this scan is required if a new group has been
# create inside an used overlay
scan_groups "${!OverlayDict[@]}"
scan_groups "${UsedOverlays[@]}"
g_env_must_be_saved='yes'
fi
if [[ -n ${GroupDepths[${arg}]} ]]; then
@@ -1615,46 +1596,46 @@ subcommand_unuse() {
"some modules are still loaded!"
fi
[[ "${OverlayDict[ol_name]:mod_root}" == "${PMODULES_HOME%%/Tools*}" ]] && \
[[ "${OverlayInfo[ol_name]:mod_root}" == "${PMODULES_HOME%%/Tools*}" ]] && \
std::die 3 "%s %s: %s -- %s" \
"${CMD}" "${subcommand}" \
"cannot remove base overlay" \
"${ol_name}"
[[ ${OverlayDict[${ol_name}:used]} != 'yes' ]] && \
[[ ${OverlayInfo[${ol_name}:used]} != 'yes' ]] && \
std::die 3 "%s %s: %s -- %s" \
"${CMD}" "${subcommand}" \
"not an used overlay" \
"${ol_name}"
# make sure first index is '0' (it should, but you never know)
OverlayList=( "${OverlayList[@]}" )
[[ "${ol_name}" != "${OverlayList[0]}" ]] && \
UsedOverlays=( "${UsedOverlays[@]}" )
[[ "${ol_name}" != "${UsedOverlays[0]}" ]] && \
std::die 3 "%s %s: %s %s -- %s" \
"${CMD}" "${subcommand}" \
"overlay cannot be removed since" \
"it not on top of the stack" \
"${ol_name}"
if [[ "${OverlayDict[${ol_name}:type]}" == "${ol_replacing}" ]]; then
if [[ "${OverlayInfo[${ol_name}:type]}" == "${ol_replacing}" ]]; then
# if this overlay hides groups, we have to re-add
# the modules made available by other overlays
local mod_root=${OverlayDict[${ol_name}:mod_root]}
local mod_root=${OverlayInfo[${ol_name}:mod_root]}
for group in ${UsedGroups//:/ }; do
# is this group in the to be removed overlay?
local dir="${mod_root}/${group}/${PMODULES_MODULEFILES_DIR}"
[[ -d "${dir}" ]] || continue # no
dir="/${group}/${PMODULES_MODULEFILES_DIR}"
std::prepend_path MODULEPATH "${OverlayList[@]/%/${dir}}"
std::prepend_path MODULEPATH "${UsedOverlays[@]/%/${dir}}"
done
fi
OverlayDict[${ol_name}:used]='no'
OverlayList=( "${OverlayList[@]:1}")
OverlayInfo[${ol_name}:used]='no'
UsedOverlays=( "${UsedOverlays[@]:1}")
g_env_must_be_saved='yes'
export_env OverlayList
export_env UsedOverlays
local dir
for dir in "${modulepath[@]}"; do
[[ "${dir}" =~ "${OverlayDict[${ol_name}:mod_root]}" ]] && \
[[ "${dir}" =~ "${OverlayInfo[${ol_name}:mod_root]}" ]] && \
std::remove_path MODULEPATH "${dir}"
done
}
@@ -1678,7 +1659,7 @@ subcommand_unuse() {
fi
std::remove_path UsedGroups "${arg}"
local overlay
for overlay in "${OverlayList[@]}"; do
for overlay in "${UsedOverlays[@]}"; do
local dir="${overlay}/${arg}/${PMODULES_MODULEFILES_DIR}"
std::remove_path MODULEPATH "${dir}"
done
@@ -1701,7 +1682,7 @@ subcommand_unuse() {
done
return
fi
if [[ -v OverlayDict[${arg}:type] ]]; then
if [[ -v OverlayInfo[${arg}:type] ]]; then
unuse_overlay "${arg}"
return 0
fi
@@ -1796,12 +1777,11 @@ init_modulepath() {
declare -gx MODULEPATH=''
local group
local ol
for ol in "${OverlayList[@]}"; do
for ol in "${UsedOverlays[@]}"; do
for group in ${UsedGroups//:/ }; do
local dir="${OverlayDict[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
local dir="${OverlayInfo[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
if [[ -d "${dir}" ]]; then
std::prepend_path MODULEPATH "${dir}"
Dir2OverlayMap[${dir}]="${ol}"
fi
done
done
@@ -1842,6 +1822,10 @@ pmodules_init() {
done
g_env_must_be_saved='yes'
}
init_overlay_vars() {
declare -ag UsedOverlays=( 'base' )
OverlayInfo['base:used']='yes'
}
pm::read_config
@@ -1856,6 +1840,7 @@ pmodules_init() {
init_overlay_vars
init_modulepath
init_manpath
save_env
export_env \
LOADEDMODULES \
_LMFILES_ \
@@ -1910,13 +1895,15 @@ subcommand_purge() {
# is a Pmodule module loaded?
# if yes, save name in variable 'pmodule'
local pmodule=''
# We also have to save PMODULES_HOME since it will be
# unset while sourcing the shell's init script.
IFS=':'
local -a lmfiles=($_LMFILES_)
unset IFS
for f in "${lmfiles[@]}"; do
if [[ $f == */${PMODULES_MODULEFILES_DIR}/Pmodules/* ]]; then
pmodule="${f##*/${PMODULES_MODULEFILES_DIR}/}"
local pm_home="${PMODULES_HOME}"
local pmodule="${f##*/${PMODULES_MODULEFILES_DIR}/}"
break;
fi
done
@@ -1946,16 +1933,18 @@ subcommand_purge() {
echo "${error}" 1>&2
fi
if [[ -n "${pmodule}" ]]; then
if [[ -v pmodule ]]; then
# reload a previously loaded Pmodule module
# stderr is redirected to /dev/null, otherwise
# we may get output like
# 'unstable module has been loaded'
PMODULES_HOME="${pm_home}"
export_env PMODULES_HOME
subcommand_load "${pmodule}" 2> /dev/null
fi
init_modulepath
export_env MODULEPATH PMODULES_HOME
export_env MODULEPATH
}
##############################################################################
@@ -2045,7 +2034,6 @@ subcommand_clear() {
"no arguments allowed"
fi
pmodules_init
export_env LOADEDMODULES MODULEPATH _LMFILES_
}
##############################################################################
@@ -2130,7 +2118,7 @@ subcommand_search() {
local fmt=''
print_default() {
fmt="%-${max_len_modulename}s %-10s %-12s %-s"
fmt="%-${max_len_modulename}s %-10s %-12s %-12s %-s"
if [[ ${opt_print_header} == 'yes' ]]; then
func_print_header='print_header_default'
else
@@ -2141,7 +2129,7 @@ subcommand_search() {
print_header_default() {
std::info ''
std::info "${fmt}" "Module" "Rel.stage" "Group" "Requires"
std::info "${fmt}" "Module" "Rel.stage" "Group" "Overlay" "Requires"
std::info '-%.0s' $(seq 1 ${cols})
}
@@ -2154,12 +2142,12 @@ subcommand_search() {
std::info "${str}"
}
if [[ "${opt_wrap}" == 'no' ]]; then
local deps="${@:5}"
local str=$(printf "${fmt}" "$1" "$2" "$3" "${deps[@]}")
local deps="${@:6}"
local str=$(printf "${fmt}" "$1" "$2" "$3" "$5" "${deps[@]}")
write_line "${str}"
else
local deps=( "${@:5}" )
local str=$(printf "${fmt}" "$1" "$2" "$3" "${deps[0]}")
local deps=( "${@:6}" )
local str=$(printf "${fmt}" "$1" "$2" "$3" "$5" "${deps[0]}")
for (( i = 1; i < ${#deps[@]}; i++ )); do
if (( ${#str} + ${#deps[i]} + 1 <= cols )); then
str+=" ${deps[i]}"
@@ -2173,21 +2161,26 @@ subcommand_search() {
}
print_verbose() {
fmt="%-${max_len_modulename}s %-10s %-12s %-s"
fmt="%-${max_len_modulename}s %-12s %-14s %-s"
func_print_header='print_header_verbose'
func_print_line='print_line_verbose'
}
print_header_verbose() {
std::info ''
std::info "${fmt}" "Module" "Rel.stage" "Group" "Dependencies/Modulefile"
std::info '-%.0s' $(seq 1 ${cols})
#std::info "${fmt}" "Module" "Rel.stage" "Group" "Overlay" "Dependencies/Modulefile"
#std::info '-%.0s' $(seq 1 ${cols})
}
print_line_verbose() {
local deps="${@:5}"
std::info "${fmt}" "$1" "$2" "$3" "dependencies: ${deps}"
std::info "${fmt}" "" "" "" "modulefile: $4"
local deps="${@:6}"
[[ -z ${deps} ]] && deps="(none)"
std::info "$1:"
std::info " release stage: $2"
std::info " group: $3"
std::info " overlay: $5"
std::info " modulefile: $4"
std::info " dependencies: ${deps}"
}
# print full modulefile names only
@@ -2228,7 +2221,7 @@ subcommand_search() {
${func_print_header}
while read -a toks; do
${func_print_line} "${toks[@]}"
done < <("${sort}" --version-sort -k 1,1 -k 4,4 -k 5,5 "${tmpfile}" | \
done < <("${sort}" --version-sort -k 1,1 -k 6,6 -k 7,7 "${tmpfile}" | \
${awk} "${with_modules}")
}
@@ -2271,10 +2264,11 @@ subcommand_search() {
"${opt_use_rel_stages}" \
"${modulepath[@]}" \
for (( i=0; i<${#mods[@]}; i+=3 )); do
for (( i=0; i<${#mods[@]}; i+=4 )); do
local name=${mods[i]}
local rel_stage=${mods[i+1]}
local modulefile=${mods[i+2]}
local ol=${mods[i+3]}
if (( ${#name} > max_len_modulename)); then
max_len_modulename=${#name}
@@ -2302,6 +2296,7 @@ subcommand_search() {
fi
echo ${name} ${rel_stage} ${group} ${modulefile} \
${ol} \
${deps[@]} >> "${tmpfile}"
done
done
@@ -2405,7 +2400,10 @@ subcommand_search() {
shift
done
if [[ -z "${src_prefix}" ]]; then
local -a src_prefix=( "${OverlayList[@]}" )
local ol=''
for ol in "${UsedOverlays[@]}"; do
src_prefix+=( "${OverlayInfo[${ol}:mod_root]}" )
done
fi
if [[ "${opt_use_rel_stages}" == ":" ]]; then
@@ -2740,21 +2738,6 @@ if [[ -z "${Subcommands[${subcommand}]}" ]]; then
std::die 1 "${CMD}: unknown sub-command -- ${subcommand}"
fi
init_overlay_vars() {
declare -ag OverlayList=( 'base' )
OverlayDict['base:used']='yes'
#declare -Ag Dir2OverlayMap=()
for ol in "${OverlayList[@]}"; do
local group
for group in ${UsedGroups//:/ }; do
local dir="${OverlayDict[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
if [[ -d "${dir}" ]]; then
Dir2OverlayMap[${dir}]=${ol}
fi
done
done
}
case ${subcommand} in
add )
subcommand='load'
@@ -2777,51 +2760,25 @@ if [[ -n ${PMODULES_ENV} ]]; then
eval "$("${base64}" -d <<< "${PMODULES_ENV}" 2>/dev/null)"
fi
if [[ -z ${Version} ]] || [[ ${Version} != ${PMODULES_VERSION} ]]; then
# this can only happen if the last command was
# module load Pmodules/${PMODULES_VERSION}
#
# the values these two variables must be saved before initialising
declare _tmp_loaded_modules_="${LOADEDMODULES}"
declare _tmp_lmfiles_="${_LMFILES_}"
pmodules_init
g_env_must_be_saved='yes'
# restore and export
LOADEDMODULES="${_tmp_loaded_modules_}"
_LMFILES_="${_tmp_lmfiles_}"
export_env \
LOADEDMODULES \
_LMFILES_
fi
#if [[ -n ${PMODULES_ENV} ]]; then
# eval "$("${base64}" -d <<< "${PMODULES_ENV}" 2>/dev/null)"
# if [[ -z ${Version} ]] || [[ ${Version} != ${PMODULES_VERSION} ]]; then
# # the Pmodules version changed!
# declare -g Version="${PMODULES_VERSION}"
# pm::read_config
# init_overlay_vars
# # renamed in version 1.0.0rc10 and type changed from
# # associative array to normal array
# if [[ -v UseFlags ]]; then
# declare -a UsedFlags=( "${!UseFlags[@]}" )
# unset UseFlags
# fi
# if [[ ! -v UsedFlags ]]; then
# declare -a UsedFlags=()
# fi
# if [[ -v UsedReleases ]]; then
# declare -- UsedReleaseStages="${UsedReleases}"
# unset UsedReleases
# fi
# if [[ -v PMODULES_DEFAULT_GROUPS ]]; then
# declare -- DefaultGroups="${PMODULES_DEFAULT_GROUPS}"
# unset PMODULES_DEFAULT_GROUPS
# fi
# if [[ -v PMODULES_DEFINED_RELEASES ]]; then
# declare -- ReleaseStages="${PMODULES_DEFINED_RELEASES}"
# unset PMODULES_DEFINED_RELEASES
# fi
# if [[ -v PMODULES_DEFAULT_RELEASES ]]; then
# declare -- DefaultReleaseStages="${PMODULES_DEFAULT_RELEASES}"
# unset PMODULES_DEFAULT_RELEASES
# fi
# g_env_must_be_saved='yes'
# fi
#else
# pmodules_init
# g_env_must_be_saved='yes'
#fi
if (( ${#GroupDepths[@]} == 0 )); then
scan_groups "${OverlayList[@]}"
scan_groups "${UsedOverlays[@]}"
g_env_must_be_saved='yes'
fi
+8 -4
View File
@@ -10,9 +10,8 @@ Pmodules are a hierarchical module environment based on Environment Modules.
"
#
# It might be that '${PMODULES_HOME}' is in PATH.
# Why? With older version the PATH might have been set without loading
# a module.
# Older versions add '$PREFIX/bin' to PATH without loading Pmodules as
# a module. Remove it ...
#
if { [module-info mode load] } {
set PATH ":$::env(PATH):"
@@ -21,4 +20,9 @@ if { [module-info mode load] } {
remove-path PATH $str
}
}
}
remove-path C_INCLUDE_PATH "$PREFIX/include"
remove-path CPLUS_INCLUDE_PATH "$PREFIX/include"
set shell [module-info shell]
puts "source \"$PREFIX/init/$shell\""
}
+8
View File
@@ -34,6 +34,14 @@ module() {
}
export -f module
modbuild(){
(
eval $("${PMODULES_HOME}/bin/modulecmd" bash load System:bash)
"${PMODULES_HOME}/bin/modbuild" "$@"
)
}
export -f modbuild
# Local Variables:
# mode: sh
# sh-basic-offset: 8