mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 11:51:14 +02:00
Merge pull request #131 from marineam/turtle-chain
Turtle chain: Building native compilers with cross compilers!
This commit is contained in:
commit
39e377dff5
@ -33,6 +33,7 @@ assert_inside_chroot
|
||||
|
||||
# Load functions and constants for chromeos-install
|
||||
. /usr/lib/installer/chromeos-common.sh || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ cat <<EOF
|
||||
target: stage4
|
||||
pkgcache_path: $BINPKGS
|
||||
stage4/packages: coreos-devel/sdk-depends
|
||||
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_sdk_stage4.sh
|
||||
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_default_stage4.sh
|
||||
stage4/root_overlay: ${TEMPDIR}/stage4_overlay
|
||||
EOF
|
||||
catalyst_stage_default
|
||||
|
||||
@ -24,7 +24,7 @@ cat <<EOF
|
||||
target: stage4
|
||||
pkgcache_path: $BINPKGS
|
||||
stage4/packages: coreos-devel/buildhost-depends
|
||||
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_buildbot_stage4.sh
|
||||
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_default_stage4.sh
|
||||
EOF
|
||||
catalyst_stage_default
|
||||
}
|
||||
|
||||
@ -71,6 +71,7 @@ check_gsutil_opts
|
||||
|
||||
# N.B. Ordering matters for some of the libraries below, because
|
||||
# some of the files contain initialization used by later files.
|
||||
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
|
||||
|
||||
@ -39,11 +39,9 @@ cleanup_mounts() {
|
||||
create_base_image() {
|
||||
local image_name=$1
|
||||
local rootfs_verification_enabled=$2
|
||||
local image_type="base"
|
||||
|
||||
if [[ "${FLAGS_disk_layout}" != "default" ]]; then
|
||||
image_type="${FLAGS_disk_layout}"
|
||||
fi
|
||||
get_disk_layout_type
|
||||
local image_type="${DISK_LAYOUT_TYPE}"
|
||||
|
||||
check_valid_layout "base"
|
||||
check_valid_layout ${image_type}
|
||||
|
||||
@ -9,24 +9,7 @@ fi
|
||||
|
||||
BOARD="${FLAGS_board}"
|
||||
BOARD_ROOT="/build/${BOARD}"
|
||||
ARCH=$(get_board_arch ${BOARD})
|
||||
|
||||
# What cross-build are we targeting?
|
||||
. "${BOARD_ROOT}/etc/make.conf.board_setup"
|
||||
|
||||
# Figure out ARCH from the given toolchain.
|
||||
# TODO(jrbarnette): There's a copy of this code in setup_board;
|
||||
# it should be shared.
|
||||
case "$(echo "${CHOST}" | awk -F'-' '{ print $1 }')" in
|
||||
arm*)
|
||||
ARCH="arm"
|
||||
;;
|
||||
*86)
|
||||
ARCH="x86"
|
||||
;;
|
||||
*x86_64)
|
||||
ARCH="amd64"
|
||||
;;
|
||||
*)
|
||||
error "Unable to determine ARCH from toolchain: ${CHOST}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
@ -77,9 +77,14 @@ EOF
|
||||
}
|
||||
|
||||
catalystrc() {
|
||||
echo "export MAKEOPTS='--jobs=${NUM_JOBS} --load-average=${NUM_JOBS}'"
|
||||
echo "export EMERGE_DEFAULT_OPTS=--jobs=${NUM_JOBS}"
|
||||
echo "export FEATURES='parallel-install -ebuild-locks'"
|
||||
local load=$((NUM_JOBS * 2))
|
||||
cat <<EOF
|
||||
export TERM='${TERM}'
|
||||
export MAKEOPTS='--jobs=${NUM_JOBS} --load-average=${load}'
|
||||
export EMERGE_DEFAULT_OPTS="\$MAKEOPTS"
|
||||
# Catalyst overrides FEATURES so set it's own variable instead.
|
||||
export clst_myfeatures='-ebuild-locks'
|
||||
EOF
|
||||
}
|
||||
|
||||
# Common values for all stage spec files
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
source /tmp/chroot-functions.sh
|
||||
|
||||
# Build cross toolchains
|
||||
for cross_chost in x86_64-cros-linux-gnu; do
|
||||
echo "Installing toolchain for ${cross_chost}"
|
||||
cross_pkgs=( cross-${cross_chost}/{binutils,gcc,gdb,glibc,linux-headers} )
|
||||
crossdev --ov-output "/usr/local/portage/crossdev" \
|
||||
--env 'FEATURES=splitdebug' \
|
||||
--stable --ex-gdb --init-target \
|
||||
--target "${cross_chost}" || exit 1
|
||||
|
||||
# If PKGCACHE is enabled check to see if binary packages are available.
|
||||
# If so then don't perform a full bootstrap and just call emerge instead.
|
||||
if [[ -n "${clst_PKGCACHE}" ]] && \
|
||||
emerge ${clst_myemergeopts} --usepkgonly --binpkg-respect-use=y \
|
||||
--pretend "${cross_pkgs[@]}" &>/dev/null
|
||||
then
|
||||
run_merge -u "${cross_pkgs[@]}"
|
||||
else
|
||||
crossdev --ov-output "/usr/local/portage/crossdev" \
|
||||
--portage "${clst_myemergeopts}" \
|
||||
--env 'FEATURES=splitdebug' \
|
||||
--stable --ex-gdb --stage4 \
|
||||
--target "${cross_chost}" || exit 1
|
||||
fi
|
||||
|
||||
# There is no point to including the built packages in the final tarball
|
||||
# because the packages will have to be downloaded anyway due to how the
|
||||
# cross toolchains are managed in board sysroots.
|
||||
crossdev --force -C "${cross_chost}"
|
||||
done
|
||||
|
||||
echo "Double checking everything is fresh and happy."
|
||||
run_merge -uDN --with-bdeps=y world
|
||||
@ -11,83 +11,18 @@ source /tmp/toolchain_util.sh
|
||||
# build deps in crossdev's sysroot use ${PKGDIR}/cross/${CHOST} (no upload)
|
||||
# native toolchains use ${PKGDIR}/target/${BOARD} (uploaded to board location)
|
||||
|
||||
get_dependency_list() {
|
||||
local ROOT="$1"
|
||||
local IFS=$'| \t\n'
|
||||
shift
|
||||
|
||||
PORTAGE_CONFIGROOT="$ROOT" SYSROOT="$ROOT" \
|
||||
ROOT="$ROOT" emerge ${clst_myemergeopts} \
|
||||
--pretend --with-bdeps=y --onlydeps --quiet \
|
||||
"$@" | sed -e 's/.*\] \([^ :]*\).*/=\1/' |
|
||||
egrep -v "(=$(echo "$*")-[0-9])"
|
||||
}
|
||||
|
||||
configure_portage() {
|
||||
local pkg_path="$1"
|
||||
local profile="$2"
|
||||
|
||||
mkdir -p "${ROOT}/etc/portage"
|
||||
echo "eselect will report '!!! Warning: Strange path.' but that's OK"
|
||||
eselect profile set --force "$profile"
|
||||
|
||||
cat >"${ROOT}/etc/portage/make.conf" <<EOF
|
||||
CHOST=${CHOST}
|
||||
CBUILD=$(portageq envvar CBUILD)
|
||||
HOSTCC=\${CBUILD}-gcc
|
||||
ROOT="${ROOT}"
|
||||
SYSROOT="${SYSROOT}"
|
||||
PKG_CONFIG_PATH="\${SYSROOT}/usr/lib/pkgconfig/"
|
||||
PORTDIR="$(portageq envvar PORTDIR)"
|
||||
DISTDIR="\${PORTDIR}/distfiles"
|
||||
PKGDIR="\${PORTDIR}/packages/${pkg_path}"
|
||||
PORTDIR_OVERLAY="$(portageq envvar PORTDIR_OVERLAY)"
|
||||
EOF
|
||||
}
|
||||
|
||||
build_cross_toolchain() {
|
||||
local cross_chost="$1"
|
||||
local cross_pkgs=( "${TOOLCHAIN_PKGS[@]/*\//cross-${cross_chost}/}" )
|
||||
local PORTDIR="$(portageq envvar PORTDIR)"
|
||||
local PKGDIR="${PORTDIR}/packages/crossdev"
|
||||
|
||||
PKGDIR="${PKGDIR}" crossdev \
|
||||
--ov-output "/tmp/crossdev" --stable \
|
||||
--portage "${clst_myemergeopts}" \
|
||||
--init-target --target "${cross_chost}"
|
||||
|
||||
# If PKGCACHE is enabled check to see if binary packages are available.
|
||||
# If so then don't perform a full bootstrap and just call emerge instead.
|
||||
if [[ -n "${clst_PKGCACHE}" ]] && \
|
||||
PKGDIR="${PKGDIR}" emerge ${clst_myemergeopts} \
|
||||
--usepkgonly --binpkg-respect-use=y \
|
||||
--pretend "${cross_pkgs[@]}" &>/dev/null
|
||||
then
|
||||
PKGDIR="${PKGDIR}" run_merge -u "${cross_pkgs[@]}"
|
||||
else
|
||||
PKGDIR="${PKGDIR}" crossdev \
|
||||
--ov-output "/tmp/crossdev" --stable \
|
||||
--env PKGDIR="${PORTDIR}/packages/crossdev" \
|
||||
--portage "${clst_myemergeopts}" \
|
||||
--stage4 --target "${cross_chost}"
|
||||
fi
|
||||
|
||||
# Setup ccache for our shiny new toolchain
|
||||
ccache-config --install-links "${cross_chost}"
|
||||
}
|
||||
|
||||
configure_cross_root() {
|
||||
build_cross_libs() {
|
||||
local cross_chost="$1"
|
||||
local ROOT="/usr/${cross_chost}"
|
||||
|
||||
CHOST="${cross_chost}" ROOT="$ROOT" SYSROOT="$ROOT" \
|
||||
configure_portage "cross/${cross_chost}" \
|
||||
"${CROSS_PROFILE[${cross_chost}]}"
|
||||
_configure_sysroot "${CROSS_PROFILE[${cross_chost}]}"
|
||||
|
||||
# In order to get a dependency list we must calculate it before
|
||||
# updating package.provided. Otherwise portage will no-op.
|
||||
get_dependency_list "$ROOT" "${TOOLCHAIN_PKGS[@]}" \
|
||||
> "$ROOT/etc/portage/cross-${cross_chost}-depends"
|
||||
ROOT="$ROOT" _get_dependency_list \
|
||||
${clst_myemergeopts} "${TOOLCHAIN_PKGS[@]}" > \
|
||||
"$ROOT/etc/portage/cross-${cross_chost}-depends"
|
||||
|
||||
# Add toolchain to packages.provided since they are on the host system
|
||||
mkdir -p "$ROOT/etc/portage/profile/package.provided"
|
||||
@ -97,11 +32,6 @@ configure_cross_root() {
|
||||
cross_pkg_version=$(portageq match / "${cross_pkg}")
|
||||
echo "${native_pkg%/*}/${cross_pkg_version#*/}"
|
||||
done > "$ROOT/etc/portage/profile/package.provided/cross-${cross_chost}"
|
||||
}
|
||||
|
||||
build_cross_libs() {
|
||||
local cross_chost="$1"
|
||||
local ROOT="/usr/${cross_chost}"
|
||||
local cross_deps=$(<"$ROOT/etc/portage/cross-${cross_chost}-depends")
|
||||
|
||||
# --root is required because run_merge overrides ROOT=
|
||||
@ -111,10 +41,12 @@ build_cross_libs() {
|
||||
configure_target_root() {
|
||||
local board="$1"
|
||||
local cross_chost=$(get_board_chost "$1")
|
||||
local profile=$(get_board_profile "${board}")
|
||||
|
||||
CHOST="${cross_chost}" ROOT="/build/${board}" \
|
||||
SYSROOT="/usr/${cross_chost}" configure_portage \
|
||||
"target/${board}" "$(get_board_profile "${board}")"
|
||||
CHOST="${cross_chost}" \
|
||||
ROOT="/build/${board}" \
|
||||
SYSROOT="/usr/${cross_chost}" \
|
||||
_configure_sysroot "${profile}"
|
||||
}
|
||||
|
||||
build_target_toolchain() {
|
||||
@ -126,15 +58,21 @@ build_target_toolchain() {
|
||||
run_merge -u --root="$ROOT" "${TOOLCHAIN_PKGS[@]}"
|
||||
}
|
||||
|
||||
mkdir -p "/tmp/crossdev"
|
||||
export PORTDIR_OVERLAY="/tmp/crossdev $(portageq envvar PORTDIR_OVERLAY)"
|
||||
|
||||
for cross_chost in $(get_chost_list); do
|
||||
echo "Building cross toolchain for ${cross_chost}"
|
||||
build_cross_toolchain "${cross_chost}"
|
||||
configure_cross_root "${cross_chost}"
|
||||
build_cross_libs "${cross_chost}"
|
||||
PKGDIR="$(portageq envvar PKGDIR)/crossdev" \
|
||||
install_cross_toolchain "${cross_chost}" ${clst_myemergeopts}
|
||||
|
||||
sysroot_pkgdir="$(portageq envvar PKGDIR)/cross/${cross_chost}"
|
||||
PKGDIR="${sysroot_pkgdir}" build_cross_libs "${cross_chost}"
|
||||
done
|
||||
|
||||
for board in $(get_board_list); do
|
||||
echo "Building native toolchain for ${board}"
|
||||
configure_target_root "${board}"
|
||||
build_target_toolchain "${board}"
|
||||
target_pkgdir="$(portageq envvar PKGDIR)/target/${board}"
|
||||
PKGDIR="${target_pkgdir}" configure_target_root "${board}"
|
||||
PKGDIR="${target_pkgdir}" build_target_toolchain "${board}"
|
||||
done
|
||||
|
||||
@ -47,7 +47,8 @@ class CheckDependencies(object):
|
||||
# Includes are absolute or relative to the file itself.
|
||||
line = os.path.join(os.path.dirname(path), line[8:])
|
||||
for p in glob.glob(self._root + line):
|
||||
libdirs.extend(self._ReadLdSoConf(os.path.relpath(p, self._root)))
|
||||
rel_p = "/%s" % os.path.relpath(p, self._root)
|
||||
libdirs.extend(self._ReadLdSoConf(rel_p))
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
@ -112,6 +112,10 @@ check_valid_layout() {
|
||||
|
||||
get_disk_layout_type() {
|
||||
DISK_LAYOUT_TYPE="base"
|
||||
if [[ -n "${FLAGS_disk_layout}" && \
|
||||
"${FLAGS_disk_layout}" != "default" ]]; then
|
||||
DISK_LAYOUT_TYPE="${FLAGS_disk_layout}"
|
||||
fi
|
||||
}
|
||||
|
||||
emit_gpt_scripts() {
|
||||
|
||||
@ -11,7 +11,8 @@ TOOLCHAIN_PKGS=(
|
||||
)
|
||||
|
||||
# Portage arguments to enforce the toolchain to only use binpkgs.
|
||||
TOOLCHAIN_BINONLY=( "${TOOLCHAIN_PKGS[@]/#/--useoldpkg-atoms=}" )
|
||||
TOOLCHAIN_BINONLY=( "${TOOLCHAIN_PKGS[@]/#/--useoldpkg-atoms=}"
|
||||
"${TOOLCHAIN_PKGS[@]/#/--rebuild-exclude=}" )
|
||||
|
||||
# Portage profile to use for building out the cross compiler's SYSROOT.
|
||||
# This is only used as an intermediate step to be able to use the cross
|
||||
@ -26,6 +27,30 @@ BOARD_CHOST["amd64-generic"]="x86_64-cros-linux-gnu"
|
||||
BOARD_PROFILE["amd64-generic"]="coreos:coreos/amd64/generic"
|
||||
BOARD_NAMES=( "${!BOARD_CHOST[@]}" )
|
||||
|
||||
### Generic metadata fetching functions ###
|
||||
|
||||
# map CHOST to portage ARCH, list came from crossdev
|
||||
# Usage: get_portage_arch chost
|
||||
get_portage_arch() {
|
||||
case "$1" in
|
||||
aarch64*) echo arm;;
|
||||
alpha*) echo alpha;;
|
||||
arm*) echo arm;;
|
||||
hppa*) echo hppa;;
|
||||
ia64*) echo ia64;;
|
||||
i?86*) echo x86;;
|
||||
m68*) echo m68k;;
|
||||
mips*) echo mips;;
|
||||
powerpc64*) echo ppc64;;
|
||||
powerpc*) echo ppc;;
|
||||
sparc*) echo sparc;;
|
||||
s390*) echo s390;;
|
||||
sh*) echo sh;;
|
||||
x86_64*) echo amd64;;
|
||||
*) die "Unknown CHOST '$1'";;
|
||||
esac
|
||||
}
|
||||
|
||||
get_board_list() {
|
||||
local IFS=$'\n\t '
|
||||
sort <<<"${BOARD_NAMES[*]}"
|
||||
@ -41,18 +66,128 @@ get_profile_list() {
|
||||
sort -u <<<"${BOARD_PROFILE[*]}"
|
||||
}
|
||||
|
||||
get_board_chost() {
|
||||
if [[ ${#BOARD_CHOST["$1"]} -ne 0 ]]; then
|
||||
echo "${BOARD_CHOST["$1"]}"
|
||||
else
|
||||
die "Unknown board '$1'"
|
||||
fi
|
||||
# Usage: get_board_arch board [board...]
|
||||
get_board_arch() {
|
||||
local board
|
||||
for board in "$@"; do
|
||||
get_portage_arch $(get_board_chost "${board}")
|
||||
done
|
||||
}
|
||||
|
||||
# Usage: get_board_chost board [board...]
|
||||
get_board_chost() {
|
||||
local board
|
||||
for board in "$@"; do
|
||||
if [[ ${#BOARD_CHOST["$board"]} -ne 0 ]]; then
|
||||
echo "${BOARD_CHOST["$board"]}"
|
||||
else
|
||||
die "Unknown board '$board'"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Usage: get_board_profile board [board...]
|
||||
get_board_profile() {
|
||||
if [[ ${#BOARD_PROFILE["$1"]} -ne 0 ]]; then
|
||||
echo "${BOARD_PROFILE["$1"]}"
|
||||
local board
|
||||
for board in "$@"; do
|
||||
if [[ ${#BOARD_PROFILE["$board"]} -ne 0 ]]; then
|
||||
echo "${BOARD_PROFILE["$board"]}"
|
||||
else
|
||||
die "Unknown board '$board'"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Usage: get_cross_pkgs chost [chost2...]
|
||||
get_cross_pkgs() {
|
||||
local cross_chost native_pkg
|
||||
for cross_chost in "$@"; do
|
||||
for native_pkg in "${TOOLCHAIN_PKGS[@]}"; do
|
||||
echo "${native_pkg/*\//cross-${cross_chost}/}"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
### Toolchain building utilities ###
|
||||
|
||||
# Ugly hack to get a dependency list of a set of packages.
|
||||
# This is required to figure out what to install in the crossdev sysroot.
|
||||
# Usage: ROOT=/foo/bar _get_dependency_list pkgs... [--portage-opts...]
|
||||
_get_dependency_list() {
|
||||
local pkgs=( ${*/#-*/} )
|
||||
local IFS=$'| \t\n'
|
||||
|
||||
PORTAGE_CONFIGROOT="$ROOT" emerge "$@" --pretend \
|
||||
--emptytree --root-deps=rdeps --onlydeps --quiet | \
|
||||
sed -e 's/.*\] \([^ :]*\).*/=\1/' |
|
||||
egrep -v "(=$(echo "${pkgs[*]}")-[0-9])"
|
||||
}
|
||||
|
||||
# Configure a new ROOT
|
||||
# Values are copied from the environment or the current host configuration.
|
||||
# Usage: ROOT=/foo/bar SYSROOT=/foo/bar configure_portage coreos:some/profile
|
||||
_configure_sysroot() {
|
||||
local profile="$1"
|
||||
|
||||
mkdir -p "${ROOT}/etc/portage"
|
||||
echo "eselect will report '!!! Warning: Strange path.' but that's OK"
|
||||
eselect profile set --force "$profile"
|
||||
|
||||
cat >"${ROOT}/etc/portage/make.conf" <<EOF
|
||||
$(portageq envvar -v CHOST CBUILD ROOT SYSROOT \
|
||||
PORTDIR PORTDIR_OVERLAY DISTDIR PKGDIR)
|
||||
HOSTCC=\${CBUILD}-gcc
|
||||
PKG_CONFIG_PATH="\${SYSROOT}/usr/lib/pkgconfig/"
|
||||
EOF
|
||||
}
|
||||
|
||||
# Dump crossdev information to determine if configs must be reganerated
|
||||
_crossdev_info() {
|
||||
local cross_chost="$1"; shift
|
||||
echo -n "# "; crossdev --version
|
||||
echo "# $@"
|
||||
crossdev --show-target-cfg "${cross_chost}"
|
||||
}
|
||||
|
||||
# Build/install a toolchain w/ crossdev.
|
||||
# Usage: build_cross_toolchain chost [--portage-opts....]
|
||||
install_cross_toolchain() {
|
||||
local cross_chost="$1"; shift
|
||||
local cross_pkgs=( $(get_cross_pkgs $cross_chost) )
|
||||
local cross_cfg="/usr/${cross_chost}/etc/portage/${cross_chost}-crossdev"
|
||||
local cross_cfg_data=$(_crossdev_info "${cross_chost}" stable)
|
||||
|
||||
# may be called from either catalyst (root) or upgrade_chroot (user)
|
||||
local sudo=
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
sudo="sudo -E"
|
||||
fi
|
||||
|
||||
# Only call crossdev to regenerate configs if something has changed
|
||||
if ! cmp --quiet - "${cross_cfg}" <<<"${cross_cfg_data}"
|
||||
then
|
||||
$sudo crossdev --stable --portage "$*" \
|
||||
--init-target --target "${cross_chost}"
|
||||
$sudo tee "${cross_cfg}" <<<"${cross_cfg_data}" >/dev/null
|
||||
fi
|
||||
|
||||
# If binary packages are enabled try to just emerge them instead of
|
||||
# doing a full bootstrap which speeds things up greatly. :)
|
||||
if [[ "$*" == *--usepkg* ]] && \
|
||||
emerge "$@" --usepkgonly --binpkg-respect-use=y \
|
||||
--pretend "${cross_pkgs[@]}" &>/dev/null
|
||||
then
|
||||
$sudo emerge "$@" --binpkg-respect-use=y -u "${cross_pkgs[@]}"
|
||||
else
|
||||
die "Unknown board '$1'"
|
||||
$sudo crossdev --stable --portage "$*" \
|
||||
--stage4 --target "${cross_chost}"
|
||||
fi
|
||||
|
||||
# Setup wrappers for our shiny new toolchain
|
||||
if [[ ! -e "/usr/lib/ccache/bin/${cross_chost}-gcc" ]]; then
|
||||
$sudo ccache-config --install-links "${cross_chost}"
|
||||
fi
|
||||
if [[ ! -e "/usr/lib/sysroot-wrappers/bin/${cross_chost}-gcc" ]]; then
|
||||
$sudo sysroot-config --install-links "${cross_chost}"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -126,6 +126,7 @@ fi
|
||||
"${SCRIPTS_DIR}"/setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
|
||||
|
||||
# set BOARD and BOARD_ROOT
|
||||
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
|
||||
|
||||
# Setup all the emerge command/flags.
|
||||
@ -198,11 +199,6 @@ if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
|
||||
CROS_WORKON_PKGS+=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
|
||||
fi
|
||||
|
||||
# TODO(anush): Make chrome a fake cros-workon package.
|
||||
if [[ -n "${CHROME_ORIGIN}" ]]; then
|
||||
CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome )
|
||||
fi
|
||||
|
||||
if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then
|
||||
EMERGE_FLAGS+=(
|
||||
--reinstall-atoms="${CROS_WORKON_PKGS[*]}"
|
||||
@ -210,25 +206,12 @@ if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then
|
||||
)
|
||||
fi
|
||||
|
||||
# Prepare tmp file to capture emerge output from tee.
|
||||
tmpfile=$(mktemp -t tmp.build_packages-emerge.XXXXXX)
|
||||
trap "rm -f '${tmpfile}'" EXIT
|
||||
|
||||
info "Merging board packages now"
|
||||
(
|
||||
set -o pipefail
|
||||
sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
|
||||
tee "${tmpfile}"
|
||||
)
|
||||
sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}"
|
||||
|
||||
# upload packages if enabled
|
||||
upload_packages
|
||||
|
||||
# Extract total package count from emerge output.
|
||||
package_count=$(awk '$0 ~ /^Total: [0-9]+ packages/ { print $2 }' "${tmpfile}")
|
||||
rm "${tmpfile}"
|
||||
trap - EXIT
|
||||
|
||||
echo "Builds complete"
|
||||
command_completed
|
||||
echo "Done"
|
||||
|
||||
@ -43,12 +43,14 @@ cp "${BUILD_LIBRARY_DIR}/toolchain_util.sh" "${ROOT_OVERLAY}/tmp"
|
||||
catalyst_build
|
||||
|
||||
def_upload_path="${UPLOAD_ROOT}/sdk/${ARCH}/${FLAGS_version}"
|
||||
upload_files "packages" "${def_upload_path}" "pkgs/" "${BINPKGS}/crossdev"/*
|
||||
upload_files "cross toolchain packages" "${def_upload_path}" \
|
||||
"toolchain/" "${BINPKGS}/crossdev"/*
|
||||
|
||||
for board in $(get_board_list); do
|
||||
board_packages="${BINPKGS}/target/${board}"
|
||||
def_upload_path="${UPLOAD_ROOT}/${board}/${FLAGS_version}"
|
||||
upload_files packages "${def_upload_path}" "pkgs/" "${board_packages}"/*
|
||||
upload_files "board toolchain packages" "${def_upload_path}" \
|
||||
"toolchain/" "${board_packages}"/*
|
||||
done
|
||||
|
||||
command_completed
|
||||
|
||||
@ -76,10 +76,10 @@ _dump_trace() {
|
||||
|
||||
# Declare these asap so that code below can safely assume they exist.
|
||||
_message() {
|
||||
local prefix=$1
|
||||
local prefix="$1${CROS_LOG_PREFIX:-${SCRIPT_NAME}}"
|
||||
shift
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo -e "${prefix}${CROS_LOG_PREFIX:-""}:${V_VIDOFF}" >&2
|
||||
echo -e "${prefix}:${V_VIDOFF}" >&2
|
||||
return
|
||||
fi
|
||||
(
|
||||
@ -95,7 +95,7 @@ _message() {
|
||||
set -- ''
|
||||
fi
|
||||
for line in "$@"; do
|
||||
echo -e "${prefix}${CROS_LOG_PREFIX:-}: ${line}${V_VIDOFF}" >&2
|
||||
echo -e "${prefix}: ${line}${V_VIDOFF}" >&2
|
||||
done
|
||||
)
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
# Helper scripts should be run from the same location as this script.
|
||||
SCRIPT_ROOT=$(dirname "$(readlink -f "$0")")
|
||||
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/build_common.sh" || exit 1
|
||||
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
|
||||
|
||||
88
setup_board
88
setup_board
@ -5,7 +5,7 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
. "$(dirname "$0")/common.sh" || exit 1
|
||||
. "${SRC_ROOT}/platform/dev/toolchain_utils.sh"
|
||||
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||
|
||||
# Script must run inside the chroot
|
||||
restart_in_chroot_if_needed "$@"
|
||||
@ -47,16 +47,12 @@ DEFINE_boolean latest_toolchain $FLAGS_FALSE \
|
||||
kernel). This overrides the other toolchain version options."
|
||||
DEFINE_string libc_version "[stable]" \
|
||||
"Version of libc to use."
|
||||
DEFINE_string profile "" \
|
||||
"The portage configuration profile to use. Profile must be located in overlay-board/profiles"
|
||||
DEFINE_boolean quiet $FLAGS_FALSE \
|
||||
"Don't print warnings when board already exists."
|
||||
DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
|
||||
"Don't update toolchain automatically."
|
||||
DEFINE_boolean skip_chroot_upgrade $FLAGS_FALSE \
|
||||
"Don't run the chroot upgrade automatically; use with care."
|
||||
DEFINE_string toolchain "" \
|
||||
"Toolchain. For example: i686-pc-linux-gnu, armv7a-softfloat-linux-gnueabi"
|
||||
DEFINE_string variant "" \
|
||||
"Board variant."
|
||||
DEFINE_boolean regen_configs ${FLAGS_FALSE} \
|
||||
@ -77,10 +73,8 @@ _generate_wrapper() {
|
||||
sudo_clobber "${target}" <<EOF
|
||||
#!/bin/bash
|
||||
|
||||
export CHROMEOS_ROOT="$GCLIENT_ROOT"
|
||||
export CHOST="$FLAGS_toolchain"
|
||||
export PORTAGE_CONFIGROOT="$BOARD_ROOT"
|
||||
export SYSROOT="$BOARD_ROOT"
|
||||
export SYSROOT="\${SYSROOT:-$BOARD_ROOT}"
|
||||
if [ -z "\$PORTAGE_USERNAME" ]; then
|
||||
export PORTAGE_USERNAME=\$(basename \$HOME)
|
||||
fi
|
||||
@ -116,16 +110,6 @@ EOF
|
||||
_generate_wrapper ${wrapper}
|
||||
done
|
||||
|
||||
if [ "${CHOST}" != "$FLAGS_toolchain" ] ; then
|
||||
# TODO(cmasone): Do this more cleanly, if we figure out what "cleanly"
|
||||
# means. Set up wrapper for pkg-config. Point a board-specific wrapper
|
||||
# at the generic wrapper script created by crossdev-wrapper.
|
||||
cmds+=(
|
||||
"ln -sf '/usr/bin/cross-pkg-config' \
|
||||
'/usr/bin/${FLAGS_toolchain}-pkg-config'"
|
||||
)
|
||||
fi
|
||||
|
||||
wrapper="/usr/local/bin/cros_workon-${BOARD_VARIANT}"
|
||||
sudo_clobber "${wrapper}" <<EOF
|
||||
#!/bin/bash
|
||||
@ -187,46 +171,23 @@ if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_FALSE}" ] ; then
|
||||
"${SRC_ROOT}/scripts"/update_chroot ${UPDATE_ARGS}
|
||||
fi
|
||||
|
||||
#
|
||||
# Fetch the toolchain from the board overlay.
|
||||
#
|
||||
all_toolchains=( $(get_all_board_toolchains "${BOARD}") )
|
||||
: ${FLAGS_toolchain:=${all_toolchains[0]}}
|
||||
|
||||
if [ -z "${FLAGS_toolchain}" ]; then
|
||||
error "No toolchain specified in board overlay or on command line."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ARCH=$(get_board_arch "${BOARD}") || exit 1
|
||||
|
||||
case "$BOARD" in
|
||||
*-host)
|
||||
die_notrace "host boards not supported by setup_board"
|
||||
;;
|
||||
esac
|
||||
# Locations we will need
|
||||
COREOS_CONFIG="/usr/local/portage/coreos/coreos/config"
|
||||
BOARD_ROOT="/build/${BOARD_VARIANT}"
|
||||
CROSSDEV_OVERLAY="/usr/local/portage/crossdev"
|
||||
CHROMIUMOS_OVERLAY="/usr/local/portage/coreos"
|
||||
CHROMIUMOS_CONFIG="${CHROMIUMOS_OVERLAY}/coreos/config"
|
||||
CHROMIUMOS_PROFILES="${CHROMIUMOS_OVERLAY}/profiles"
|
||||
BOARD_ETC="${BOARD_ROOT}/etc"
|
||||
BOARD_SETUP="${BOARD_ETC}/make.conf.board_setup"
|
||||
BOARD_PROFILE="${BOARD_ETC}/portage/profile"
|
||||
|
||||
#
|
||||
# Construct board overlay list.
|
||||
#
|
||||
BOARD_OVERLAY_LIST=$(cros_list_overlays \
|
||||
--board "$BOARD_VARIANT" \
|
||||
--board_overlay "$FLAGS_board_overlay")
|
||||
|
||||
eval $(portageq envvar -v CHOST PKGDIR)
|
||||
BOARD_ARCH=$(get_board_arch "$BOARD")
|
||||
PORTAGE_PROFILE=$(get_board_profile "$BOARD")
|
||||
|
||||
if [ -d "${BOARD_ROOT}" ]; then
|
||||
if [[ ${FLAGS_force} -eq ${FLAGS_TRUE} ]]; then
|
||||
echo "--force set. Re-creating ${BOARD_ROOT}..."
|
||||
info "--force set. Re-creating ${BOARD_ROOT}..."
|
||||
# Removal takes long. Make it asynchronous.
|
||||
TEMP_DIR=`mktemp -d`
|
||||
sudo mv "${BOARD_ROOT}" "${TEMP_DIR}"
|
||||
@ -246,9 +207,11 @@ else
|
||||
FLAGS_regen_configs=${FLAGS_FALSE}
|
||||
fi
|
||||
|
||||
info "Configuring portage in ${BOARD_ROOT}"
|
||||
echo "eselect will report '!!! Warning: Strange path.' but that's OK"
|
||||
cmds=(
|
||||
"mkdir -p '${BOARD_ROOT}' '${BOARD_ETC}' '${BOARD_PROFILE}' /usr/local/bin"
|
||||
"mkdir -p '${BOARD_ETC}/portage/hooks'"
|
||||
"mkdir -p '${BOARD_ROOT}' '${BOARD_PROFILE}' '${BOARD_ETC}/portage/hooks'"
|
||||
"ROOT='${BOARD_ROOT}' eselect profile set --force '${PORTAGE_PROFILE}'"
|
||||
)
|
||||
|
||||
# Setup the make.confs. We use the following:
|
||||
@ -256,9 +219,9 @@ cmds=(
|
||||
# make.conf.board_setup <- Declares CHOST, ROOT, etc.
|
||||
# make.conf.common <- Common settings across all targets
|
||||
cmds+=(
|
||||
"ln -sf '${CHROMIUMOS_CONFIG}/make.conf.${ARCH}-target' \
|
||||
"ln -sf '${COREOS_CONFIG}/make.conf.${BOARD_ARCH}-target' \
|
||||
'${BOARD_ETC}/make.conf'"
|
||||
"ln -sf '${CHROMIUMOS_CONFIG}/make.conf.common-target' \
|
||||
"ln -sf '${COREOS_CONFIG}/make.conf.common-target' \
|
||||
'${BOARD_ETC}/make.conf.common'"
|
||||
"touch /etc/portage/make.conf.user"
|
||||
"ln -sf /etc/portage/make.conf.user '${BOARD_ROOT}/etc/make.conf.user'"
|
||||
@ -280,9 +243,8 @@ fi
|
||||
|
||||
sudo_clobber "${BOARD_SETUP}" <<EOF
|
||||
# Created by setup_board
|
||||
CHOST="${FLAGS_toolchain}"
|
||||
CHOST="$(get_board_chost ${BOARD})"
|
||||
ROOT="${BOARD_ROOT}/"
|
||||
BOARD_OVERLAY="${BOARD_OVERLAY_LIST}"
|
||||
MAKEOPTS="--jobs=${NUM_JOBS} --load-average=${NUM_JOBS}"
|
||||
PKG_CONFIG="pkg-config-${BOARD_VARIANT}"
|
||||
BOARD_USE="${BOARD_VARIANT}"
|
||||
@ -290,22 +252,11 @@ ${SAVED_VERSION}
|
||||
${ACCEPT_LICENSE}
|
||||
EOF
|
||||
|
||||
# Select the profile to build based on the board and profile passed to
|
||||
# setup_board. The developer can later change profiles by running
|
||||
# cros_choose_profile manually.
|
||||
if ! cros_choose_profile \
|
||||
--board "${FLAGS_board}" \
|
||||
--board_overlay "${FLAGS_board_overlay}" \
|
||||
--variant "${FLAGS_variant}" \
|
||||
--profile "${FLAGS_profile}"; then
|
||||
error "Selecting profile failed, removing incomplete board directory!"
|
||||
sudo rm -rf "${BOARD_ROOT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
generate_all_wrappers
|
||||
|
||||
if [[ ${FLAGS_regen_configs} -eq ${FLAGS_FALSE} ]]; then
|
||||
info "Installing baselayout"
|
||||
|
||||
# First thing first, install baselayout with USE=build to create a
|
||||
# working directory tree. Don't use binpkgs due to the use flag change.
|
||||
sudo -E USE=build "${EMERGE_WRAPPER}" --usepkg=n --buildpkg=n \
|
||||
@ -335,15 +286,14 @@ if [ $FLAGS_default -eq $FLAGS_TRUE ] ; then
|
||||
fi
|
||||
|
||||
command_completed
|
||||
echo "Done!"
|
||||
echo "The SYSROOT is: ${BOARD_ROOT}"
|
||||
info "The SYSROOT is: ${BOARD_ROOT}"
|
||||
|
||||
# NOTE: Printing the working-on ebuilds does not only serve the informative
|
||||
# purpose. It also causes the ${BOARD_ROOT}/etc/portage/package.* files to be
|
||||
# regenerated.
|
||||
WORKING_ON=$(cros_workon --board=${FLAGS_board} list)
|
||||
if [ -n "${WORKING_ON}" ]; then
|
||||
echo
|
||||
echo "Currently working on the following ebuilds for this board:"
|
||||
echo "${WORKING_ON}"
|
||||
info
|
||||
info "Currently working on the following ebuilds for this board:"
|
||||
info "${WORKING_ON}"
|
||||
fi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user