blob: bb6542aef2dad7dcdc80a201882e1a7b71ac0713 [file] [log] [blame]
# Copyright 2018 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# The host (chroot) specific "setup_board" process. This separates the chroot
# specific setup from the generic board setup.
# shellcheck
. "$(dirname "$0")/" || exit 1
# Script must run inside the chroot
restart_in_chroot_if_needed "$@"
# Developer-visible flags.
DEFINE_string board "amd64-host" \
"The name of the board to set up."
DEFINE_boolean force "${FLAGS_FALSE}" \
"Force re-creating board root."
FLAGS_HELP="usage: $(basename "$0") [flags]
build_sdk_board builds the chroot for the amd64-host (chroot) board.
This should not need to be called except by the SDK Builder.
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
if [[ ${FLAGS_force} -eq ${FLAGS_TRUE} ]]; then
info_run "${SCRIPTS_DIR}/create_sdk_board_root" \
# Locations we will need
eval "$(portageq envvar -v CHOST PKGDIR)"
<("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host)
# Sanity check we got some valid results.
if [[ ${#TOOLCHAIN_PACKAGES[@]} -eq 0 ]]; then
die_notrace "cros_setup_toolchains failed"
PACKAGES=( system virtual/target-sdk )
run_emerge() {
info_run sudo -E "${EMERGE_CMD}" "$@"
# First, rebuild all packages from scratch. This is needed to make sure
# we rebuild all chroot packages.
# We build the toolchain by hand to avoid race conditions where the toolchain
# is used by other packages that we're building. See
run_emerge "${TOOLCHAIN_PACKAGES[@]}"
# Then build everything else.
run_emerge --verbose --emptytree --with-bdeps=y \
--exclude "${TOOLCHAIN_PACKAGES[*]}" \
"${PACKAGES[@]}" virtual/target-sdk-nobdeps
info_run sudo eclean -d packages
# Next, install our rebuilt packages into our separate root.
"--root=${BOARD_ROOT}" --update --verbose --deep --root-deps
--newuse --usepkgonly
run_emerge "${HOST_FLAGS[@]}" --with-bdeps=y "${PACKAGES[@]}"
# Install our rebuilt packages from the nobdeps target into our separate root
# without their build-time deps. We also avoid adding this target to the
# world set so that subsequent update_chroot commands won't re-import the
# build deps.
run_emerge "${HOST_FLAGS[@]}" --with-bdeps=n --oneshot \
# shellcheck disable=SC2154 # PKGDIR is defined via eval above
info_run sudo cp -a "${PKGDIR}" "${BOARD_ROOT}/packages"
# Copy our chroot version into the newly packaged chroot.
info_run sudo cp -a \
# Now cleanup paths referencing the ROOT from the *.la files.
info_run sudo find "${BOARD_ROOT}" -type f -name '*.la' -exec \
sed -i -e "s|${BOARD_ROOT}/|/|g" {} +
# Remove wrapper scripts and any home directory contents left behind in the
# sysroot. These are not supposed to be part of the final filesystem.
info_run sudo rm -rf \
"${BOARD_ROOT}/build" \
"${BOARD_ROOT}"/run/* \
"${BOARD_ROOT}"/home/* \
"${BOARD_ROOT}"/etc/{,portage/}make.{conf,profile} \
"${BOARD_ROOT}/etc/make.conf.user" \
# Setup host make.conf. This includes any overlay that we may be using and a
# pointer to pre-built packages.
info_run sudo mkdir -p "${BOARD_ROOT}/etc/portage"
info_run sudo ln -sf \
"${cros_overlay}/chromeos/config/make.conf.amd64-host" \
info_run sudo ln -sf \
"${cros_overlay}/profiles/default/linux/amd64/10.0/sdk" \
# Create make.conf.user.
cat <<\EOF | info_run sudo tee "${BOARD_ROOT}/etc/make.conf.user" >/dev/null
# This file is useful for doing global (chroot and all board) changes.
# Tweak emerge settings, ebuild env, etc...
# Make sure to append variables unless you really want to clobber all
# existing settings. e.g. You most likely want:
# USE="${USE} foo"
# and *not*:
# USE="foo"
# This also is a good place to setup ACCEPT_LICENSE.
info_run sudo chmod 0644 "${BOARD_ROOT}/etc/make.conf.user"
# Enable locale that some Chrome scripts assume exist.
info_run sudo sed -i -e '/^#en_US.UTF-8/s:#::' "${BOARD_ROOT}/etc/locale.gen"
info_run sudo mount --bind /dev "${BOARD_ROOT}/dev"
info_run sudo chroot "${BOARD_ROOT}" locale-gen -u
info_run sudo umount "${BOARD_ROOT}/dev"
# b/278101251: /build/amd64-host doesn't include ccache's link tree by default,
# which makes `FEATURES=ccache` quietly fail for host packages. Ensure it's
# built here.
info_run sudo ROOT="${BOARD_ROOT}" \
"${BOARD_ROOT}/usr/bin/ccache-config" --install-links
# Add chromite into python path.
for python_path in "${BOARD_ROOT}/usr/lib/"python*.*/site-packages; do
info_run sudo mkdir -p "${python_path}"
info_run sudo ln -sfT "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"/chromite
# Newer portage complains about bare overlays. Create the file that crossdev
# will also create later on.
info_run sudo mkdir -p -m 755 "${CROSSDEV_METADATA}"
cat <<EOF | sudo tee "${CROSSDEV_METADATA}/layout.conf" >/dev/null
# Autogenerated and managed by crossdev
# Delete the above line if you want to manage this file yourself
masters = portage-stable eclass-overlay chromiumos
repo-name = crossdev
use-manifests = true
thin-manifests = true
# Setup stable paths.
info_run sudo mkdir -p -m 755 \
"${BOARD_ROOT}/var/cache" \
"${BOARD_ROOT}/etc/profile.d" \
"${BOARD_ROOT}/run" \
"${BOARD_ROOT}/mnt/host" \
"${BOARD_ROOT}/mnt/host/out" \
info_run sudo ln -sfT \
/mnt/host/source/src/chromium/depot_tools \
info_run sudo ln -sfT \
chromeos-cache/distfiles "${BOARD_ROOT}/var/cache/distfiles"
# Setup cache dirs.
info_run sudo chmod 775 "${PORTAGE_CACHE_DIRS[@]}"
echo "Done!"
echo "The SYSROOT is: ${BOARD_ROOT}"