RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: [EMAIL PROTECTED] Module: rpm Date: 22-Jul-2007 03:39:29 Branch: HEAD Handle: 2007072202392900 Modified files: rpm/build parsePrep.c Log: revert 2.79. Summary: Revision Changes Path 2.86 +276 -2 rpm/build/parsePrep.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/build/parsePrep.c ============================================================================ $ cvs diff -u -r2.85 -r2.86 parsePrep.c --- rpm/build/parsePrep.c 22 Jul 2007 01:20:04 -0000 2.85 +++ rpm/build/parsePrep.c 22 Jul 2007 01:39:29 -0000 2.86 @@ -54,6 +54,132 @@ return 0; } +#ifdef DYING +/** + * Expand %patchN macro into %prep scriptlet. + * @param spec build info + * @param c patch index + * @param strip patch level (i.e. patch -p argument) + * @param db saved file suffix (i.e. patch --suffix argument) + * @param reverse include -R? + * @param removeEmpties include -E? + * @param fuzz include -F? + * @return expanded %patch macro (NULL on error) + */ +/[EMAIL PROTECTED]@*/ +/[EMAIL PROTECTED]@*/ +static char *doPatch(Spec spec, int c, int strip, const char *db, + int reverse, int removeEmpties, int fuzz, const char *subdir) + /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ + /[EMAIL PROTECTED] rpmGlobalMacroContext, fileSystem, internalState @*/ +{ + const char *fn, *Lurlfn; + static char buf[BUFSIZ]; + char args[BUFSIZ], *t = args; + struct Source *sp; + rpmCompressedMagic compressed = COMPRESSED_NOT; + int urltype; + const char *patch; + + *t = '\0'; + if (db) + t = stpcpy( stpcpy(t, "-b --suffix "), db); + if (subdir) + t = stpcpy( stpcpy(t, "-d "), subdir); + if (fuzz) { + t = stpcpy(t, "-F "); + sprintf(t, "%10.10d", fuzz); + t += strlen(t); + } + if (reverse) + t = stpcpy(t, " -R"); + if (removeEmpties) + t = stpcpy(t, " -E"); + + for (sp = spec->sources; sp != NULL; sp = sp->next) { + if ((sp->flags & RPMFILE_PATCH) && (sp->num == c)) + break; + } + if (sp == NULL) { + rpmError(RPMERR_BADSPEC, _("No patch number %d\n"), c); + return NULL; + } + + Lurlfn = rpmGenPath(NULL, "%{_patchdir}/", sp->source); + + /* XXX On non-build parse's, file cannot be stat'd or read */ + if (!spec->force && (isCompressed(Lurlfn, &compressed) || checkOwners(Lurlfn))) { + Lurlfn = _free(Lurlfn); + return NULL; + } + + fn = NULL; + urltype = urlPath(Lurlfn, &fn); + switch (urltype) { + case URL_IS_HTTPS: /* XXX WRONG WRONG WRONG */ + case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */ + case URL_IS_FTP: /* XXX WRONG WRONG WRONG */ + case URL_IS_HKP: /* XXX WRONG WRONG WRONG */ + case URL_IS_PATH: + case URL_IS_UNKNOWN: + break; + case URL_IS_DASH: + Lurlfn = _free(Lurlfn); + return NULL; + /[EMAIL PROTECTED]@*/ break; + } + + patch = rpmGetPath("%{__patch}", NULL); + if (strcmp(patch, "%{__patch}") == 0) + patch = xstrdup("patch"); + + if (compressed) { + const char *zipper; + + switch (compressed) { + default: + case COMPRESSED_NOT: /* XXX can't happen */ + case COMPRESSED_OTHER: + case COMPRESSED_ZIP: /* XXX wrong */ + zipper = "%{__gzip}"; + break; + case COMPRESSED_BZIP2: + zipper = "%{__bzip2}"; + break; + case COMPRESSED_LZOP: + zipper = "%{__lzop}"; + break; + case COMPRESSED_LZMA: + zipper = "%{__lzma}"; + break; + } + zipper = rpmGetPath(zipper, NULL); + + sprintf(buf, + "echo \"Patch #%d (%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, patch, strip, args); + zipper = _free(zipper); + } else { + sprintf(buf, + "echo \"Patch #%d (%s):\"\n" + "%s -p%d %s -s < '%s'", c, (const char *) basename(fn), + patch, strip, args, fn); + } + + patch = _free(patch); + Lurlfn = _free(Lurlfn); + return buf; +} +/[EMAIL PROTECTED]@*/ +#endif + /** * Expand %setup macro into %prep scriptlet. * @param spec build info @@ -341,6 +467,149 @@ return 0; } +#ifdef DYING +/** + * Parse %patch line. + * @param spec build info + * @param line current line from spec file + * @return 0 on success + */ +/[EMAIL PROTECTED]@*/ +static int doPatchMacro(Spec spec, char *line) + /[EMAIL PROTECTED] rpmGlobalMacroContext, h_errno, + fileSystem, internalState @*/ + /[EMAIL PROTECTED] spec->prep, rpmGlobalMacroContext, + fileSystem, internalState @*/ +{ + char *s; + char *opt_b; + char *opt_d; + int opt_P, opt_p, opt_R, opt_E, opt_F; + char buf[BUFSIZ], *bp; + int patch_nums[1024]; /* XXX - we can only handle 1024 patches! */ + int patch_index, x; + + 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])) { + /* %patchN */ + sprintf(buf, "%%patch -P %s", line + 6); + } else { + strcpy(buf, line); + } + + /[EMAIL PROTECTED]@*/ /* FIX: strtok has state */ + for (bp = buf; (s = strtok(bp, " \t\n")) != NULL;) { + if (bp) { /* remove 1st token (%patch) */ + bp = NULL; + continue; + } + if (!strcmp(s, "-P")) { + opt_P = 1; + } else if (!strcmp(s, "-R")) { + opt_R = 1; + } else if (!strcmp(s, "-E")) { + opt_E = 1; + } else if (!strcmp(s, "-b")) { + /* orig suffix */ + opt_b = strtok(NULL, " \t\n"); + if (! opt_b) { + rpmError(RPMERR_BADSPEC, + _("line %d: Need arg to %%patch -b: %s\n"), + spec->lineNum, spec->line); + return RPMERR_BADSPEC; + } + } else if (!strcmp(s, "-z")) { + /* orig suffix */ + opt_b = strtok(NULL, " \t\n"); + if (! opt_b) { + rpmError(RPMERR_BADSPEC, + _("line %d: Need arg to %%patch -z: %s\n"), + spec->lineNum, spec->line); + return RPMERR_BADSPEC; + } + } else if (!strcmp(s, "-F")) { + /* fuzz factor */ + const char * fnum = (!strchr(" \t\n", s[2]) + ? s+2 : strtok(NULL, " \t\n")); + char * end = NULL; + + opt_F = (fnum ? strtol(fnum, &end, 10) : 0); + if (! opt_F || *end) { + rpmError(RPMERR_BADSPEC, + _("line %d: Bad arg to %%patch -F: %s\n"), + 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])) { + s = s + 2; + } else { + s = strtok(NULL, " \t\n"); + if (s == NULL) { + rpmError(RPMERR_BADSPEC, + _("line %d: Need arg to %%patch -p: %s\n"), + spec->lineNum, spec->line); + return RPMERR_BADSPEC; + } + } + if (parseNum(s, &opt_p)) { + rpmError(RPMERR_BADSPEC, + _("line %d: Bad arg to %%patch -p: %s\n"), + spec->lineNum, spec->line); + return RPMERR_BADSPEC; + } + } else { + /* Must be a patch num */ + if (patch_index == 1024) { + rpmError(RPMERR_BADSPEC, _("Too many patches!\n")); + return RPMERR_BADSPEC; + } + if (parseNum(s, &(patch_nums[patch_index]))) { + rpmError(RPMERR_BADSPEC, _("line %d: Bad arg to %%patch: %s\n"), + spec->lineNum, spec->line); + return RPMERR_BADSPEC; + } + patch_index++; + } + } + /[EMAIL PROTECTED]@*/ + + /* All args processed */ + + if (! opt_P) { + 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, opt_d); + if (s == NULL) + return RPMERR_BADSPEC; + appendLineStringBuf(spec->prep, s); + } + + return 0; +} +/[EMAIL PROTECTED]@*/ +#endif + /** * Check that all sources/patches/icons exist locally, fetching if necessary. */ @@ -485,10 +754,15 @@ for (cp = *lines; *cp == ' ' || *cp == '\t'; cp++) ; /[EMAIL PROTECTED]@*/ - if (! strncmp(cp, "%setup", sizeof("%setup")-1)) + if (! strncmp(cp, "%setup", sizeof("%setup")-1)) { res = doSetupMacro(spec, cp); - else +#ifdef DYING + } else if (! strncmp(cp, "%patch", sizeof("%patch")-1)) { + res = doPatchMacro(spec, cp); +#endif + } else { appendLineStringBuf(spec->prep, *lines); + } /[EMAIL PROTECTED]@*/ if (res && !spec->force) { freeSplitString(saveLines); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org