Revert "Make use of cros_setup_toolchains, take 2"

This reverts commit baa696e37bf1c48e5db0616460f7fbb0cff01e61

Change-Id: I6dcbc8afdcb715dc9ffe7b551a882279320f9f04
Reviewed-on: https://gerrit.chromium.org/gerrit/21813
Commit-Ready: Zdenek Behan <zbehan@chromium.org>
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Tested-by: Zdenek Behan <zbehan@chromium.org>
This commit is contained in:
Zdenek Behan 2012-05-03 15:05:33 -07:00
parent 95fadc6e33
commit 26fe5709a4
3 changed files with 207 additions and 46 deletions

View File

@ -396,15 +396,19 @@ sudo sh -c "echo STAGE3=$STAGE3 > $CHROOT_STATE"
info "Updating portage" info "Updating portage"
early_enter_chroot emerge -uNv --quiet portage early_enter_chroot emerge -uNv --quiet portage
info "Updating host toolchain" info "Updating toolchain"
early_enter_chroot emerge -uNv --quiet crossdev early_enter_chroot emerge -uNv --quiet $USEPKG '>=sys-devel/gcc-4.4' \
TOOLCHAIN_ARGS=( --deleteold ) sys-libs/glibc sys-devel/binutils sys-kernel/linux-headers
if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then
TOOLCHAIN_ARGS+=( --nousepkg ) # HACK: Select the latest toolchain. We're assuming that when this is
fi # ran, the chroot has no experimental versions of new toolchains, just
# Note: early_enter_chroot executes as root. # one that is very old, and one that was just emerged.
early_enter_chroot "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \ GCC_ATOM="$(early_enter_chroot portageq best_version / sys-devel/gcc)"
--hostonly "${TOOLCHAIN_ARGS[@]}" early_enter_chroot emerge --unmerge "<${GCC_ATOM}"
CHOST="$(early_enter_chroot portageq envvar CHOST)"
LATEST="$(early_enter_chroot gcc-config -l | grep "${CHOST}" | tail -n1 | \
cut -f3 -d' ')"
early_enter_chroot gcc-config "${LATEST}"
# dhcpcd is included in 'world' by the stage3 that we pull in for some reason. # dhcpcd is included in 'world' by the stage3 that we pull in for some reason.
# We have no need to install it in our host environment, so pull it out here. # We have no need to install it in our host environment, so pull it out here.
@ -423,10 +427,8 @@ if [ -n "${INITIALIZE_CHROOT}" ]; then
fi fi
# Update chroot. # Update chroot.
# Skip toolchain update because it already happened above, and the chroot is UPDATE_ARGS=()
# not ready to emerge all cross toolchains. if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
UPDATE_ARGS=( --skip_toolchain_update )
if [[ ${FLAGS_usepkg} -eq ${FLAGS_TRUE} ]]; then
UPDATE_ARGS+=( --usepkg ) UPDATE_ARGS+=( --usepkg )
else else
UPDATE_ARGS+=( --nousepkg ) UPDATE_ARGS+=( --nousepkg )
@ -446,11 +448,6 @@ if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot" CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
fi fi
# As a final pass, build all desired cross-toolchains.
info "Updating toolchains"
enter_chroot sudo "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \
"${TOOLCHAIN_ARGS[@]}"
print_time_elapsed print_time_elapsed
cat <<EOF cat <<EOF

View File

