Bug 31933 - fixup-binconfig: a mode for verifying complex /usr/bin/*-config scripts (not modifying)
Summary: fixup-binconfig: a mode for verifying complex /usr/bin/*-config scripts (not ...
Status: NEW
Alias: None
Product: Sisyphus
Classification: Development
Component: rpm-build (show other bugs)
Version: unstable
Hardware: all Linux
: P3 enhancement
Assignee: placeholder@altlinux.org
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-31 03:27 MSK by Ivan Zakharyaschev
Modified: 2016-03-31 03:27 MSK (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2016-03-31 03:27:53 MSK
rpm-4.0.4-alt100.90

Example: python3-3.5 installs a complex python3.5m-config shell script (unlike python3-3.3 which implemented it in Python).

Certainly, fixup-binconfig doesn't expect such a complex script and tries to do stupid things with it by extracting some lines with assignments (but the assigned values are computed from other stuff defined elsewhere in the script).

It's not critical, because ultimately fixup-binconfig has no effect in this case, but errors are reported during its work. And it's not quite clear for the maintainer of such a package what fixup-binconfig tries to prevent, and whether something should be done with his /usr/bin/*-config.

If fixup-binconfig had a verifying-only mode, which would actually run /usr/bin/*-config with certain options (instead of trying to process its source code) and report whether the output has some deficiencies. If the output is OK, it could silently return successfully, if it is not OK, it could try to fix it up or fail with an error.

How the errors look like when building python3-3.5 (I've added "set -x" to fixup-binconfig) -- they come from "sed" invoked in /usr/bin/python3.5m-config:

+++ mktemp -dt fixup-binconfig.XXXXXXXX
++ tmpdir=/usr/src/tmp/fixup-binconfig.sEUnGVSt
++ trap 'remove_tmpdir $?' EXIT
+ TMPFILE=/usr/src/tmp/fixup-binconfig.sEUnGVSt/tmp
+ f_saved=/usr/src/tmp/fixup-binconfig.sEUnGVSt/sav
+ f_new=/usr/src/tmp/fixup-binconfig.sEUnGVSt/new
+ :
+ rc=0
+ for f in '"$@"'
+ '[' '!' -f ./usr/bin/python3.5m-config ']'
+ fname=./usr/bin/python3.5m-config
+ fname=/usr/bin/python3.5m-config
+ '[' -n '' ']'
++ file -b ./usr/bin/python3.5m-config
+ t='Bourne shell script text executable'
+ '[' -z '' ']'
+ fix
+ local includedir=
+ local libdir=
+ local prefix=
+ local exec_prefix=
+ sed -ne 's/^\(\([a-z_A-Z]*\)\(prefix\|dir\|path\)\)=\(.*\)$/local \1=\4/pg' ./usr/bin/python3.5m-config
+ '[' '!' -s /usr/src/tmp/fixup-binconfig.sEUnGVSt/tmp ']'
+ . /usr/src/tmp/fixup-binconfig.sEUnGVSt/tmp
+++ echo ''
+++ sed s###
sed: -e expression #1, char 0: no previous regular expression
++ local prefix=
+++ echo ''
+++ sed s###
sed: -e expression #1, char 0: no previous regular expression
++ local exec_prefix=
+++ echo /usr/include
+++ sed s###
sed: -e expression #1, char 0: no previous regular expression
++ local includedir=
+++ echo /usr/lib64
+++ sed s###
sed: -e expression #1, char 0: no previous regular expression
++ local libdir=
++ printf %s ''
++ tr -s /
+ prefix=
++ printf %s ''
++ tr -s /
+ exec_prefix=
++ printf %s ''
++ tr -s /
+ includedir=
++ printf %s ''
++ tr -s /
+ libdir=
+ cat ./usr/bin/python3.5m-config
+ cmp -s /usr/src/tmp/fixup-binconfig.sEUnGVSt/new /usr/src/tmp/fixup-binconfig.sEUnGVSt/sav

The script's source code -- for example, $prefix is computed from other values (which get lost by fixup-binconfig):

#!/bin/sh

# Keep this script in sync with python-config.in

exit_with_usage ()
{
    echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir"
    exit $1
}

if [ "$1" = "" ] ; then
    exit_with_usage 1
fi

# Returns the actual prefix where this script was installed to.
installed_prefix ()
{
    RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
    if which readlink >/dev/null 2>&1 ; then
        if readlink -f "$RESULT" >/dev/null 2>&1; then
          RESULT=$(readlink -f "$RESULT")
        fi
    fi
    echo $RESULT
}

prefix_build="/usr"
prefix_real=$(installed_prefix "$0")

# Use sed to fix paths from their built-to locations to their installed-to
# locations.
prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
exec_prefix_build="/usr"
exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
includedir=$(echo "/usr/include" | sed "s#$prefix_build#$prefix_real#")
libdir=$(echo "/usr/lib64" | sed "s#$prefix_build#$prefix_real#")
CFLAGS=$(echo "-pipe -Wall -g -O3" | sed "s#$prefix_build#$prefix_real#")
VERSION="3.5"
LIBM="-lm"
LIBC=""
SYSLIBS="$LIBM $LIBC"
ABIFLAGS="m"
LIBS="-lpython${VERSION}${ABIFLAGS} -lpthread -ldl  -lutil $SYSLIBS"
BASECFLAGS=" -Wno-unused-result -Wsign-compare -Wunreachable-code"
LDLIBRARY="libpython${VERSION}${ABIFLAGS}.a"
LINKFORSHARED="-Xlinker -export-dynamic"
OPT="-DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes"
PY_ENABLE_SHARED="0"
LDVERSION="${VERSION}${ABIFLAGS}"
LIBDEST=${prefix}/lib/python${VERSION}
LIBPL=$(echo "${prefix}/lib/python3.5/config-${VERSION}${ABIFLAGS}" | sed "s#$prefix_build#$prefix_real#")
SO=".cpython-35m.so"
PYTHONFRAMEWORK=""
INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"

# Scan for --help or unknown argument.
for ARG in $*
do
    case $ARG in
        --help)
            exit_with_usage 0
        ;;
        --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
        ;;
        *)
            exit_with_usage 1
        ;;
    esac
done

for ARG in "$@"
do
    case "$ARG" in
        --prefix)
            echo "$prefix"
        ;;
        --exec-prefix)
            echo "$exec_prefix"
        ;;
        --includes)
            echo "$INCDIR $PLATINCDIR"
        ;;
        --cflags)
            echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
        ;;
        --libs)
            echo "$LIBS"
        ;;
        --ldflags)
            LINKFORSHAREDUSED=
            if [ -z "$PYTHONFRAMEWORK" ] ; then
                LINKFORSHAREDUSED=$LINKFORSHARED
            fi
            LIBPLUSED=
            if [ "$PY_ENABLE_SHARED" = "0" ] ; then
                LIBPLUSED="-L$LIBPL"
            fi
            echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
        ;;
        --extension-suffix)
            echo "$SO"
        ;;
        --abiflags)
            echo "$ABIFLAGS"
        ;;
        --configdir)
            echo "$LIBPL"
        ;;
esac
done