From 7bbb787e87fb224d89412599d2fdadf688ea3bee Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Feb 24 2020 17:00:43 +0000 Subject: Manage /usr/bin/cc with update-alternatives https://fedoraproject.org/wiki/Changes/Use-Update-Alternatives-For-usr-bin-cc --- diff --git a/gcc.spec b/gcc.spec index f39c7d1..473575d 100644 --- a/gcc.spec +++ b/gcc.spec @@ -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.8 +%global gcc_release 0.9 %global nvptx_tools_gitrev 5f6f343a302d620b0868edab376c00b15741e39e %global newlib_cygwin_gitrev 50e2a63b04bdd018484605fbb954fd1bd5147fa0 %global _unpackaged_files_terminate_build 0 @@ -244,6 +244,8 @@ Requires: glibc >= 2.16 %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 @@ -338,6 +340,8 @@ Requires: libstdc++-devel = %{version}-%{release} 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. @@ -1906,6 +1910,12 @@ rm -f %{buildroot}%{mandir}/man3/ffi* # 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} @@ -1927,6 +1937,12 @@ tar cf - testlogs-%{_target_platform}-%{version}-%{release} | xz -9e \ | uuencode testlogs-%{_target_platform}.tar.xz || : rm -rf testlogs-%{_target_platform}-%{version}-%{release} +%post +%{_sbindir}/update-alternatives --install %{_bindir}/cc cc %{_bindir}/gcc 50 + +%post c++ +%{_sbindir}/update-alternatives --install %{_bindir}/c++ c++ %{_bindir}/g++ 50 + %post go %{_sbindir}/update-alternatives --install \ %{_prefix}/bin/go go %{_prefix}/bin/go.gcc 92 \ @@ -1950,6 +1966,16 @@ if posix.access ("/sbin/ldconfig", "x") then 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 if posix.access ("/sbin/ldconfig", "x") then local pid = posix.fork () @@ -1993,7 +2019,7 @@ end %ldconfig_scriptlets -n libgo %files -f %{name}.lang -%{_prefix}/bin/cc +%ghost %{_prefix}/bin/cc %{_prefix}/bin/c89 %{_prefix}/bin/c99 %{_prefix}/bin/gcc @@ -2331,7 +2357,7 @@ end %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} @@ -3003,6 +3029,10 @@ end %endif %changelog +* Mon Feb 24 2020 Tom Stellard 10.0.1-0.9 +- Manage /usr/bin/cc with update-alternatives +- https://fedoraproject.org/wiki/Changes/Use-Update-Alternatives-For-usr-bin-cc + * Sun Feb 16 2020 Jakub Jelinek 10.0.1-0.8 - update from trunk - PRs analyzer/93212, analyzer/93288, analyzer/93350, analyzer/93356, diff --git a/tests/cc-alternative/hello.c b/tests/cc-alternative/hello.c new file mode 100644 index 0000000..237a2b2 --- /dev/null +++ b/tests/cc-alternative/hello.c @@ -0,0 +1,5 @@ +#include + +int main() { + printf("Hello world\n"); +} diff --git a/tests/cc-alternative/hello.cpp b/tests/cc-alternative/hello.cpp new file mode 100644 index 0000000..c3d3882 --- /dev/null +++ b/tests/cc-alternative/hello.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "Hello world\n"; +} diff --git a/tests/cc-alternative/runtest.sh b/tests/cc-alternative/runtest.sh new file mode 100644 index 0000000..efc5474 --- /dev/null +++ b/tests/cc-alternative/runtest.sh @@ -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++ diff --git a/tests/tests-cc-alternative.yml b/tests/tests-cc-alternative.yml new file mode 100644 index 0000000..b104e89 --- /dev/null +++ b/tests/tests-cc-alternative.yml @@ -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