# build/reqprov.c

Go to the documentation of this file.

    00001
    00006 #include "system.h"
    00007
    00008 #include "rpmbuild.h"
    00009 #include "debug.h"
    00010
    00011 int addReqProv(/*@unused@*/ Spec spec, Header h,
    00012                rpmsenseFlags depFlags, const char *depName, const char *depEVR,
    00013                 int index)
    00014 {
    00015     HGE_t hge = (HGE_t)headerGetEntryMinMemory;
    00016     HFD_t hfd = headerFreeData;
    00017     const char ** names;
    00018     rpmTagType dnt;
    00019     rpmTag nametag = 0;
    00020     rpmTag versiontag = 0;
    00021     rpmTag flagtag = 0;
    00022     rpmTag indextag = 0;
    00023     int len;
    00024     rpmsenseFlags extra = RPMSENSE_ANY;
    00025     int xx;
    00026
    00027     if (depFlags & RPMSENSE_PROVIDES) {
    00028         nametag = RPMTAG_PROVIDENAME;
    00029         versiontag = RPMTAG_PROVIDEVERSION;
    00030         flagtag = RPMTAG_PROVIDEFLAGS;
    00031         extra = depFlags & RPMSENSE_FIND_PROVIDES;
    00032     } else if (depFlags & RPMSENSE_OBSOLETES) {
    00033         nametag = RPMTAG_OBSOLETENAME;
    00034         versiontag = RPMTAG_OBSOLETEVERSION;
    00035         flagtag = RPMTAG_OBSOLETEFLAGS;
    00036     } else if (depFlags & RPMSENSE_CONFLICTS) {
    00037         nametag = RPMTAG_CONFLICTNAME;
    00038         versiontag = RPMTAG_CONFLICTVERSION;
    00039         flagtag = RPMTAG_CONFLICTFLAGS;
    00040     } else if (depFlags & RPMSENSE_PREREQ) {
    00041         nametag = RPMTAG_REQUIRENAME;
    00042         versiontag = RPMTAG_REQUIREVERSION;
    00043         flagtag = RPMTAG_REQUIREFLAGS;
    00044         extra = depFlags & _ALL_REQUIRES_MASK;
    00045     } else if (depFlags & RPMSENSE_TRIGGER) {
    00046         nametag = RPMTAG_TRIGGERNAME;
    00047         versiontag = RPMTAG_TRIGGERVERSION;
    00048         flagtag = RPMTAG_TRIGGERFLAGS;
    00049         indextag = RPMTAG_TRIGGERINDEX;
    00050         extra = depFlags & RPMSENSE_TRIGGER;
    00051     } else {
    00052         nametag = RPMTAG_REQUIRENAME;
    00053         versiontag = RPMTAG_REQUIREVERSION;
    00054         flagtag = RPMTAG_REQUIREFLAGS;
    00055         extra = depFlags & _ALL_REQUIRES_MASK;
    00056     }
    00057
    00058     depFlags = (depFlags & (RPMSENSE_SENSEMASK | RPMSENSE_MULTILIB)) | extra;
    00059
    00060     /*@-branchstate@*/
    00061     if (depEVR == NULL)
    00062         depEVR = "";
    00063     /*@=branchstate@*/
    00064
    00065     /* Check for duplicate dependencies. */
    00066     if (hge(h, nametag, &dnt, (void **) &names, &len)) {
    00067         const char ** versions = NULL;
    00068         rpmTagType dvt = RPM_STRING_ARRAY_TYPE;
    00069         int *flags = NULL;
    00070         int *indexes = NULL;
    00071         int duplicate = 0;
    00072
    00073         if (flagtag) {
    00074             xx = hge(h, versiontag, &dvt, (void **) &versions, NULL);
    00075             xx = hge(h, flagtag, NULL, (void **) &flags, NULL);
    00076         }
    00077         if (indextag)
    00078             xx = hge(h, indextag, NULL, (void **) &indexes, NULL);
    00079
    00080         while (len > 0) {
    00081             len--;
    00082             if (strcmp(names[len], depName))
    00083                 continue;
    00084             if (flagtag && versions != NULL &&
    00085                 (strcmp(versions[len], depEVR) ||
    00086         ((flags[len] | RPMSENSE_MULTILIB) != (depFlags | RPMSENSE_MULTILIB))))
    00087                 continue;
    00088             if (indextag && indexes != NULL && indexes[len] != index)
    00089                 continue;
    00090
    00091             /* This is a duplicate dependency. */
    00092             duplicate = 1;
    00093
    00094             if (flagtag && isDependsMULTILIB(depFlags) &&
    00095                 !isDependsMULTILIB(flags[len]))
    00096                     flags[len] |= RPMSENSE_MULTILIB;
    00097
    00098             break;
    00099         }
    00100         names = hfd(names, dnt);
    00101         versions = hfd(versions, dvt);
    00102         if (duplicate)
    00103             return 0;
    00104     }
    00105
    00106     /* Add this dependency. */
    00107     xx = headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &depName, 1);
    00108     if (flagtag) {
    00109         xx = headerAddOrAppendEntry(h, versiontag,
    00110                                RPM_STRING_ARRAY_TYPE, &depEVR, 1);
    00111         xx = headerAddOrAppendEntry(h, flagtag,
    00112                                RPM_INT32_TYPE, &depFlags, 1);
    00113     }
    00114     if (indextag)
    00115         xx = headerAddOrAppendEntry(h, indextag, RPM_INT32_TYPE, &index, 1);
    00116
    00117     return 0;
    00118 }
    00119
    00120 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
    00121 {
    00122     char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
    00123
    00124     (void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
    00125
    00126     /* XXX 1st arg is unused */
    00127    return addReqProv(NULL, h, RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL),
    00128         reqname, featureEVR, 0);
    00129 }