xbps-src: reduce basename(1) usage.

This saves a few exec()s.
This commit is contained in:
Juan RP 2019-04-13 13:43:07 +02:00 committed by maxice8
parent 64061588fc
commit 1ee6a3174f
5 changed files with 19 additions and 13 deletions

View file

@ -5,7 +5,8 @@ do_extract() {
mkdir -p ${wrksrc} mkdir -p ${wrksrc}
for f in ${distfiles}; do for f in ${distfiles}; do
curfile=$(basename "${f#*>}") curfile="${f#*>}"
curfile="${curfile##*/}"
cp ${XBPS_SRCDISTDIR}/${pkgname}-${version}/${curfile} ${wrksrc}/${curfile} cp ${XBPS_SRCDISTDIR}/${pkgname}-${version}/${curfile} ${wrksrc}/${curfile}
done done
} }

View file

@ -3,6 +3,7 @@
hook() { hook() {
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version" local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
local f j curfile found extractdir
if [ -z "$distfiles" -a -z "$checksum" ]; then if [ -z "$distfiles" -a -z "$checksum" ]; then
mkdir -p $wrksrc mkdir -p $wrksrc
@ -11,7 +12,8 @@ hook() {
# Check that distfiles are there before anything else. # Check that distfiles are there before anything else.
for f in ${distfiles}; do for f in ${distfiles}; do
curfile=$(basename "${f#*>}") curfile="${f#*>}"
curfile="${curfile##*/}"
if [ ! -f $srcdir/$curfile ]; then if [ ! -f $srcdir/$curfile ]; then
msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n" msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n"
fi fi
@ -24,7 +26,8 @@ hook() {
msg_normal "$pkgver: extracting distfile(s), please wait...\n" msg_normal "$pkgver: extracting distfile(s), please wait...\n"
for f in ${distfiles}; do for f in ${distfiles}; do
curfile=$(basename "${f#*>}") curfile="${f#*>}"
curfile="${curfile##*/}"
for j in ${skip_extraction}; do for j in ${skip_extraction}; do
if [ "$curfile" = "$j" ]; then if [ "$curfile" = "$j" ]; then
found=1 found=1
@ -122,7 +125,7 @@ hook() {
fi fi
;; ;;
gem) 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 if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n" msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi fi

View file

@ -212,8 +212,10 @@ hook() {
# Detect distfiles with obsolete checksum and purge them from the cache # Detect distfiles with obsolete checksum and purge them from the cache
for f in ${distfiles}; do for f in ${distfiles}; do
curfile=$(basename "${f#*>}") curfile="${f#*>}"
curfile="${curfile##*/}"
distfile="$srcdir/$curfile" distfile="$srcdir/$curfile"
if [ -f "$distfile" ]; then if [ -f "$distfile" ]; then
cksum=$(get_cksum $curfile $dfcount) cksum=$(get_cksum $curfile $dfcount)
if [ "${cksum:0:1}" = "@" ]; then if [ "${cksum:0:1}" = "@" ]; then
@ -239,7 +241,8 @@ hook() {
# Download missing distfiles and verify their checksums # Download missing distfiles and verify their checksums
dfcount=0 dfcount=0
for f in ${distfiles}; do for f in ${distfiles}; do
curfile=$(basename "${f#*>}") curfile="${f#*>}"
curfile="${curfile##*/}"
distfile="$srcdir/$curfile" distfile="$srcdir/$curfile"
# If file lock cannot be acquired wait until it's available. # If file lock cannot be acquired wait until it's available.

View file

@ -99,7 +99,8 @@ show_pkg_build_depends() {
_pkgname="$f" _pkgname="$f"
fi fi
_pkgname=${_pkgname/-32bit} _pkgname=${_pkgname/-32bit}
_srcpkg=$(basename $(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})) _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
_srcpkg=${_srcpkg##*/}
echo "${_srcpkg}" >> $result echo "${_srcpkg}" >> $result
done done
sort -u $result sort -u $result

View file

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
# vim: set ts=4 sw=4 et: # vim: set ts=4 sw=4 et:
readonly PROGNAME="${0##*/}"
print_cross_targets() { print_cross_targets() {
local f local f
for f in common/cross-profiles/*.sh; do for f in common/cross-profiles/*.sh; do
@ -10,7 +12,7 @@ print_cross_targets() {
usage() { usage() {
cat << _EOF cat << _EOF
$(basename $0): [options] <target> [arguments] $PROGNAME: [options] <target> [arguments]
Targets: (only one may be specified) Targets: (only one may be specified)
@ -380,14 +382,10 @@ exit_func() {
exit 2 exit 2
} }
basename_cwd() {
echo $(basename $(pwd))
}
read_pkg() { read_pkg() {
if [ -z "${XBPS_TARGET_PKG}" ]; then if [ -z "${XBPS_TARGET_PKG}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n" [ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
XBPS_TARGET_PKG=$(basename_cwd) XBPS_TARGET_PKG=${PWD##*/}
fi fi
setup_pkg "$XBPS_TARGET_PKG" "$XBPS_CROSS_BUILD" "$1" setup_pkg "$XBPS_TARGET_PKG" "$XBPS_CROSS_BUILD" "$1"
} }