RE: [PATCH 1/1] perf beauty: Don't use 'find ... -printf' as it isn't available in busybox

From: David Laight
Date: Fri Dec 01 2023 - 12:16:35 EST


From: Arnaldo Carvalho de Melo
> Sent: 01 December 2023 17:02
>
> Em Fri, Dec 01, 2023 at 12:05:31PM +0000, David Laight escreveu:
> > ...
> > > # Create list of architectures that have a specific errno.h.
> > > archlist=""
> > > -for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | sort -r); do
> > > +for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d | while read arch ; do basename
> > > $arch ; done | sort -r); do
> > > test -f $toolsdir/arch/$arch/include/uapi/asm/errno.h && archlist="$archlist $arch"
> > > done
> >
> > Jeepers ...
> > Does this work?
> > for f in $toolsdir/arch/*/include/uapi/asm/errno.h; do
> > [ ! -f $f ] && break
> > d=${f%/include/uapi/asm/errno.h}
> > archlist="${d##*/} $archlist"
> > done
> > No fork()s or exec()s.
> > I think it only differs in having a trailing space instead of a leading one.
>
> ⬢[acme@toolbox perf-tools-next]$ for f in tools/arch/*/include/uapi/asm/errno.h; do
> d=${f%/include/uapi/asm/errno.h} ; arch="${d##*/}" ; echo "'$arch'" ; done
> 'alpha'
> 'mips'
> 'parisc'
> 'powerpc'
> 'sparc'
> 'x86'
> ⬢[acme@toolbox perf-tools-next]$ for arch in $(find tools/arch -maxdepth 1 -mindepth 1 -type d |
> while read arch ; do basename $arch ; done | sort -r) ; do test -f
> tools/arch/$arch/include/uapi/asm/errno.h && echo "'$arch'" ; done
> 'x86'
> 'sparc'
> 'powerpc'
> 'parisc'
> 'mips'
> 'alpha'
> ⬢[acme@toolbox perf-tools-next]$
>
> There was a reason for having x86 first, lemme dig it... Just to have
> as the first strcmp in:

I reversed the order by adding the names at the front of $archlist - so the order
would still be reverse sorted (the shell sorts filename globs).

The '[ -f $f ] || break' line is only there in case there are no matching files.
If that can happen putting [ "$archlist" = "* " ] && archlist=
after the loop would be slightly better.
But with only 6 item the extra stat() will be noise.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)