From 00626700a88c018c6bddb00e805c10fddee64482 Mon Sep 17 00:00:00 2001 From: Zdenek Behan Date: Fri, 26 Aug 2011 01:00:28 +0200 Subject: [PATCH] version_hooks: add a version hook for host gcc upgrade Recently, a gcc-4.4.6 has been unmasked in the host, but no effort has been made to make sure the developers select it with gcc-config. BUG=chromium-os:19613 TEST=ran the tests below with set -x and observed 1) manually set the MINIMUM version to 4.4.7, see it fail 2) two gccs, current + old, set to old, observed the switch and unmerge 3) above, but set to new, same result 4) only one gcc, the current, observed nothing happening 5) only have old gcc, let the script update&select new one, unmerge old Change-Id: Id2a285a13f5b27d7531eae4db35e36f6b8cc5f4f Reviewed-on: http://gerrit.chromium.org/gerrit/6694 Reviewed-by: David James Tested-by: Zdenek Behan --- chroot_version_hooks.d/7_host_gcc_upgrade | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 chroot_version_hooks.d/7_host_gcc_upgrade diff --git a/chroot_version_hooks.d/7_host_gcc_upgrade b/chroot_version_hooks.d/7_host_gcc_upgrade new file mode 100644 index 0000000000..6e81ac9ac1 --- /dev/null +++ b/chroot_version_hooks.d/7_host_gcc_upgrade @@ -0,0 +1,48 @@ +#!/bin/bash + +# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This is a generic script for upgrading the host toolchain. It should: +# - be able to run repeatedly, in case someone has ancient chroot with +# several missed gcc upgrades +# - be easily tweakable for future upgrades of the same kind, if needed + +CHOST="$(portageq envvar CHOST)" + +# This is the lowest we want to go in this particular case. +MINIMUM_GCC="4.4.6" + +GCC_VERSIONS="$(gcc-config -l | grep "${CHOST}" | \ + cut -f3 -d' ')" +GCC_LATEST="$(gcc-config -l | grep "${CHOST}" | tail -n1 | \ + cut -f3 -d' ')" + +if ! [ "$(portageq match / ">=sys-devel/gcc-${MINIMUM_GCC}")" ]; +then + info "You don't have the latest gcc installed, trying to build it" + if ! sudo emerge -u --getbinpkg sys-devel/gcc; then + error "Emerging gcc failed. Please recreate your chroot." + exit 1 + fi + if ! [ "$(portageq match / ">=sys-devel/gcc-${MINIMUM_GCC}")" ]; + then + error "You still don't have the latest gcc. Something is very" + error "wrong with your tree. Recreating your chroot will likely fix it." + exit 1 + fi +fi + +info "Updating the host toolchain. crosbug.com/19613" +info "Currently installed host gcc versions: $(echo -n ${GCC_VERSIONS})" + +if ! sudo gcc-config "${GCC_LATEST}"; then + error "gcc-config failed. This is really bad. Recreate your chroot." + exit 1 +fi + +info "Cleaning up the old toolchain" +sudo emerge --unmerge "