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

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