From 1ee6a3174f7b41b13943fc073e907108e7632eab Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 13 Apr 2019 13:43:07 +0200 Subject: [PATCH] xbps-src: reduce basename(1) usage. This saves a few exec()s. --- common/build-style/fetch.sh | 3 ++- common/hooks/do-extract/00-distfiles.sh | 9 ++++++--- common/hooks/do-fetch/00-distfiles.sh | 7 +++++-- common/xbps-src/shutils/show.sh | 3 ++- xbps-src | 10 ++++------ 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/common/build-style/fetch.sh b/common/build-style/fetch.sh index e765b0ecbd..f501cc6d53 100644 --- a/common/build-style/fetch.sh +++ b/common/build-style/fetch.sh @@ -5,7 +5,8 @@ do_extract() { mkdir -p ${wrksrc} for f in ${distfiles}; do - curfile=$(basename "${f#*>}") + curfile="${f#*>}" + curfile="${curfile##*/}" cp ${XBPS_SRCDISTDIR}/${pkgname}-${version}/${curfile} ${wrksrc}/${curfile} done } diff --git a/common/hooks/do-extract/00-distfiles.sh b/common/hooks/do-extract/00-distfiles.sh index c9f98589a4..c1eacf4700 100644 --- a/common/hooks/do-extract/00-distfiles.sh +++ b/common/hooks/do-extract/00-distfiles.sh @@ -3,6 +3,7 @@ hook() { local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version" + local f j curfile found extractdir if [ -z "$distfiles" -a -z "$checksum" ]; then mkdir -p $wrksrc @@ -11,7 +12,8 @@ hook() { # Check that distfiles are there before anything else. for f in ${distfiles}; do - curfile=$(basename "${f#*>}") + curfile="${f#*>}" + curfile="${curfile##*/}" if [ ! -f $srcdir/$curfile ]; then msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n" fi @@ -24,7 +26,8 @@ hook() { msg_normal "$pkgver: extracting distfile(s), please wait...\n" for f in ${distfiles}; do - curfile=$(basename "${f#*>}") + curfile="${f#*>}" + curfile="${curfile##*/}" for j in ${skip_extraction}; do if [ "$curfile" = "$j" ]; then found=1 @@ -122,7 +125,7 @@ hook() { fi ;; gem) - tar -xOf $srcdir/$curfile data.tar.gz | tar -xz -C $extractdir --transform="s,^,$(basename $wrksrc)/," + tar -xOf $srcdir/$curfile data.tar.gz | tar -xz -C $extractdir --transform="s,^,${wrksrc##*/}/," if [ $? -ne 0 ]; then msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n" fi diff --git a/common/hooks/do-fetch/00-distfiles.sh b/common/hooks/do-fetch/00-distfiles.sh index 2b479b56dd..a07d0af7f4 100644 --- a/common/hooks/do-fetch/00-distfiles.sh +++ b/common/hooks/do-fetch/00-distfiles.sh @@ -212,8 +212,10 @@ hook() { # Detect distfiles with obsolete checksum and purge them from the cache for f in ${distfiles}; do - curfile=$(basename "${f#*>}") + curfile="${f#*>}" + curfile="${curfile##*/}" distfile="$srcdir/$curfile" + if [ -f "$distfile" ]; then cksum=$(get_cksum $curfile $dfcount) if [ "${cksum:0:1}" = "@" ]; then @@ -239,7 +241,8 @@ hook() { # Download missing distfiles and verify their checksums dfcount=0 for f in ${distfiles}; do - curfile=$(basename "${f#*>}") + curfile="${f#*>}" + curfile="${curfile##*/}" distfile="$srcdir/$curfile" # If file lock cannot be acquired wait until it's available. diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh index 0052293312..84db717dc3 100644 --- a/common/xbps-src/shutils/show.sh +++ b/common/xbps-src/shutils/show.sh @@ -99,7 +99,8 @@ show_pkg_build_depends() { _pkgname="$f" fi _pkgname=${_pkgname/-32bit} - _srcpkg=$(basename $(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})) + _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname}) + _srcpkg=${_srcpkg##*/} echo "${_srcpkg}" >> $result done sort -u $result diff --git a/xbps-src b/xbps-src index 2fc2823df1..375cf3f9e8 100755 --- a/xbps-src +++ b/xbps-src @@ -1,6 +1,8 @@ #!/bin/bash # vim: set ts=4 sw=4 et: +readonly PROGNAME="${0##*/}" + print_cross_targets() { local f for f in common/cross-profiles/*.sh; do @@ -10,7 +12,7 @@ print_cross_targets() { usage() { cat << _EOF -$(basename $0): [options] [arguments] +$PROGNAME: [options] [arguments] Targets: (only one may be specified) @@ -380,14 +382,10 @@ exit_func() { exit 2 } -basename_cwd() { - echo $(basename $(pwd)) -} - read_pkg() { if [ -z "${XBPS_TARGET_PKG}" ]; then [ ! -r ./template ] && msg_error "missing build template in $(pwd).\n" - XBPS_TARGET_PKG=$(basename_cwd) + XBPS_TARGET_PKG=${PWD##*/} fi setup_pkg "$XBPS_TARGET_PKG" "$XBPS_CROSS_BUILD" "$1" }