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

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

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

This stresses repo patching, patch ordering, strip level and the apply
parameter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 .../recipes-app/example-hello/example-hello.bb     |  5 ++-
 .../example-hello/files/0001-Add-some-help.patch   | 40 ++++++++++++++++++++++
 .../example-hello/files/yet-another-change.txt     | 11 ++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 meta-isar/recipes-app/example-hello/files/0001-Add-some-help.patch
 create mode 100644 meta-isar/recipes-app/example-hello/files/yet-another-change.txt

diff --git a/meta-isar/recipes-app/example-hello/example-hello.bb b/meta-isar/recipes-app/example-hello/example-hello.bb
index 73cca0a..9788ec0 100644
--- a/meta-isar/recipes-app/example-hello/example-hello.bb
+++ b/meta-isar/recipes-app/example-hello/example-hello.bb
@@ -14,7 +14,10 @@ PV = "0.2-86cc719"
 #       for now it's the only way to correctly build bitbake pipeline.
 DEPENDS += "libhello"
 
-SRC_URI = "git://github.com/ilbers/hello.git;protocol=https"
+SRC_URI = " \
+    git://github.com/ilbers/hello.git;protocol=https \
+    file://0001-Add-some-help.patch \
+    file://yet-another-change.txt;apply=yes;striplevel=0"
 SRCREV = "86cc719b3359adc3c4e243387feba50360a860f3"
 
 S = "git"
diff --git a/meta-isar/recipes-app/example-hello/files/0001-Add-some-help.patch b/meta-isar/recipes-app/example-hello/files/0001-Add-some-help.patch
new file mode 100644
index 0000000..3c68a93
--- /dev/null
+++ b/meta-isar/recipes-app/example-hello/files/0001-Add-some-help.patch
@@ -0,0 +1,40 @@
+From 4615f473881aaff12a52aa3bb625bfb38753b4f2 Mon Sep 17 00:00:00 2001
+From: Jan Kiszka <jan.kiszka@siemens.com>
+Date: Sun, 18 Feb 2018 09:02:11 +0100
+Subject: [PATCH] Add some help
+
+This just provides a commit to demonstrate patching in Isar recipes.
+
+Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
+---
+ hello.c | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/hello.c b/hello.c
+index 269c24b..329a0c5 100644
+--- a/hello.c
++++ b/hello.c
+@@ -5,10 +5,19 @@
+  * version 2.
+  */
+ 
++#include <stdio.h>
+ #include <hello.h>
+ 
+-int main(void)
++int main(int argc, char *argv[])
+ {
++	while (argc > 1) {
++		if (strcmp(argv[argc - 1], "--help") == 0) {
++			printf("42\n");
++			return 0;
++		}
++		argc--;
++	}
++
+ 	say_hello();
+ 	return 0;
+ }
+-- 
+2.13.6
+
diff --git a/meta-isar/recipes-app/example-hello/files/yet-another-change.txt b/meta-isar/recipes-app/example-hello/files/yet-another-change.txt
new file mode 100644
index 0000000..0f8c1c8
--- /dev/null
+++ b/meta-isar/recipes-app/example-hello/files/yet-another-change.txt
@@ -0,0 +1,11 @@
+--- hello.c.orig	2018-02-18 09:09:26.712855740 +0100
++++ hello.c	2018-02-18 09:09:51.969056718 +0100
+@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
+ {
+ 	while (argc > 1) {
+ 		if (strcmp(argv[argc - 1], "--help") == 0) {
+-			printf("42\n");
++			printf("42. Or what was the question?\n");
+ 			return 0;
+ 		}
+ 		argc--;
-- 
2.13.6

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

* Re: [PATCH 1/2] Add basic patch support
  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 ` Alexander Smirnov
  2018-02-21  9:36   ` Jan Kiszka
  1 sibling, 1 reply; 4+ messages in thread
From: Alexander Smirnov @ 2018-02-20 11:12 UTC (permalink / raw)
  To: Jan Kiszka, isar-users

On 02/18/2018 10:39 PM, Jan Kiszka wrote:
> 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.

What's the issue to take the full implementation from OE? How this 
user-interface differs from OE?

Alex

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

* Re: [PATCH 1/2] Add basic patch support
  2018-02-20 11:12 ` [PATCH 1/2] Add basic patch support Alexander Smirnov
@ 2018-02-21  9:36   ` Jan Kiszka
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2018-02-21  9:36 UTC (permalink / raw)
  To: Alexander Smirnov, isar-users

On 2018-02-20 12:12, Alexander Smirnov wrote:
> On 02/18/2018 10:39 PM, Jan Kiszka wrote:
>> 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.
> 
> What's the issue to take the full implementation from OE? How this
> user-interface differs from OE?

The OE version is much more complex, consisting of a class + some
library code at least. The library code seems to have further
dependencies on OE functions. Importing all that, possibly changing
things to work again, requires some clear maintenance/synchronization
strategy. TBH, that appeared too complex to me at this point, and so
went for the simpler solution. That does not exclude enhancing/replacing
this later on, specifically as this implementation here is compatible
from user-perspective.

Jan

^ 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