1 diff -dur rpm-4.3.orig/build/rpmfc.c rpm-4.3/build/rpmfc.c
2 --- rpm-4.3.orig/build/rpmfc.c 2004-01-16 14:21:42.283166337 +0100
3 +++ rpm-4.3/build/rpmfc.c 2004-01-16 14:38:10.000000000 +0100
7 #include <signal.h> /* getOutputFrom() */
13 #define _RPMDS_INTERNAL
25 +regex_t * rpmfcExpandRegexps(const char * str,int *count){
28 + ARGV_t patterns=NULL;
29 + regex_t *compiled=NULL;
31 + s=rpmExpand(str,NULL);
33 + poptParseArgvString(s,count,(const char ***)&patterns);
36 + if (patterns==NULL){
45 + compiled=malloc(sizeof(regex_t)*(*count));
47 + for(i=0;i<*count;i++){
48 + r=regcomp(&compiled[j],patterns[i],REG_NOSUB);
51 + rpmMessage(RPMMESS_NORMAL,
52 + "Compilation of regular expresion '%s'"
53 + " (expanded from '%s') failed. Skipping it.\n",
57 + patterns=_free(patterns);
59 + compiled=_free(compiled);
67 +regex_t * rpmfcFreeRegexps(regex_t *regexps,int count){
71 + for(i=0;i<count;i++)
72 + regfree(®exps[i]);
73 + return _free(regexps);
77 * Run per-interpreter dependency helper.
78 * @param fc file classifier
84 + regex_t *noauto=NULL;
93 + noauto=rpmfcExpandRegexps("%{_noautoprov}",&noauto_c);
94 + rpmMessage(RPMMESS_DEBUG, "%i _noautoprov patterns.\n",noauto_c);
95 xx = snprintf(buf, sizeof(buf), "%%{?__%s_provides}", nsdep);
96 depsp = &fc->provides;
97 dsContext = RPMSENSE_FIND_PROVIDES;
102 + noauto=rpmfcExpandRegexps("%{_noautoreq}",&noauto_c);
103 + rpmMessage(RPMMESS_DEBUG, "%i _noautoreq patterns.\n",noauto_c);
104 xx = snprintf(buf, sizeof(buf), "%%{?__%s_requires}", nsdep);
105 depsp = &fc->requires;
106 dsContext = RPMSENSE_FIND_REQUIRES;
111 + for(j=0;j<noauto_c;j++){
112 + rpmMessage(RPMMESS_DEBUG, "Checking %c: '%s'"
113 + " against _noauto expr. #%i\n",deptype,N,j);
114 + if (!regexec(&noauto[j],N,0,NULL,0)) {
115 + rpmMessage(RPMMESS_NORMAL, "Skipping %c: '%s'"
116 + " as it matches _noauto expr. #%i\n",deptype,N,j);
120 + if (j<noauto_c) continue;
122 /* Add tracking dependency for versioned Provides: */
123 if (!fc->tracked && deptype == 'P' && *EVR != '\0') {
126 sb_stdout = freeStringBuf(sb_stdout);
128 + noauto=rpmfcFreeRegexps(noauto,noauto_c);
134 * Extract script dependencies.
135 * @param fc file classifier
136 + * @param findprov 1 to enable provides
137 + * @param findreq 1 to enable requires
138 * @return 0 on success
140 -static int rpmfcSCRIPT(rpmfc fc)
141 +static int rpmfcSCRIPT(rpmfc fc,int findprov,int findreq)
142 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
143 /*@modifies fc, rpmGlobalMacroContext, fileSystem, internalState @*/
149 - if (is_executable) {
150 + if (is_executable && findreq) {
151 /* Add to package requires. */
152 ds = rpmdsSingle(RPMTAG_REQUIRENAME, s, "", RPMSENSE_FIND_REQUIRES);
153 xx = rpmdsMerge(&fc->requires, ds);
154 @@ -718,19 +792,22 @@
157 if (fc->fcolor->vals[fc->ix] & RPMFC_PERL) {
158 - if (fc->fcolor->vals[fc->ix] & RPMFC_MODULE)
159 + if (findprov && fc->fcolor->vals[fc->ix] & RPMFC_MODULE)
160 xx = rpmfcHelper(fc, 'P', "perl");
161 - if (is_executable || (fc->fcolor->vals[fc->ix] & RPMFC_MODULE))
162 + if (findreq && (is_executable || (fc->fcolor->vals[fc->ix] & RPMFC_MODULE)))
163 xx = rpmfcHelper(fc, 'R', "perl");
165 if (fc->fcolor->vals[fc->ix] & RPMFC_PYTHON) {
166 - xx = rpmfcHelper(fc, 'P', "python");
169 + xx = rpmfcHelper(fc, 'P', "python");
170 + if (findreq && is_executable)
171 xx = rpmfcHelper(fc, 'R', "python");
173 if (fc->fcolor->vals[fc->ix] & RPMFC_PHP) {
175 xx = rpmfcHelper(fc, 'P', "php");
176 - xx = rpmfcHelper(fc, 'R', "php");
178 + xx = rpmfcHelper(fc, 'R', "php");
184 * Extract Elf dependencies.
185 * @param fc file classifier
186 + * @param findprov 1 to enable provides
187 + * @param findreq 1 to enable requires
188 * @return 0 on success
190 -static int rpmfcELF(rpmfc fc)
191 +static int rpmfcELF(rpmfc fc,int findprov,int findreq)
192 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
193 /*@modifies fc, rpmGlobalMacroContext, fileSystem, internalState @*/
195 @@ -853,17 +932,19 @@
196 t = stpcpy(t, "(64bit)");
201 + /* Add to package provides. */
202 + ds = rpmdsSingle(RPMTAG_PROVIDES,
203 + buf, "", RPMSENSE_FIND_PROVIDES);
204 + xx = rpmdsMerge(&fc->provides, ds);
206 - /* Add to package provides. */
207 - ds = rpmdsSingle(RPMTAG_PROVIDES,
208 - buf, "", RPMSENSE_FIND_PROVIDES);
209 - xx = rpmdsMerge(&fc->provides, ds);
211 - /* Add to file dependencies. */
212 - xx = rpmfcSaveArg(&fc->ddict,
213 - rpmfcFileDep(t, fc->ix, ds));
214 + /* Add to file dependencies. */
215 + xx = rpmfcSaveArg(&fc->ddict,
216 + rpmfcFileDep(t, fc->ix, ds));
218 - ds = rpmdsFree(ds);
219 + ds = rpmdsFree(ds);
222 auxoffset += aux->vda_next;
224 @@ -914,15 +995,17 @@
228 - /* Add to package dependencies. */
229 - ds = rpmdsSingle(RPMTAG_REQUIRENAME,
230 - buf, "", RPMSENSE_FIND_REQUIRES);
231 - xx = rpmdsMerge(&fc->requires, ds);
233 + /* Add to package dependencies. */
234 + ds = rpmdsSingle(RPMTAG_REQUIRENAME,
235 + buf, "", RPMSENSE_FIND_REQUIRES);
236 + xx = rpmdsMerge(&fc->requires, ds);
238 - /* Add to file dependencies. */
239 - xx = rpmfcSaveArg(&fc->ddict,
240 - rpmfcFileDep(t, fc->ix, ds));
241 - ds = rpmdsFree(ds);
242 + /* Add to file dependencies. */
243 + xx = rpmfcSaveArg(&fc->ddict,
244 + rpmfcFileDep(t, fc->ix, ds));
245 + ds = rpmdsFree(ds);
248 auxoffset += aux->vna_next;
251 /* Files with executable bit set only. */
252 if (fc->skipReq || !(st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
253 /*@innercontinue@*/ continue;
254 + if (!findreq) continue;
255 /* Add to package requires. */
256 depsp = &fc->requires;
257 tagN = RPMTAG_REQUIRENAME;
259 /* Add to package provides. */
261 /*@innercontinue@*/ continue;
262 + if (!findprov) continue;
263 depsp = &fc->provides;
264 tagN = RPMTAG_PROVIDENAME;
265 dsContext = RPMSENSE_FIND_PROVIDES;
267 /*@=branchstate =uniondef @*/
269 /* For DSO's, provide the basename of the file if DT_SONAME not found. */
270 - if (!fc->skipProv && isDSO && !gotSONAME) {
271 + if (findprov && !fc->skipProv && isDSO && !gotSONAME) {
272 depsp = &fc->provides;
273 tagN = RPMTAG_PROVIDENAME;
274 dsContext = RPMSENSE_FIND_PROVIDES;
275 @@ -1045,7 +1130,7 @@
278 typedef struct rpmfcApplyTbl_s {
279 - int (*func) (rpmfc fc);
280 + int (*func) (rpmfc fc,int findprov,int findreq);
284 @@ -1058,6 +1143,109 @@
288 +int rpmfcFindRequiredPackages(rpmfc fc)
297 + unsigned char deptype;
305 + const char * hname;
306 + rpmdbMatchIterator it;
308 + regex_t *noautoreqdep;
309 + int noautoreqdep_c;
311 + noautoreqdep=rpmfcExpandRegexps("%{_noautoreqdep}",&noautoreqdep_c);
313 + ts = rpmtsCreate(); /* XXX ts created in main() should be used */
315 + rpmMessage(RPMMESS_NORMAL, "Searching for required packages....\n");
317 + nddict = argvCount(fc->ddict);
319 + for (i = 0; i < nddict; i++) {
322 + /* Parse out (file#,deptype,N,EVR,Flags) */
323 + ix = strtol(s, &se, 10);
324 + assert(se != NULL);
328 + while (*se && *se != ' ')
332 + while (*se && *se != ' ')
335 + Flags = strtol(se, NULL, 16);
337 + if (deptype!='R') continue;
339 + rpmMessage(RPMMESS_DEBUG, "#%i requires: %s,%s,%i\n",ix,N,EVR,Flags);
340 + if (EVR && EVR[0]) {
341 + rpmMessage(RPMMESS_DEBUG, "skipping #%i require\n");
344 + for(j=0;j<noautoreqdep_c;j++)
345 + if (!regexec(&noautoreqdep[j],N,0,NULL,0)) {
346 + rpmMessage(RPMMESS_NORMAL,
347 + "skipping %s requirement processing"
348 + " (matches noautoreqdep pattern: #%i)\n",N,j);
351 + if (j<noautoreqdep_c) continue;
353 + rpmMessage(RPMMESS_DEBUG, "skipping #%i require (is file requirement)\n");
356 + it=rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, N, 0);
358 + rpmMessage(RPMMESS_DEBUG, "%s -> not found\n",N);
361 + rpmMessage(RPMMESS_DEBUG, "Iterator: %p\n",it);
362 + if (rpmdbGetIteratorCount(it)>1) {
363 + rpmMessage(RPMMESS_DEBUG, "%s -> multiple (skipping)\n",N);
364 + rpmdbFreeIterator(it);
367 + hdr=rpmdbNextIterator(it);
369 + r=rpmHeaderGetEntry(hdr,RPMTAG_NAME,NULL,(void **)&hname, NULL);
371 + if (!strcmp(hname,N)) {
372 + rpmMessage(RPMMESS_DEBUG, "%s -> %s (skipping)\n",N,hname);
373 + rpmdbFreeIterator(it);
377 + rpmMessage(RPMMESS_DEBUG, "%s -> %s\n",N,hname);
379 + ds = rpmdsSingle(RPMTAG_REQUIRENAME, hname, "", RPMSENSE_FIND_REQUIRES);
380 + xx = rpmdsMerge(&fc->requires, ds);
381 + ds = rpmdsFree(ds);
383 + rpmdbFreeIterator(it);
386 + noautoreqdep=rpmfcFreeRegexps(noautoreqdep,noautoreqdep_c);
387 + ts = rpmtsFree(ts);
391 int rpmfcApply(rpmfc fc)
394 @@ -1075,6 +1263,21 @@
401 + regex_t *noautoreqfiles=NULL;
402 + int noautoreqfiles_c;
403 + regex_t *noautoprovfiles=NULL;
404 + int noautoprovfiles_c;
405 + const char *buildroot;
408 + buildroot=rpmExpand("%{buildroot}",NULL);
409 + buildroot_l=strlen(buildroot);
411 + noautoreqfiles=rpmfcExpandRegexps("%{_noautoreqfiles}",&noautoreqfiles_c);
412 + noautoprovfiles=rpmfcExpandRegexps("%{_noautoprovfiles}",&noautoprovfiles_c);
414 /* Generate package and per-file dependencies. */
415 for (fc->ix = 0; fc->fn[fc->ix] != NULL; fc->ix++) {
416 @@ -1082,10 +1285,41 @@
417 for (fcat = rpmfcApplyTable; fcat->func != NULL; fcat++) {
418 if (!(fc->fcolor->vals[fc->ix] & fcat->colormask))
419 /*@innercontinue@*/ continue;
420 - xx = (*fcat->func) (fc);
423 + if (strncmp(fc->fn[fc->ix],buildroot,buildroot_l)==0) {/* sanity check */
424 + for(j=0;j<noautoprovfiles_c;j++) {
425 + if (!regexec(&noautoprovfiles[j],
426 + fc->fn[fc->ix]+buildroot_l,0,NULL,0)) {
427 + rpmMessage(RPMMESS_NORMAL,
428 + "skipping %s provides detection"
429 + " (matches noautoprovfiles pattern #%i)\n",
435 + for(j=0;j<noautoreqfiles_c;j++) {
436 + if (!regexec(&noautoreqfiles[j],
437 + fc->fn[fc->ix]+buildroot_l,0,NULL,0)) {
438 + rpmMessage(RPMMESS_NORMAL,
439 + "skipping %s requires detection"
440 + " (matches noautoreqfiles pattern #%i)\n",
447 + xx = (*fcat->func) (fc,findprov,findreq);
451 + noautoreqfiles=rpmfcFreeRegexps(noautoreqfiles,noautoreqfiles_c);
452 + noautoprovfiles=rpmfcFreeRegexps(noautoprovfiles,noautoprovfiles_c);
454 + rpmfcFindRequiredPackages(fc);
457 /* Generate per-file indices into package dependencies. */
458 nddict = argvCount(fc->ddict);