]> git.ipfire.org Git - thirdparty/libsolv.git/blame - tools/cudftest.c
build: use GNUInstallDirs
[thirdparty/libsolv.git] / tools / cudftest.c
CommitLineData
a4e2caae
MS
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4
5#include "pool.h"
6#include "evr.h"
7#include "solver.h"
8#include "solverdebug.h"
9#include "repo_cudf.h"
10#include "repo_write.h"
11#include "solv_xfopen.h"
12
13static void
14dump_repo(Repo *repo, char *name)
15{
16 FILE *fp;
17 if ((fp = fopen(name, "w")) == 0)
18 {
19 perror(name);
20 exit(1);
21 }
22 repo_write(repo, fp);
23 fclose(fp);
24}
25
26static int
27sortfunc(const void *ap, const void *bp, void *dp)
28{
29 Pool *pool = dp;
30 Solvable *sa, *sb;
31 sa = pool->solvables + *(Id *)ap;
32 sb = pool->solvables + *(Id *)bp;
33 if (sa->name != sb->name)
34 {
35 int r = strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name));
36 if (r)
37 return r;
38 }
39 if (sa->evr != sb->evr)
40 {
41 int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
42 if (r)
43 return r;
44 }
45 return *(Id *)ap - *(Id *)bp;
46}
47
48int
49main(int argc, char **argv)
50{
51 char *cudfin;
52 char *cudfout = 0;
53 Pool *pool;
54 Repo *installed, *repo;
55 FILE *fp, *ofp;
56 Solver *solv;
57 Transaction *trans;
58 Queue job;
59 Queue dq;
60 int i;
61 int debug = 0;
62
63 while (argc > 1 && !strcmp(argv[1], "-d"))
64 {
65 debug++;
66 argc--;
67 argv++;
68 }
69 if (argc < 2)
70 {
d103a964 71 fprintf(stderr, "Usage: cudftest <cudfin> [cudfout]\n");
a4e2caae
MS
72 exit(1);
73 }
74 cudfin = argv[1];
75 cudfout = argc > 2 ? argv[2] : 0;
76
77 if ((fp = solv_xfopen(cudfin, 0)) == 0)
78 {
79 perror(cudfin);
80 exit(1);
81 }
82 pool = pool_create();
83 if (debug > 1)
84 pool_setdebuglevel(pool, debug - 1);
85 installed = repo_create(pool, "installed");
86 pool_set_installed(pool, installed);
87 repo = repo_create(pool, "repo");
88 queue_init(&job);
89 repo_add_cudf(repo, installed, fp, &job, 0);
1617994a
MS
90 fclose(fp);
91
a4e2caae
MS
92 pool_createwhatprovides(pool);
93
94 /* debug */
95 if (debug)
96 {
97 dump_repo(installed, "cudf_installed.solv");
98 dump_repo(repo, "cudf_repo.solv");
99 }
100
101 solv = solver_create(pool);
102 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1);
bdb4bbc7
MS
103 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
104
d5986ae6 105 queue_push2(&job, SOLVER_VERIFY | SOLVER_SOLVABLE_ALL, 0);
a4e2caae
MS
106 if (solver_solve(solv, &job) != 0)
107 {
108 int problem;
109 int pcnt = solver_problem_count(solv);
110 printf("Found %d problems:\n", pcnt);
111 for (problem = 1; problem <= pcnt; problem++)
112 {
113 printf("Problem %d:\n", problem);
114 solver_printprobleminfo(solv, problem);
115 printf("\n");
116 }
117 }
118 trans = solver_create_transaction(solv);
119 solver_free(solv);
120
121 if (debug)
122 transaction_print(trans);
123
124 queue_init(&dq);
125 transaction_installedresult(trans, &dq);
126 solv_sort(dq.elements, dq.count, sizeof(Id), sortfunc, pool);
127
128 ofp = stdout;
129 if (cudfout && ((ofp = fopen(cudfout, "w")) == 0))
130 {
131 perror(cudfout);
132 exit(1);
133 }
134 for (i = 0; i < dq.count; i++)
135 {
136 Solvable *s = pool_id2solvable(pool, dq.elements[i]);
137 fprintf(ofp, "package: %s\n", pool_id2str(pool, s->name));
138 fprintf(ofp, "version: %s\n", pool_id2str(pool, s->evr));
139 fprintf(ofp, "installed: true\n");
140 if (s->repo == pool->installed)
141 fprintf(ofp, "was-installed: true\n");
142 fprintf(ofp, "\n");
143 }
144 queue_free(&dq);
145 transaction_free(trans);
146 queue_free(&job);
147 pool_free(pool);
148 if (ofp != stdout)
149 {
150 if (fclose(ofp))
151 {
152 perror("fclose");
153 exit(1);
154 }
155 }
156 exit(0);
157}
158