modbuild: quering group, supported systems and compilers added to YAML

another big change is the re-ordering of the public pbuild:: functions
This commit is contained in:
2022-07-29 14:53:01 +02:00
parent c8b61bbf5f
commit bc38136787
2 changed files with 264 additions and 206 deletions
+247 -181
View File
@@ -116,136 +116,26 @@ pbuild.verbose() {
readonly -f pbuild.verbose
###############################################################################
#******************************************************************************
#
# function in the "namespace" (with prefix) 'pbuild::' can be used in
# build-scripts
#
#..............................................................................
###############################################################################
#
# compare two version numbers
# general functions
#
# original implementation found on stackoverflow:
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
#
pbuild::version_compare () {
is_uint() {
[[ $1 =~ ^[0-9]+$ ]]
}
[[ $1 == $2 ]] && return 0
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
[[ -z ${ver2[i]} ]] && ver2[i]=0
if is_uint ${ver1[i]} && is_uint ${ver2[i]}; then
((10#${ver1[i]} > 10#${ver2[i]})) && return 1
((10#${ver1[i]} < 10#${ver2[i]})) && return 2
else
[[ ${ver1[i]} > ${ver2[i]} ]] && return 1
[[ ${ver1[i]} < ${ver2[i]} ]] && return 2
fi
done
return 0
}
readonly -f pbuild::version_compare
#..............................................................................
# version less than
#
# return 0 if version passed in $1 is older then $2
#
pbuild::version_lt() {
pbuild::version_compare "$1" "$2"
(( $? == 2 ))
}
readonly -f pbuild::version_lt
#..............................................................................
# version less than or equal
#
# return 0 if version passed in $1 is older or equal then $2
#
pbuild::version_le() {
pbuild::version_compare "$1" "$2"
local -i exit_code=$?
(( exit_code == 0 || exit_code == 2 ))
}
readonly -f pbuild::version_le
#..............................................................................
# version greater than
#
# return 0 if version passed in $1 is newer then $2
#
pbuild::version_gt() {
pbuild::version_compare "$1" "$2"
(( $? == 1 ))
local -i exit_code=$?
(( exit_code == 0 || exit_code == 1 ))
}
readonly -f pbuild::version_gt
#..............................................................................
# version greater than
#
# return 0 if version passed in $1 and $2 are equal
#
pbuild::version_eq() {
pbuild::version_compare "$1" "$2"
}
readonly -f pbuild::version_eq
##############################################################################
#
# Set flag to build module in source tree.
#
# Arguments:
# none
#
pbuild::compile_in_sourcetree() {
BUILD_DIR="${SRC_DIR}"
}
readonly -f pbuild::compile_in_sourcetree
##############################################################################
#
# Check whether the script is running on a supported OS.
#
# Arguments:
# $@: supported opertating systems (something like RHEL6, macOS10.14, ...).
# Default is all.
#
pbuild::supported_systems() {
SUPPORTED_SYSTEMS+=( "$@" )
}
readonly -f pbuild::supported_systems
##############################################################################
#
# Check whether the loaded compiler is supported.
#
# Arguments:
# $@: supported compiler (like GCC, Intel, PGI).
# Default is all.
#
pbuild::supported_compilers() {
SUPPORTED_COMPILERS+=( "$@" )
}
readonly -f pbuild::supported_compilers
##############################################################################
#
# Install module in given group.
#
# Note:
# This function is deprecated with YAML module configuration files.
#
# Arguments:
# $1: group
# $1: group
#
pbuild::add_to_group() {
if (( $# == 0 )); then
@@ -253,23 +143,25 @@ pbuild::add_to_group() {
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: missing group argument."
fi
GROUP="$1"
if (( $# > 1 )); then
std::die 42 \
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: only one argument is allowed."
fi
if [[ ${yaml_config} == 'yes' ]]; then
std::info \
"Using ${FUNCNAME} is deprecated with YAML module configuration files."
fi
pbuild.add_to_group "$@"
}
readonly -f pbuild::add_to_group
##############################################################################
#
# Set documentation file to be installed.
#
# Arguments:
# $@: documentation files relative to source
#
pbuild::install_docfiles() {
MODULE_DOCFILES+=("$@")
pbuild.add_to_group(){
GROUP="$1"
}
readonly -f pbuild::install_docfiles
readonly -f pbuild.add_to_group
##############################################################################
#..............................................................................
#
# Test whether a module with the given name is available. If yes, return
# release
@@ -302,8 +194,153 @@ pbuild::module_is_avail() {
}
readonly -f pbuild::module_is_avail
#..............................................................................
#
# compare two version numbers
#
# pbuild::version_compare
# - returns 0 if the version numbers are equal
# - returns 1 if first version number is higher
# - returns 2 if second version number is higher
#
# pbuild::version_lt
# - returns 0 if second version number is higher
# pbuild::version_le
# - returns 0 if second version number is higher or equal
# pbuild::version_gt
# - returns 0 if first version number is higher
# pbuild::version_ge
# - returns 0 if first version number is higher or equal
# pbuild::version_eq
# - returns 0 if version numbers are equal
#
# otherwise a value != 0 is returned
#
# Arguments:
# $1 first version number
# $2 second version number
#
# Note:
# Original implementation found on stackoverflow:
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
#
pbuild::version_compare () {
is_uint() {
[[ $1 =~ ^[0-9]+$ ]]
}
[[ $1 == $2 ]] && return 0
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
[[ -z ${ver2[i]} ]] && ver2[i]=0
if is_uint ${ver1[i]} && is_uint ${ver2[i]}; then
((10#${ver1[i]} > 10#${ver2[i]})) && return 1
((10#${ver1[i]} < 10#${ver2[i]})) && return 2
else
[[ ${ver1[i]} > ${ver2[i]} ]] && return 1
[[ ${ver1[i]} < ${ver2[i]} ]] && return 2
fi
done
return 0
}
readonly -f pbuild::version_compare
pbuild::version_lt() {
pbuild::version_compare "$1" "$2"
(( $? == 2 ))
}
readonly -f pbuild::version_lt
pbuild::version_le() {
pbuild::version_compare "$1" "$2"
local -i exit_code=$?
(( exit_code == 0 || exit_code == 2 ))
}
readonly -f pbuild::version_le
pbuild::version_gt() {
pbuild::version_compare "$1" "$2"
(( $? == 1 ))
local -i exit_code=$?
(( exit_code == 1 ))
}
readonly -f pbuild::version_gt
pbuild::version_ge() {
pbuild::version_compare "$1" "$2"
(( $? == 1 ))
local -i exit_code=$?
(( exit_code == 0 || exit_code == 1 ))
}
readonly -f pbuild::version_gt
pbuild::version_eq() {
pbuild::version_compare "$1" "$2"
}
readonly -f pbuild::version_eq
#..............................................................................
#
# Check whether the loaded compiler is supported.
#
# Arguments:
# $@: supported compiler (like GCC, Intel, PGI).
# Default is all.
#
pbuild::supported_compilers() {
if [[ ${yaml_config} == 'yes' ]]; then
std::info \
"Using ${FUNCNAME} is deprecated with YAML module configuration files."
fi
pbuild.supported_compilers "$@"
}
readonly -f pbuild::supported_compilers
pbuild.supported_compilers(){
SUPPORTED_COMPILERS+=( "$@" )
}
readonly -f pbuild.supported_compilers
#..............................................................................
#
# Check whether the script is running on a supported OS.
#
# Arguments:
# $@: supported opertating systems (something like RHEL6, macOS10.14, ...).
# Default is all.
#
pbuild::supported_systems() {
if [[ ${yaml_config} == 'yes' ]]; then
std::info \
"Using ${FUNCNAME} is deprecated with YAML module configuration files."
fi
pbuild.supported_systems "$@"
}
readonly -f pbuild::supported_systems
pbuild.supported_systems() {
SUPPORTED_SYSTEMS+=( "$@" )
}
#..............................................................................
#
pbuild::use_flag() {
[[ "${USE_FLAGS}" =~ ":${1}:" ]]
}
readonly -f pbuild::use_flag
##############################################################################
#
# functions to prepare the sources
#..............................................................................
#
# Set the download URL and name of downloaded file.
#
# Arguments:
@@ -320,7 +357,7 @@ pbuild::set_download_url() {
}
readonly -f pbuild::set_download_url
##############################################################################
#..............................................................................
#
# Set hash sum for file.
#
@@ -335,7 +372,7 @@ pbuild::set_sha256sum() {
}
readonly -f pbuild::set_sha256sum
##############################################################################
#..............................................................................
#
# Unpack file $1 in directory $2
#
@@ -348,23 +385,7 @@ pbuild::set_unpack_dir() {
}
readonly -f pbuild::set_unpack_dir
##############################################################################
#
# Use this C-compiler
#
# Arguments:
# $1 C-compiler to use.
#
pbuild::use_cc() {
[[ -x "$1" ]] || std::die 3 \
"%s " "${module_name}/${module_version}:" \
"Error in setting CC:" \
"'$1' is not an executable!"
CC="$1"
}
readonly -f pbuild::use_cc
###############################################################################
#..............................................................................
#
pbuild::add_patch() {
[[ -z "$1" ]] && \
@@ -380,7 +401,7 @@ pbuild::add_patch() {
}
readonly -f pbuild::add_patch
###############################################################################
#..............................................................................
#
pbuild::set_default_patch_strip() {
[[ -n "$1" ]] || \
@@ -392,35 +413,7 @@ pbuild::set_default_patch_strip() {
}
readonly -f pbuild::set_default_patch_strip
###############################################################################
#
pbuild::use_flag() {
[[ "${USE_FLAGS}" =~ ":${1}:" ]]
}
readonly -f pbuild::use_flag
###############################################################################
#
pbuild::add_configure_args() {
CONFIGURE_ARGS+=( "$@" )
}
readonly -f pbuild::add_configure_args
###############################################################################
#
pbuild::use_autotools() {
configure_with='autotools'
}
readonly -f pbuild::use_autotools
###############################################################################
#
pbuild::use_cmake() {
configure_with='cmake'
}
readonly -f pbuild::use_cmake
###############################################################################
#..............................................................................
#
# extract sources. For the time being only tar-files are supported.
#
@@ -582,6 +575,59 @@ pbuild::prep() {
###############################################################################
#
# functions to configure the sources
#..............................................................................
#
pbuild::add_configure_args() {
CONFIGURE_ARGS+=( "$@" )
}
readonly -f pbuild::add_configure_args
#..............................................................................
#
pbuild::use_autotools() {
configure_with='autotools'
}
readonly -f pbuild::use_autotools
#..............................................................................
#
pbuild::use_cmake() {
configure_with='cmake'
}
readonly -f pbuild::use_cmake
#..............................................................................
#
# Use this C-compiler
#
# Arguments:
# $1 C-compiler to use.
#
pbuild::use_cc() {
[[ -x "$1" ]] || std::die 3 \
"%s " "${module_name}/${module_version}:" \
"Error in setting CC:" \
"'$1' is not an executable!"
CC="$1"
}
readonly -f pbuild::use_cc
#..............................................................................
#
# Set flag to build module in source tree.
#
# Arguments:
# none
#
pbuild::compile_in_sourcetree() {
BUILD_DIR="${SRC_DIR}"
}
readonly -f pbuild::compile_in_sourcetree
#..............................................................................
#
# Configure the software to be compiled.
#
# Arguments:
@@ -635,7 +681,11 @@ pbuild::configure() {
}
###############################################################################
##############################################################################
#
# functions to compile the sources
#..............................................................................
#
# Default compile function.
#
@@ -650,7 +700,23 @@ pbuild::compile() {
"compilation failed!"
}
###############################################################################
##############################################################################
#
# functions to install everything
#..............................................................................
#
# Set documentation file to be installed.
#
# Arguments:
# $@: documentation files relative to source
#
pbuild::install_docfiles() {
MODULE_DOCFILES+=("$@")
}
readonly -f pbuild::install_docfiles
#..............................................................................
#
# Default install function.
#
@@ -664,7 +730,7 @@ pbuild::install() {
"compilation failed!"
}
###############################################################################
#..............................................................................
#
pbuild::install_shared_libs() {
local -r binary="$1"
+17 -25
View File
@@ -519,25 +519,25 @@ build_modules_yaml(){
local fname="$2"
local version="$3"
local idx="$4"
_result=$(${yq} -Ne e ".\"${version}\"[${idx}].systems" \
"${fname}" 2>/dev/null)
_result=( $(${yq} -Ne e ".\"${version}\"[${idx}].systems" \
"${fname}" 2>/dev/null) )
(( $? == 0 )) && return
_result=$(${yq} -Ne e ".systems" "${fname}" 2>/dev/null)
_result=( $(${yq} -Ne e ".systems" "${fname}" 2>/dev/null) )
(( $? == 0 )) && return
_result='any'
_result=()
}
yaml_get_operating_systems(){
yaml_get_compilers(){
local -n _result="$1"
local fname="$2"
local version="$3"
local idx="$4"
_result=$(${yq} -Ne e ".\"${version}\"[${idx}].operating_systems" \
"${fname}" 2>/dev/null)
_result=( $(${yq} -Ne e ".\"${version}\"[${idx}].compilers" \
"${fname}" 2>/dev/null) )
(( $? == 0 )) && return
_result=$(${yq} -Ne e ".operating_systems" "${fname}" 2>/dev/null)
_result=( $(${yq} -Ne e ".compilers" "${fname}" 2>/dev/null) )
(( $? == 0 )) && return
_result='any'
_result=()
}
yaml_get_dependencies(){
@@ -595,6 +595,7 @@ build_modules_yaml(){
local -a deps=()
local -a build_requires=()
local relstage
local group
local ol_name
for (( i=0; i<n_variants; i++)); do
if [[ -z ${opt_overlay} ]]; then
@@ -613,6 +614,8 @@ build_modules_yaml(){
yaml_get_relstage relstage "${fname}" "${v}" $i
yaml_get_dependencies deps "${fname}" "${v}" $i
yaml_get_build_requirements build_requires "${fname}" "${v}" $i
yaml_get_group group "${fname}" "${v}" $i
pbuild.add_to_group "${group}"
# :FIXME:
# for the time being we prefix the build requirements
# with 'b:' and append them to the other dependencies.
@@ -623,23 +626,12 @@ build_modules_yaml(){
declare ol_inst_root="${OverlayInfo[${ol_name}:inst_root]}"
declare ol_mod_root="${OverlayInfo[${ol_name}:mod_root]}"
local systems
local -a systems=()
local -a compilers=()
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
yaml_get_compilers compilers "${fname}" "${v}" $i
pbuild.supported_systems "${systems[@]}"
pbuild.supported_compilers "${compilers[@]}"
if (( ${#deps[@]} > 0 )); then
while read -a with_modules; do
pbuild.build_module \