3232#include <syslog.h>
3333
3434#include <xbps.h>
35+ #include "defs.h"
3536
3637static void __attribute__((noreturn ))
3738usage (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)
9093int
9194main (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 }
0 commit comments