public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH 1/2] Add basic patch support
@ 2018-02-18 19:39 Jan Kiszka
  2018-02-18 19:40 ` [PATCH 2/2] example-app: Add two patches for demonstration and testing purposes Jan Kiszka
  2018-02-20 11:12 ` [PATCH 1/2] Add basic patch support Alexander Smirnov
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kiszka @ 2018-02-18 19:39 UTC (permalink / raw)
  To: isar-users

From: Jan Kiszka <jan.kiszka@siemens.com>

Add a do_patch task after unpack the processes .patch files in the
SRC_URI. We likely miss some special features compared to OE, but this
covers the common case of few individual patches. Application order is
derived from appearance in SRC_URI list. Strip level can be configured
via "striplevel=N" URI parameter. The application is controlled
explicitly via the "apply=yes|no" parameter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/classes/dpkg-base.bbclass |  5 ++++-
 meta/classes/patch.bbclass     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 meta/classes/patch.bbclass

diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 78709f9..0e2d0e2 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -8,9 +8,12 @@ do_adjust_git() {
     fi
 }
 
-addtask adjust_git after do_unpack before do_build
+addtask adjust_git after do_unpack before do_patch
 do_adjust_git[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}"
 
+inherit patch
+addtask patch after do_adjust_git before do_build
+
 # Add dependency from buildchroot creation
 do_build[depends] = "buildchroot:do_build"
 
diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
new file mode 100644
index 0000000..26a0c81
--- /dev/null
+++ b/meta/classes/patch.bbclass
@@ -0,0 +1,33 @@
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+
+python do_patch() {
+    import subprocess
+
+    workdir = d.getVar("WORKDIR", True) + "/"
+    src_dir = workdir + (d.getVar("S", True) or "")
+
+    for src_uri in (d.getVar("SRC_URI", True) or "").split():
+        try:
+            fetcher = bb.fetch2.Fetch([src_uri], d)
+
+            apply = fetcher.ud[src_uri].parm.get("apply")
+            if apply == "no":
+                continue
+
+            basename = fetcher.ud[src_uri].basename or ""
+            if not (basename.endswith(".patch") or apply == "yes"):
+                continue
+
+            striplevel = fetcher.ud[src_uri].parm.get("striplevel") or "1"
+
+            cmd = "patch --no-backup-if-mismatch -p " + striplevel + \
+                  " --directory " + src_dir + " --input " + workdir + basename
+            bb.note(cmd)
+            if subprocess.call(cmd, shell=True) != 0:
+                bb.fatal("patching failed")
+        except bb.fetch2.BBFetchException as e:
+            raise bb.build.FuncFailed(e)
+}
+
+do_patch[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}"
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-21  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-18 19:39 [PATCH 1/2] Add basic patch support Jan Kiszka
2018-02-18 19:40 ` [PATCH 2/2] example-app: Add two patches for demonstration and testing purposes Jan Kiszka
2018-02-20 11:12 ` [PATCH 1/2] Add basic patch support Alexander Smirnov
2018-02-21  9:36   ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox