Blame SOURCES/redhat-annobin-plugin-select.sh

8ca6f7
#!/usr/bin/sh
8ca6f7
# This is a script to select which GCC spec file fragment
8ca6f7
# should be the destination of the redhat-annobin-cc1 symlink.
8ca6f7
8ca6f7
# Author: Nick Clifton  <nickc@redhat.com>
8ca6f7
# Copyright (c) 2021 Red Hat.
8ca6f7
#
8ca6f7
# This is free software; you can redistribute it and/or modify it
8ca6f7
# under the terms of the GNU General Public License as published
8ca6f7
# by the Free Software Foundation; either version 2, or (at your
8ca6f7
# option) any later version.
8ca6f7
8ca6f7
# It is distributed in the hope that it will be useful, but
8ca6f7
# WITHOUT ANY WARRANTY; without even the implied warranty of
8ca6f7
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8ca6f7
# GNU General Public License for more details.
8ca6f7
#
8ca6f7
# Usage:
8ca6f7
#   redhat-annobin-plugin-select [script-dir]
8ca6f7
#
8ca6f7
# If script-dir is not provided then /usr/lib/rpm/redhat is used
8ca6f7
# as the location where all of the annobin plugin selection files
8ca6f7
# can be found.
8ca6f7
8ca6f7
if test "x$1" = "x" ;
8ca6f7
then
8ca6f7
    rrcdir=/usr/lib/rpm/redhat
8ca6f7
else
8ca6f7
    rrcdir=$1
8ca6f7
fi
8ca6f7
8ca6f7
# Set this variable to non-zero to enable the generation of debugging
8ca6f7
# messages.
8ca6f7
debug=0
8ca6f7
8ca6f7
# Decide which version of the annobin plugin for gcc should be used.
8ca6f7
# There are two possible versions, one created by the annobin package and one
8ca6f7
# created by the gcc package.  The logic selects the gcc version unless both
8ca6f7
# have been built by the same version of the compiler.  In that case the
8ca6f7
# annobin version is selected instead.
8ca6f7
#
8ca6f7
# The point of all this is that the annobin plugin is very sensitive to
8ca6f7
# mismatches with the version of gcc that built it.  If the plugin is built
8ca6f7
# by version A of gcc, but then run on version B of gcc, it is possible for
8ca6f7
# the plugin to misbehave, which then causes problems if gating tests examine
8ca6f7
# the plugin's output.  (This has happened more than once in RHEL...).
8ca6f7
#
8ca6f7
# So the plugin is built both by gcc and by the annobin package.  This means
8ca6f7
# that whenever gcc is updated a fresh plugin is built, and the logic below
8ca6f7
# will select that version.  But in order to allow annobin development to
8ca6f7
# proceed independtently of gcc, the annobin package can also update its
8ca6f7
# version of the plugin, and the logic will select this new version.
8ca6f7
8ca6f7
# This is where the annobin package stores the information on the version
8ca6f7
# of gcc that built the annobin plugin.
8ca6f7
aver=`gcc --print-file-name=plugin`/annobin-plugin-version-info
8ca6f7
8ca6f7
# This is where the gcc package stores its version information.
8ca6f7
gver=`gcc --print-file-name=rpmver`
8ca6f7
8ca6f7
aplugin=`gcc --print-file-name=plugin`/annobin.so.0.0.0
8ca6f7
gplugin=`gcc --print-file-name=plugin`/gcc-annobin.so.0.0.0
8ca6f7
8ca6f7
# This is the file that needs to be updated when either of those version
8ca6f7
# files changes.
8ca6f7
rac1=redhat-annobin-cc1
8ca6f7
8ca6f7
# This is the GCC spec file fragment that selects the gcc-built version of
8ca6f7
# the annobin plugin
8ca6f7
select_gcc=redhat-annobin-select-gcc-built-plugin
8ca6f7
8ca6f7
# This is the GCC spec file fragment that selects the annobin-built version
8ca6f7
# of the annobin plugin
8ca6f7
select_annobin=redhat-annobin-select-annobin-built-plugin
8ca6f7
8ca6f7
install_annobin_version=0
8ca6f7
install_gcc_version=0
8ca6f7
8ca6f7
if [ -f $aplugin ]
8ca6f7
then
8ca6f7
    if [ -f $gplugin ]
8ca6f7
    then
8ca6f7
	if [ $debug -eq 1 ]
8ca6f7
	then
8ca6f7
	    echo "  redhat-rpm-config: Both plugins exist, checking version information"
8ca6f7
	fi
8ca6f7
8ca6f7
	if [ -f $gver ]
8ca6f7
	then
8ca6f7
	    if [ -f $aver ]
8ca6f7
	    then
8ca6f7
		if [ $debug -eq 1 ]
8ca6f7
		then
8ca6f7
		    echo "  redhat-rpm-config: Both plugin version files exist - comparing..."
8ca6f7
		fi
8ca6f7
8ca6f7
		# Get the first line from the version info files.  This is just in
8ca6f7
		# vase there are extra lines in the files.
