diff mbox series

[1/2] arm/classes: Introduce apply_local_src_patches bbclass

Message ID 20221121142346.1502347-1-peter.hoyes@arm.com
State New
Headers show
Series [1/2] arm/classes: Introduce apply_local_src_patches bbclass | expand

Commit Message

Peter Hoyes Nov. 21, 2022, 2:23 p.m. UTC
From: Diego Sueiro <diego.sueiro@arm.com>

This class is to be inherited by recipes where there are patches located inside
the fetched source code which need to be applied.

The following variables need to be set:
LOCAL_SRC_PATCHES_INPUT_DIR is the directory from where the patches are located
LOCAL_SRC_PATCHES_DEST_DIR is the directory where the patches will be applied

Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Change-Id: I8f9c16a5fbc9d5569cba60136560f1951408bd60
---
 .../classes/apply_local_src_patches.bbclass   | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 meta-arm/classes/apply_local_src_patches.bbclass

Comments

Jon Mason Nov. 21, 2022, 8 p.m. UTC | #1
On Mon, 21 Nov 2022 14:23:45 +0000, Peter Hoyes wrote:
> This class is to be inherited by recipes where there are patches located inside
> the fetched source code which need to be applied.
> 
> The following variables need to be set:
> LOCAL_SRC_PATCHES_INPUT_DIR is the directory from where the patches are located
> LOCAL_SRC_PATCHES_DEST_DIR is the directory where the patches will be applied

Applied, thanks!

[1/2] arm/classes: Introduce apply_local_src_patches bbclass
      commit: 7fcff00498480d72ad536e785b2297f39dd1071e
[2/2] arm/trusted-firmware-m: Fix local source patches application
      commit: f7c9f58eeb446130e2af77bf2b26be95b6134cef

Best regards,
diff mbox series

Patch

diff --git a/meta-arm/classes/apply_local_src_patches.bbclass b/meta-arm/classes/apply_local_src_patches.bbclass
new file mode 100644
index 00000000..daa85f4c
--- /dev/null
+++ b/meta-arm/classes/apply_local_src_patches.bbclass
@@ -0,0 +1,48 @@ 
+# This class is to be inherited by recipes where there are patches located inside
+# the fetched source code which need to be applied.
+
+# The following variables need to be set:
+# LOCAL_SRC_PATCHES_INPUT_DIR is the directory from where the patches are located
+# LOCAL_SRC_PATCHES_DEST_DIR is the directory where the patches will be applied
+
+do_patch[depends] += "quilt-native:do_populate_sysroot"
+
+LOCAL_SRC_PATCHES_INPUT_DIR ??= ""
+LOCAL_SRC_PATCHES_DEST_DIR ??= "${LOCAL_SRC_PATCHES_INPUT_DIR}"
+
+python() {
+    if not d.getVar('LOCAL_SRC_PATCHES_INPUT_DIR'):
+        bb.warn("LOCAL_SRC_PATCHES_INPUT_DIR variable needs to be set.")
+}
+
+apply_local_src_patches() {
+
+    input_dir="${LOCAL_SRC_PATCHES_INPUT_DIR}"
+    dest_dir="${LOCAL_SRC_PATCHES_DEST_DIR}"
+
+    if [ ! -d "$input_dir" ] ; then
+        bbfatal "LOCAL_SRC_PATCHES_INPUT_DIR=$input_dir not found."
+    fi
+
+    if [ ! -d "$dest_dir" ] ; then
+        bbfatal "LOCAL_SRC_PATCHES_DEST_DIR=$dest_dir not found."
+    fi
+
+    cd $dest_dir
+    export QUILT_PATCHES=./patches-extra
+    mkdir -p patches-extra
+
+    for patch in $(find $input_dir -type f -name *.patch -or -name *.diff)
+    do
+        patch_basename=`basename $patch`
+        if ! quilt applied $patch_basename >/dev/null ; then
+            bbdebug 1 "Applying $patch_basename in $dest_dir."
+            echo $patch_basename >> patches-extra/series
+            cp $patch patches-extra
+            quilt push $patch_basename
+        else
+            bbdebug 1 "$patch_basename already applied."
+        fi
+    done
+}
+do_patch[postfuncs] += "apply_local_src_patches"