#6 Manage /usr/bin/cc with update-alternatives
Opened a month ago by tstellar. Modified 15 days ago
rpms/ tstellar/gcc cc-alternatives  into  master

file modified
+33 -3

@@ -4,7 +4,7 @@ 

  %global gcc_major 10

  # Note, gcc_release must be integer, if you want to add suffixes to

  # %%{release}, append them after %%{gcc_release} on Release: line.

- %global gcc_release 0.7

+ %global gcc_release 0.8

  %global nvptx_tools_gitrev 5f6f343a302d620b0868edab376c00b15741e39e

  %global newlib_cygwin_gitrev 50e2a63b04bdd018484605fbb954fd1bd5147fa0

  %global _unpackaged_files_terminate_build 0

@@ -239,6 +239,8 @@ 

  %endif

  Requires: libgcc >= %{version}-%{release}

  Requires: libgomp = %{version}-%{release}

+ Requires(post): %{_sbindir}/alternatives

+ Requires(preun): %{_sbindir}/alternatives

  %if !%{build_ada}

  Obsoletes: gcc-gnat < %{version}-%{release}

  %endif

@@ -334,6 +336,8 @@ 

  Provides: gcc-g++ = %{version}-%{release}

  Provides: g++ = %{version}-%{release}

  Autoreq: true

+ Requires(post): %{_sbindir}/alternatives

+ Requires(preun): %{_sbindir}/alternatives

  

  %description c++

  This package adds C++ support to the GNU Compiler Collection.

@@ -1903,6 +1907,12 @@ 

  # Help plugins find out nvra.

  echo gcc-%{version}-%{release}.%{_arch} > $FULLPATH/rpmver

  

+ for f in cc c++; do

+   rm %{buildroot}%{_bindir}/$f

+   touch %{buildroot}%{_bindir}/$f

+ done

+ 

+ 

  %check

  cd obj-%{gcc_target_platform}

  

@@ -1924,6 +1934,12 @@ 

    | uuencode testlogs-%{_target_platform}.tar.xz || :

  rm -rf testlogs-%{_target_platform}-%{version}-%{release}

  

+ %post

+ %{_sbindir}/update-alternatives --install %{_bindir}/cc cc %{_bindir}/gcc 1

+ 

+ %post c++

+ %{_sbindir}/update-alternatives --install %{_bindir}/c++ c++ %{_bindir}/g++ 1

+ 

  %post go

  %{_sbindir}/update-alternatives --install \

    %{_prefix}/bin/go go %{_prefix}/bin/go.gcc 92 \

@@ -1947,6 +1963,16 @@ 

    end

  end

  

+ %postun

+ if [ $1 -eq 0 ] ; then

+   %{_sbindir}/update-alternatives --remove cc %{_bindir}/gcc

+ fi

+ 

+ %postun c++

+ if [ $1 -eq 0 ] ; then

+   %{_sbindir}/update-alternatives --remove c++ %{_bindir}/g++

+ fi

+ 

  %postun -n libgcc -p <lua>

  if posix.access ("/sbin/ldconfig", "x") then

    local pid = posix.fork ()

@@ -1990,7 +2016,7 @@ 

  %ldconfig_scriptlets -n libgo

  

  %files -f %{name}.lang

- %{_prefix}/bin/cc

+ %ghost %{_prefix}/bin/cc

  %{_prefix}/bin/c89

  %{_prefix}/bin/c99

  %{_prefix}/bin/gcc

@@ -2328,7 +2354,7 @@ 

  %files c++

  %{_prefix}/bin/%{gcc_target_platform}-*++

  %{_prefix}/bin/g++

- %{_prefix}/bin/c++

+ %ghost %{_prefix}/bin/c++

  %{_mandir}/man1/g++.1*

  %dir %{_prefix}/lib/gcc

  %dir %{_prefix}/lib/gcc/%{gcc_target_platform}

@@ -3000,6 +3026,10 @@ 

  %endif

  

  %changelog

+ * Mon Feb 03 2020 Tom Stellard <tstellar@redhat.com> 10.0.1-0.8

+ - Manage /usr/bin/cc with update-alternatives

+ - https://fedoraproject.org/wiki/Changes/Use-Update-Alternatives-For-usr-bin-cc

+ 

  * Thu Jan 30 2020 Jakub Jelinek <jakub@redhat.com> 10.0.1-0.7

  - update from trunk

    - PRs analyzer/93276, analyzer/93291, analyzer/93349, analyzer/93450,

@@ -0,0 +1,5 @@ 

+ #include <stdio.h>

+ 

+ int main() {

+   printf("Hello world\n");

+ }

@@ -0,0 +1,5 @@ 

+ #include <iostream>

+ 

+ int main() {

+   std::cout << "Hello world\n";

+ }

@@ -0,0 +1,36 @@ 

+ #!/bin/bash

+ 

+ # This test assumes gcc and gcc-c++ are already installed.

+ 

+ set -exo pipefail

+ 

+ # Verify that /usr/bin/cc points to gcc.

+ ls -l /etc/alternatives/cc | grep gcc

+ 

+ # Verify that /usr/bin/c++ points to g++

+ ls -l /etc/alternatives/c++ | grep g++

+ 

+ # Run cc and verify it invokes gcc

+ /usr/bin/cc --version | grep 'cc (GCC)'

+ 

+ # Run c++ and verify it invokes g++

+ /usr/bin/c++ --version | grep 'c++ (GCC)'

+ 

+ # Compile a C program

+ /usr/bin/cc -o hello-c hello.c

+ ./hello-c | grep 'Hello world'

+ 

+ # Compile a C++ program

+ /usr/bin/c++ -o hello-cpp hello.cpp

+ ./hello-cpp | grep 'Hello world'

+ 

+ # Uninstall gcc and verify that cc and c++ are gone.

+ dnf remove -y gcc gcc-c++

+ 

+ test ! -h /etc/alternatives/cc

+ 

+ test ! -h /etc/alternatives/c++

+ 

+ test ! -e /usr/bin/cc

+ 

+ test ! -e /usr/bin/c++

@@ -0,0 +1,14 @@ 

+ # The cc-alternative test uninstalls gcc, so it needs to be run by

+ # itself in a separate .yml file so it doesn't modify the test

+ # environment for other tests.

+ 

+ - hosts: localhost

+   roles:

+   - role: standard-test-basic

+     tags:

+       - classic

+     required_packages:

+       - gcc

+       - gcc-c++

+     tests:

+       - cc-alternative