Added by Jesse Zhang, last edited by Jesse Zhang on Aug 18, 2009  (view change)

Labels:

recipe recipe Delete
patch patch Delete
Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.

Here is a subtle problem you may encounter when your package needs a patch.

TypeError: not enough arguments for format string

The addPatch method receives a "macros" option, with which you can use macros (e.g. those directory macros like %(libdir)) in your patch. When the patch is applied, the macros will be substituted. (Read the manual for more, "$ cvc explain addPatch")

Now the problem. The following example comes from evolution-data-server:source=foresight.rpath.org@fl:devel/2.26.1.1-0.1 .

First, here is how the patch is added in the recipe. Notice macros=True

         r.addPatch('servicedir.patch', macros=True,
                   use=(r.macros.servicedir != '/var'))

Then, please take a look at the right patch,

 --- camel/providers/local/camel-local-folder.c    2009-05-06 03:59:32.000000000 -0500
+++ camel/providers/local/camel-local-folder.c    2009-05-06 03:58:29.000000000 -0500
@@ -391,8 +391,8 @@
                     /* $HOME relative path + protocol string */
                     folder->description = g_strdup_printf(_("~%%s (%%s)"), path+strlen(tmp),
                                           ((CamelService *)folder->parent_store)->url->protocol);
-                else if ((tmp = "/var/spool/mail") && strncmp(tmp, path, strlen(tmp)) == 0)
-                    /* /var/spool/mail relative path + protocol */
+                else if ((tmp = "%(servicedir)s/spool/mail") && strncmp(tmp, path, strlen(tmp)) == 0)
+                    /* %(servicedir)s/spool/mail relative path + protocol */
                     folder->description = g_strdup_printf(_("mailbox: %%s (%%s)"), path+strlen(tmp),
                                           ((CamelService *)folder->parent_store)->url->protocol);
                 else if ((tmp = "/var/mail") && strncmp(tmp, path, strlen(tmp)) == 0)

and the wrong one. Look hard to find out the difference

 --- camel/providers/local/camel-local-folder.c    2009-05-06 03:59:32.000000000 -0500
+++ camel/providers/local/camel-local-folder.c    2009-05-06 03:58:29.000000000 -0500
@@ -391,8 +391,8 @@
                     /* $HOME relative path + protocol string */
                     folder->description = g_strdup_printf(_("~%s (%s)"), path+strlen(tmp),
                                           ((CamelService *)folder->parent_store)->url->protocol);
-                else if ((tmp = "/var/spool/mail") && strncmp(tmp, path, strlen(tmp)) == 0)
-                    /* /var/spool/mail relative path + protocol */
+                else if ((tmp = "%(servicedir)s/spool/mail") && strncmp(tmp, path, strlen(tmp)) == 0)
+                    /* %(servicedir)s/spool/mail relative path + protocol */
                     folder->description = g_strdup_printf(_("mailbox: %s (%s)"), path+strlen(tmp),
                                           ((CamelService *)folder->parent_store)->url->protocol);
                 else if ((tmp = "/var/mail") && strncmp(tmp, path, strlen(tmp)) == 0)

"%s" !! Conary would think this is also a macro and tries to substitute it and, of course, trigger a python exception somewhere.

So if you are using "macros" in your patch, take a moment to update the non-macros, like %s.