From 58f6a2ed4e92953bb815d3ef5a741ee63110955a Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Tue, 16 Apr 2024 15:32:43 +0200 Subject: [PATCH] build-system: configurable number directory components to be strip The tar command is called with the option --strip-components. Till now the value was 1 and hardcoded. In some cases more or less components must be removed. This can now be configured in the YAML file. --- CHANGELOG.md | 3 +++ Pmodules/libpbuild.bash | 26 +++++++++++++++++--------- Pmodules/modbuild.in | 10 +++++++++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 014ae10..98665a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ * Option '--clean-install' added. If this option is set, the module is removed before building, if the module already exist. (issue #247) +* The number of directory components to be removed while + un-taring can now be configured in the YAML configuration + file. If not specified, 1 is used as default. (issue #251) ## Version 1.1.18 ### modulecmd diff --git a/Pmodules/libpbuild.bash b/Pmodules/libpbuild.bash index eaf9749..a5cd7f9 100644 --- a/Pmodules/libpbuild.bash +++ b/Pmodules/libpbuild.bash @@ -18,6 +18,7 @@ declare -r _DOCDIR='share/doc' declare -a SOURCE_URLS=() declare -a SOURCE_SHA256_SUMS=() declare -a SOURCE_NAMES=() +declare -a SOURCE_STRIP_DIRS=() declare -A SOURCE_UNPACK_DIRS=() declare -a CONFIGURE_ARGS=() declare -a PATCH_FILES=() @@ -398,11 +399,6 @@ pbuild::set_download_url() { std::info \ "Using ${FUNCNAME} is deprecated with YAML module configuration files." fi - pbuild.set_urls "$@" -} -readonly -f pbuild::set_download_url - -pbuild.set_urls(){ local -i _i=${#SOURCE_URLS[@]} SOURCE_URLS[_i]=$1 if (( $# > 1 )); then @@ -410,6 +406,15 @@ pbuild.set_urls(){ else SOURCE_NAMES[$_i]="${1##*/}" fi + SOURCE_STRIP_DIRS[_i]='1' +} +readonly -f pbuild::set_download_url + +pbuild.set_urls(){ + local -i _i=${#SOURCE_URLS[@]} + SOURCE_URLS[_i]="$1" + SOURCE_NAMES[$_i]="$2" + SOURCE_STRIP_DIRS[_i]="$3" } #.............................................................................. @@ -495,7 +500,8 @@ readonly -f pbuild::set_default_patch_strip pbuild::unpack(){ local -r file="$1" local -r dir="${2:-${SRC_DIR}}" - ${tar} --directory="${dir}" -xv --strip-components 1 -f "${file}" + local -r strip="${3:-1}" + ${tar} --directory="${dir}" -xv --strip-components "${strip}" -f "${file}" } #.............................................................................. @@ -601,10 +607,11 @@ pbuild::prep() { unpack() { local -r file="$1" - local -r dir="${2:-${SRC_DIR}}" + local -r dir="$2" + local -r strip="$3" { mkdir -p "${dir}" - pbuild::unpack "${file}" "${dir}" + pbuild::unpack "${file}" "${dir}" "${strip}" } || { ${rm} -f "${file}" std::die 4 \ @@ -657,7 +664,8 @@ pbuild::prep() { else dir="${SRC_DIR}" fi - unpack "${source_fname}" "${dir}" + local strip_dirs="${SOURCE_STRIP_DIRS[i]}" + unpack "${source_fname}" "${dir}" "${strip_dirs}" done patch_sources # create build directory diff --git a/Pmodules/modbuild.in b/Pmodules/modbuild.in index 8d00443..b348596 100755 --- a/Pmodules/modbuild.in +++ b/Pmodules/modbuild.in @@ -1143,6 +1143,7 @@ build_modules_yaml_v1(){ std::die 3 "error parsing YAML configuration" local url='' local fname='' + local strip_dirs='' while read key value; do key=${key:0:-1} case "${key}" in @@ -1152,6 +1153,10 @@ build_modules_yaml_v1(){ name ) fname=$(envsubst <<<"${value}") ;; + strip_dirs ) + strip_dirs="${value}" + # :FIXME: add check for unsigned int! + ;; * ) std::die 3 "Invalid key in list of URLs -- ${key}" ;; @@ -1160,7 +1165,10 @@ build_modules_yaml_v1(){ std::die 3 "URL missing!" fi done <<<"${url_yaml}" - pbuild.set_urls "${url}" "${fname}" + [[ -z "${url}" ]] && std::die 3 "url missing in:\n${yaml}" + [[ -z "${fname}" ]] && fname="${url##*/}" + [[ -z "${strip_dirs}" ]] && strip_dirs=1 + pbuild.set_urls "${url}" "${fname}" "${strip_dirs}" done }