rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpmdeps.c
Go to the documentation of this file.
1 #include "system.h"
2 const char *__progname;
3
4 #include <rpmio.h>
5 #include <rpmiotypes.h>
6 #include <rpmcb.h>
7 #include <argv.h>
8 #include <rpmtypes.h>
9 #include <rpmtag.h>
10
11 #include <rpmds.h>
12 #define _RPMFC_INTERNAL /* XXX for debugging */
13 #include <rpmfc.h>
14
15 #include <rpmcli.h>
16
17 #include "debug.h"
18
19 /*@unchecked@*/
20 char *progname;
21
22 #define RPMDEP_RPMFC 1
23 #define RPMDEP_RPMDSCPUINFO 2
24 #define RPMDEP_RPMDSRPMLIB 3
25 #define RPMDEP_RPMDSSYSINFO 4
26 #define RPMDEP_RPMDSGETCONF 5
27 #define RPMDEP_RPMDSELF 6
28 #define RPMDEP_RPMDSLDCONFIG 7
29 #define RPMDEP_RPMDSUNAME 8
30 #define RPMDEP_RPMDSPIPE 9
31
32 #define RPMDEP_RPMDSPERL 10
33 #define RPMDEP_RPMDSPYTHON 11
34 #define RPMDEP_RPMDSLIBTOOL 12
35 #define RPMDEP_RPMDSPKGCONFIG 13
36
37 #define RPMDEP_RPMDSPUBKEY 14
38 #define RPMDEP_RPMDSARCH 15
39 #define RPMDEP_RPMDSFILE 16
40 #define RPMDEP_RPMDSSONAME 17
41 #define RPMDEP_RPMDSPACKAGE 18
42
43 #define RPMDEP_RPMDSJAVA 20
44 #define RPMDEP_RPMDSRUBY 21
45 #define RPMDEP_RPMDSPHP 22
46
47 #define RPMDEP_RPMDSDPKGRPM 32
48 #define RPMDEP_RPMDSRPMDPKG 33
49
50 /*@unchecked@*/
51 static int rpmdeps_mode = RPMDEP_RPMFC;
52
53 /*@unchecked@*/
54 static int print_provides = 1;
55
56 /*@unchecked@*/
57 static int print_requires = 1;
58
59 /*@unchecked@*/
60 static int print_closure = 0;
61
62 #define _PERL_PROVIDES "/usr/bin/find /usr/lib/perl5 | /usr/lib/rpm/perl.prov"
63 /*@unchecked@*/ /*@observer@*/
64 static const char * _perl_provides = _PERL_PROVIDES;
65
66 #define _PERL_REQUIRES "rpm -qa --fileclass | grep 'perl script' | sed -e 's/\t.*$//' | /usr/lib/rpm/perl.req"
67 /*@unchecked@*/ /*@observer@*/
68 static const char * _perl_requires = _PERL_REQUIRES;
69
70 #define _JAVA_PROVIDES "rpm -qal | egrep '\\.(jar|class)$' | /usr/lib/rpm/javadeps.sh -P"
71 /*@unchecked@*/ /*@observer@*/
72 static const char * _java_provides = _JAVA_PROVIDES;
73
74 #define _JAVA_REQUIRES "rpm -qal | egrep '\\.(jar|class)$' | /usr/lib/rpm/javadeps.sh -R"
75 /*@unchecked@*/ /*@observer@*/
76 static const char * _java_requires = _JAVA_REQUIRES;
77
78 #define _LIBTOOL_PROVIDES "/usr/bin/find /usr/lib -name '*.la' | /usr/lib/rpm/libtooldeps.sh -P /"
79 /*@unchecked@*/ /*@observer@*/
80 static const char * _libtool_provides = _LIBTOOL_PROVIDES;
81
82 #define _LIBTOOL_REQUIRES "rpm -qal | grep '\\.la$' | /usr/lib/rpm/libtooldeps.sh -R /"
83 /*@unchecked@*/ /*@observer@*/
84 static const char * _libtool_requires = _LIBTOOL_REQUIRES;
85
86 #define _PKGCONFIG_PROVIDES "/usr/bin/find /usr/lib -name '*.pc' | /usr/lib/rpm/pkgconfigdeps.sh -P"
87 static const char * _pkgconfig_provides = _PKGCONFIG_PROVIDES;
88
89 #define _PKGCONFIG_REQUIRES "rpm -qal | grep '\\.pc$' | /usr/lib/rpm/pkgconfigdeps.sh -R"
90 static const char * _pkgconfig_requires = _PKGCONFIG_REQUIRES;
91
92 #define _DPKG_PROVIDES "egrep '^(Package|Status|Version|Provides):' /var/lib/dpkg/status | sed -e '\n\
93 /^Package: / {\n\
94 N\n\
95 /not-installed/d\n\
96 N\n\
97 s|^Package: \\([^\\n]*\\)\\n[^\\n]*\\nVersion: \\(.*\\)$|\\1 = \\2|\n\
98 }\n\
99 /^Provides: / {\n\
100 s|^Provides: ||\n\
101 s|, |\\n|g\n\
102 }' | sed -f /usr/lib/rpm/dpkg2fc.sed | sort -u | tee /tmp/dpkg"
103 static const char * _dpkg_provides = _DPKG_PROVIDES;
104
105 #define _DPKG_REQUIRES "egrep '^(Package|Status|Pre-Depends|Depends):' /var/lib/dpkg/status | sed -e '\n\
106 /^Package: / {\n\
107 N\n\
108 /not-installed/d\n\
109 s|^Package: [^\\n]*\\n.*$||\n\
110 }\n\
111 /^Depends: / {\n\
112 s|^Depends: ||\n\
113 s|(\\([^)]*\\))|\\1|g\n\
114 s|>>|>|\n\
115 s|<<|<|\n\
116 s|, |\\n|g\n\
117 }\n\
118 /^Pre-Depends: / {\n\
119 s|^Pre-Depends: ||\n\
120 s|(\\([^)]*\\))|\\1|g\n\
121 s|>>|>|\n\
122 s|<<|<|\n\
123 s|, |\\n|g\n\
124 }' | sed -f /usr/lib/rpm/dpkg2fc.sed | sed -e 's/ |.*$//' | sort -u | tee /tmp/dpkg"
125 static const char * _dpkg_requires = _DPKG_REQUIRES;
126
127 #define _RPMDB_PACKAGE_PROVIDES "rpm -qa --qf '%{name} = %|epoch?{%{epoch}:}|%{version}-%{release}\n' | sort -u"
128 static const char * _rpmdb_package_provides = _RPMDB_PACKAGE_PROVIDES;
129
130 #define _RPMDB_PACKAGE_REQUIRES "rpm -qa --requires | sort -u | sed -e '/^\\//d' -e '/.*\\.so.*/d' -e '/^%/d' -e '/^.*(.*)/d'"
131 static const char * _rpmdb_package_requires = _RPMDB_PACKAGE_REQUIRES;
132
133 #define _RPMDB_SONAME_REQUIRES "rpm -qa --requires | grep -v '^/' | grep '.*\\.so.*' | sort -u"
134 static const char * _rpmdb_soname_requires = _RPMDB_SONAME_REQUIRES;
135
136 #define _RPMDB_FILE_REQUIRES "rpm -qa --requires | grep '^/' | sort -u"
137 static const char * _rpmdb_file_requires = _RPMDB_FILE_REQUIRES;
138
139 static int rpmdepPrint(const char * msg, rpmds ds, FILE * fp)
140 {
141 if (fp == NULL) fp = stderr;
142
143 if (msg)
144 fprintf(fp, "===================================== %s\n", msg);
145
146 ds = rpmdsInit(ds);
147 while (rpmdsNext(ds) >= 0) {
148 if (_rpmfc_debug || rpmIsDebug())
149 fprintf(fp, "%6d\t", rpmdsIx(ds));
150 if (_rpmfc_debug || rpmIsVerbose())
151 fprintf(fp, "%s: ", rpmdsType(ds));
152 fprintf(fp, "%s\n", rpmdsDNEVR(ds)+2);
153 }
154 return 0;
155 }
156
157 static struct poptOption optionsTable[] = {
158
159 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
160 N_("Common options:"),
161 NULL },
162
163 { "cpuinfo", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSCPUINFO,
164 N_("print cpuinfo(...) dependency set"), NULL },
165 { "rpmlib", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSRPMLIB,
166 N_("print rpmlib(...) dependency set"), NULL },
167 { "sysinfo", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSSYSINFO,
168 N_("print /etc/rpm/sysinfo dependency set"), NULL },
169 { "getconf", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSGETCONF,
170 N_("print getconf(...) dependency set"), NULL },
171 { "elf", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSELF,
172 N_("print soname(...) dependencies for elf files"), NULL },
173 { "ldconfig", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSLDCONFIG,
174 N_("print soname(...) dependencies from /etc/ld.so.cache"), NULL },
175 { "uname", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSUNAME,
176 N_("print uname(...) dependency set"), NULL },
177 { "pipe", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSPIPE,
178 N_("print dependency set from a command pipe"), NULL },
179
180 { "perl", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSPERL,
181 N_("print perl(...) dependency set"), NULL },
182 { "python", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSPYTHON,
183 N_("print python(...) dependency set"), NULL },
184 { "libtool", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSLIBTOOL,
185 N_("print libtool(...) dependency set"), NULL },
186 { "pkgconfig", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSPKGCONFIG,
187 N_("print pkgconfig(...) dependency set"), NULL },
188
189 { "pubkey", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSPUBKEY,
190 N_("print pubkey(...) dependency set"), NULL },
191 { "arch", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSARCH,
192 N_("print arch(...) dependency set"), NULL },
193 { "file", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSFILE,
194 N_("print file(...) dependency set"), NULL },
195 { "soname", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSSONAME,
196 N_("print soname(...) dependency set"), NULL },
197 { "package", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSPACKAGE,
198 N_("print package(...) dependency set"), NULL },
199
200 { "java", 0, POPT_ARG_VAL, &rpmdeps_mode, RPMDEP_RPMDSJAVA,
201 N_("print java(...) dependency set"), NULL },
202 { "php", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSPHP,
203 N_("print php(...) dependency set"), NULL },
204 { "ruby", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSRUBY,
205 N_("print ruby(...) dependency set"), NULL },
206 { "dpkgrpm", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSDPKGRPM,
207 N_("print /var/lib/dpkg Provides: dependency set"), NULL },
208 { "rpmdpkg", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmdeps_mode, RPMDEP_RPMDSRPMDPKG,
209 N_("print /var/lib/dpkg Requires: dependency set"), NULL },
210
211 { "provides", 'P', POPT_ARG_VAL, &print_provides, -1,
212 N_("print Provides: dependency set"), NULL },
213 { "requires", 'R', POPT_ARG_VAL, &print_requires, -1,
214 N_("print Requires: dependency set"), NULL },
215 { "closure", 0, POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &print_closure, -1,
216 N_("check Requires: against Provides: for dependency closure"), NULL },
217
218 POPT_AUTOALIAS
219 POPT_AUTOHELP
220 POPT_TABLEEND
221 };
222
223
224 int
225 main(int argc, char *argv[])
226 {
227 static const char rpmdeps_string[] = "rpmdeps";
228 poptContext optCon;
229 ARGV_t av = NULL;
230 rpmfc fc = NULL;
231 rpmds P = NULL;
232 rpmds R = NULL;
233 rpmPRCO PRCO = rpmdsNewPRCO(NULL);
234 const char * closure_name = "for";
235 FILE * fp = NULL;
236 int flags = 0;
237 int ac = 0;
238 int ec = 1;
239 int xx;
240 int i;
241 char buf[BUFSIZ];
242
243 /*@-modobserver@*/
244 if ((progname = strrchr(argv[0], '/')) != NULL)
245 progname++;
246 else
247 progname = argv[0];
248 /*@=modobserver@*/
249
250 optCon = rpmcliInit(argc, argv, optionsTable);
251 if (optCon == NULL)
252 goto exit;
253
254 av = poptGetArgs(optCon);
255 ac = argvCount(av);
256
257 if (rpmdeps_mode == RPMDEP_RPMFC && ac == 0) {
258 av = NULL;
259 xx = argvFgets(&av, NULL);
260 ac = argvCount(av);
261 }
262
263 /* Make sure file names are sorted. */
264 xx = argvSort(av, NULL);
265
266 switch (rpmdeps_mode) {
267 case RPMDEP_RPMFC:
268 if (ac <= 0) /* XXX avoid rpmfcApply() segfault */
269 break;
270
271 /* Build file class dictionary. */
272 fc = rpmfcNew();
273 xx = rpmfcClassify(fc, av, NULL);
274
275 /* Build file/package dependency dictionary. */
276 xx = rpmfcApply(fc);
277
278 if (_rpmfc_debug) {
279 sprintf(buf, "final: files %d cdict[%d] %d%% ddictx[%d]", (int)fc->nfiles, argvCount(fc->cdict), (int)((100 * fc->fknown)/fc->nfiles), argiCount(fc->ddictx));
280 rpmfcPrint(buf, fc, NULL);
281 }
282 if (print_provides > 0) print_provides = 0;
283 if (print_requires > 0) print_requires = 0;
284 P = fc->provides; fc->provides = NULL;
285 R = fc->requires; fc->requires = NULL;
286 fp = stdout;
287 break;
288 case RPMDEP_RPMDSCPUINFO:
289 closure_name = "cpuinfo(...)";
290 xx = rpmdsCpuinfo(&P, NULL);
291 break;
292 case RPMDEP_RPMDSRPMLIB:
293 closure_name = "rpmlib(...)";
294 xx = rpmdsRpmlib(&P, NULL);
295 break;
296 case RPMDEP_RPMDSSYSINFO:
297 xx = rpmdsSysinfo(PRCO, NULL);
298 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), rpmdeps_string);
299 R = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_REQUIRENAME), rpmdeps_string);
300 break;
301 case RPMDEP_RPMDSGETCONF:
302 closure_name = "getconf(...)";
303 xx = rpmdsGetconf(&P, NULL);
304 break;
305 case RPMDEP_RPMDSELF:
306 closure_name = "soname(...)";
307 for (i = 0; i < ac; i++)
308 xx = rpmdsELF(av[i], flags, rpmdsMergePRCO, PRCO);
309 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), rpmdeps_string);
310 R = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_REQUIRENAME), rpmdeps_string);
311 break;
312 case RPMDEP_RPMDSLDCONFIG:
313 closure_name = "soname(...)";
314 xx = rpmdsLdconfig(PRCO, NULL);
315 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), rpmdeps_string);
316 R = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_REQUIRENAME), rpmdeps_string);
317 break;
318 case RPMDEP_RPMDSUNAME:
319 closure_name = "uname(...)";
320 xx = rpmdsUname(&P, NULL);
321 break;
322
323 case RPMDEP_RPMDSPIPE:
324 break;
325 case RPMDEP_RPMDSPERL:
326 closure_name = "perl(...)";
327 if (rpmIsVerbose())
328 fprintf(stderr, "\n*** Gathering %s Provides: using\n\t%s\n", closure_name, _perl_provides);
329 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _perl_provides);
330 if (print_closure || rpmIsVerbose()) {
331 fprintf(stderr, "\n*** Gathering %s Requires: using\n\t%s\n", closure_name, _perl_requires);
332 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _perl_requires);
333 print_closure = 1;
334 }
335 break;
336 case RPMDEP_RPMDSPYTHON:
337 break;
338 case RPMDEP_RPMDSLIBTOOL:
339 closure_name = "libtool(...)";
340 if (rpmIsVerbose())
341 fprintf(stderr, "\n*** Gathering %s Provides: using\n\t%s\n", closure_name, _libtool_provides);
342 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _libtool_provides);
343 if (print_closure || rpmIsVerbose()) {
344 fprintf(stderr, "\n*** Gathering %s Requires: using\n\t%s\n", closure_name, _libtool_requires);
345 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _libtool_requires);
346 print_closure = 1;
347 }
348 break;
349 case RPMDEP_RPMDSPKGCONFIG:
350 closure_name = "pkgconfig(...)";
351 if (rpmIsVerbose())
352 fprintf(stderr, "\n*** Gathering %s Provides: using\n\t%s\n", closure_name, _pkgconfig_provides);
353 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _pkgconfig_provides);
354 if (print_closure || rpmIsVerbose()) {
355 fprintf(stderr, "\n*** Gathering %s Requires: using\n\t%s\n", closure_name, _pkgconfig_requires);
356 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _pkgconfig_requires);
357 print_closure = 1;
358 }
359 break;
360
361 case RPMDEP_RPMDSPUBKEY:
362 break;
363 case RPMDEP_RPMDSARCH:
364 break;
365 case RPMDEP_RPMDSFILE:
366 if (rpmIsVerbose())
367 fprintf(stderr, "\n*** Gathering rpmdb file Requires: using\n\t%s\n", _rpmdb_file_requires);
368 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _rpmdb_file_requires);
369 break;
370 case RPMDEP_RPMDSSONAME:
371 closure_name = "soname(...)";
372 xx = rpmdsLdconfig(PRCO, NULL);
373 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), rpmdeps_string);
374 if (print_closure || rpmIsVerbose()) {
375 fprintf(stderr, "\n*** Gathering rpmdb soname Requires: using\n\t%s\n", _rpmdb_soname_requires);
376 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _rpmdb_soname_requires);
377 print_closure = 1;
378 }
379 break;
380 case RPMDEP_RPMDSPACKAGE:
381 closure_name = "package(...)";
382 if (rpmIsVerbose())
383 fprintf(stderr, "\n*** Gathering rpmdb package Provides: using\n\t%s\n", _rpmdb_package_provides);
384 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _rpmdb_package_provides);
385 if (print_closure || rpmIsVerbose()) {
386 fprintf(stderr, "\n*** Gathering rpmdb package Requires: using\n\t%s\n", _rpmdb_package_requires);
387 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _rpmdb_package_requires);
388 print_closure = 1;
389 }
390 break;
391
392 case RPMDEP_RPMDSJAVA:
393 closure_name = "java(...)";
394 if (rpmIsVerbose())
395 fprintf(stderr, "\n*** Gathering %s Provides: using\n\t%s\n", closure_name, _java_provides);
396 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _java_provides);
397 if (print_closure || rpmIsVerbose()) {
398 fprintf(stderr, "\n*** Gathering %s Requires: using\n\t%s\n", closure_name, _java_requires);
399 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _java_requires);
400 print_closure = 1;
401 }
402 break;
403 case RPMDEP_RPMDSRUBY:
404 break;
405 case RPMDEP_RPMDSPHP:
406 break;
407 case RPMDEP_RPMDSDPKGRPM:
408 closure_name = "dpkgrpm(...)";
409 if (rpmIsVerbose())
410 fprintf(stderr, "\n*** Gathering dpkg Provides: using\n\t%s\n", _dpkg_provides);
411 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _dpkg_provides);
412 if (print_closure || rpmIsVerbose()) {
413 fprintf(stderr, "\n*** Gathering rpmdb package Requires: using\n\t%s\n", _rpmdb_package_requires);
414 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _rpmdb_package_requires);
415 print_closure = 1;
416 }
417 break;
418 case RPMDEP_RPMDSRPMDPKG:
419 closure_name = "rpmdpkg(...)";
420 if (print_closure || rpmIsVerbose()) {
421 fprintf(stderr, "\n*** Gathering rpmdb package Provides: using\n\t%s\n", _rpmdb_package_provides);
422 xx = rpmdsPipe(&P, RPMTAG_PROVIDENAME, _rpmdb_package_provides);
423 print_closure = 1;
424 }
425 if (rpmIsVerbose())
426 fprintf(stderr, "\n*** Gathering dpkg Requires: using\n\t%s\n", _dpkg_requires);
427 xx = rpmdsPipe(&R, RPMTAG_REQUIRENAME, _dpkg_requires);
428 break;
429 }
430
431 if (print_provides && P != NULL)
432 xx = rpmdepPrint(NULL, P, fp);
433 if (print_requires && R != NULL)
434 xx = rpmdepPrint(NULL, R, fp);
435 if (print_closure) {
436 if (rpmIsVerbose())
437 fprintf(stderr, "\n*** Checking %s Requires(%d): against Provides(%d): closure:\n", closure_name, rpmdsCount(R), rpmdsCount(P));
438 xx = rpmdsPrintClosure(P, R, fp);
439 }
440
441 fc = rpmfcFree(fc);
442 (void)rpmdsFree(P);
443 P = NULL;
444 (void)rpmdsFree(R);
445 R = NULL;
446 PRCO = rpmdsFreePRCO(PRCO);
447
448 ec = 0;
449
450 exit:
451 optCon = rpmcliFini(optCon);
452 return ec;
453 }