8ca6f7
		avers=`head --lines=1 $aver`
8ca6f7
		gvers=`head --lines=1 $gver`
8ca6f7
8ca6f7
		if [ $debug -eq 1 ]
8ca6f7
		then
8ca6f7
		    echo "  redhat-rpm-config: Annobin plugin built by gcc $avers"
8ca6f7
		    echo "  redhat-rpm-config: GCC     plugin built by gcc $gvers"
8ca6f7
		fi
8ca6f7
8ca6f7
		# If both plugins were built by the same version of gcc then select
8ca6f7
		# the one from the annobin package (in case it is built from newer
8ca6f7
		# sources).  If the plugin builder versions differ, select the gcc
8ca6f7
		# built version instead.  This assumes that the gcc built version
8ca6f7
		# always matches the installed gcc, which should be true.
8ca6f7
		if [ $avers = $gvers ]
8ca6f7
		then
8ca6f7
		    if [ $debug -eq 1 ]
8ca6f7
		    then
8ca6f7
			echo "  redhat-rpm-config: Both plugins built by the same compiler - using annobin-built plugin"
8ca6f7
		    fi
8ca6f7
		    install_annobin_version=1
8ca6f7
		else
8ca6f7
		    if [ $debug -eq 1 ]
8ca6f7
		    then
8ca6f7
			echo "  redhat-rpm-config: Versions differ - using gcc-built plugin"
8ca6f7
		    fi
8ca6f7
		    install_gcc_version=1
8ca6f7
		fi
8ca6f7
	    else
8ca6f7
		if [ $debug -eq 1 ]
8ca6f7
		then
8ca6f7
		    echo "  redhat-rpm-config: Annobin version file does not exist, using gcc-built plugin"
8ca6f7
		fi
8ca6f7
		install_gcc_version=1
8ca6f7
	    fi
8ca6f7
	else
8ca6f7
	    if [ -f $aver ]
8ca6f7
	    then
8ca6f7
		# FIXME: This is suspicious.  If the installed GCC does not supports plugins
8ca6f7
		# then enabling the annobin plugin will not work.
8ca6f7
		if [ $debug -eq 1 ]
8ca6f7
		then
8ca6f7
		    echo "  redhat-rpm-config: GCC plugin version file does not exist, using annobin-built plugin"
8ca6f7
		fi
8ca6f7
		install_annobin_version=1
8ca6f7
	    else
8ca6f7
		if [ $debug -eq 1 ]
8ca6f7
		then
8ca6f7
		    echo "  redhat-rpm-config: Neither version file exists - playing safe and using gcc-built plugin"
8ca6f7
		    echo "  redhat-rpm-config: Note: expected to find $aver and/or $gver"
8ca6f7
		fi
8ca6f7
		install_gcc_version=1
8ca6f7
	    fi
8ca6f7
	fi
8ca6f7
    else
8ca6f7
	if [ $debug -eq 1 ]
8ca6f7
	then
8ca6f7
	    echo "  redhat-rpm-config: Only the annobin plugin exists - using that"
8ca6f7
	fi
8ca6f7
	install_annobin_version=1
8ca6f7
    fi
8ca6f7
else
8ca6f7
    if [ -f $gplugin ]
8ca6f7
    then
8ca6f7
	if [ $debug -eq 1 ]
8ca6f7
	then
8ca6f7
	    echo "  redhat-rpm-config: Only the gcc plugin exists - using that"
8ca6f7
	fi
8ca6f7
    else
8ca6f7
	if [ $debug -eq 1 ]
8ca6f7
	then
8ca6f7
	    echo "  redhat-rpm-config: Neither plugin exists - playing safe and using gcc-built plugin"
8ca6f7
	    echo "  redhat-rpm-config: Note: expected to find $aplugin and/or $gplugin"
8ca6f7
	fi
8ca6f7
    fi
8ca6f7
    install_gcc_version=1
8ca6f7
fi
8ca6f7
8ca6f7
if [ $install_annobin_version -eq 1 ]
8ca6f7
then
8ca6f7
    if [ $debug -eq 1 ]
8ca6f7
    then
8ca6f7
	echo "  redhat-rpm-config: Installing annobin version of $rac1"
8ca6f7
    fi
8ca6f7
    pushd $rrcdir > /dev/null
8ca6f7
    rm -f $rac1
8ca6f7
    ln -s $select_annobin "$rac1"
8ca6f7
    popd > /dev/null
8ca6f7
    
8ca6f7
else if [ $install_gcc_version -eq 1 ]
8ca6f7
     then
8ca6f7
	if [ $debug -eq 1 ]
8ca6f7
	then
8ca6f7
	    echo "  redhat-rpm-config: Installing gcc version of $rac1"
8ca6f7
	fi
8ca6f7
	pushd $rrcdir > /dev/null
8ca6f7
	rm -f $rac1
8ca6f7
	ln -s $select_gcc $rac1
8ca6f7
	popd > /dev/null
8ca6f7
     fi
8ca6f7
fi