@ -131,6 +131,139 @@ board_needs_libc_update() {
return 0 return 0
} }
# Check whether any new toolchain packages are available.
# Returns true if new toolchain packages are available and false otherwise.
toolchain_needs_update() {
# Skip toolchain updates if requested.
if [ $FLAGS_skip_toolchain_update -eq $FLAGS_TRUE ]; then
return 1
fi
local toolchain=$1 crossdev_cfg category arch
# Query crossdev for how it will be laying things out.
crossdev_cfg=$(crossdev --show-target-cfg "${toolchain}" --ex-gdb)
category=$(eval "${crossdev_cfg}"; echo "${category}")
arch=$(eval "${crossdev_cfg}"; echo "${arch}")
# If toolchain symlinks weren't created yet, we definitely need to update.
if [ ! -d ${CROSSDEV_OVERLAY}/${category} ]; then
# NOTE: In this branch, the versions have not been resolved, and will
# be passed directly to crossdev. That works because crossdev understands
# '[stable]'.
# We cannot resolve the versions because the cross toolchain category is
# not yet set up.
return 0
fi
# Unmask any ebuilds previously [un]masked by crossdev. crossdev will
# re-setup its masks appropriately the next time we run it.
local d
for d in package.{mask,keywords} ; do
d="/etc/portage/${d}"
if [[ -e ${d}/${category} ]] ; then
sudo mv -f ${d}/{,.bak.}${category}
fi
done
# Now get the atoms out of crossdev for the emerge below.
local pfx
if [[ ${FLAGS_latest_toolchain} -eq ${FLAGS_TRUE} ]] ; then
pfx=""
elif [[ ${FLAGS_usepkg} -eq ${FLAGS_TRUE} ]] ; then
pfx="<="
else
pfx="="
fi
local crosspkgs=$(eval "${crossdev_cfg}"; echo "${crosspkgs}")
local pkgs=()
for pkg in ${crosspkgs} ; do
local pn=$(eval "${crossdev_cfg}" \; echo \${${pkg}_pn})
local atom="${category}/${pn}"
if [[ -z ${pn} ]] ; then
# Not all toolchains provide all packages
# e.g. arm-elf does not have "kernel" headers.
continue
fi
if [[ ${FLAGS_latest_toolchain} -ne ${FLAGS_TRUE} ]] ; then
local flagname="FLAGS_${pkg}_version"
# Some packages (like gdb) don't have pinned versions.
if [[ -n ${!flagname} ]] ; then
if [[ ${!flagname} == "[stable]" ]] ; then
# This will return the full cat/pn-ver for us.
atom="${pfx}"$(ACCEPT_KEYWORDS="${arch}" \
portageq best_visible / ebuild "${atom}")
else
atom="${pfx}${atom}-${!flagname}"
fi
fi
fi
pkgs+=( "${atom}" )
done
local flags=( --pretend --quiet --update --nodeps )
if [[ ${FLAGS_usepkg} -eq ${FLAGS_TRUE} ]] ; then
flags+=( --getbinpkg --usepkgonly )
fi
ACCEPT_KEYWORDS="~* *" emerge "${flags[@]}" "${pkgs[@]}" | grep ${category}/
local ret=$?
# Restore the masks in case we don't end up running crossdev.
for d in package.{mask,keywords} ; do
d="/etc/portage/${d}"
if [[ -e ${d}/.bak.${category} ]] ; then
sudo mv -f ${d}/{.bak.,}${category}
fi
done
return ${ret}
}
uninstall_toolchain() {
local toolchain=$1
info "Uninstalling the toolchain."
# Even if the uninstall fails, keep going. It's likely
# that it didn't exist in the first place.
sudo crossdev -v --force -C "${toolchain}" || true
}
# Build the toolchain with crossdev.
build_toolchain() {
local toolchain=$1
info "Building the toolchain."
local CROSS_ARGS=( --show-fail-log --target "${toolchain}" -P --oneshot )
if [ $FLAGS_usepkg -eq $FLAGS_TRUE ]; then
# Grab the latest packages from the prebuilt server.
# --getbinpkg: Use packages from the prebuilt server.
# --usepkgonly: Always use prebuilts. Don't build from source.
# --without-headers: Don't build headers-only versions of packages for
# bootstrapping. Because we use binary packages, this
# isn't necessary.
CROSS_ARGS+=( -P --getbinpkg -P --usepkgonly --without-headers )
fi
if [ $FLAGS_latest_toolchain -ne $FLAGS_TRUE ]; then
CROSS_ARGS+=(
--binutils "${FLAGS_binutils_version}"
--gcc "${FLAGS_gcc_version}"
--kernel "${FLAGS_kernel_version}"
--libc "${FLAGS_libc_version}"
)
fi
CROSS_ARGS+=(
--overlays "${CHROMIUMOS_OVERLAY} /usr/local/portage/stable"
--ov-output "${CROSSDEV_OVERLAY}"
--ex-gdb
)
sudo -E FEATURES="splitdebug ${FEATURES}" crossdev "${CROSS_ARGS[@]}"
}
# Get the version number of a toolchain package. # Get the version number of a toolchain package.
cross_get_version() { cross_get_version() {
local pkg="$1" local pkg="$1"
@ -410,33 +543,62 @@ BOARD_OVERLAY_LIST=$(cros_overlay_list \
eval $(portageq envvar -v CHOST PKGDIR) eval $(portageq envvar -v CHOST PKGDIR)
if [ -d "${BOARD_ROOT}" ] ; then # Update all the toolchains that this board wants.
if [[ ${FLAGS_force} -eq ${FLAGS_TRUE} ]]; then for toolchain in ${all_toolchains[@]} ; do
echo "--force set. Re-creating ${BOARD_ROOT}..." [[ "${CHOST}" == "${toolchain}" ]] && continue
# Removal takes long. Make it asynchronous. info "Checking for updates to ${toolchain} ..."
TEMP_DIR=`mktemp -d`
sudo mv "${BOARD_ROOT}" "${TEMP_DIR}" toolchain_updated=${FLAGS_FALSE}
sudo rm -rf "${TEMP_DIR}" & if toolchain_needs_update ${toolchain} ; then
else toolchain_updated=${FLAGS_TRUE}
if ! ${HOST_BOARD}; then
{ print_board_make_conf; print_board_binhost_config; } | \ warn "Toolchain needs to be updated! Updating ${toolchain} ..."
sudo_clobber $BOARD_ETC/make.conf.board uninstall_toolchain ${toolchain}
build_toolchain ${toolchain}
if [[ "${toolchain}" != arm* ]] ; then
info "Switching on gold as the default linker."
BINUTILS_VERSION=$(cross_get_version binutils ${toolchain} | \
sed 's/-r[0-9]\+//g')
sudo binutils-config "${toolchain}-${BINUTILS_VERSION}-gold"
fi fi
if [[ ${FLAGS_quiet} -eq ${FLAGS_FALSE} ]]; then fi
warn "Board output directory '$BOARD_ROOT' already exists."
warn "Not setting up board root. " if [[ "${toolchain}" == "${FLAGS_toolchain}" ]] &&
warn "Use --force to clobber the board root and start again." [ -d "$BOARD_ROOT" ] && [ "$FLAGS_force" == "$FLAGS_FALSE" ] ; then
fi if [[ "${toolchain_updated}" == "${FLAGS_TRUE}" ]] ; then
if board_needs_libc_update; then # If the board root already exists, re-install the toolchain there.
install_toolchain_in_board
elif board_needs_libc_update; then
# Update the users libc in their board if needed. # Update the users libc in their board if needed.
echo "Updating libc in the board." echo "Updating libc in the board."
install_toolchain_in_board install_toolchain_in_board
fi fi
fi
done
if [ -d "$BOARD_ROOT" ] ; then
if [[ $FLAGS_force -eq $FLAGS_TRUE ]]; then
echo "--force set. Re-creating $BOARD_ROOT..."
# Removal takes long. Make it asynchronous.
TEMP_DIR=`mktemp -d`
sudo mv $BOARD_ROOT $TEMP_DIR
sudo rm -rf $TEMP_DIR &
else
if ! $HOST_BOARD; then
{ print_board_make_conf; print_board_binhost_config; } | \
sudo_clobber $BOARD_ETC/make.conf.board
fi
if [[ $FLAGS_quiet -eq $FLAGS_FALSE ]]; then
warn "Board output directory '$BOARD_ROOT' already exists."
warn "Not setting up board root. "
warn "Use --force to clobber the board root and start again."
fi
exit 0 exit 0
fi fi
fi fi
sudo mkdir -p "${BOARD_ROOT}" "${BOARD_ETC}" "${BOARD_PROFILE}" sudo mkdir -p "$BOARD_ROOT" "${BOARD_ETC}" "${BOARD_PROFILE}"
if [ "${CHOST}" != "$FLAGS_toolchain" ] ; then if [ "${CHOST}" != "$FLAGS_toolchain" ] ; then
# TODO(cmasone): Do this more cleanly, if we figure out what "cleanly" means. # TODO(cmasone): Do this more cleanly, if we figure out what "cleanly" means.

View File

@ -29,8 +29,6 @@ show_help_if_requested "$@"
DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
DEFINE_integer jobs -1 \ DEFINE_integer jobs -1 \
"How many packages to build in parallel at maximum." "How many packages to build in parallel at maximum."
DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
"Don't update the toolchains."
# Parse command line flags # Parse command line flags
FLAGS "$@" || exit 1 FLAGS "$@" || exit 1
@ -82,14 +80,18 @@ fi
# In first pass, update portage and toolchains. Lagged updates of both # In first pass, update portage and toolchains. Lagged updates of both
# can cause serious issues later. # can cause serious issues later.
if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then export CHOST="$(portageq envvar CHOST)"
TOOLCHAIN_FLAGS="" LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \
# This should really only be skipped while bootstrapping. sort -V | tail -n 1)
if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then CURRENT="$(gcc-config -c)" || true # This fails if current profile is invalid.
TOOLCHAIN_FLAGS="--nousepkg" sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
fi sys-devel/gcc sys-devel/binutils sys-libs/glibc sys-apps/portage
# Expand the path before sudo, as root doesn't have the same path magic. # If the latest toolchain wasn't already selected before we updated, do nothing,
sudo $(type -p cros_setup_toolchains) ${TOOLCHAIN_FLAGS} # otherwise autoselect the latest. Also fix if the current profile is invalid.
if [ "${LATEST}" != "${CURRENT}" ] || ! gcc-config -c &> /dev/null; then
LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \
sort -V | tail -n 1 )
sudo -E gcc-config "${LATEST}"
fi fi
# Second pass, update everything else. # Second pass, update everything else.