While there's nothing wrong withe your patch, there's simply
no reason not to just pass *all* patch options directly to
patch. That dumps a bunch of silly code from rpmbuild.

The reason for the parsePrep.c jiggery pokery is transparently remapping
ancient patch's CLI option change that was encoded in %patch syntax
to the new (heh, now 7+ year old) patch-2.5.

There's no reason why the return code of patch execution with bogus
arguments cannot be substituted for the feeble syntax checks imho.

Yes I should have done that implementation instead of tricking
Panu into adding a -F patch for rpm-4.4.2.1 ;-)

73 de Jeff

On Jun 21, 2007, at 2:08 PM, Ralf S. Engelschall wrote:

  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
______________________________________________________________________ ______

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
Module: rpm Date: 21-Jun-2007 20:08:38
  Branch: HEAD                             Handle: 2007062119083701

  Modified files:
    rpm                     CHANGES
    rpm/build               parsePrep.c

  Log:
    Improve %setup and %patch:

1. Let %setup use the existing %{__tar} macro (instead of hard- coding a
        simple "tar") and let %patch use the existing %{__patch} macro
(instead of hard-coding a simple "patch") in order to allow one to specify particular absolute paths to tar(1) and patch(1) via "macros"
        file.

2. Add support for patch(1)'s "-d" option (for changing into a sub-dir
        before applying the patch) in %patch macros.

    PS: The expansion of %{__tar} and %{__patch} soon might
        be replaced with a more elegant approach, too.

  Summary:
    Revision    Changes     Path
    1.1388      +2  -0      rpm/CHANGES
    2.74        +42 -10     rpm/build/parsePrep.c
______________________________________________________________________ ______

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
====================================================================== ======
  $ cvs diff -u -r1.1387 -r1.1388 CHANGES
  --- rpm/CHANGES       21 Jun 2007 15:55:29 -0000      1.1387
  +++ rpm/CHANGES       21 Jun 2007 18:08:37 -0000      1.1388
  @@ -1,4 +1,6 @@
   4.5 -> 5.0:
+ - rse: allow actually used tar(1) and patch(1) tools to be set via %__tar and %__patch + - rse: add support for patch(1)'s "-d" option to internal macro %patch
       - fray: allow -bb --short-circuit
- rse: allow leading whitespaces on %setup and %patch lines in *.spec files - rse: resolve portability issue related to double definition of mergesort(3)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/build/parsePrep.c
====================================================================== ======
  $ cvs diff -u -r2.73 -r2.74 parsePrep.c
  --- rpm/build/parsePrep.c     21 Jun 2007 13:53:44 -0000      2.73
  +++ rpm/build/parsePrep.c     21 Jun 2007 18:08:38 -0000      2.74
  @@ -68,7 +68,7 @@
   /[EMAIL PROTECTED]@*/
   /[EMAIL PROTECTED]@*/
   static char *doPatch(Spec spec, int c, int strip, const char *db,
  -                  int reverse, int removeEmpties, int fuzz)
