summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c')
-rw-r--r--meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c117
1 files changed, 110 insertions, 7 deletions
diff --git a/meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c b/meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c
index 9f6cdf28b8..2d9ed141f4 100644
--- a/meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c
+++ b/meta/recipes-devtools/rpm/rpmresolve/rpmresolve.c
@@ -204,10 +204,104 @@ int processPackages(rpmts *ts, int tscount, const char *packagelistfn, int ignor
204 return rc; 204 return rc;
205} 205}
206 206
207int lookupProvider(rpmts ts, const char *req, char **provider)
208{
209 int rc = 0;
210 rpmmi provmi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, req, 0);
211 if(provmi) {
212 Header h;
213 if ((h = rpmmiNext(provmi)) != NULL) {
214 HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
215 he->tag = RPMTAG_NAME;
216 rc = (headerGet(h, he, 0) != 1);
217 if(rc==0)
218 *provider = strdup((char *)he->p.ptr);
219 }
220 (void)rpmmiFree(provmi);
221 }
222 else {
223 rc = -1;
224 }
225 return rc;
226}
227
228int printDepList(rpmts *ts, int tscount)
229{
230 int rc = 0;
231
232 if( tscount > 1 )
233 printf(">1 database specified with dependency list, using first only\n");
234
235 /* Get list of names */
236 rpmdb db = rpmtsGetRdb(ts[0]);
237 ARGV_t names = NULL;
238 rc = rpmdbMireApply(db, RPMTAG_NAME,
239 RPMMIRE_STRCMP, NULL, &names);
240 int nnames = argvCount(names);
241
242 /* Get list of NVRAs */
243 ARGV_t keys = NULL;
244 rc = rpmdbMireApply(db, RPMTAG_NVRA,
245 RPMMIRE_STRCMP, NULL, &keys);
246 if (keys) {
247 int i, j;
248 HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
249 int nkeys = argvCount(keys);
250 for(i=0; i<nkeys; i++) {
251 rpmmi mi = rpmtsInitIterator(ts[0], RPMTAG_NVRA, keys[i], 0);
252 Header h;
253 if ((h = rpmmiNext(mi)) != NULL) {
254 /* Get name of package */
255 he->tag = RPMTAG_NAME;
256 rc = (headerGet(h, he, 0) != 1);
257 char *name = strdup((char *)he->p.ptr);
258 /* Get its requires */
259 he->tag = RPMTAG_REQUIRENAME;
260 rc = (headerGet(h, he, 0) != 1);
261 ARGV_t reqs = (ARGV_t)he->p.ptr;
262 /* Get its requireflags */
263 he->tag = RPMTAG_REQUIREFLAGS;
264 rc = (headerGet(h, he, 0) != 1);
265 rpmuint32_t *reqflags = (rpmuint32_t *)he->p.ui32p;
266 for(j=0; j<he->c; j++) {
267 int k;
268 char *prov = NULL;
269 for(k=0; k<nnames; k++) {
270 if(strcmp(names[k], reqs[j]) == 0) {
271 prov = names[k];
272 break;
273 }
274 }
275 if(prov) {
276 if((int)reqflags[j] & 0x80000)
277 printf("%s|%s [REC]\n", name, prov);
278 else
279 printf("%s|%s\n", name, prov);
280 }
281 else {
282 rc = lookupProvider(ts[0], reqs[j], &prov);
283 if(rc==0 && prov) {
284 if((int)reqflags[j] & 0x80000)
285 printf("%s|%s [REC]\n", name, prov);
286 else
287 printf("%s|%s\n", name, prov);
288 free(prov);
289 }
290 }
291 }
292 free(name);
293 }
294 (void)rpmmiFree(mi);
295 }
296 }
297
298 return rc;
299}
300
207void usage() 301void usage()
208{ 302{
209 fprintf(stderr, "OpenEmbedded rpm resolver utility\n"); 303 fprintf(stderr, "OpenEmbedded rpm resolver utility\n");
210 fprintf(stderr, "syntax: rpmresolve [-i] <dblistfile> <packagelistfile>\n"); 304 fprintf(stderr, "syntax: rpmresolve [-i] [-d] <dblistfile> <packagelistfile>\n");
211} 305}
212 306
213int main(int argc, char **argv) 307int main(int argc, char **argv)
@@ -218,13 +312,17 @@ int main(int argc, char **argv)
218 int i; 312 int i;
219 int c; 313 int c;
220 int ignoremissing = 0; 314 int ignoremissing = 0;
315 int deplistmode = 0;
221 316
222 opterr = 0; 317 opterr = 0;
223 while ((c = getopt (argc, argv, "i")) != -1) { 318 while ((c = getopt (argc, argv, "id")) != -1) {
224 switch (c) { 319 switch (c) {
225 case 'i': 320 case 'i':
226 ignoremissing = 1; 321 ignoremissing = 1;
227 break; 322 break;
323 case 'd':
324 deplistmode = 1;
325 break;
228 case '?': 326 case '?':
229 if(isprint(optopt)) 327 if(isprint(optopt))
230 fprintf(stderr, "Unknown option `-%c'.\n", optopt); 328 fprintf(stderr, "Unknown option `-%c'.\n", optopt);
@@ -258,12 +356,17 @@ int main(int argc, char **argv)
258 return 1; 356 return 1;
259 } 357 }
260 358
261 if( argc - optind < 2 ) { 359 if(deplistmode) {
262 fprintf(stderr, "Please specify package list file\n"); 360 rc = printDepList(ts, tscount);
263 return 1; 361 }
362 else {
363 if( argc - optind < 2 ) {
364 fprintf(stderr, "Please specify package list file\n");
365 return 1;
366 }
367 const char *pkglistfn = argv[optind+1];
368 rc = processPackages(ts, tscount, pkglistfn, ignoremissing);
264 } 369 }
265 const char *pkglistfn = argv[optind+1];
266 rc = processPackages(ts, tscount, pkglistfn, ignoremissing);
267 370
268 for(i=0; i<tscount; i++) 371 for(i=0; i<tscount; i++)
269 (void) rpmtsCloseDB(ts[i]); 372 (void) rpmtsCloseDB(ts[i]);