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

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