+ int reverse, int removeEmpties, int fuzz, const char *subdir) /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
        /[EMAIL PROTECTED] rpmGlobalMacroContext, fileSystem, internalState @*/
   {
  @@ -78,6 +78,7 @@
       struct Source *sp;
       rpmCompressedMagic compressed = COMPRESSED_NOT;
       int urltype;
  +    const char *patch;

       *t = '\0';
       if (db) {
  @@ -86,6 +87,8 @@
   #endif
        t = stpcpy( stpcpy(t, "--suffix "), db);
       }
  +    if (subdir)
  +     t = stpcpy( stpcpy(t, "-d "), subdir);
       if (fuzz) {
        t = stpcpy(t, "-F ");
        sprintf(t, "%10.10d", fuzz);
  @@ -129,6 +132,10 @@
        /[EMAIL PROTECTED]@*/ break;
       }

  +    patch = rpmGetPath("%{__patch}", NULL);
  +    if (strcmp(patch, "%{__patch}") == 0)
  +        patch = "patch";
  +
       if (compressed) {
        const char *zipper;

  @@ -153,22 +160,23 @@

        sprintf(buf,
                "echo \"Patch #%d (%s):\"\n"
  -             "%s -d < '%s' | patch -p%d %s -s\n"
  +             "%s -d < '%s' | %s -p%d %s -s\n"
                "STATUS=$?\n"
                "if [ $STATUS -ne 0 ]; then\n"
                "  exit $STATUS\n"
                "fi",
                c, /[EMAIL PROTECTED]@*/ (const char *) basename(fn), /[EMAIL 
PROTECTED]@*/
                zipper,
  -             fn, strip, args);
  +             fn, patch, strip, args);
        zipper = _free(zipper);
       } else {
        sprintf(buf,
                "echo \"Patch #%d (%s):\"\n"
  -             "patch -p%d %s -s < '%s'", c, (const char *) basename(fn),
  -             strip, args, fn);
  +             "%s -p%d %s -s < '%s'", c, (const char *) basename(fn),
  +             patch, strip, args, fn);
       }

  +    patch = _free(patch);
       Lurlfn = _free(Lurlfn);
       return buf;
   }
  @@ -194,6 +202,7 @@
       struct Source *sp;
       rpmCompressedMagic compressed = COMPRESSED_NOT;
       int urltype;
  +    const char *tar;

       for (sp = spec->sources; sp != NULL; sp = sp->next) {
        if ((sp->flags & RPMFILE_SOURCE) && (sp->num == c)) {
  @@ -233,6 +242,10 @@
        /[EMAIL PROTECTED]@*/ break;
       }

  +    tar = rpmGetPath("%{_tarbin}", NULL);
  +    if (strcmp(tar, "%{_tarbin}") == 0)
  +        tar = "tar";
  +
       if (compressed != COMPRESSED_NOT) {
        const char *zipper;
        int needtar = 1;
  @@ -267,8 +280,13 @@
        *t++ = '\'';
        t = stpcpy(t, fn);
        *t++ = '\'';
  -     if (needtar)
  -         t = stpcpy( stpcpy( stpcpy(t, " | tar "), taropts), " -");
  +     if (needtar) {
  +         t = stpcpy(t, " | ");
  +         t = stpcpy(t, tar);
  +         t = stpcpy(t, " ");
  +         t = stpcpy(t, taropts);
  +         t = stpcpy(t, " -");
  +        }
        t = stpcpy(t,
                "\n"
                "STATUS=$?\n"
  @@ -277,11 +295,14 @@
                "fi");
       } else {
        buf[0] = '\0';
  -     t = stpcpy( stpcpy(buf, "tar "), taropts);
  +     t = stpcpy(buf, tar);
  +     t = stpcpy(t, " ");
  +     t = stpcpy(t, taropts);
        *t++ = ' ';
        t = stpcpy(t, fn);
       }

  +    tar = _free(tar);
       Lurlfn = _free(Lurlfn);
       return buf;
   }
  @@ -457,6 +478,7 @@
                fileSystem, internalState  @*/
   {
       char *opt_b;
  +    char *opt_d;
       int opt_P, opt_p, opt_R, opt_E, opt_F;
       char *s;
       char buf[BUFSIZ], *bp;
  @@ -466,6 +488,7 @@
       memset(patch_nums, 0, sizeof(patch_nums));
       opt_P = opt_p = opt_R = opt_E = opt_F = 0;
       opt_b = NULL;
  +    opt_d = NULL;
       patch_index = 0;

       if (! strchr(" \t\n", line[6])) {
  @@ -518,6 +541,15 @@
                        spec->lineNum, spec->line);
                return RPMERR_BADSPEC;
            }
  +     } else if (!strcmp(s, "-d")) {
  +         /* subdirectory */
  +         opt_d = strtok(NULL, " \t\n");
  +         if (! opt_d) {
  +             rpmError(RPMERR_BADSPEC,
  +                     _("line %d: Need arg to %%patch -d: %s\n"),
  +                     spec->lineNum, spec->line);
  +             return RPMERR_BADSPEC;
  +         }
        } else if (!strncmp(s, "-p", sizeof("-p")-1)) {
            /* unfortunately, we must support -pX */
            if (! strchr(" \t\n", s[2])) {
  @@ -556,14 +588,14 @@
       /* All args processed */

       if (! opt_P) {
  -     s = doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F);
  +     s = doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
        if (s == NULL)
            return RPMERR_BADSPEC;
        appendLineStringBuf(spec->prep, s);
       }

       for (x = 0; x < patch_index; x++) {
- s = doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F); + s = doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E, opt_F, opt_d);
        if (s == NULL)
            return RPMERR_BADSPEC;
        appendLineStringBuf(spec->prep, s);
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [EMAIL PROTECTED]

______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
Developer Communication List                        rpm-devel@rpm5.org

Reply via email to