Skip to contentSkip to conversation

patch.bbclass: when the patch fails show more info on the fatal error

PATCH Superseded Jose Quaresma 2 participants 3 messages Oct 3, 2021

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 patch.bbclass: when the patch fails show more info on the fatal error

There are situration when the user have the 'patchdir' defined as a parameter on SRC_URI. However he doesn't know with this, the patch is applied relatively to the receipe source dir 'S'.

When user have 'patchdir' defined check if this directory exist. If the patch fails show addition info to the user:
* Import: show the striplevel
* Resolver: show the expanded 'patchdir' to the user.

On the next example, the patch is applied on ${WORKDIR}/contrib.

S = "${WORKDIR}/git"
SRCREV_FORMAT = "opencv_contrib"

SRC_URI = "git://github.com/opencv/opencv.git;name=opencv \
           git://github.com/opencv/opencv_contrib.git;destsuffix=contrib;name=contrib \
           file://0001-sfm-link-with-Glog_LIBS.patch;patchdir=../contrib \
           "

But if the user specifies a path on 'patchdir' that don't exist, (patchdir=../no-found-on-file-system) the patch will fail and there are no message that indicates the real cause.

---
 meta/classes/patch.bbclass | 5 +++++
 1 file changed, 5 insertions(+)
meta/classes/patch.bbclass +5 -0
index 388773a237..30753dc65b 100644
@@ -131,6 +131,9 @@ python patch_do_patch() {
             patchdir = parm["patchdir"]
             if not os.path.isabs(patchdir):
                 patchdir = os.path.join(s, patchdir)
+            if not os.path.isdir(patchdir):
+                bb.fatal("Patch target source directory '%s' not found, 'patchdir' is incorrect in '%s'" %
+                    (patchdir, parm['patchname']))
         else:
             patchdir = s
 
@@ -147,11 +150,13 @@ python patch_do_patch() {
             patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
         except Exception as exc:
             bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Import patch '%s' with striplevel '%s'" % (parm['patchname'], parm['striplevel']))
             bb.fatal(str(exc))
         try:
             resolver.Resolve()
         except bb.BBHandledException as e:
             bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Resolve patch '%s' on target directory '%s'" % (parm['patchname'], patchdir))
             bb.fatal(str(e))
 
     bb.utils.remove(process_tmpdir, True)
Signature · 1 line
2.33.0
#1 lore raw
Quoted 10 lines · Jose Quaresma

There are situration when the user have the 'patchdir' defined as a parameter on SRC_URI. However he doesn't know with this, the patch is applied relatively to the receipe source dir 'S'.

When user have 'patchdir' defined check if this directory exist. If the patch fails show addition info to the user:
* Import: show the striplevel
* Resolver: show the expanded 'patchdir' to the user.

On the next example, the patch is applied on ${WORKDIR}/contrib.

Nice patch, that will turn really helpful, thanks for that one

Quoted 32 lines

S = "${WORKDIR}/git"
SRCREV_FORMAT = "opencv_contrib"

SRC_URI = "git://github.com/opencv/opencv.git;name=opencv \
            git://github.com/opencv/opencv_contrib.git;destsuffix=contrib;name=contrib \
            file://0001-sfm-link-with-Glog_LIBS.patch;patchdir=../contrib \
            "

But if the user specifies a path on 'patchdir' that don't exist, (patchdir=../no-found-on-file-system) the patch will fail and there are no message that indicates the real cause.

---
  meta/classes/patch.bbclass | 5 +++++
  1 file changed, 5 insertions(+)
meta/classes/patch.bbclass +3 -0
index 388773a237..30753dc65b 100644
@@ -131,6 +131,9 @@ python patch_do_patch() {
              patchdir = parm["patchdir"]
              if not os.path.isabs(patchdir):
                  patchdir = os.path.join(s, patchdir)
+            if not os.path.isdir(patchdir):
+                bb.fatal("Patch target source directory '%s' not found, 'patchdir' is incorrect in '%s'" %
+                    (patchdir, parm['patchname']))
          else:
              patchdir = s
 

meta/classes/patch.bbclass python patch_do_patch() { · line 154

Quoted 5 lines
meta/classes/patch.bbclass +1 -0
@@ -147,11 +150,13 @@ python patch_do_patch() {
              patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
          except Exception as exc:
              bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Import patch '%s' with striplevel '%s'" % (parm['patchname'], parm['striplevel']))
              bb.fatal(str(exc))

I'm not a 100% sure about consecutive bb.fatal calls. To my understanding each of the calls will raise a BBHandledException, which is caught at toplevel and leading to sys.exit - so a bb.fatal after a bb.fatal is likely dead code, as it will be never called.

But I might be wrong here - looking for more insights from the bitbake experts

Quoted 19 lines
meta/classes/patch.bbclass +1 -1
          try:
              resolver.Resolve()
          except bb.BBHandledException as e:
              bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Resolve patch '%s' on target directory '%s'" % (parm['patchname'], patchdir))
              bb.fatal(str(e))
 
      bb.utils.remove(process_tmpdir, True)
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#156549): https://lists.openembedded.org/g/openembedded-core/message/156549
Mute This Topic: https://lists.openembedded.org/mt/86039997/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

Konrad Weihmann <[email protected]> escreveu no dia domingo, 3/10/2021 à(s) 12:54:

Quoted 56 lines · Jose Quaresma
Quoted 10 lines

There are situration when the user have the 'patchdir' defined as a parameter on SRC_URI. However he doesn't know with this, the patch is applied relatively to the receipe source dir 'S'.

When user have 'patchdir' defined check if this directory exist. If the patch fails show addition info to the user:
* Import: show the striplevel
* Resolver: show the expanded 'patchdir' to the user.

On the next example, the patch is applied on ${WORKDIR}/contrib.

Nice patch, that will turn really helpful, thanks for that one

Quoted 5 lines

S = "${WORKDIR}/git"
SRCREV_FORMAT = "opencv_contrib"

SRC_URI = "git://github.com/opencv/opencv.git;name=opencv \
            git://

github.com/opencv/opencv_contrib.git;destsuffix=contrib;name=contrib \

Quoted 1 line

file://0001-sfm-link-with-Glog_LIBS.patch;patchdir=../contrib \

Quoted 16 lines
            "

But if the user specifies a path on 'patchdir' that don't exist, (patchdir=../no-found-on-file-system) the patch will fail and there are no message that indicates the real cause.

---
  meta/classes/patch.bbclass | 5 +++++
  1 file changed, 5 insertions(+)
meta/classes/patch.bbclass +0 -0
index 388773a237..30753dc65b 100644

meta/classes/patch.bbclass python patch_do_patch() { · line 135

Quoted 5 lines
meta/classes/patch.bbclass +2 -0
@@ -131,6 +131,9 @@ python patch_do_patch() {
              patchdir = parm["patchdir"]
              if not os.path.isabs(patchdir):
                  patchdir = os.path.join(s, patchdir)
+            if not os.path.isdir(patchdir):
+                bb.fatal("Patch target source directory '%s' not found,

'patchdir' is incorrect in '%s'" %

meta/classes/patch.bbclass python patch_do_patch() { · line 150

Quoted 6 lines
meta/classes/patch.bbclass +1 -0
+                    (patchdir, parm['patchname']))
          else:
              patchdir = s
 
@@ -147,11 +150,13 @@ python patch_do_patch() {
              patchset.Import({"file":local, "strippath":

parm['striplevel']}, True)

meta/classes/patch.bbclass python patch_do_patch() {

Quoted 3 lines
meta/classes/patch.bbclass +1 -0
          except Exception as exc:
              bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Import patch '%s' with striplevel '%s'" %
Quoted 8 lines

(parm['patchname'], parm['striplevel']))

meta/classes/patch.bbclass python patch_do_patch() { · line 154

Quoted 1 line
meta/classes/patch.bbclass +0 -0
              bb.fatal(str(exc))

I'm not a 100% sure about consecutive bb.fatal calls. To my understanding each of the calls will raise a BBHandledException, which is caught at toplevel and leading to sys.exit - so a bb.fatal after a bb.fatal is likely dead code, as it will be never called.

Thanks, good catch.
Does not make sense to call bb.fatal one after the other. I will send a V5.

Quoted 27 lines

But I might be wrong here - looking for more insights from the bitbake experts

meta/classes/patch.bbclass python patch_do_patch() {

Quoted 5 lines
meta/classes/patch.bbclass +1 -0
          try:
              resolver.Resolve()
          except bb.BBHandledException as e:
              bb.utils.remove(process_tmpdir, True)
+            bb.fatal("Resolve patch '%s' on target directory '%s'" %

(parm['patchname'], patchdir))

Quoted 9 lines
meta/classes/patch.bbclass +0 -1
              bb.fatal(str(e))
 
      bb.utils.remove(process_tmpdir, True)
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group. View/Reply Online (#156549):

https://lists.openembedded.org/g/openembedded-core/message/156549

Quoted 3 lines

Mute This Topic: https://lists.openembedded.org/mt/86039997/3647476
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [

[email protected]]

Quoted 2 lines

-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Best regards,

José Quaresma