Skip to content

Commit be7e532

Browse files
classabbyampDuncaen
authored andcommitted
xbps-reconfigure: add ability to reconfigure dependencies
adds `-x/--deps` and `--fulldeptree`, that behave similar to the xbps-query modes fixes #464
1 parent f5d84e8 commit be7e532

5 files changed

Lines changed: 145 additions & 7 deletions

File tree

bin/xbps-reconfigure/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ TOPDIR = ../..
22
-include $(TOPDIR)/config.mk
33

44
BIN = xbps-reconfigure
5+
OBJS = main.o find-deps.o
56

67
include $(TOPDIR)/mk/prog.mk

bin/xbps-reconfigure/defs.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*-
2+
* Copyright (c) 2022 classabbyamp.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#ifndef _XBPS_RECONFIGURE_DEFS_H_
27+
#define _XBPS_RECONFIGURE_DEFS_H_
28+
29+
#include <xbps.h>
30+
31+
/* from find-deps.c */
32+
int find_pkg_deps(struct xbps_handle *, const char *, bool, xbps_array_t *);
33+
34+
#endif /* !_XBPS_RECONFIGURE_DEFS_H_ */

bin/xbps-reconfigure/find-deps.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* Copyright (c) 2022 classabbyamp.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include <errno.h>
27+
28+
#include <xbps.h>
29+
#include "defs.h"
30+
31+
int
32+
find_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool full, xbps_array_t *rdeps)
33+
{
34+
xbps_dictionary_t pkgd;
35+
36+
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
37+
return errno;
38+
}
39+
40+
if (full) {
41+
*rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgname);
42+
43+
if (*rdeps == NULL)
44+
return errno;
45+
} else {
46+
*rdeps = xbps_dictionary_get(pkgd, "run_depends");
47+
}
48+
return 0;
49+
}

bin/xbps-reconfigure/main.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <syslog.h>
3333

3434
#include <xbps.h>
35+
#include "defs.h"
3536

3637
static void __attribute__((noreturn))
3738
usage(bool fail)
@@ -43,9 +44,11 @@ usage(bool fail)
4344
" -C, --config <dir> Path to confdir (xbps.d)\n"
4445
" -d, --debug Debug mode shown to stderr\n"
4546
" -f, --force Force reconfiguration\n"
47+
" --fulldeptree Full dependency tree for -x/--deps\n"
4648
" -h, --help Show usage\n"
4749
" -i, --ignore PKG Ignore PKG with -a/--all\n"
4850
" -r, --rootdir <dir> Full path to rootdir\n"
51+
" -x, --deps Also process dependencies for each package\n"
4952
" -v, --verbose Verbose messages\n"
5053
" -V, --version Show XBPS version\n");
5154
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
@@ -90,7 +93,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbd UNUSED)
9093
int
9194
main(int argc, char **argv)
9295
{
93-
const char *shortopts = "aC:dfhi:r:Vv";
96+
const char *shortopts = "aC:dfhi:r:xVv";
9497
const struct option longopts[] = {
9598
{ "all", no_argument, NULL, 'a' },
9699
{ "config", required_argument, NULL, 'C' },
@@ -99,15 +102,17 @@ main(int argc, char **argv)
99102
{ "help", no_argument, NULL, 'h' },
100103
{ "ignore", required_argument, NULL, 'i' },
101104
{ "rootdir", required_argument, NULL, 'r' },
105+
{ "deps", no_argument, NULL, 'x' },
102106
{ "verbose", no_argument, NULL, 'v' },
103107
{ "version", no_argument, NULL, 'V' },
108+
{ "fulldeptree", no_argument, NULL, 1 },
104109
{ NULL, 0, NULL, 0 }
105110
};
106111
struct xbps_handle xh;
107112
const char *confdir = NULL, *rootdir = NULL;
108113
int c, i, rv, flags = 0;
109-
bool all = false;
110-
xbps_array_t ignpkgs = NULL;
114+
bool all = false, rdeps = false, fulldeptree = false;
115+
xbps_array_t ignpkgs = NULL, deps = NULL;
111116

112117
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
113118
switch (c) {
@@ -135,12 +140,18 @@ main(int argc, char **argv)
135140
case 'r':
136141
rootdir = optarg;
137142
break;
143+
case 'x':
144+
rdeps = true;
145+
break;
138146
case 'v':
139147
flags |= XBPS_FLAG_VERBOSE;
140148
break;
141149
case 'V':
142150
printf("%s\n", XBPS_RELVER);
143151
exit(EXIT_SUCCESS);
152+
case 1:
153+
fulldeptree = true;
154+
break;
144155
case '?':
145156
default:
146157
usage(true);
@@ -168,18 +179,51 @@ main(int argc, char **argv)
168179
}
169180

170181
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
171-
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
182+
xbps_error_printf("failed to lock pkgdb: %s\n", strerror(rv));
172183
exit(EXIT_FAILURE);
173184
}
174185

175186
if (all) {
176187
rv = xbps_configure_packages(&xh, ignpkgs);
177188
} else {
178189
for (i = optind; i < argc; i++) {
179-
rv = xbps_configure_pkg(&xh, argv[i], true, false);
190+
const char* pkg = argv[i];
191+
if (rdeps) {
192+
rv = find_pkg_deps(&xh, pkg, fulldeptree, &deps);
193+
if (rv != 0) {
194+
xbps_error_printf("failed to collect dependencies for "
195+
"`%s': %s\n", pkg, strerror(rv));
196+
}
197+
for (unsigned int j = 0; j < xbps_array_count(deps); j++) {
198+
const char *pkgdep = NULL;
199+
char pkgname[XBPS_NAME_SIZE];
200+
xbps_array_get_cstring_nocopy(deps, j, &pkgdep);
201+
202+
if (fulldeptree) {
203+
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgdep)) {
204+
xbps_error_printf(
205+
"unable to get package name for dependency `%s'\n", pkgdep);
206+
exit(EXIT_FAILURE);
207+
}
208+
} else {
209+
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgdep)) {
210+
xbps_error_printf(
211+
"unable to get package name for dependency `%s'\n", pkgdep);
212+
exit(EXIT_FAILURE);
213+
}
214+
}
215+
216+
rv = xbps_configure_pkg(&xh, pkgname, true, false);
217+
if (rv != 0) {
218+
xbps_error_printf("failed to reconfigure "
219+
"`%s': %s\n", pkgname, strerror(rv));
220+
}
221+
}
222+
}
223+
rv = xbps_configure_pkg(&xh, pkg, true, false);
180224
if (rv != 0) {
181-
fprintf(stderr, "Failed to reconfigure "
182-
"`%s': %s\n", argv[i], strerror(rv));
225+
xbps_error_printf("failed to reconfigure "
226+
"`%s': %s\n", pkg, strerror(rv));
183227
}
184228
}
185229
}

bin/xbps-reconfigure/xbps-reconfigure.1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ argument can be a package name or a package name with version.
5656
This option can be specified multiple times.
5757
.It Fl r, Fl -rootdir Ar dir
5858
Specifies a path for the target root directory.
59+
.It Fl x, Fl -deps
60+
Configure
61+
.Ar PKGNAME...
62+
and its direct dependencies.
63+
.It Fl -fulldeptree
64+
Configure the full dependency tree of
65+
.Ar PKGNAME...
66+
when used with
67+
.Fl x, Fl -deps .
68+
.
5969
.It Fl v, Fl -verbose
6070
Enables verbose messages.
6171
.It Fl V, Fl -version

0 commit comments

Comments
 (0)