1 |
commit: d301ed27e28417f185c374a044cfabeb32beb607 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 26 14:32:32 2022 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 26 14:32:32 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d301ed27 |
7 |
|
8 |
qdepends: add --resolve flag to lookup depstrings |
9 |
|
10 |
This doesn't respect keywords or masks, but with installed packages |
11 |
shows which packages currently match the deps as expressed |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
man/qdepends.1 | 11 ++++++++++- |
16 |
qdepends.c | 51 +++++++++++++++++++++++++++++++++++---------------- |
17 |
2 files changed, 45 insertions(+), 17 deletions(-) |
18 |
|
19 |
diff --git a/man/qdepends.1 b/man/qdepends.1 |
20 |
index 0690f16..5e5b00a 100644 |
21 |
--- a/man/qdepends.1 |
22 |
+++ b/man/qdepends.1 |
23 |
@@ -1,5 +1,5 @@ |
24 |
.\" generated by mkman.py, please do NOT edit! |
25 |
-.TH qdepends "1" "Feb 2021" "Gentoo Foundation" "qdepends" |
26 |
+.TH qdepends "1" "May 2022" "Gentoo Foundation" "qdepends" |
27 |
.SH NAME |
28 |
qdepends \- show dependency info |
29 |
.SH SYNOPSIS |
30 |
@@ -68,6 +68,9 @@ Search installed packages using VDB. |
31 |
\fB\-t\fR, \fB\-\-tree\fR |
32 |
Search available ebuilds in the tree. |
33 |
.TP |
34 |
+\fB\-U\fR, \fB\-\-use\fR |
35 |
+Apply profile USE-flags to conditional deps. |
36 |
+.TP |
37 |
\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR |
38 |
Pretty-print DEPEND declaration to be used in an ebuild. This |
39 |
option initiates a very different mode of operation. Instead of |
40 |
@@ -82,6 +85,9 @@ e.g.\ the DEPEND= part is skipped. |
41 |
\fB\-S\fR, \fB\-\-pretty\fR |
42 |
Pretty format specified depend strings. |
43 |
.TP |
44 |
+\fB\-R\fR, \fB\-\-resolve\fR |
45 |
+Resolve found dependencies to package versions. |
46 |
+.TP |
47 |
\fB\-\-root\fR \fI<arg>\fR |
48 |
Set the ROOT env var. |
49 |
.TP |
50 |
@@ -97,6 +103,9 @@ Suppress DEPEND= output for \fB\-f\fR. Only print the matching atom for \fB\-Q\ |
51 |
\fB\-C\fR, \fB\-\-nocolor\fR |
52 |
Don't output color. |
53 |
.TP |
54 |
+\fB\-\-color\fR |
55 |
+Force color in output. |
56 |
+.TP |
57 |
\fB\-h\fR, \fB\-\-help\fR |
58 |
Print this help and exit. |
59 |
.TP |
60 |
|
61 |
diff --git a/qdepends.c b/qdepends.c |
62 |
index f1bc3ad..bd7c379 100644 |
63 |
--- a/qdepends.c |
64 |
+++ b/qdepends.c |
65 |
@@ -22,7 +22,7 @@ |
66 |
#include "xasprintf.h" |
67 |
#include "xregex.h" |
68 |
|
69 |
-#define QDEPENDS_FLAGS "drpbQitUF:S" COMMON_FLAGS |
70 |
+#define QDEPENDS_FLAGS "drpbQitUF:SR" COMMON_FLAGS |
71 |
static struct option const qdepends_long_opts[] = { |
72 |
{"depend", no_argument, NULL, 'd'}, |
73 |
{"rdepend", no_argument, NULL, 'r'}, |
74 |
@@ -34,6 +34,7 @@ static struct option const qdepends_long_opts[] = { |
75 |
{"use", no_argument, NULL, 'U'}, |
76 |
{"format", a_argument, NULL, 'F'}, |
77 |
{"pretty", no_argument, NULL, 'S'}, |
78 |
+ {"resolve", no_argument, NULL, 'R'}, |
79 |
COMMON_LONG_OPTS |
80 |
}; |
81 |
static const char * const qdepends_opts_help[] = { |
82 |
@@ -47,20 +48,23 @@ static const char * const qdepends_opts_help[] = { |
83 |
"Apply profile USE-flags to conditional deps", |
84 |
"Print matched atom using given format string", |
85 |
"Pretty format specified depend strings", |
86 |
+ "Resolve found dependencies to package versions", |
87 |
COMMON_OPTS_HELP |
88 |
}; |
89 |
#define qdepends_usage(ret) usage(ret, QDEPENDS_FLAGS, qdepends_long_opts, qdepends_opts_help, NULL, lookup_applet_idx("qdepends")) |
90 |
|
91 |
/* structures / types / etc ... */ |
92 |
struct qdepends_opt_state { |
93 |
- unsigned int qmode; |
94 |
- array_t *atoms; |
95 |
- array_t *deps; |
96 |
- set *udeps; |
97 |
- char *depend; |
98 |
- size_t depend_len; |
99 |
- const char *format; |
100 |
- tree_ctx *vdb; |
101 |
+ unsigned int qmode; |
102 |
+ array_t *atoms; |
103 |
+ array_t *deps; |
104 |
+ set *udeps; |
105 |
+ char *depend; |
106 |
+ size_t depend_len; |
107 |
+ const char *format; |
108 |
+ char resolve:1; |
109 |
+ tree_ctx *vdb; |
110 |
+ tree_ctx *rtree; |
111 |
}; |
112 |
|
113 |
#define QMODE_DEPEND (1<<0) |
114 |
@@ -174,6 +178,10 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
115 |
continue; |
116 |
} |
117 |
|
118 |
+ /* try and resolve expressions to real package atoms */ |
119 |
+ if (state->resolve) |
120 |
+ dep_resolve_tree(dep_tree, state->rtree); |
121 |
+ |
122 |
if (state->qmode & QMODE_TREE && |
123 |
!(state->qmode & QMODE_REVERSE) && |
124 |
verbose) |
125 |
@@ -301,12 +309,14 @@ int qdepends_main(int argc, char **argv) |
126 |
DECLARE_ARRAY(atoms); |
127 |
DECLARE_ARRAY(deps); |
128 |
struct qdepends_opt_state state = { |
129 |
- .atoms = atoms, |
130 |
- .deps = deps, |
131 |
- .udeps = create_set(), |
132 |
- .qmode = 0, |
133 |
- .format = "%[CATEGORY]%[PF]", |
134 |
- .vdb = NULL, |
135 |
+ .atoms = atoms, |
136 |
+ .deps = deps, |
137 |
+ .udeps = create_set(), |
138 |
+ .qmode = 0, |
139 |
+ .format = "%[CATEGORY]%[PF]", |
140 |
+ .resolve = false, |
141 |
+ .vdb = NULL, |
142 |
+ .rtree = NULL, |
143 |
}; |
144 |
size_t i; |
145 |
int ret; |
146 |
@@ -328,6 +338,7 @@ int qdepends_main(int argc, char **argv) |
147 |
case 't': state.qmode |= QMODE_TREE; break; |
148 |
case 'U': state.qmode |= QMODE_FILTERUSE; break; |
149 |
case 'S': do_pretty = true; break; |
150 |
+ case 'R': state.resolve = true; break; |
151 |
case 'F': state.format = optarg; break; |
152 |
} |
153 |
} |
154 |
@@ -391,6 +402,8 @@ int qdepends_main(int argc, char **argv) |
155 |
array_for_each(overlays, n, overlay) { |
156 |
t = tree_open(portroot, overlay); |
157 |
if (t != NULL) { |
158 |
+ if (state.resolve) |
159 |
+ state.rtree = tree_open(portroot, overlay); |
160 |
if (!(state.qmode & QMODE_REVERSE) && array_cnt(atoms) > 0) { |
161 |
array_for_each(atoms, i, atom) { |
162 |
ret |= tree_foreach_pkg_sorted(t, |
163 |
@@ -401,9 +414,13 @@ int qdepends_main(int argc, char **argv) |
164 |
qdepends_results_cb, &state, NULL); |
165 |
} |
166 |
tree_close(t); |
167 |
+ if (state.rtree) |
168 |
+ tree_close(state.rtree); |
169 |
} |
170 |
} |
171 |
- } else { |
172 |
+ } else { /* INSTALLED */ |
173 |
+ if (state.resolve) |
174 |
+ state.rtree = tree_open_vdb(portroot, portvdb); |
175 |
if (!(state.qmode & QMODE_REVERSE) && array_cnt(atoms) > 0) { |
176 |
array_for_each(atoms, i, atom) { |
177 |
ret |= tree_foreach_pkg_fast(state.vdb, |
178 |
@@ -413,6 +430,8 @@ int qdepends_main(int argc, char **argv) |
179 |
ret |= tree_foreach_pkg_fast(state.vdb, |
180 |
qdepends_results_cb, &state, NULL); |
181 |
} |
182 |
+ if (state.rtree) |
183 |
+ tree_close(state.rtree); |
184 |
} |
185 |
|
186 |
if (state.vdb != NULL) |