mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-05 20:26:44 +02:00
Switching to a selinux profile caused more USE flags to be enabled (selinux, audit, caps), thus more dependencies to be pulled. More dependencies caused two things: - cyclic dependencies appeared - sys-apps/baselayout is being pulled in Cyclic dependencies need to be handled in a similar way it was done in build_packages, thus factor out the code doing it into a separate and reusable part. The dependency on baselayout needs to be handled by installing the package as a first thing in $ROOT, followed by a more careful way of copying things from $SYSROOT to $ROOT (due to split-usr differences), followed by installing the rest of the packages. Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
120 lines
4.5 KiB
Bash
120 lines
4.5 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
source /tmp/chroot-functions.sh
|
|
source /tmp/toolchain_util.sh
|
|
source /tmp/break_dep_loop.sh
|
|
|
|
# A note on packages:
|
|
# The default PKGDIR is /usr/portage/packages
|
|
# To make sure things are uploaded to the correct places we split things up:
|
|
# crossdev build packages use ${PKGDIR}/crossdev (uploaded to SDK location)
|
|
# build deps in crossdev's sysroot use ${PKGDIR}/cross/${CHOST} (no upload)
|
|
# native toolchains use ${PKGDIR}/target/${BOARD} (uploaded to board location)
|
|
|
|
configure_target_root() {
|
|
local board="$1"
|
|
local cross_chost=$(get_board_chost "$1")
|
|
local profile=$(get_board_profile "${board}")
|
|
|
|
CBUILD="$(portageq envvar CBUILD)" \
|
|
CHOST="${cross_chost}" \
|
|
ROOT="/build/${board}" \
|
|
SYSROOT="/build/${board}" \
|
|
_configure_sysroot "${profile}"
|
|
}
|
|
|
|
build_target_toolchain() {
|
|
local board="$1"
|
|
local ROOT="/build/${board}"
|
|
local SYSROOT="/usr/$(get_board_chost "${board}")"
|
|
|
|
function btt_emerge() {
|
|
# --root is required because run_merge overrides ROOT=
|
|
PORTAGE_CONFIGROOT="$ROOT" run_merge --root="$ROOT" --sysroot="$ROOT" "${@}"
|
|
}
|
|
|
|
# install baselayout first so we have the basic directory
|
|
# structure for libraries and binaries copied from sysroot
|
|
btt_emerge --oneshot --nodeps sys-apps/baselayout
|
|
|
|
# copy libraries, binaries and header files from sysroot to root -
|
|
# sysroot may be using split-usr, whereas root does not, so take
|
|
# this into account
|
|
(
|
|
shopt -s nullglob
|
|
local d f
|
|
local -a files
|
|
for d in "${SYSROOT}"/{,usr/}{bin,sbin,lib*}; do
|
|
if [[ ! -d ${d} ]]; then
|
|
continue
|
|
fi
|
|
files=( "${d}"/* )
|
|
if [[ ${#files[@]} -gt 0 ]]; then
|
|
f=${d##*/}
|
|
cp -at "${ROOT}/usr/${f}" "${files[@]}"
|
|
fi
|
|
done
|
|
cp -at "${ROOT}"/usr "${SYSROOT}"/usr/include
|
|
)
|
|
|
|
local -a args_for_bdl=()
|
|
if [[ -n ${clst_VERBOSE} ]]; then
|
|
args_for_bdl+=(-v)
|
|
fi
|
|
function btt_bdl_portageq() {
|
|
ROOT=${ROOT} SYSROOT=${ROOT} PORTAGE_CONFIGROOT=${ROOT} portageq "${@}"
|
|
}
|
|
function btt_bdl_equery() {
|
|
ROOT=${ROOT} SYSROOT=${ROOT} PORTAGE_CONFIGROOT=${ROOT} equery "${@}"
|
|
}
|
|
# Breaking the following loops here:
|
|
#
|
|
# glibc[nscd] -> libcap[pam] -> pam -> libcrypt -> libxcrypt[system] -> glibc
|
|
# glibc[nscd] -> audit[python] -> python -> libcrypt -> libxcrypt[system] -> glibc
|
|
# glibc[selinux] -> libselinux[python] -> python -> libcrypt -> libxcrypt[system] -> glibc
|
|
# systemd[cryptsetup] -> cryptsetup[udev] -> libudev[systemd] -> systemd
|
|
# systemd[cryptsetup] -> cryptsetup -> lvm2[udev] -> libudev[systemd] -> systemd
|
|
# systemd[cryptsetup] -> cryptsetup -> lvm2[lvm,systemd] -> systemd
|
|
# systemd[cryptsetup] -> cryptsetup -> tmpfiles[systemd] -> systemd
|
|
# systemd[curl] -> curl -> nghttp2[systemd] -> systemd
|
|
# importd requires curl, so needs to be disabled too
|
|
# systemd[pam] -> pam[systemd] -> systemd
|
|
# dropping USE=pam from systemd requires dropping USE=systemd
|
|
# from pambase
|
|
# systemd[tpm] -> tpm2-tss -> tmpfiles[systemd] -> systemd
|
|
# util-linux[audit] -> audit[python] -> python -> util-linux
|
|
# util-linux[cryptsetup] -> cryptsetup -> util-linux
|
|
# util-linux[pam] -> pam[audit] -> audit[python] -> python -> util-linux
|
|
# su requires pam, so needs to be disabled too
|
|
# util-linux[selinux] -> libselinux[python] -> python -> util-linux
|
|
# util-linux[systemd] -> systemd -> util-linux
|
|
# util-linux[udev] -> libudev[systemd] -> systemd -> util-linux
|
|
# pambase[sssd] -> sssd -> shadow[pam] -> pambase
|
|
args_for_bdl+=(
|
|
sys-apps/systemd cryptsetup,curl,importd,pam,tpm
|
|
sys-apps/util-linux audit,cryptsetup,pam,selinux,su,systemd,udev
|
|
sys-auth/pambase sssd,systemd
|
|
sys-libs/glibc nscd,selinux
|
|
sys-libs/pam systemd
|
|
)
|
|
BDL_ROOT=${ROOT} \
|
|
BDL_PORTAGEQ=btt_bdl_portageq \
|
|
BDL_EQUERY=btt_bdl_equery \
|
|
BDL_EMERGE=btt_emerge \
|
|
break_dep_loop "${args_for_bdl[@]}"
|
|
unset btt_bdl_portageq btt_bdl_equery
|
|
|
|
btt_emerge --changed-use --update --deep "${TOOLCHAIN_PKGS[@]}"
|
|
unset btt_emerge
|
|
}
|
|
|
|
configure_crossdev_overlay / /usr/local/portage/crossdev
|
|
|
|
for board in $(get_board_list); do
|
|
echo "Building native toolchain for ${board}"
|
|
target_pkgdir="$(portageq envvar PKGDIR)/target/${board}"
|
|
PKGDIR="${target_pkgdir}" configure_target_root "${board}"
|
|
PKGDIR="${target_pkgdir}" build_target_toolchain "${board}"
|
|
done
|