2 * \file build/parseReqs.c
3 * Parse dependency tag from spec file or from auto-dependency generator.
8 #include <rpm/rpmtypes.h>
9 #include <rpm/rpmbuild.h>
10 #include <rpm/rpmlog.h>
15 static struct ReqComp {
18 } const ReqComparisons[] = {
19 { "<=", RPMSENSE_LESS | RPMSENSE_EQUAL},
20 { "=<", RPMSENSE_LESS | RPMSENSE_EQUAL},
21 { "<", RPMSENSE_LESS},
23 { "==", RPMSENSE_EQUAL},
24 { "=", RPMSENSE_EQUAL},
26 { ">=", RPMSENSE_GREATER | RPMSENSE_EQUAL},
27 { "=>", RPMSENSE_GREATER | RPMSENSE_EQUAL},
28 { ">", RPMSENSE_GREATER},
33 #define SKIPWHITE(_x) {while(*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
34 #define SKIPNONWHITE(_x){while(*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
36 rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char *field, rpmTag tagN,
37 int index, rpmsenseFlags tagflags)
39 const char *r, *re, *v, *ve;
45 case RPMTAG_PROVIDEFLAGS:
46 tagflags |= RPMSENSE_PROVIDES;
49 case RPMTAG_OBSOLETEFLAGS:
50 tagflags |= RPMSENSE_OBSOLETES;
53 case RPMTAG_CONFLICTFLAGS:
54 tagflags |= RPMSENSE_CONFLICTS;
57 case RPMTAG_BUILDCONFLICTS:
58 tagflags |= RPMSENSE_CONFLICTS;
59 h = spec->buildRestrictions;
62 /* XXX map legacy PreReq into Requires(pre,preun) */
63 tagflags |= (RPMSENSE_SCRIPT_PRE|RPMSENSE_SCRIPT_PREUN);
66 case RPMTAG_TRIGGERPREIN:
67 tagflags |= RPMSENSE_TRIGGERPREIN;
70 case RPMTAG_TRIGGERIN:
71 tagflags |= RPMSENSE_TRIGGERIN;
74 case RPMTAG_TRIGGERPOSTUN:
75 tagflags |= RPMSENSE_TRIGGERPOSTUN;
78 case RPMTAG_TRIGGERUN:
79 tagflags |= RPMSENSE_TRIGGERUN;
82 case RPMTAG_BUILDPREREQ:
83 case RPMTAG_BUILDREQUIRES:
84 tagflags |= RPMSENSE_ANY;
85 h = spec->buildRestrictions;
88 case RPMTAG_REQUIREFLAGS:
89 tagflags |= RPMSENSE_ANY;
94 for (r = field; *r != '\0'; r = re) {
99 Flags = (tagflags & ~RPMSENSE_SENSEMASK);
102 * Tokens must begin with alphanumeric, _, or /, but we don't know
103 * the spec's encoding so we only check what we can: plain ascii.
105 if (isascii(r[0]) && !(risalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
107 _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
108 spec->lineNum, spec->line);
114 N = xmalloc((re-r) + 1);
115 rstrlcpy(N, r, (re-r) + 1);
117 /* Check for weird characters in Requires/Provides, etc.*/
119 if (charCheck(spec, N, re-r, ".-_+()")) return RPMRC_FAIL;
128 re = v; /* ==> next token (if no EVR found) starts here */
130 /* Check for possible logical operator */
132 const struct ReqComp *rc;
133 for (rc = ReqComparisons; rc->token != NULL; rc++) {
134 if ((ve-v) != strlen(rc->token) || strncmp(v, rc->token, (ve-v)))
139 _("line %d: Versioned file name not permitted: %s\n"),
140 spec->lineNum, spec->line);
145 case RPMTAG_BUILDPREREQ:
147 case RPMTAG_PROVIDEFLAGS:
148 case RPMTAG_OBSOLETEFLAGS:
149 /* Add prereq on rpmlib that has versioned dependencies. */
150 if (!rpmExpandNumeric("%{?_noVersionedDependencies}"))
151 (void) rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
167 if (Flags & RPMSENSE_SENSEMASK) {
168 if (*v == '\0' || ve == v) {
169 rpmlog(RPMLOG_ERR, _("line %d: Version required: %s\n"),
170 spec->lineNum, spec->line);
173 EVR = xmalloc((ve-v) + 1);
174 rstrlcpy(EVR, v, (ve-v) + 1);
175 if (charCheck(spec, N, ve-v, ".-_+")) return RPMRC_FAIL;
176 re = ve; /* ==> next token after EVR string starts here */
180 (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);