xbps-reconfigure: add ability to reconfigure dependencies

adds `-x/--deps` and `--fulldeptree`, that behave similar to the xbps-query modes

fixes #464
This commit is contained in:
classabbyamp 2022-04-23 18:49:25 -04:00 committed by Duncan Overbruck
parent f5d84e8339
commit be7e532c3c
5 changed files with 145 additions and 7 deletions

View File

@ -2,5 +2,6 @@ TOPDIR = ../..
-include $(TOPDIR)/config.mk -include $(TOPDIR)/config.mk
BIN = xbps-reconfigure BIN = xbps-reconfigure
OBJS = main.o find-deps.o
include $(TOPDIR)/mk/prog.mk include $(TOPDIR)/mk/prog.mk

View File

@ -0,0 +1,34 @@
/*-
* Copyright (c) 2022 classabbyamp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _XBPS_RECONFIGURE_DEFS_H_
#define _XBPS_RECONFIGURE_DEFS_H_
#include <xbps.h>
/* from find-deps.c */
int find_pkg_deps(struct xbps_handle *, const char *, bool, xbps_array_t *);
#endif /* !_XBPS_RECONFIGURE_DEFS_H_ */

View File

@ -0,0 +1,49 @@
/*-
* Copyright (c) 2022 classabbyamp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <xbps.h>
#include "defs.h"
int
find_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool full, xbps_array_t *rdeps)
{
xbps_dictionary_t pkgd;
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
return errno;
}
if (full) {
*rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgname);
if (*rdeps == NULL)
return errno;
} else {
*rdeps = xbps_dictionary_get(pkgd, "run_depends");
}
return 0;
}

View File

@ -32,6 +32,7 @@
#include <syslog.h> #include <syslog.h>
#include <xbps.h> #include <xbps.h>
#include "defs.h"
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(bool fail) usage(bool fail)
@ -43,9 +44,11 @@ usage(bool fail)
" -C, --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -d, --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -f, --force Force reconfiguration\n" " -f, --force Force reconfiguration\n"
" --fulldeptree Full dependency tree for -x/--deps\n"
" -h, --help Show usage\n" " -h, --help Show usage\n"
" -i, --ignore PKG Ignore PKG with -a/--all\n" " -i, --ignore PKG Ignore PKG with -a/--all\n"
" -r, --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -x, --deps Also process dependencies for each package\n"
" -v, --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -V, --version Show XBPS version\n"); " -V, --version Show XBPS version\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
@ -90,7 +93,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbd UNUSED)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *shortopts = "aC:dfhi:r:Vv"; const char *shortopts = "aC:dfhi:r:xVv";
const struct option longopts[] = { const struct option longopts[] = {
{ "all", no_argument, NULL, 'a' }, { "all", no_argument, NULL, 'a' },
{ "config", required_argument, NULL, 'C' }, { "config", required_argument, NULL, 'C' },
@ -99,15 +102,17 @@ main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "ignore", required_argument, NULL, 'i' }, { "ignore", required_argument, NULL, 'i' },
{ "rootdir", required_argument, NULL, 'r' }, { "rootdir", required_argument, NULL, 'r' },
{ "deps", no_argument, NULL, 'x' },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "fulldeptree", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
struct xbps_handle xh; struct xbps_handle xh;
const char *confdir = NULL, *rootdir = NULL; const char *confdir = NULL, *rootdir = NULL;
int c, i, rv, flags = 0; int c, i, rv, flags = 0;
bool all = false; bool all = false, rdeps = false, fulldeptree = false;
xbps_array_t ignpkgs = NULL; xbps_array_t ignpkgs = NULL, deps = NULL;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (c) { switch (c) {
@ -135,12 +140,18 @@ main(int argc, char **argv)
case 'r': case 'r':
rootdir = optarg; rootdir = optarg;
break; break;
case 'x':
rdeps = true;
break;
case 'v': case 'v':
flags |= XBPS_FLAG_VERBOSE; flags |= XBPS_FLAG_VERBOSE;
break; break;
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 1:
fulldeptree = true;
break;
case '?': case '?':
default: default:
usage(true); usage(true);
@ -168,7 +179,7 @@ main(int argc, char **argv)
} }
if ((rv = xbps_pkgdb_lock(&xh)) != 0) { if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv)); xbps_error_printf("failed to lock pkgdb: %s\n", strerror(rv));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -176,10 +187,43 @@ main(int argc, char **argv)
rv = xbps_configure_packages(&xh, ignpkgs); rv = xbps_configure_packages(&xh, ignpkgs);
} else { } else {
for (i = optind; i < argc; i++) { for (i = optind; i < argc; i++) {
rv = xbps_configure_pkg(&xh, argv[i], true, false); const char* pkg = argv[i];
if (rdeps) {
rv = find_pkg_deps(&xh, pkg, fulldeptree, &deps);
if (rv != 0) { if (rv != 0) {
fprintf(stderr, "Failed to reconfigure " xbps_error_printf("failed to collect dependencies for "
"`%s': %s\n", argv[i], strerror(rv)); "`%s': %s\n", pkg, strerror(rv));
}
for (unsigned int j = 0; j < xbps_array_count(deps); j++) {
const char *pkgdep = NULL;
char pkgname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(deps, j, &pkgdep);
if (fulldeptree) {
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgdep)) {
xbps_error_printf(
"unable to get package name for dependency `%s'\n", pkgdep);
exit(EXIT_FAILURE);
}
} else {
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgdep)) {
xbps_error_printf(
"unable to get package name for dependency `%s'\n", pkgdep);
exit(EXIT_FAILURE);
}
}
rv = xbps_configure_pkg(&xh, pkgname, true, false);
if (rv != 0) {
xbps_error_printf("failed to reconfigure "
"`%s': %s\n", pkgname, strerror(rv));
}
}
}
rv = xbps_configure_pkg(&xh, pkg, true, false);
if (rv != 0) {
xbps_error_printf("failed to reconfigure "
"`%s': %s\n", pkg, strerror(rv));
} }
} }
} }

View File

@ -56,6 +56,16 @@ argument can be a package name or a package name with version.
This option can be specified multiple times. This option can be specified multiple times.
.It Fl r, Fl -rootdir Ar dir .It Fl r, Fl -rootdir Ar dir
Specifies a path for the target root directory. Specifies a path for the target root directory.
.It Fl x, Fl -deps
Configure
.Ar PKGNAME...
and its direct dependencies.
.It Fl -fulldeptree
Configure the full dependency tree of
.Ar PKGNAME...
when used with
.Fl x, Fl -deps .
.
.It Fl v, Fl -verbose .It Fl v, Fl -verbose
Enables verbose messages. Enables verbose messages.
.It Fl V, Fl -version .It Fl V, Fl -version