mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 08:56:58 +02:00
eclass/multibuild: Sync with Gentoo
It's from Gentoo commit d7317785d04e7de172de3bff05852fca3cd15af2.
This commit is contained in:
parent
c8355e2b31
commit
cdeec876fd
@ -1,4 +1,4 @@
|
||||
# Copyright 1999-2021 Gentoo Authors
|
||||
# Copyright 1999-2022 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
# @ECLASS: multibuild.eclass
|
||||
@ -6,27 +6,22 @@
|
||||
# Michał Górny <mgorny@gentoo.org>
|
||||
# @AUTHOR:
|
||||
# Author: Michał Górny <mgorny@gentoo.org>
|
||||
# @SUPPORTED_EAPIS: 4 5 6 7 8
|
||||
# @SUPPORTED_EAPIS: 6 7 8
|
||||
# @BLURB: A generic eclass for building multiple variants of packages.
|
||||
# @DESCRIPTION:
|
||||
# The multibuild eclass aims to provide a generic framework for building
|
||||
# multiple 'variants' of a package (e.g. multilib, Python
|
||||
# implementations).
|
||||
|
||||
case "${EAPI:-0}" in
|
||||
[0-3])
|
||||
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
|
||||
;;
|
||||
[4-8])
|
||||
;;
|
||||
*)
|
||||
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
|
||||
;;
|
||||
case ${EAPI} in
|
||||
6|7|8) ;;
|
||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||
esac
|
||||
|
||||
if [[ ! ${_MULTIBUILD} ]]; then
|
||||
if [[ ! ${_MULTIBUILD_ECLASS} ]]; then
|
||||
_MULTIBUILD_ECLASS=1
|
||||
|
||||
# @ECLASS-VARIABLE: MULTIBUILD_VARIANTS
|
||||
# @ECLASS_VARIABLE: MULTIBUILD_VARIANTS
|
||||
# @REQUIRED
|
||||
# @DESCRIPTION:
|
||||
# An array specifying all enabled variants which multibuild_foreach*
|
||||
@ -43,7 +38,7 @@ if [[ ! ${_MULTIBUILD} ]]; then
|
||||
# }
|
||||
# @CODE
|
||||
|
||||
# @ECLASS-VARIABLE: MULTIBUILD_VARIANT
|
||||
# @ECLASS_VARIABLE: MULTIBUILD_VARIANT
|
||||
# @OUTPUT_VARIABLE
|
||||
# @DESCRIPTION:
|
||||
# The current variant which the function was executed for.
|
||||
@ -53,7 +48,7 @@ if [[ ! ${_MULTIBUILD} ]]; then
|
||||
# python2_6
|
||||
# @CODE
|
||||
|
||||
# @ECLASS-VARIABLE: MULTIBUILD_ID
|
||||
# @ECLASS_VARIABLE: MULTIBUILD_ID
|
||||
# @OUTPUT_VARIABLE
|
||||
# @DESCRIPTION:
|
||||
# The unique identifier for a multibuild run. In a simple run, it is
|
||||
@ -67,7 +62,7 @@ if [[ ! ${_MULTIBUILD} ]]; then
|
||||
# amd64-double
|
||||
# @CODE
|
||||
|
||||
# @ECLASS-VARIABLE: BUILD_DIR
|
||||
# @ECLASS_VARIABLE: BUILD_DIR
|
||||
# @OUTPUT_VARIABLE
|
||||
# @DEFAULT_UNSET
|
||||
# @DESCRIPTION:
|
||||
@ -137,25 +132,6 @@ multibuild_foreach_variant() {
|
||||
return ${ret}
|
||||
}
|
||||
|
||||
# @FUNCTION: multibuild_parallel_foreach_variant
|
||||
# @USAGE: [<argv>...]
|
||||
# @DESCRIPTION:
|
||||
# Run the passed command repeatedly for each of the enabled package
|
||||
# variants. This used to run the commands in parallel but now it's
|
||||
# just a deprecated alias to multibuild_foreach_variant.
|
||||
#
|
||||
# The function returns 0 if all commands return 0, or the first non-zero
|
||||
# exit status otherwise. However, it performs all the invocations
|
||||
# nevertheless. It is preferred to call 'die' inside of the passed
|
||||
# function.
|
||||
multibuild_parallel_foreach_variant() {
|
||||
debug-print-function ${FUNCNAME} "${@}"
|
||||
|
||||
[[ ${EAPI} == [45] ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}"
|
||||
|
||||
multibuild_foreach_variant "${@}"
|
||||
}
|
||||
|
||||
# @FUNCTION: multibuild_for_best_variant
|
||||
# @USAGE: [<argv>...]
|
||||
# @DESCRIPTION:
|
||||
@ -172,10 +148,7 @@ multibuild_for_best_variant() {
|
||||
[[ ${MULTIBUILD_VARIANTS} ]] \
|
||||
|| die "MULTIBUILD_VARIANTS need to be set"
|
||||
|
||||
# bash-4.1 can't handle negative subscripts
|
||||
local MULTIBUILD_VARIANTS=(
|
||||
"${MULTIBUILD_VARIANTS[$(( ${#MULTIBUILD_VARIANTS[@]} - 1 ))]}"
|
||||
)
|
||||
local MULTIBUILD_VARIANTS=( "${MULTIBUILD_VARIANTS[-1]}" )
|
||||
multibuild_foreach_variant "${@}"
|
||||
}
|
||||
|
||||
@ -192,15 +165,10 @@ multibuild_copy_sources() {
|
||||
|
||||
einfo "Will copy sources from ${_MULTIBUILD_INITIAL_BUILD_DIR}"
|
||||
|
||||
local cp_args=()
|
||||
if cp --reflink=auto --version &>/dev/null; then
|
||||
# enable reflinking if possible to make this faster
|
||||
cp_args+=( --reflink=auto )
|
||||
fi
|
||||
|
||||
_multibuild_create_source_copy() {
|
||||
einfo "${MULTIBUILD_VARIANT}: copying to ${BUILD_DIR}"
|
||||
cp -p -R "${cp_args[@]}" \
|
||||
# enable reflinking if possible to make this faster
|
||||
cp -p -R --reflink=auto \
|
||||
"${_MULTIBUILD_INITIAL_BUILD_DIR}" "${BUILD_DIR}" || die
|
||||
}
|
||||
|
||||
@ -234,43 +202,14 @@ run_in_build_dir() {
|
||||
# (the real root). Both directories have to be real, absolute paths
|
||||
# (i.e. including ${D}). Source root will be removed.
|
||||
multibuild_merge_root() {
|
||||
debug-print-function ${FUNCNAME} "${@}"
|
||||
|
||||
local src=${1}
|
||||
local dest=${2}
|
||||
|
||||
local ret
|
||||
|
||||
if use userland_BSD; then
|
||||
# Most of BSD variants fail to copy broken symlinks, #447370
|
||||
# also, they do not support --version
|
||||
|
||||
tar -C "${src}" -f - -c . \
|
||||
| tar -x -f - -C "${dest}"
|
||||
[[ ${PIPESTATUS[*]} == '0 0' ]]
|
||||
ret=${?}
|
||||
else
|
||||
local cp_args=()
|
||||
|
||||
if cp -a --version &>/dev/null; then
|
||||
cp_args+=( -a )
|
||||
else
|
||||
cp_args+=( -P -R -p )
|
||||
fi
|
||||
|
||||
if cp --reflink=auto --version &>/dev/null; then
|
||||
# enable reflinking if possible to make this faster
|
||||
cp_args+=( --reflink=auto )
|
||||
fi
|
||||
|
||||
cp "${cp_args[@]}" "${src}"/. "${dest}"/
|
||||
ret=${?}
|
||||
fi
|
||||
|
||||
if [[ ${ret} -ne 0 ]]; then
|
||||
die "${MULTIBUILD_VARIANT:-(unknown)}: merging image failed."
|
||||
fi
|
||||
|
||||
rm -rf "${src}"
|
||||
# enable reflinking if possible to make this faster
|
||||
cp -a --reflink=auto "${src}"/. "${dest}"/ || die "${MULTIBUILD_VARIANT:-(unknown)}: merging image failed"
|
||||
rm -rf "${src}" || die
|
||||
}
|
||||
|
||||
_MULTIBUILD=1
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user