All of lore.kernel.org
 help / color / mirror / Atom feed
* [oe][OE-core][Patch v2 0/2] implement applying patches from a directory
@ 2021-12-20 10:14 Max Krummenacher
  2021-12-20 10:14 ` [oe][OE-core][Patch v2 1/2] lib/oe/patch.py: apply patches from src_uri specified directories Max Krummenacher
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Max Krummenacher @ 2021-12-20 10:14 UTC (permalink / raw)
  To: openembedded-core
  Cc: Max Krummenacher, kweihmann, bruce.ashfield, richard.purdie,
	alex.kanavin, quentin.schulz

The current developer manual [1] specifies that patches that are
part of a directory which is given in SRC_URI are applied by
the do_patch task. However that is not implemented in the
current code.

This patchset implements that, but deviates from what is
documented. If the patches are applied I will send a patch
for the documentation changing the relevant part to:

```
If you have a directory full of patch files and you want to
apply them all you can add the directory to SRC_URI and add
the "apply=yes" parameter. This will apply ALL files in the
directiory, including files in subdirectories.
The patches will be applied sorted by their filename. Files
from subdirectories will be sorted into the list at the
position given by the subdirectory name.

   SRC_URI = " \
       git://path_to_repo/some_package \
       file://path_to_lots_of_patch_files;apply=yes \
       "

