190 lines
5.3 KiB
C
190 lines
5.3 KiB
C
/** \ingroup rpmbuild
|
|
* \file build/reqprov.c
|
|
* Add dependency tags to package header(s).
|
|
*/
|
|
|
|
#include "system.h"
|
|
|
|
#include "rpmbuild.h"
|
|
#include "debug.h"
|
|
|
|
int addReqProv(/*@unused@*/ Spec spec, Header h,
|
|
rpmsenseFlags depFlags, const char *depName, const char *depEVR,
|
|
int index)
|
|
{
|
|
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
|
|
HFD_t hfd = headerFreeData;
|
|
const char ** names;
|
|
rpmTagType dnt;
|
|
rpmTag nametag = 0;
|
|
rpmTag versiontag = 0;
|
|
rpmTag flagtag = 0;
|
|
rpmTag indextag = 0;
|
|
int len;
|
|
rpmsenseFlags extra = RPMSENSE_ANY;
|
|
int xx;
|
|
|
|
if (depFlags & RPMSENSE_PROVIDES) {
|
|
nametag = RPMTAG_PROVIDENAME;
|
|
versiontag = RPMTAG_PROVIDEVERSION;
|
|
flagtag = RPMTAG_PROVIDEFLAGS;
|
|
extra = depFlags & RPMSENSE_FIND_PROVIDES;
|
|
} else if (depFlags & RPMSENSE_OBSOLETES) {
|
|
nametag = RPMTAG_OBSOLETENAME;
|
|
versiontag = RPMTAG_OBSOLETEVERSION;
|
|
flagtag = RPMTAG_OBSOLETEFLAGS;
|
|
} else if (depFlags & RPMSENSE_CONFLICTS) {
|
|
nametag = RPMTAG_CONFLICTNAME;
|
|
versiontag = RPMTAG_CONFLICTVERSION;
|
|
flagtag = RPMTAG_CONFLICTFLAGS;
|
|
} else if (depFlags & RPMSENSE_PREREQ) {
|
|
nametag = RPMTAG_REQUIRENAME;
|
|
versiontag = RPMTAG_REQUIREVERSION;
|
|
flagtag = RPMTAG_REQUIREFLAGS;
|
|
extra = depFlags & _ALL_REQUIRES_MASK;
|
|
} else if (depFlags & RPMSENSE_TRIGGER) {
|
|
nametag = RPMTAG_TRIGGERNAME;
|
|
versiontag = RPMTAG_TRIGGERVERSION;
|
|
flagtag = RPMTAG_TRIGGERFLAGS;
|
|
indextag = RPMTAG_TRIGGERINDEX;
|
|
extra = depFlags & RPMSENSE_TRIGGER;
|
|
} else {
|
|
nametag = RPMTAG_REQUIRENAME;
|
|
versiontag = RPMTAG_REQUIREVERSION;
|
|
flagtag = RPMTAG_REQUIREFLAGS;
|
|
extra = depFlags & _ALL_REQUIRES_MASK;
|
|
}
|
|
|
|
depFlags = (depFlags & (RPMSENSE_SENSEMASK | RPMSENSE_MULTILIB)) | extra;
|
|
|
|
/*@-branchstate@*/
|
|
if (depEVR == NULL)
|
|
depEVR = "";
|
|
/*@=branchstate@*/
|
|
|
|
/* Check for duplicate dependencies. */
|
|
if (hge(h, nametag, &dnt, (void **) &names, &len)) {
|
|
const char ** versions = NULL;
|
|
rpmTagType dvt = RPM_STRING_ARRAY_TYPE;
|
|
int *flags = NULL;
|
|
int *indexes = NULL;
|
|
int duplicate = 0;
|
|
rpmsenseFlags sense_mask = ~(RPMSENSE_FIND_REQUIRES | RPMSENSE_FIND_PROVIDES | RPMSENSE_MULTILIB);
|
|
|
|
if (flagtag) {
|
|
xx = hge(h, versiontag, &dvt, (void **) &versions, NULL);
|
|
xx = hge(h, flagtag, NULL, (void **) &flags, NULL);
|
|
}
|
|
if (indextag)
|
|
xx = hge(h, indextag, NULL, (void **) &indexes, NULL);
|
|
|
|
while (len > 0) {
|
|
len--;
|
|
if (indextag && indexes && indexes[len] != index)
|
|
continue;
|
|
|
|
if (strcmp(names[len], depName))
|
|
continue;
|
|
|
|
if (flagtag && flags) {
|
|
rpmsenseFlags old_flags = flags[len] & sense_mask;
|
|
rpmsenseFlags new_flags = depFlags & sense_mask;
|
|
if (old_flags != new_flags) {
|
|
if ((old_flags & ~RPMSENSE_SENSEMASK) != (new_flags & ~RPMSENSE_SENSEMASK))
|
|
continue;
|
|
/* flags differ by RPMSENSE_SENSEMASK only */
|
|
if ((new_flags & sense_mask & (_ALL_REQUIRES_MASK | RPMSENSE_PREREQ)) ||
|
|
!(new_flags & sense_mask & ~RPMSENSE_SENSEMASK)) {
|
|
/* some kind of requires */
|
|
if (new_flags & RPMSENSE_SENSEMASK)
|
|
continue;
|
|
}
|
|
else
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (flagtag && versions) {
|
|
if (*depEVR && strcmp (versions[len], depEVR))
|
|
continue;
|
|
if (!*depEVR && *versions[len] && (depFlags & ~(sense_mask | _ALL_REQUIRES_MASK | RPMSENSE_PREREQ | RPMSENSE_SENSEMASK)))
|
|
continue;
|
|
}
|
|
|
|
/* This is a duplicate dependency. */
|
|
duplicate = 1;
|
|
|
|
if (flagtag && isDependsMULTILIB(depFlags) &&
|
|
!isDependsMULTILIB(flags[len]))
|
|
flags[len] |= RPMSENSE_MULTILIB;
|
|
|
|
break;
|
|
}
|
|
names = hfd(names, dnt);
|
|
versions = hfd(versions, dvt);
|
|
if (duplicate)
|
|
return 0;
|
|
}
|
|
|
|
/* Do not add provided requires. */
|
|
if ((nametag == RPMTAG_REQUIRENAME) &&
|
|
(flagtag == RPMTAG_REQUIREFLAGS) &&
|
|
!(depFlags & _notpre(RPMSENSE_RPMLIB | RPMSENSE_KEYRING | RPMSENSE_SCRIPT_PRE | RPMSENSE_SCRIPT_POSTUN)) &&
|
|
!isLegacyPreReq(depFlags) &&
|
|
hge(h, RPMTAG_PROVIDENAME, &dnt, (void **) &names, &len)) {
|
|
|
|
int skip = 0;
|
|
int *flags = 0;
|
|
const char ** versions = 0;
|
|
rpmTagType dvt = RPM_STRING_ARRAY_TYPE;
|
|
|
|
hge(h, RPMTAG_PROVIDEVERSION, &dvt, (void **) &versions, NULL);
|
|
hge(h, RPMTAG_PROVIDEFLAGS, NULL, (void **) &flags, NULL);
|
|
|
|
while (flags && versions && (len > 0)) {
|
|
--len;
|
|
|
|
if (strcmp (depName, names[len]))
|
|
continue;
|
|
if (!(depFlags & RPMSENSE_SENSEMASK)) {
|
|
skip = 1;
|
|
break;
|
|
}
|
|
if (!(flags[len] & RPMSENSE_SENSEMASK))
|
|
continue;
|
|
if (rpmRangesOverlap (names[len], versions[len], flags[len], depName, depEVR, depFlags)) {
|
|
skip = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
versions = hfd(versions, dvt);
|
|
names = hfd(names, dnt);
|
|
if (skip) return 0;
|
|
}
|
|
|
|
/* Add this dependency. */
|
|
xx = headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &depName, 1);
|
|
if (flagtag) {
|
|
xx = headerAddOrAppendEntry(h, versiontag,
|
|
RPM_STRING_ARRAY_TYPE, &depEVR, 1);
|
|
xx = headerAddOrAppendEntry(h, flagtag,
|
|
RPM_INT32_TYPE, &depFlags, 1);
|
|
}
|
|
if (indextag)
|
|
xx = headerAddOrAppendEntry(h, indextag, RPM_INT32_TYPE, &index, 1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
|
|
{
|
|
char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
|
|
|
|
(void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
|
|
|
|
/* XXX 1st arg is unused */
|
|
return addReqProv(NULL, h, RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL),
|
|
reqname, featureEVR, 0);
|
|
}
|