Commit a882800a authored by gsell's avatar gsell

bugfix in pbuild::module_is_available()

parent 3e79fa68
......@@ -306,7 +306,14 @@ pbuild::module_is_avail() {
[[ -n "${uvar}" ]] || uvar="__unused__"
local output=( $("${MODULECMD}" bash avail -a -m "$1" \
2>&1 1>/dev/null) )
[[ "${output[0]}" == "$1" ]] && std::upvar "${uvar}" "${output[1]}"
local i
for (( i=0; i+=2; i < ${#output[@]})); do
if [[ "${output[0]}" == "$1" ]]; then
std::upvar "${uvar}" "${output[1]}"
return 0
fi
done
return 1
}
pbuild::set_download_url() {
......@@ -320,14 +327,14 @@ pbuild::set_sha256sum() {
}
pbuild::set_unpack_dir() {
SOURCE_UNPACK_DIRS[$1]=$2
SOURCE_UNPACK_DIRS[$1]=$2
}
pbuild::use_cc() {
[[ -x "$1" ]] || std::die 3 \
"%s " "${module_name}/${module_version}:" \
"Error in setting CC:" \
"'$1' is not an executable!"
"%s " "${module_name}/${module_version}:" \
"Error in setting CC:" \
"'$1' is not an executable!"
CC="$1"
}
......@@ -344,22 +351,22 @@ pbuild::post_prep() {
# extract sources. For the time being only tar-files are supported.
#
pbuild::prep() {
#......................................................................
#
# Find/download tarball for given module.
#
# Arguments:
# $1: store file name with upvar here
# $2: download URL
# $3: output filename (can be empty string)
# $4...: download directories
#
# Returns:
# 0 on success otherwise a value > 0
#
download_with_curl() {
local -r output="$1"
local -r url="$2"
#......................................................................
#
# Find/download tarball for given module.
#
# Arguments:
# $1: store file name with upvar here
# $2: download URL
# $3: output filename (can be empty string)
# $4...: download directories
#
# Returns:
# 0 on success otherwise a value > 0
#
download_with_curl() {
local -r output="$1"
local -r url="$2"
curl \
-L \
--output "${output}" \
......@@ -370,8 +377,8 @@ pbuild::prep() {
--output "${output}" \
"${url}"
fi
}
}
check_hash_sum() {
local -r fname="$1"
local -r expected_hash_sum="$2"
......@@ -383,61 +390,61 @@ pbuild::prep() {
hash_sum=$(shasum -a 256 "${fname}" | awk '{print $1}')
else
std::die 42 \
"%s " "${module_name}/${module_version}:" \
"Binary to compute SHA256 sum missing!"
"%s " "${module_name}/${module_version}:" \
"Binary to compute SHA256 sum missing!"
fi
test "${hash_sum}" == "${expected_hash_sum}" || \
std::die 42 \
"%s " "${module_name}/${module_version}:" \
"hash-sum missmatch for file '%s'" "${fname}"
std::die 42 \
"%s " "${module_name}/${module_version}:" \
"hash-sum missmatch for file '%s'" "${fname}"
}
download_source_file() {
local "$1"
local var="$1"
local -r url="$2"
local fname="$3"
shift 3
dirs+=( "$@" )
[[ -n "${fname}" ]] || fname="${url##*/}"
local expr='s/.*\(.tar.bz2\|.tbz2\|.tar.gz\|.tgz\|.tar.xz\|.zip\)/\1/'
local -r extension=$(echo ${fname} | sed "${expr}")
local dir=''
dirs+=( 'not found' )
for dir in "${dirs[@]}"; do
[[ -r "${dir}/${fname}" ]] && break
done
if [[ "${dir}" == 'not found' ]]; then
dir="${dirs[0]}"
local -r method="${url%:*}"
case "${method}" in
http | https | ftp )
download_with_curl "${dir}/${fname}" "${url}"
;;
* )
std::die 4 \
"%s " "${module_name}/${module_version}:" \
"Error in download URL:" \
"unknown download method '${method}'!"
;;
esac
fi
local sha256_sum=''
local hash=''
for hash in "${SOURCE_SHA256_SUMS[@]}"; do
if [[ ${hash} =~ $fname: ]]; then
sha256_sum="${hash#*:}"
fi
done
if [[ -n "${sha256_sum}" ]]; then
check_hash_sum "${dir}/${fname}" "${sha256_sum}"
fi
std::upvar "${var}" "${dir}/${fname}"
[[ -r "${dir}/${fname}" ]]
}
unpack() {
download_source_file() {
local "$1"
local var="$1"
local -r url="$2"
local fname="$3"
shift 3
dirs+=( "$@" )
[[ -n "${fname}" ]] || fname="${url##*/}"
local expr='s/.*\(.tar.bz2\|.tbz2\|.tar.gz\|.tgz\|.tar.xz\|.zip\)/\1/'
local -r extension=$(echo ${fname} | sed "${expr}")
local dir=''
dirs+=( 'not found' )
for dir in "${dirs[@]}"; do
[[ -r "${dir}/${fname}" ]] && break
done
if [[ "${dir}" == 'not found' ]]; then
dir="${dirs[0]}"
local -r method="${url%:*}"
case "${method}" in
http | https | ftp )
download_with_curl "${dir}/${fname}" "${url}"
;;
* )
std::die 4 \
"%s " "${module_name}/${module_version}:" \
"Error in download URL:" \
"unknown download method '${method}'!"
;;
esac
fi
local sha256_sum=''
local hash=''
for hash in "${SOURCE_SHA256_SUMS[@]}"; do
if [[ ${hash} =~ $fname: ]]; then
sha256_sum="${hash#*:}"
fi
done
if [[ -n "${sha256_sum}" ]]; then
check_hash_sum "${dir}/${fname}" "${sha256_sum}"
fi
std::upvar "${var}" "${dir}/${fname}"
[[ -r "${dir}/${fname}" ]]
}
unpack() {
local -r file="$1"
local -r dir="${2:-${SRC_DIR}}"
(
......@@ -451,34 +458,34 @@ pbuild::prep() {
patch_sources() {
cd "${SRC_DIR}"
local i=0
local i=0
for ((_i = 0; _i < ${#PATCH_FILES[@]}; _i++)); do
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"Appling patch '${PATCH_FILES[_i]}' ..."
"Appling patch '${PATCH_FILES[_i]}' ..."
local -i strip_val="${PATCH_STRIPS[_i]:-${PATCH_STRIP_DEFAULT}}"
patch -p${strip_val} < "${BUILDBLOCK_DIR}/${PATCH_FILES[_i]}"
done
}
[[ -z "${SOURCE_URLS}" ]] && \
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"Download source not set!"
mkdir -p "${PMODULES_DISTFILESDIR}"
local i=0
local source_fname
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"Download source not set!"
mkdir -p "${PMODULES_DISTFILESDIR}"
local i=0
local source_fname
for ((i = 0; i < ${#SOURCE_URLS[@]}; i++)); do
download_source_file \
source_fname \
"${SOURCE_URLS[i]}" \
"${SOURCE_NAMES[i]}" \
"${PMODULES_DISTFILESDIR}" \
"${BUILDBLOCK_DIR}" ||
std::die 4 \
"%s " "${module_name}/${module_version}:" \
"sources for not found."
source_fname \
"${SOURCE_URLS[i]}" \
"${SOURCE_NAMES[i]}" \
"${PMODULES_DISTFILESDIR}" \
"${BUILDBLOCK_DIR}" ||
std::die 4 \
"%s " "${module_name}/${module_version}:" \
"sources for not found."
unpack "${source_fname}" "${SOURCE_UNPACK_DIRS[${source_fname##*/}]}"
done
patch_sources
......@@ -488,18 +495,18 @@ pbuild::prep() {
pbuild::add_patch() {
[[ -z "$1" ]] && \
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: missing argument!"
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: missing argument!"
PATCH_FILES+=( "$1" )
PATCH_STRIPS+=( "$2" )
}
pbuild::set_default_patch_strip() {
[[ -n "$1" ]] || \
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: missing argument!"
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"${FUNCNAME}: missing argument!"
PATCH_STRIP_DEFAULT="$1"
}
......@@ -532,48 +539,48 @@ pbuild::use_cmake() {
}
pbuild::configure() {
case "${configure_with}" in
autotools )
if [[ ! -r "${SRC_DIR}/configure" ]]; then
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${FNCNAME[0]}:" \
"autotools configuration not available, aborting..."
fi
;;
cmake )
if [[ ! -r "${SRC_DIR}/CMakeLists.txt" ]]; then
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${FNCNAME[0]}:" \
"CMake script not available, aborting..."
fi
;;
esac
case "${configure_with}" in
autotools )
if [[ ! -r "${SRC_DIR}/configure" ]]; then
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${FNCNAME[0]}:" \
"autotools configuration not available, aborting..."
fi
;;
cmake )
if [[ ! -r "${SRC_DIR}/CMakeLists.txt" ]]; then
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${FNCNAME[0]}:" \
"CMake script not available, aborting..."
fi
;;
esac
if [[ -r "${SRC_DIR}/configure" ]] && \
[[ "${configure_with}" == 'undef' ]] || \
[[ "${configure_with}" == 'autotools' ]]; then
[[ "${configure_with}" == 'undef' ]] || \
[[ "${configure_with}" == 'autotools' ]]; then
${SRC_DIR}/configure \
--prefix="${PREFIX}" \
"${CONFIGURE_ARGS[@]}" || \
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"configure failed"
--prefix="${PREFIX}" \
"${CONFIGURE_ARGS[@]}" || \
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"configure failed"
elif [[ -r "${SRC_DIR}/CMakeLists.txt" ]] && \
[[ "${configure_with}" == 'undef' ]] || \
[[ "${configure_with}" == "cmake" ]]; then
[[ "${configure_with}" == 'undef' ]] || \
[[ "${configure_with}" == "cmake" ]]; then
cmake \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
"${CONFIGURE_ARGS[@]}" \
"${SRC_DIR}" || \
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"cmake failed"
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"cmake failed"
else
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"${FUNCNAME[0]}: skipping..."
"${FUNCNAME[0]}: skipping..."
fi
}
......@@ -606,38 +613,38 @@ pbuild::install_shared_libs() {
local -r dstdir="$2"
local -r pattern="${3//\//\\/}" # escape slash
install_shared_libs_Linux() {
local libs=( $(ldd "${binary}" | \
awk "/ => \// && /${pattern}/ {print \$3}") )
if [[ -n "${libs}" ]]; then
cp -vL "${libs[@]}" "${dstdir}" || return $?
fi
return 0
}
install_shared_libs_Darwin() {
# https://stackoverflow.com/questions/33991581/install-name-tool-to-update-a-executable-to-search-for-dylib-in-mac-os-x
local libs=( $(otool -L "${binary}" | \
awk "/${pattern}/ {print \$1}"))
if [[ -n "${libs}" ]]; then
cp -vL "${libs[@]}" "${dstdir}" || return $?
fi
return 0
}
install_shared_libs_Linux() {
local libs=( $(ldd "${binary}" | \
awk "/ => \// && /${pattern}/ {print \$3}") )
if [[ -n "${libs}" ]]; then
cp -vL "${libs[@]}" "${dstdir}" || return $?
fi
return 0
}
install_shared_libs_Darwin() {
# https://stackoverflow.com/questions/33991581/install-name-tool-to-update-a-executable-to-search-for-dylib-in-mac-os-x
local libs=( $(otool -L "${binary}" | \
awk "/${pattern}/ {print \$1}"))
if [[ -n "${libs}" ]]; then
cp -vL "${libs[@]}" "${dstdir}" || return $?
fi
return 0
}
test -e "${binary}" || \
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${binary}: does not exist or is not executable!"
std::die 3 \
"%s " "${module_name}/${module_version}:" \
"${binary}: does not exist or is not executable!"
mkdir -p "${dstdir}"
case "${OS}" in
Linux )
install_shared_libs_Linux
;;
Darwin )
install_shared_libs_Darwin
;;
esac
case "${OS}" in
Linux )
install_shared_libs_Linux
;;
Darwin )
install_shared_libs_Darwin
;;
esac
}
pbuild::post_install() {
......@@ -648,10 +655,10 @@ pbuild::post_install() {
# The 'do it all' function.
#
pbuild::make_all() {
source "${BUILD_SCRIPT}"
source "${BUILD_SCRIPT}"
set -e
local -r logfile="${BUILDBLOCK_DIR}/pbuild.log"
local -r logfile="${BUILDBLOCK_DIR}/pbuild.log"
#
# To be able to set environment variables in one of the 'pbuild::TARGET'
......@@ -670,9 +677,9 @@ pbuild::make_all() {
# everything set up?
#
[[ -n ${GROUP} ]] || \
std::die 5 \
"%s " "${module_name}/${module_version}:" \
"Module group not set! Aborting ..."
std::die 5 \
"%s " "${module_name}/${module_version}:" \
"Module group not set! Aborting ..."
#
......@@ -686,8 +693,8 @@ pbuild::make_all() {
[[ ${sys,,} == ${system,,} ]] && return 0
done
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"Not available for ${system}."
"%s " "${module_name}/${module_version}:" \
"Not available for ${system}."
}
#......................................................................
......@@ -697,8 +704,8 @@ pbuild::make_all() {
[[ ${os,,} == ${OS,,} ]] && return 0
done
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"Not available for ${OS}."
"%s " "${module_name}/${module_version}:" \
"Not available for ${OS}."
}
#......................................................................
......@@ -708,8 +715,8 @@ pbuild::make_all() {
[[ ${compiler,,} == ${COMPILER,,} ]] && return 0
done
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"Not available for ${COMPILER}."
"%s " "${module_name}/${module_version}:" \
"Not available for ${COMPILER}."
}
#......................................................................
......@@ -720,13 +727,13 @@ pbuild::make_all() {
local -r docdir="${PREFIX}/${_DOCDIR}/${module_name}"
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"Installing documentation to ${docdir}"
"Installing documentation to ${docdir}"
install -m 0755 -d \
"${docdir}"
"${docdir}"
install -m0444 \
"${MODULE_DOCFILES[@]/#/${SRC_DIR}/}" \
"${MODULE_DOCFILES[@]/#/${SRC_DIR}/}" \
"${docdir}"
return 0
}
......@@ -739,31 +746,31 @@ pbuild::make_all() {
local -r target_dir="${PREFIX}/share/$GROUP/${module_name}"
install -m 0756 \
-d "${target_dir}/files"
-d "${target_dir}/files"
install -m0444 \
"${BUILD_SCRIPT}" \
"${target_dir}"
"${BUILD_SCRIPT}" \
"${target_dir}"
install -m0444 \
"${BUILDBLOCK_DIR}/modulefile" \
"${target_dir}"
"${BUILDBLOCK_DIR}/modulefile" \
"${target_dir}"
#install -m0444 \
# "${variants_file}" \
# "${target_dir}/files"
# "${variants_file}" \
# "${target_dir}/files"
local -r fname="${target_dir}/dependencies"
"${MODULECMD}" bash list -t 2>&1 1>/dev/null | \
grep -v "Currently Loaded" > "${fname}" || :
grep -v "Currently Loaded" > "${fname}" || :
}
#..............................................................
# write run time dependencies to file
write_runtime_dependencies() {
local -r fname="$1"
shift
shift
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"writing run-time dependencies to ${fname} ..."
"writing run-time dependencies to ${fname} ..."
local dep
echo -n "" > "${fname}"
for dep in "$@"; do
......@@ -772,7 +779,7 @@ pbuild::make_all() {
# no version given: derive the version
# from the currently loaded module
dep=$( "${MODULECMD}" bash list -t 2>&1 1>/dev/null \
| grep "^${dep}/" )
| grep "^${dep}/" )
fi
echo "${dep}" >> "${fname}"
done
......@@ -782,12 +789,12 @@ pbuild::make_all() {
# sometimes we need an system depended post-install
post_install_linux() {
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"running post-installation for ${OS} ..."
"running post-installation for ${OS} ..."
cd "${PREFIX}"
# solve multilib problem with LIBRARY_PATH
# on 64bit Linux
# on 64bit Linux
[[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64
return 0
}
......@@ -796,16 +803,16 @@ pbuild::make_all() {
[[ "${OS}" == "Linux" ]] && post_install_linux
install_doc
install_pmodules_files
if [[ -n "${runtime_dependencies}" ]]; then
write_runtime_dependencies \
"${PREFIX}/${FNAME_RDEPS}" \
"${runtime_dependencies[@]}"
fi
if [[ -n "${install_dependencies}" ]]; then
write_runtime_dependencies \
"${PREFIX}/${FNAME_IDEPS}" \
"${install_dependencies[@]}"
fi
if [[ -n "${runtime_dependencies}" ]]; then
write_runtime_dependencies \
"${PREFIX}/${FNAME_RDEPS}" \
"${runtime_dependencies[@]}"
fi
if [[ -n "${install_dependencies}" ]]; then
write_runtime_dependencies \
"${PREFIX}/${FNAME_IDEPS}" \
"${install_dependencies[@]}"
fi
return 0
}
......@@ -815,9 +822,9 @@ pbuild::make_all() {
local -r src="${BUILDBLOCK_DIR}/modulefile"
if [[ ! -r "${src}" ]]; then
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"skipping modulefile installation ..."
"skipping modulefile installation ..."
return
fi
# assemble name of modulefile
......@@ -830,90 +837,90 @@ pbuild::make_all() {
local -r dstdir=${dst%/*}
std::info \
"%s %s\n" \
"%s %s\n" \
"${module_name}/${module_version}:" \
"installing modulefile in '${dstdir}' ..."
"installing modulefile in '${dstdir}' ..."
mkdir -p "${dstdir}"
install -m 0444 "${src}" "${dst}"
}
install_release_file() {
install_release_file() {
local dst="${PMODULES_ROOT}/"
dst+="${GROUP}/"
dst+="${PMODULES_MODULEFILES_DIR}/"
dst+="${fully_qualified_module_name}"
# directory where to install release file
local -r dstdir=${dst%/*}
mkdir -p "${dstdir}"
local -r dstdir=${dst%/*}
mkdir -p "${dstdir}"
local -r release_file="${dst%/*}/.release-${module_version}"
if [[ -r "${release_file}" ]]; then
local release
read release < "${release_file}"
if [[ "${release}" != "${module_release}" ]]; then
std::info \
"%s %s %s\n" \
if [[ -r "${release_file}" ]]; then
local release
read release < "${release_file}"
if [[ "${release}" != "${module_release}" ]]; then
std::info \
"%s %s %s\n" \
"${module_name}/${module_version}:" \
"changing release from" \
"'${release}' to '${module_release}' ..."
echo "${module_release}" > "${release_file}"
fi
else
std::info \
"%s %s\n" \
"changing release from" \
"'${release}' to '${module_release}' ..."
echo "${module_release}" > "${release_file}"
fi
else
std::info \
"%s %s\n" \
"${module_name}/${module_version}:" \
"setting release to '${module_release}' ..."
echo "${module_release}" > "${release_file}"
fi
}
cleanup_build() {
[[ ${enable_cleanup_build} == yes ]] || return 0
[[ "${BUILD_DIR}" == "${SRC_DIR}" ]] && return 0
{
cd "/${BUILD_DIR}/.." || std::die 42 "Internal error"
[[ "$(pwd)" == "/" ]] && \
std::die 1 \
"%s " "${module_name}/${module_version}:" \
"Oops: internal error:" \
"BUILD_DIR is set to '/'"
std::info \
"%s %s\n" \
"setting release to '${module_release}' ..."
echo "${module_release}" > "${release_file}"
fi