In the previous example all the files in the directory holding
the patch files would be applied as a patch.
```

Changes in v2:
- using python glob to get a directories content recursively as
  proposed by Konrad Weihmann
- dropped 'lib/oe/recipeutils.py: follow changed method argument list',
  the use of glob allowed to keep the original argument list
- added a oe-selftest which tests applying patches aspects

Max

[1] https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#ref-tasks-patch

Max Krummenacher (2):
  lib/oe/patch.py: apply patches from src_uri specified directories
  oe-selftest: bbtests: add test_patching test

 .../patchtest/patchtest/0001-10.patch         | 25 +++++
 .../patchtest/patchtest/0001-111.patch        | 25 +++++
 .../patchtest/patchtest/expected_source_file  | 11 +++
 .../patchtest/patchtest/expected_src_patches  |  5 +
 .../patchtest/patchtest/expected_src_sources  |  7 ++
 .../patchtest/patchset1/0001-11.patch         | 25 +++++
 .../patchtest/patchset2/0001-2.patch          | 25 +++++
 .../patchset2/0002_subset1/0001-4.patch       | 27 ++++++
 .../patchset2/0002_subset1/0002-6.patch       | 26 ++++++
 .../patchtest/patchset2/0003-8.patch          | 25 +++++
 .../patchtest/patchset3/0001-111.patch        | 25 +++++
 .../patchtest/patchtest/src_patches           |  5 +
 .../patchtest/patchtest/the_source_file       |  5 +
 .../recipes-test/patchtest/patchtest_1.0.bb   | 37 ++++++++
 meta/lib/oe/patch.py                          | 92 +++++++++++--------
 meta/lib/oeqa/selftest/cases/bbtests.py       | 18 ++++
 16 files changed, 346 insertions(+), 37 deletions(-)
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_source_file
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/src_patches
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/the_source_file
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest_1.0.bb

-- 
2.20.1



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

* [oe][OE-core][Patch v2 1/2] lib/oe/patch.py: apply patches from src_uri specified directories
  2021-12-20 10:14 [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Max Krummenacher
@ 2021-12-20 10:14 ` Max Krummenacher
  2021-12-20 10:14 ` [oe][OE-core][Patch v2 2/2] oe-selftest: bbtests: add test_patching test Max Krummenacher
  2021-12-20 10:45 ` [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Alexander Kanavin
  2 siblings, 0 replies; 4+ messages in thread
From: Max Krummenacher @ 2021-12-20 10:14 UTC (permalink / raw)
  To: openembedded-core
  Cc: Max Krummenacher, kweihmann, bruce.ashfield, richard.purdie,
	alex.kanavin, quentin.schulz

The current developer manual specifies that patches that are
part of a directory which is given in SRC_URI are applied by
the do_patch task. However that is not implemented in the
current code.

Implement part of it with two differences:
- The implementation requires the parameter "apply=yes" and
  adds all files as patches, not only files ending in .patch
  and .diff.
  This keeps recipes which depend on the current implementation
  working.
- The possibility to exclude a file in that directory from being
  applied by a follow up entry with "apply=no" is dropped.

Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
---
 meta/lib/oe/patch.py | 92 ++++++++++++++++++++++++++------------------
 1 file changed, 55 insertions(+), 37 deletions(-)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 950fe723dc..39f8fb5097 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 
+import glob
 import oe.path
 import oe.types
 import subprocess
@@ -794,68 +795,85 @@ class UserResolver(Resolver):
             raise
         os.chdir(olddir)
 
-
-def patch_path(url, fetch, workdir, expand=True):
-    """Return the local path of a patch, or return nothing if this isn't a patch"""
-
-    local = fetch.localpath(url)
-    if os.path.isdir(local):
-        return
+def is_patch(local, workdir, apply_all, expand):
     base, ext = os.path.splitext(os.path.basename(local))
     if ext in ('.gz', '.bz2', '.xz', '.Z'):
         if expand:
             local = os.path.join(workdir, base)
         ext = os.path.splitext(base)[1]
 
+    if ext in (".diff", ".patch") or apply_all:
+        return True
+    return False
+
+def patch_path(url, fetch, workdir, expand=True):
+    """Return a list of local paths of patches or return an empty list if there are no patches"""
+    patches = []
+    local = fetch.localpath(url)
     urldata = fetch.ud[url]
+
+    apply_all = False
     if "apply" in urldata.parm:
         apply = oe.types.boolean(urldata.parm["apply"])
         if not apply:
-            return
-    elif ext not in (".diff", ".patch"):
-        return
+            return patches
+        else:
+            apply_all = True
 
-    return local
+    if os.path.isdir(local) and apply_all:
+        for f in sorted(glob.glob(local + "/**", recursive=True)):
+            if os.path.isdir(f):
+                continue
+            if is_patch(f, workdir, apply_all, expand):
+                    patches.append(f)
+    else:
+        if is_patch(local, workdir, apply_all, expand):
+            patches.append(local)
+
+    return patches
 
 def src_patches(d, all=False, expand=True):
+    """Return a list of local paths from SRC_URI. With all=False all patches targeting do_patch, with all=True all other local paths"""
     workdir = d.getVar('WORKDIR')
     fetch = bb.fetch2.Fetch([], d)
     patches = []
     sources = []
     for url in fetch.urls:
-        local = patch_path(url, fetch, workdir, expand)
-        if not local:
+        locals = []
+        locals = locals + patch_path(url, fetch, workdir, expand)
+
+        if not locals:
             if all:
                 local = fetch.localpath(url)
                 sources.append(local)
             continue
-
-        urldata = fetch.ud[url]
-        parm = urldata.parm
-        patchname = parm.get('pname') or os.path.basename(local)
-
-        apply, reason = should_apply(parm, d)
-        if not apply:
-            if reason:
-                bb.note("Patch %s %s" % (patchname, reason))
-            continue
-
-        patchparm = {'patchname': patchname}
-        if "striplevel" in parm:
-            striplevel = parm["striplevel"]
-        elif "pnum" in parm:
-            #bb.msg.warn(None, "Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
-            striplevel = parm["pnum"]
         else:
-            striplevel = '1'
-        patchparm['striplevel'] = striplevel
+            for patch in locals:
+                parm = fetch.ud[url].parm
+                patchname = parm.get('pname') or os.path.basename(patch)
+
+                apply, reason = should_apply(parm, d)
+                if not apply:
+                    if reason:
+                        bb.note("Patch %s %s" % (patchname, reason))
+                    continue
+
+                patchparm = {'patchname': patchname}
+                if "striplevel" in parm:
+                    striplevel = parm["striplevel"]
+                elif "pnum" in parm:
+                    #bb.warn("Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
+                    striplevel = parm["pnum"]
+                else:
+                    striplevel = '1'
+                patchparm['striplevel'] = striplevel
 
-        patchdir = parm.get('patchdir')
-        if patchdir:
-            patchparm['patchdir'] = patchdir
+                patchdir = parm.get('patchdir')
+                if patchdir:
+                    patchparm['patchdir'] = patchdir
 
-        localurl = bb.fetch.encodeurl(('file', '', local, '', '', patchparm))
-        patches.append(localurl)
+                localurl = bb.fetch.encodeurl(('file', '', patch, '', '', patchparm))
+                patches.append(localurl)
 
     if all:
         return sources
-- 
2.20.1



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

* [oe][OE-core][Patch v2 2/2] oe-selftest: bbtests: add test_patching test
  2021-12-20 10:14 [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Max Krummenacher
  2021-12-20 10:14 ` [oe][OE-core][Patch v2 1/2] lib/oe/patch.py: apply patches from src_uri specified directories Max Krummenacher
@ 2021-12-20 10:14 ` Max Krummenacher
  2021-12-20 10:45 ` [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Alexander Kanavin
  2 siblings, 0 replies; 4+ messages in thread
From: Max Krummenacher @ 2021-12-20 10:14 UTC (permalink / raw)
  To: openembedded-core
  Cc: Max Krummenacher, kweihmann, bruce.ashfield, richard.purdie,
	alex.kanavin, quentin.schulz

This adds a test which tests the do_patch task.
Execute it with:

oe-selftest -r bbtests.BitbakeTests.test_patching

Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
---
 .../patchtest/patchtest/0001-10.patch         | 25 +++++++++++++
 .../patchtest/patchtest/0001-111.patch        | 25 +++++++++++++
 .../patchtest/patchtest/expected_source_file  | 11 ++++++
 .../patchtest/patchtest/expected_src_patches  |  5 +++
 .../patchtest/patchtest/expected_src_sources  |  7 ++++
 .../patchtest/patchset1/0001-11.patch         | 25 +++++++++++++
 .../patchtest/patchset2/0001-2.patch          | 25 +++++++++++++
 .../patchset2/0002_subset1/0001-4.patch       | 27 ++++++++++++++
 .../patchset2/0002_subset1/0002-6.patch       | 26 +++++++++++++
 .../patchtest/patchset2/0003-8.patch          | 25 +++++++++++++
 .../patchtest/patchset3/0001-111.patch        | 25 +++++++++++++
 .../patchtest/patchtest/src_patches           |  5 +++
 .../patchtest/patchtest/the_source_file       |  5 +++
 .../recipes-test/patchtest/patchtest_1.0.bb   | 37 +++++++++++++++++++
 meta/lib/oeqa/selftest/cases/bbtests.py       | 18 +++++++++
 15 files changed, 291 insertions(+)
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_source_file
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/src_patches
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest/the_source_file
 create mode 100644 meta-selftest/recipes-test/patchtest/patchtest_1.0.bb

diff --git a/meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch b/meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch
new file mode 100644
index 0000000000..6756d90fa3
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch
@@ -0,0 +1,25 @@
+From 285ae404b72b28f09ea4dadc3982f2b5209394e4 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:46:20 +0100
+Subject: [PATCH] 10
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/the_source_file b/the_source_file
+index 0719398..0bdd73e 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -7,3 +7,5 @@
+ 7
+ 8
+ 9
++10
++
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch b/meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch
new file mode 100644
index 0000000000..2ffb92b541
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch
@@ -0,0 +1,25 @@
+From 8401f132616a357f8d31f4f8a8671e3af2a951e9 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:46:56 +0100
+Subject: [PATCH] 111
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/the_source_file b/the_source_file
+index 0bdd73e..3c6745a 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -8,4 +8,4 @@
+ 8
+ 9
+ 10
+-
++111
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/expected_source_file b/meta-selftest/recipes-test/patchtest/patchtest/expected_source_file
new file mode 100644
index 0000000000..0bdd73e9ea
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/expected_source_file
@@ -0,0 +1,11 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches b/meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches
new file mode 100644
index 0000000000..3958fa6687
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches
@@ -0,0 +1,5 @@
+file://.../patchtest/patchset2/0001-2.patch;patchname=0001-2.patch;striplevel=1
+file://.../patchtest/patchset2/0002_subset1/0001-4.patch;patchname=0001-4.patch;striplevel=1
+file://.../patchtest/patchset2/0002_subset1/0002-6.patch;patchname=0002-6.patch;striplevel=1
+file://.../patchtest/patchset2/0003-8.patch;patchname=0003-8.patch;striplevel=1
+file://.../patchtest/0001-10.patch;patchname=0001-10.patch;striplevel=1
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources b/meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources
new file mode 100644
index 0000000000..e537590e34
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources
@@ -0,0 +1,7 @@
+.../patchtest/the_source_file
+.../patchtest/expected_source_file
+.../patchtest/expected_src_sources
+.../patchtest/expected_src_patches
+.../patchtest/patchset1/
+.../patchtest/patchset3/
+.../patchtest/0001-111.patch
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch
new file mode 100644
index 0000000000..5f7d252acc
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch
@@ -0,0 +1,25 @@
+From c39f579aceff00e61103993e9232ce76e4da1bd8 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:38:44 +0100
+Subject: [PATCH] 11
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/the_source_file b/the_source_file
+index 2738e8e..44caf78 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -1,4 +1,4 @@
+-1
++11
+ 3
+ 5
+ 7
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch
new file mode 100644
index 0000000000..ddb803f549
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch
@@ -0,0 +1,25 @@
+From 61300af3a14887d6f25d68481a0d328f4cce4864 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:41:21 +0100
+Subject: [PATCH 1/4] 2
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/the_source_file b/the_source_file
+index 2738e8e..ecaefbd 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -1,4 +1,5 @@
+ 1
++2
+ 3
+ 5
+ 7
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch
new file mode 100644
index 0000000000..9dbb1ee052
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch
@@ -0,0 +1,27 @@
+From 71cc95135bd1a0864e8a35131d2982aeaad7bb88 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:41:42 +0100
+Subject: [PATCH 2/4] 4
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/the_source_file b/the_source_file
+index ecaefbd..2c32db0 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -1,6 +1,7 @@
+ 1
+ 2
+ 3
++4
+ 5
+ 7
+ 9
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch
new file mode 100644
index 0000000000..bb31b2956a
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch
@@ -0,0 +1,26 @@
+From 3f182bc1b413911187264340f661c637b2afe766 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:41:55 +0100
+Subject: [PATCH 3/4] 6
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/the_source_file b/the_source_file
+index 2c32db0..ef28dff 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -3,5 +3,6 @@
+ 3
+ 4
+ 5
++6
+ 7
+ 9
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch
new file mode 100644
index 0000000000..9cfdd45c6a
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch
@@ -0,0 +1,25 @@
+From 442a036ef3be12c68b4c8f4ae6a6b9954879c094 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:42:12 +0100
+Subject: [PATCH 4/4] 8
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/the_source_file b/the_source_file
+index ef28dff..0719398 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -5,4 +5,5 @@
+ 5
+ 6
+ 7
++8
+ 9
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch b/meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch
new file mode 100644
index 0000000000..2ffb92b541
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch
@@ -0,0 +1,25 @@
+From 8401f132616a357f8d31f4f8a8671e3af2a951e9 Mon Sep 17 00:00:00 2001
+From: Max Krummenacher <max.krummenacher@toradex.com>
+Date: Wed, 8 Dec 2021 15:46:56 +0100
+Subject: [PATCH] 111
+
+Upstream-Status: Inappropriate [native]
+
+Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
+---
+ the_source_file | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/the_source_file b/the_source_file
+index 0bdd73e..3c6745a 100644
+--- a/the_source_file
++++ b/the_source_file
+@@ -8,4 +8,4 @@
+ 8
+ 9
+ 10
+-
++111
+-- 
+2.20.1
+
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/src_patches b/meta-selftest/recipes-test/patchtest/patchtest/src_patches
new file mode 100644
index 0000000000..c45568da42
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/src_patches
@@ -0,0 +1,5 @@
+file:///build/krm/poky_master/poky/meta/recipes-bsp/patchtest/patchtest/patchset2/0001-2.patch;patchname=0001-2.patch;striplevel=1
+file:///build/krm/poky_master/poky/meta/recipes-bsp/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch;patchname=0001-4.patch;striplevel=1
+file:///build/krm/poky_master/poky/meta/recipes-bsp/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch;patchname=0002-6.patch;striplevel=1
+file:///build/krm/poky_master/poky/meta/recipes-bsp/patchtest/patchtest/patchset2/0003-8.patch;patchname=0003-8.patch;striplevel=1
+file:///build/krm/poky_master/poky/meta/recipes-bsp/patchtest/patchtest/0001-10.patch;patchname=0001-10.patch;striplevel=1
diff --git a/meta-selftest/recipes-test/patchtest/patchtest/the_source_file b/meta-selftest/recipes-test/patchtest/patchtest/the_source_file
new file mode 100644
index 0000000000..2738e8e70a
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest/the_source_file
@@ -0,0 +1,5 @@
+1
+3
+5
+7
+9
diff --git a/meta-selftest/recipes-test/patchtest/patchtest_1.0.bb b/meta-selftest/recipes-test/patchtest/patchtest_1.0.bb
new file mode 100644
index 0000000000..6ecea61ecc
--- /dev/null
+++ b/meta-selftest/recipes-test/patchtest/patchtest_1.0.bb
@@ -0,0 +1,37 @@
+SUMMARY = "Testrecipe to test do_patch"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+SRC_URI = " \
+    file://the_source_file \
+    file://expected_source_file \
+    file://expected_src_sources \
+    file://expected_src_patches \
+    \
+    file://patchset1/ \
+    file://patchset2/;apply=yes \
+    file://patchset3/;apply=no \
+    file://0001-10.patch \
+    file://0001-111.patch;apply=no \
+"
+
+S = "${WORKDIR}"
+
+do_configure[noexec] = "1"
+do_compile[noexec] = "1"
+do_install[noexec] = "1"
+
+python patch_do_patch:append() {
+    import re
+    abs_paths = d.getVar('FILE_DIRNAME')
+    f = open('src_patches', 'w')
+    for uri in src_patches(d):
+        uri = re.sub(abs_paths, r'...', uri)
+        f.write(uri + '\n')
+
+    f = open('src_sources', 'w')
+    for uri in src_patches(d, all=True):
+        uri = re.sub(abs_paths, r'...', uri)
+        f.write(uri + '\n')
+}
diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py
index a74576bc02..11fd7e10f3 100644
--- a/meta/lib/oeqa/selftest/cases/bbtests.py
+++ b/meta/lib/oeqa/selftest/cases/bbtests.py
@@ -81,6 +81,24 @@ class BitbakeTests(OESelftestTestCase):
                 found = l
         self.assertTrue(found and found.startswith("ERROR:"), msg = "Incorrectly formed patch application didn't fail. bitbake output: %s" % result.output)
 
+    def test_patching(self):
+        # The patchtest recipe patches 'the_source_file' with patches which
+        # then must match the content of 'expected_source_file'.
+        # Additionally it creates the files 'src_patches' and 'src_sources',
+        # containing the returned lists from src_patches() with 'all' set to
+        # False (src_patches) and True (src_sources). They must match the
+        # content of 'expected_src_patches' and 'expected_src_sources'.
+        from filecmp import cmp
+        bb_vars = get_bb_vars(['S'], 'patchtest')
+        dir = bb_vars['S']
+
+        result = bitbake('patchtest -fc patch', ignore_status=True)
+
+        self.assertNotEqual(result.status, 1, msg="do_patch failed. bitbake output: %s" % result.output)
+        self.assertTrue(cmp(dir + '/the_source_file', dir + '/expected_source_file', False), msg = "patches were not applied correctly")
+        self.assertTrue(cmp(dir + '/src_patches', dir + '/expected_src_patches', False), msg = "patches consumed by do_patch were not identified correctly")
+        self.assertTrue(cmp(dir + '/src_sources', dir + '/expected_src_sources', False), msg = "src_uri entries which are not consumed by do_patch were not identified correctly")
+
     def test_force_task_1(self):
         # test 1 from bug 5875
         import uuid
-- 
2.20.1



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

* Re: [oe][OE-core][Patch v2 0/2] implement applying patches from a directory
  2021-12-20 10:14 [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Max Krummenacher
  2021-12-20 10:14 ` [oe][OE-core][Patch v2 1/2] lib/oe/patch.py: apply patches from src_uri specified directories Max Krummenacher
  2021-12-20 10:14 ` [oe][OE-core][Patch v2 2/2] oe-selftest: bbtests: add test_patching test Max Krummenacher
@ 2021-12-20 10:45 ` Alexander Kanavin
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Kanavin @ 2021-12-20 10:45 UTC (permalink / raw)
  To: Max Krummenacher
  Cc: Max Krummenacher, bruce.ashfield, kweihmann, openembedded-core,
	quentin.schulz, richard.purdie

[-- Attachment #1: Type: text/plain, Size: 4239 bytes --]

I still want to question the need for this. I’d rather allow only an
explicit list giving an explicit order in the recipe.

Alex

On Mon 20. Dec 2021 at 13.15, Max Krummenacher <max.oss.09@gmail.com> wrote:

> The current developer manual [1] specifies that patches that are
> part of a directory which is given in SRC_URI are applied by
> the do_patch task. However that is not implemented in the
> current code.
>
> This patchset implements that, but deviates from what is
> documented. If the patches are applied I will send a patch
> for the documentation changing the relevant part to:
>
> ```
> If you have a directory full of patch files and you want to
> apply them all you can add the directory to SRC_URI and add
> the "apply=yes" parameter. This will apply ALL files in the
> directiory, including files in subdirectories.
> The patches will be applied sorted by their filename. Files
> from subdirectories will be sorted into the list at the
> position given by the subdirectory name.
>
>    SRC_URI = " \
>        git://path_to_repo/some_package \
>        file://path_to_lots_of_patch_files;apply=yes \
>        "
>
> In the previous example all the files in the directory holding
> the patch files would be applied as a patch.
> ```
>
> Changes in v2:
> - using python glob to get a directories content recursively as
>   proposed by Konrad Weihmann
> - dropped 'lib/oe/recipeutils.py: follow changed method argument list',
>   the use of glob allowed to keep the original argument list
> - added a oe-selftest which tests applying patches aspects
>
> Max
>
> [1]
> https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#ref-tasks-patch
>
> Max Krummenacher (2):
>   lib/oe/patch.py: apply patches from src_uri specified directories
>   oe-selftest: bbtests: add test_patching test
>
>  .../patchtest/patchtest/0001-10.patch         | 25 +++++
>  .../patchtest/patchtest/0001-111.patch        | 25 +++++
>  .../patchtest/patchtest/expected_source_file  | 11 +++
>  .../patchtest/patchtest/expected_src_patches  |  5 +
>  .../patchtest/patchtest/expected_src_sources  |  7 ++
>  .../patchtest/patchset1/0001-11.patch         | 25 +++++
>  .../patchtest/patchset2/0001-2.patch          | 25 +++++
>  .../patchset2/0002_subset1/0001-4.patch       | 27 ++++++
>  .../patchset2/0002_subset1/0002-6.patch       | 26 ++++++
>  .../patchtest/patchset2/0003-8.patch          | 25 +++++
>  .../patchtest/patchset3/0001-111.patch        | 25 +++++
>  .../patchtest/patchtest/src_patches           |  5 +
>  .../patchtest/patchtest/the_source_file       |  5 +
>  .../recipes-test/patchtest/patchtest_1.0.bb   | 37 ++++++++
>  meta/lib/oe/patch.py                          | 92 +++++++++++--------
>  meta/lib/oeqa/selftest/cases/bbtests.py       | 18 ++++
>  16 files changed, 346 insertions(+), 37 deletions(-)
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/0001-10.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/0001-111.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/expected_source_file
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/expected_src_patches
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/expected_src_sources
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset1/0001-11.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset2/0001-2.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0001-4.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset2/0002_subset1/0002-6.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset2/0003-8.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/patchset3/0001-111.patch
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/src_patches
>  create mode 100644
> meta-selftest/recipes-test/patchtest/patchtest/the_source_file
>  create mode 100644 meta-selftest/recipes-test/patchtest/patchtest_1.0.bb
>
> --
> 2.20.1
>
>

[-- Attachment #2: Type: text/html, Size: 5200 bytes --]

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

end of thread, other threads:[~2021-12-20 10:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 10:14 [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Max Krummenacher
2021-12-20 10:14 ` [oe][OE-core][Patch v2 1/2] lib/oe/patch.py: apply patches from src_uri specified directories Max Krummenacher
2021-12-20 10:14 ` [oe][OE-core][Patch v2 2/2] oe-selftest: bbtests: add test_patching test Max Krummenacher
2021-12-20 10:45 ` [oe][OE-core][Patch v2 0/2] implement applying patches from a directory Alexander Kanavin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.