Main Page Modules Data Structures File List Data Fields Globals Related Pages

# 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 /*@-boundsread@*/
    00081         while (len > 0) {
    00082             len--;
    00083             if (strcmp(names[len], depName))
    00084                 continue;
    00085             if (flagtag && versions != NULL &&
    00086                 (strcmp(versions[len], depEVR) ||
    00087         ((flags[len] | RPMSENSE_MULTILIB) != (depFlags | RPMSENSE_MULTILIB))))
    00088                 continue;
    00089             if (indextag && indexes != NULL && indexes[len] != index)
    00090                 continue;
    00091
    00092             /* This is a duplicate dependency. */
    00093             duplicate = 1;
    00094
    00095             if (flagtag && isDependsMULTILIB(depFlags) &&
    00096                 !isDependsMULTILIB(flags[len]))
    00097                     flags[len] |= RPMSENSE_MULTILIB;
    00098
    00099             break;
    00100         }
    00101 /*@=boundsread@*/
    00102         names = hfd(names, dnt);
    00103         versions = hfd(versions, dvt);
    00104         if (duplicate)
    00105             return 0;
    00106     }
    00107
    00108     /* Add this dependency. */
    00109     xx = headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &depName, 1);
    00110     if (flagtag) {
    00111         xx = headerAddOrAppendEntry(h, versiontag,
    00112                                RPM_STRING_ARRAY_TYPE, &depEVR, 1);
    00113         xx = headerAddOrAppendEntry(h, flagtag,
    00114                                RPM_INT32_TYPE, &depFlags, 1);
    00115     }
    00116     if (indextag)
    00117         xx = headerAddOrAppendEntry(h, indextag, RPM_INT32_TYPE, &index, 1);
    00118
    00119     return 0;
    00120 }
    00121
    00122 /*@-boundswrite@*/
    00123 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
    00124 {
    00125     char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
    00126
    00127     (void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
    00128
    00129     /* XXX 1st arg is unused */
    00130    return addReqProv(NULL, h, RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL),
    00131         reqname, featureEVR, 0);
    00132 }
    00133 /*@=boundswrite@*/