[yocto] New: "extrapatches" bbclass.
Kaz Kylheku (poky)
442-103-8455 at kylheku.com
Thu Mar 7 19:26:38 PST 2019
#
# extrapatches bbclass
#
# This bbclass allows for a recipe to apply additional patches.
#
# "Additional patches" refers to patches that are not individually
# fetched by the SRC_URI mechanism, but are already present
# inside the source trees that are fetched and unpacked.
# Referring directly to recipe-side patches
# without fetching them via SRC_URI is also possible.
#
# How to use this class:
#
# 1. Add inherit extrapatches to your recipe.
# 2. Optionally set the EXTRAPATCHES_WORKDIR,
# 3. List the patches in EXTRAPATCHES in order of application.
# - Relative paths are interpreted relative to
EXTRAPATCHES_WORKDIR.
# - Absolute paths are allowed
#
# Influential variables:
#
# Name Default Desc
#
--------------------------------------------------------------------------
# EXTRAPATCHES_WORKDIR ${S} extrapatches changes to this
directory.
#
# EXTRAPATCHES "" list of path names of patch files
# relative paths are resolved from
# the EXTRAPATCHES_WORKDIR directory.
# EXTRAPATCHES entries must not
contain
# spaces or shell meta-characters.
#
# The following SRC_URI style options supported in EXTRAPATCHES
variable:
#
# Name Default Desc
#
--------------------------------------------------------------------------
# apply 1 Boolean, apply the patch or not.
#
# striplevel 1 How many leading directory
components
# to remove, passed as the -p option
# of patch.
#
# For Boolean options: yes, y, true, t, and 1 all specify "true";
# no, n, false, f and 0 specify "false".
#
# Additional usage notes:
#
# The patches you list in EXTRAPATCHES will be applied *AFTER* any
# patches that Yocto applies that are specified on the SRC_URI.
#
# If this is a problem, you can follow this method, or the alternative:
#
# 1. Add do_patch[noexec] = "1" to your recipe.
# 2. List your SRC_URI patches again in the EXTRAPATCHES variable,
# keeping in mind they are fetched into ${WORKDIR}.
# Absolute paths may be used like ${WORKDIR}/001-foo.patch
#
# Alternative:
#
# 1. Add do_patch[noexec] = "1" to suppress Yocto's do_patch.
# 2. Do *NOT* list any patches in SRC_URI.
# 3. Refer directly to your recipe-side patches in EXTRAPATCHES,
# for instance EXTRAPATCHES = "${THISDIR}/files/my-patch.patch ..."
#
EXTRAPATCHES_WORKDIR = "${S}"
do_patch_extra() {
cd ${EXTRAPATCHES_WORKDIR}
mkdir -p patches
if [ "$(quilt top)" = patches/empty-last.patch ] ; then
# extra patches already applied: delete them, but
# keep the empty-first.patch
while [ "$(quilt top)" != patches/empty-first.patch ] ; do
quilt delete
done
elif quilt series | grep -q '^patches/empty-first[.]patch$' ; then
# our patches are half-applied; the markers exist, but
# the patches/empty-last.patch is not on top.
# Let's try to recover.
# blow off all unapplied patches
for patch in $(quilt unapplied) ; do
quilt delete $patch
done
if quilt applied empty-first.patch > /dev/null ; then
# if the empty-first.patch marker is applied, then
# delete everything above it
while [ "$(quilt top)" != patches/empty-first.patch ] ; do
quilt delete
done
else
# the empty-first.patch is not applied, and no
# unapplied patches exist. Let's assume that we
# have a clean slate with the only patches that exist
# being the ones from Yocto's do_patch. We begin our marker.
# quilt ref ensures that the empty patch file is actually
created
quilt new empty-first.patch ; quilt ref
fi
else
# dummy marker patch indicating start of extra patches
quilt new empty-first.patch ; quilt ref
fi
for patch in ${EXTRAPATCHES} ; do
import_patch_with_options "$patch"
quilt push
done
# dummy marker patch indicating that all patches are applied
quilt new empty-last.patch ; quilt ref
}
addtask patch_extra after do_patch before do_configure
import_patch_with_options()
{
local patch=$1
local striplevel=1
local apply=1
local opt
local arg
while true ; do
case $patch in
*' '* )
printf "patch name %s contains spaces\n" "$patch"
exit 1
;;
*\;* )
opt=${patch##*;}
patch=${patch%;*}
case $opt in
*=* )
arg=${opt##*=}
opt=${opt%=*}
case $opt in
striplevel )
striplevel=$arg
;;
apply )
apply=$arg
;;
* )
printf "patch %s specifies unrecognized option:
%s\n" \
$patch $opt
exit 1
esac
;;
* )
printf "patch %s specifies option with no argument:
%s\n" \
$patch $opt
exit 1
;;
esac
;;
* )
break
;;
esac
done
case $apply in
yes | y | true | t | 1 )
quilt import -p $striplevel $patch
;;
no | n | false | f | 0 )
printf "patch %s disabled by apply option\n" $patch
;;
* )
printf "patch %s specifies invalid boolean value for apply:
%s\n" \
$patch $apply
;;
esac
}
More information about the yocto
mailing list