2010-11-09 03:57:15 +05:30
|
|
|
/*-
|
2014-03-10 14:50:04 +05:30
|
|
|
* Copyright (c) 2010-2014 Juan Romero Pardines.
|
2010-11-09 03:57:15 +05:30
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <unistd.h>
|
2010-12-23 21:53:14 +05:30
|
|
|
#include <inttypes.h>
|
2014-11-20 18:02:21 +05:30
|
|
|
#include <assert.h>
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2014-11-20 18:02:21 +05:30
|
|
|
#include "queue.h"
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-01-04 15:05:00 +05:30
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
#endif
|
|
|
|
|
2010-11-09 03:57:15 +05:30
|
|
|
#ifndef __arraycount
|
|
|
|
# define __arraycount(a) (sizeof(a) / sizeof(*(a)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _DGRAPH_CFFILE "xbps-dgraph.conf"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Properties written to default configuration file.
|
|
|
|
*/
|
|
|
|
struct defprops {
|
|
|
|
const char *sect;
|
|
|
|
const char *prop;
|
|
|
|
const char *val;
|
|
|
|
} dfprops[] = {
|
|
|
|
{ .sect = "graph", .prop = "rankdir", .val = "LR" },
|
|
|
|
{ .sect = "graph", .prop = "ranksep", .val = ".1" },
|
|
|
|
{ .sect = "graph", .prop = "nodesep", .val = ".1" },
|
|
|
|
{ .sect = "graph", .prop = "splines", .val = "polyline" },
|
|
|
|
{ .sect = "graph", .prop = "ratio", .val = "compress" },
|
|
|
|
|
|
|
|
{ .sect = "edge", .prop = "constraint", .val = "true" },
|
|
|
|
{ .sect = "edge", .prop = "arrowhead", .val = "vee" },
|
|
|
|
{ .sect = "edge", .prop = "arrowsize", .val = ".4" },
|
|
|
|
{ .sect = "edge", .prop = "fontname", .val = "Sans" },
|
|
|
|
{ .sect = "edge", .prop = "fontsize", .val = "8" },
|
|
|
|
|
|
|
|
{ .sect = "node", .prop = "height", .val = ".1" },
|
|
|
|
{ .sect = "node", .prop = "width", .val = ".1" },
|
2014-11-20 21:45:43 +05:30
|
|
|
{ .sect = "node", .prop = "shape", .val = "ellipse" },
|
2010-11-09 03:57:15 +05:30
|
|
|
{ .sect = "node", .prop = "fontname", .val = "Sans" },
|
|
|
|
{ .sect = "node", .prop = "fontsize", .val = "8" },
|
|
|
|
|
|
|
|
{ .sect = "node-sub", .prop = "main-style", .val = "filled" },
|
|
|
|
{ .sect = "node-sub", .prop = "main-fillcolor", .val = "darksalmon" },
|
|
|
|
{ .sect = "node-sub", .prop = "style", .val = "filled" },
|
|
|
|
{ .sect = "node-sub", .prop = "fillcolor", .val = "yellowgreen" },
|
|
|
|
{ .sect = "node-sub", .prop = "opt-style", .val = "filled" },
|
|
|
|
{ .sect = "node-sub", .prop = "opt-fillcolor", .val = "grey" }
|
|
|
|
};
|
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
struct pkgdep {
|
|
|
|
SLIST_ENTRY(pkgdep) pkgdep_entries;
|
|
|
|
unsigned int idx;
|
|
|
|
const char *pkgver;
|
|
|
|
};
|
|
|
|
|
2014-11-20 20:54:43 +05:30
|
|
|
static xbps_dictionary_t confd;
|
2014-11-20 18:02:21 +05:30
|
|
|
static SLIST_HEAD(pkgdep_head, pkgdep) pkgdep_list =
|
|
|
|
SLIST_HEAD_INITIALIZER(pkgdep_list);
|
|
|
|
|
2011-01-15 16:29:44 +05:30
|
|
|
static void __attribute__((noreturn))
|
2010-11-09 03:57:15 +05:30
|
|
|
die(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int save_errno = errno;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "xbps-dgraph: ERROR ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
2014-11-19 22:51:32 +05:30
|
|
|
if (save_errno)
|
|
|
|
fprintf(stderr, " (%s)\n", strerror(save_errno));
|
|
|
|
else
|
|
|
|
fprintf(stderr, "\n");
|
2010-11-09 03:57:15 +05:30
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2011-01-15 16:29:44 +05:30
|
|
|
static void __attribute__((noreturn))
|
2010-11-09 03:57:15 +05:30
|
|
|
usage(void)
|
|
|
|
{
|
2012-09-24 14:19:45 +05:30
|
|
|
fprintf(stdout,
|
2010-11-09 03:57:15 +05:30
|
|
|
"Usage: xbps-dgraph [options] <pkgname>\n\n"
|
|
|
|
" Options\n"
|
|
|
|
" -c\t\tPath to configuration file\n"
|
2014-11-20 18:02:21 +05:30
|
|
|
" -d\t\tDebug mode shown to stderr\n"
|
2010-11-09 03:57:15 +05:30
|
|
|
" -g\t\tGenerate a default config file\n"
|
2014-11-19 22:51:32 +05:30
|
|
|
" -R\t\tEnable repository mode\n"
|
2014-11-20 18:02:21 +05:30
|
|
|
" -f\t\tGenerate a full dependency graph\n"
|
2010-11-09 03:57:15 +05:30
|
|
|
" -r\t\t<rootdir>\n\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2013-06-20 13:56:12 +05:30
|
|
|
convert_proptype_to_string(xbps_object_t obj)
|
2010-11-09 03:57:15 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
switch (xbps_object_type(obj)) {
|
|
|
|
case XBPS_TYPE_ARRAY:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "array";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_BOOL:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "bool";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_DICTIONARY:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "dictionary";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_DICT_KEYSYM:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "dictionary key";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_NUMBER:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "integer";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_STRING:
|
2010-11-09 03:57:15 +05:30
|
|
|
return "string";
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_DATA:
|
2013-06-12 14:04:01 +05:30
|
|
|
return "data";
|
2010-11-09 03:57:15 +05:30
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 22:51:32 +05:30
|
|
|
static xbps_dictionary_t
|
|
|
|
create_defconf(void)
|
2010-11-09 03:57:15 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t d, d2;
|
2010-11-09 03:57:15 +05:30
|
|
|
struct defprops *dfp;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
d = xbps_dictionary_create();
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
d2 = xbps_dictionary_create();
|
|
|
|
xbps_dictionary_set(d, "graph", d2);
|
|
|
|
xbps_object_release(d2);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
d2 = xbps_dictionary_create();
|
|
|
|
xbps_dictionary_set(d, "edge", d2);
|
|
|
|
xbps_object_release(d2);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
d2 = xbps_dictionary_create();
|
|
|
|
xbps_dictionary_set(d, "node", d2);
|
|
|
|
xbps_object_release(d2);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
d2 = xbps_dictionary_create();
|
|
|
|
xbps_dictionary_set(d, "node-sub", d2);
|
|
|
|
xbps_object_release(d2);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < __arraycount(dfprops); i++) {
|
2010-11-09 03:57:15 +05:30
|
|
|
dfp = &dfprops[i];
|
2013-06-20 13:56:12 +05:30
|
|
|
d2 = xbps_dictionary_get(d, dfp->sect);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(d2, dfp->prop, dfp->val);
|
2010-11-09 03:57:15 +05:30
|
|
|
}
|
|
|
|
|
2014-11-19 22:51:32 +05:30
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
generate_conf_file(void)
|
|
|
|
{
|
|
|
|
xbps_dictionary_t d;
|
|
|
|
|
|
|
|
d = create_defconf();
|
|
|
|
if (xbps_dictionary_externalize_to_file(d, _DGRAPH_CFFILE) == false) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(d);
|
2014-11-19 22:51:32 +05:30
|
|
|
die("couldn't write conf_file to %s", _DGRAPH_CFFILE);
|
2010-11-09 03:57:15 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(d);
|
2010-11-09 03:57:15 +05:30
|
|
|
printf("Wrote configuration file: %s\n", _DGRAPH_CFFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-11-20 20:54:43 +05:30
|
|
|
write_conf_property_on_stream(FILE *f, const char *section)
|
2010-11-09 03:57:15 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t allkeys, allkeys2;
|
|
|
|
xbps_dictionary_keysym_t dksym, dksym2;
|
|
|
|
xbps_object_t keyobj, keyobj2;
|
2010-11-09 03:57:15 +05:30
|
|
|
const char *cf_val, *keyname, *keyname2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the main dictionary.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
allkeys = xbps_dictionary_all_keys(confd);
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
dksym = xbps_array_get(allkeys, i);
|
|
|
|
keyname = xbps_dictionary_keysym_cstring_nocopy(dksym);
|
|
|
|
keyobj = xbps_dictionary_get_keysym(confd, dksym);
|
2010-11-09 03:57:15 +05:30
|
|
|
if (strcmp(keyname, section))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the dictionary sections [edge/graph/node].
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
allkeys2 = xbps_dictionary_all_keys(keyobj);
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int x = 0; x < xbps_array_count(allkeys2); x++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
dksym2 = xbps_array_get(allkeys2, x);
|
|
|
|
keyname2 = xbps_dictionary_keysym_cstring_nocopy(dksym2);
|
|
|
|
keyobj2 = xbps_dictionary_get_keysym(keyobj, dksym2);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
cf_val = xbps_string_cstring_nocopy(keyobj2);
|
2010-11-09 03:57:15 +05:30
|
|
|
fprintf(f, "%s=\"%s\"", keyname2, cf_val);
|
2013-06-20 13:56:12 +05:30
|
|
|
if (x + 1 >= xbps_array_count(allkeys2))
|
2010-11-09 03:57:15 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
fprintf(f, ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
strip_dashes_from_key(const char *str)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
p = strdup(str);
|
|
|
|
if (p == NULL)
|
|
|
|
die("%s alloc p", __func__);
|
|
|
|
|
|
|
|
for (i = 0; i < strlen(p); i++) {
|
|
|
|
if (p[i] == '-')
|
|
|
|
p[i] = '_';
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-20 13:56:12 +05:30
|
|
|
parse_array_in_pkg_dictionary(FILE *f, xbps_dictionary_t plistd,
|
|
|
|
xbps_dictionary_t sub_confd,
|
|
|
|
xbps_array_t allkeys)
|
2010-11-09 03:57:15 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_keysym_t dksym;
|
|
|
|
xbps_object_t keyobj, sub_keyobj;
|
2014-11-20 15:18:28 +05:30
|
|
|
const char *tmpkeyname, *cfprop;
|
|
|
|
char *keyname;
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
dksym = xbps_array_get(allkeys, i);
|
|
|
|
tmpkeyname = xbps_dictionary_keysym_cstring_nocopy(dksym);
|
|
|
|
keyobj = xbps_dictionary_get_keysym(plistd, dksym);
|
2010-11-09 03:57:15 +05:30
|
|
|
keyname = strip_dashes_from_key(tmpkeyname);
|
|
|
|
|
|
|
|
fprintf(f, " main -> %s [label=\"%s\"];\n",
|
|
|
|
keyname, convert_proptype_to_string(keyobj));
|
|
|
|
|
|
|
|
/*
|
2013-06-12 14:04:01 +05:30
|
|
|
* Process array objects.
|
2010-11-09 03:57:15 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_object_type(keyobj) == XBPS_TYPE_ARRAY) {
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int x = 0; x < xbps_array_count(keyobj); x++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
sub_keyobj = xbps_array_get(keyobj, x);
|
|
|
|
if (xbps_object_type(sub_keyobj) == XBPS_TYPE_STRING) {
|
2013-06-13 21:11:16 +05:30
|
|
|
/*
|
|
|
|
* Process arrays of strings.
|
|
|
|
*/
|
|
|
|
fprintf(f, " %s -> %s_%u_string "
|
2013-06-12 14:04:01 +05:30
|
|
|
"[label=\"string\"];\n",
|
|
|
|
keyname, keyname, x);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(sub_confd,
|
2013-06-12 14:04:01 +05:30
|
|
|
"style", &cfprop);
|
2013-06-13 21:11:16 +05:30
|
|
|
fprintf(f, " %s_%u_string [style=\"%s\",",
|
2013-06-12 14:04:01 +05:30
|
|
|
keyname, x, cfprop);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(sub_confd,
|
2013-06-12 14:04:01 +05:30
|
|
|
"fillcolor", &cfprop);
|
|
|
|
fprintf(f, "fillcolor=\"%s\","
|
|
|
|
"label=\"%s\"];\n", cfprop,
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_string_cstring_nocopy(sub_keyobj));
|
2013-06-12 14:04:01 +05:30
|
|
|
}
|
2010-11-09 03:57:15 +05:30
|
|
|
}
|
|
|
|
free(keyname);
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 15:18:28 +05:30
|
|
|
fprintf(f, " %s -> %s_value;\n", keyname, keyname);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(sub_confd, "style", &cfprop);
|
2010-11-09 03:57:15 +05:30
|
|
|
fprintf(f, " %s_value [style=\"%s\",", keyname, cfprop);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(sub_confd,
|
2010-11-09 03:57:15 +05:30
|
|
|
"fillcolor", &cfprop);
|
|
|
|
fprintf(f, "fillcolor=\"%s\"", cfprop);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all other object types...
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
switch (xbps_object_type(keyobj)) {
|
|
|
|
case XBPS_TYPE_BOOL:
|
2010-11-09 03:57:15 +05:30
|
|
|
fprintf(f, ",label=\"%s\"",
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_bool_true(keyobj) ? "true" : "false");
|
2010-11-09 03:57:15 +05:30
|
|
|
break;
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_DATA:
|
|
|
|
fprintf(f, ",label=\"%zu bytes\"", xbps_data_size(keyobj));
|
2013-06-13 21:11:16 +05:30
|
|
|
break;
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_NUMBER:
|
2013-06-14 08:42:15 +05:30
|
|
|
fprintf(f, ",label=\"%"PRIu64" bytes\"",
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_number_unsigned_integer_value(keyobj));
|
2010-11-09 03:57:15 +05:30
|
|
|
break;
|
2013-06-20 13:56:12 +05:30
|
|
|
case XBPS_TYPE_STRING:
|
2014-11-20 21:45:43 +05:30
|
|
|
fprintf(f, ",label=\"%s\"", xbps_string_cstring_nocopy(keyobj));
|
2010-11-09 03:57:15 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(f, "];\n");
|
|
|
|
free(keyname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
static void
|
|
|
|
process_fulldeptree(struct xbps_handle *xhp, FILE *f,
|
|
|
|
xbps_dictionary_t pkgd, xbps_array_t rdeps,
|
|
|
|
bool repomode)
|
|
|
|
{
|
|
|
|
xbps_array_t rpkgrdeps;
|
|
|
|
struct pkgdep *pd;
|
|
|
|
const char *pkgver;
|
|
|
|
unsigned int i, x;
|
|
|
|
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
|
|
|
|
for (i = 0; i < xbps_array_count(rdeps); i++) {
|
|
|
|
xbps_dictionary_t rpkgd;
|
|
|
|
const char *pkgdep;
|
|
|
|
unsigned int pkgidx = 0;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(rdeps, i, &pkgdep);
|
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
|
|
|
|
if (strcmp(pd->pkgver, pkgdep) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pkgidx++;
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
pd = malloc(sizeof(*pd));
|
|
|
|
assert(pd);
|
|
|
|
pd->idx = pkgidx;
|
|
|
|
pd->pkgver = pkgdep;
|
|
|
|
SLIST_INSERT_HEAD(&pkgdep_list, pd, pkgdep_entries);
|
|
|
|
}
|
|
|
|
if (repomode) {
|
|
|
|
rpkgd = xbps_rpool_get_pkg(xhp, pkgdep);
|
|
|
|
} else {
|
|
|
|
rpkgd = xbps_pkgdb_get_pkg(xhp, pkgdep);
|
|
|
|
}
|
|
|
|
assert(rpkgd);
|
|
|
|
rpkgrdeps = xbps_dictionary_get(rpkgd, "run_depends");
|
|
|
|
for (x = 0; x < xbps_array_count(rpkgrdeps); x++) {
|
|
|
|
struct pkgdep *ppd;
|
|
|
|
const char *rpkgdep;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(rpkgrdeps, x, &rpkgdep);
|
|
|
|
SLIST_FOREACH(ppd, &pkgdep_list, pkgdep_entries) {
|
|
|
|
if (xbps_pkgpattern_match(ppd->pkgver, rpkgdep))
|
|
|
|
fprintf(f, "\t%u -> %u;\n", pkgidx, ppd->idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f, "\t%u [label=\"%s\"", pkgidx, pkgdep);
|
|
|
|
if (repomode && xbps_pkgdb_get_pkg(xhp, pkgdep))
|
|
|
|
fprintf(f, ",style=\"filled\",fillcolor=\"yellowgreen\"");
|
|
|
|
|
|
|
|
fprintf(f, "]\n");
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries)
|
|
|
|
++i;
|
|
|
|
|
|
|
|
fprintf(f, "\t%u [label=\"%s\",style=\"filled\",fillcolor=\"darksalmon\"];\n", i, pkgver);
|
|
|
|
rpkgrdeps = xbps_dictionary_get(pkgd, "run_depends");
|
|
|
|
for (x = 0; x < xbps_array_count(rpkgrdeps); x++) {
|
|
|
|
const char *rpkgdep;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(rpkgrdeps, x, &rpkgdep);
|
|
|
|
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
|
|
|
|
if (xbps_pkgpattern_match(pd->pkgver, rpkgdep))
|
|
|
|
fprintf(f, "\t%u -> %u;\n", i, pd->idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 03:57:15 +05:30
|
|
|
static void
|
2012-06-14 11:52:11 +05:30
|
|
|
create_dot_graph(struct xbps_handle *xhp,
|
|
|
|
FILE *f,
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t plistd,
|
2014-11-20 18:02:21 +05:30
|
|
|
bool repomode,
|
|
|
|
bool fulldepgraph)
|
2010-11-09 03:57:15 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t sub_confd;
|
|
|
|
xbps_array_t allkeys, rdeps;
|
2013-06-12 14:04:01 +05:30
|
|
|
const char *pkgver, *cfprop;
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(plistd, "pkgver", &pkgver);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Start filling the output file...
|
|
|
|
*/
|
|
|
|
fprintf(f, "/* Graph created for %s by xbps-graph %s */\n\n",
|
|
|
|
pkgver, XBPS_RELVER);
|
|
|
|
fprintf(f, "digraph pkg_dictionary {\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the graph section in config file.
|
|
|
|
*/
|
|
|
|
fprintf(f, " graph [");
|
2014-11-20 20:54:43 +05:30
|
|
|
write_conf_property_on_stream(f, "graph");
|
2014-11-20 20:58:47 +05:30
|
|
|
if (fulldepgraph)
|
|
|
|
fprintf(f, ",label=\"[XBPS] %s full dependency graph "
|
|
|
|
"[%s]\"];\n", pkgver, repomode ? "repo" : "pkgdb");
|
|
|
|
else
|
|
|
|
fprintf(f, ",label=\"[XBPS] %s metadata properties\"];\n", pkgver);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the edge section in config file.
|
|
|
|
*/
|
|
|
|
fprintf(f, " edge [");
|
2014-11-20 20:54:43 +05:30
|
|
|
write_conf_property_on_stream(f, "edge");
|
2010-11-09 03:57:15 +05:30
|
|
|
fprintf(f, "];\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the node section in config file.
|
|
|
|
*/
|
|
|
|
fprintf(f, " node [");
|
2014-11-20 20:54:43 +05:30
|
|
|
write_conf_property_on_stream(f, "node");
|
2010-11-09 03:57:15 +05:30
|
|
|
fprintf(f, "];\n");
|
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
if (fulldepgraph) {
|
|
|
|
if (repomode) {
|
|
|
|
rdeps = xbps_rpool_get_pkg_fulldeptree(xhp, pkgver);
|
|
|
|
} else {
|
|
|
|
rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgver);
|
|
|
|
}
|
|
|
|
process_fulldeptree(xhp, f, plistd, rdeps, repomode);
|
2014-11-19 22:51:32 +05:30
|
|
|
} else {
|
2014-11-20 18:02:21 +05:30
|
|
|
/*
|
|
|
|
* Process the node-sub section in config file.
|
|
|
|
*/
|
|
|
|
fprintf(f, " main [");
|
|
|
|
sub_confd = xbps_dictionary_get(confd, "node-sub");
|
|
|
|
if (xbps_dictionary_get_cstring_nocopy(sub_confd, "main-style", &cfprop))
|
|
|
|
fprintf(f, "style=%s,", cfprop);
|
|
|
|
if (xbps_dictionary_get_cstring_nocopy(sub_confd, "main-fillcolor", &cfprop))
|
|
|
|
fprintf(f, "fillcolor=\"%s\",", cfprop);
|
|
|
|
|
|
|
|
fprintf(f, "label=\"Dictionary\"];\n");
|
|
|
|
if (repomode) {
|
|
|
|
rdeps = xbps_rpool_get_pkg_revdeps(xhp, pkgver);
|
|
|
|
} else {
|
|
|
|
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver);
|
|
|
|
}
|
|
|
|
if (xbps_array_count(rdeps))
|
|
|
|
xbps_dictionary_set(plistd, "requiredby", rdeps);
|
2014-11-19 22:51:32 +05:30
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
allkeys = xbps_dictionary_all_keys(plistd);
|
|
|
|
parse_array_in_pkg_dictionary(f, plistd, sub_confd, allkeys);
|
|
|
|
}
|
2010-11-09 03:57:15 +05:30
|
|
|
/*
|
|
|
|
* Terminate the stream...
|
|
|
|
*/
|
|
|
|
fprintf(f, "}\n");
|
|
|
|
fflush(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2014-11-20 20:54:43 +05:30
|
|
|
xbps_dictionary_t plistd = NULL;
|
2012-01-17 20:47:03 +05:30
|
|
|
struct xbps_handle xh;
|
2010-11-09 03:57:15 +05:30
|
|
|
FILE *f = NULL;
|
2011-02-21 22:12:47 +05:30
|
|
|
const char *conf_file = NULL, *rootdir = NULL;
|
2014-11-20 18:02:21 +05:30
|
|
|
int c, rv, flags = 0;
|
|
|
|
bool repomode = false, fulldepgraph = false;
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
while ((c = getopt(argc, argv, "c:dgfRr:")) != -1) {
|
2010-11-09 03:57:15 +05:30
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
/* Configuration file. */
|
|
|
|
conf_file = optarg;
|
|
|
|
break;
|
2014-11-20 18:02:21 +05:30
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
2010-11-09 03:57:15 +05:30
|
|
|
case 'g':
|
|
|
|
/* Generate auto conf file. */
|
|
|
|
generate_conf_file();
|
|
|
|
exit(EXIT_SUCCESS);
|
2014-11-20 18:02:21 +05:30
|
|
|
case 'f':
|
|
|
|
/* generate a full dependency graph */
|
|
|
|
fulldepgraph = true;
|
|
|
|
break;
|
2010-11-09 03:57:15 +05:30
|
|
|
case 'R':
|
2014-11-20 18:02:21 +05:30
|
|
|
/* enable repository mode */
|
2014-11-19 22:51:32 +05:30
|
|
|
repomode = true;
|
2010-11-09 03:57:15 +05:30
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
/* Set different rootdir. */
|
2011-02-21 22:12:47 +05:30
|
|
|
rootdir = optarg;
|
2010-11-09 03:57:15 +05:30
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
2011-02-21 22:12:47 +05:30
|
|
|
/* Initialize libxbps */
|
2012-01-17 20:47:03 +05:30
|
|
|
memset(&xh, 0, sizeof(xh));
|
2014-03-10 14:50:04 +05:30
|
|
|
if (rootdir != NULL)
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
|
2014-03-10 14:50:04 +05:30
|
|
|
|
2014-11-20 18:02:21 +05:30
|
|
|
xh.flags = flags;
|
2012-01-17 20:47:03 +05:30
|
|
|
if ((rv = xbps_init(&xh)) != 0)
|
2011-12-15 15:49:20 +05:30
|
|
|
die("failed to initialize libxbps: %s", strerror(rv));
|
2011-02-21 22:12:47 +05:30
|
|
|
|
2010-11-09 03:57:15 +05:30
|
|
|
/*
|
2014-11-19 22:51:32 +05:30
|
|
|
* If -c not set and config file does not exist, use defaults.
|
2010-11-09 03:57:15 +05:30
|
|
|
*/
|
|
|
|
if (conf_file == NULL)
|
|
|
|
conf_file = _DGRAPH_CFFILE;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
confd = xbps_dictionary_internalize_from_zfile(conf_file);
|
2014-11-19 22:51:32 +05:30
|
|
|
if (confd == NULL) {
|
|
|
|
if (errno != ENOENT)
|
|
|
|
die("cannot read conf file `%s'", conf_file);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
2014-11-19 22:51:32 +05:30
|
|
|
confd = create_defconf();
|
|
|
|
}
|
2010-11-09 03:57:15 +05:30
|
|
|
/*
|
|
|
|
* Internalize the plist file of the target installed package.
|
|
|
|
*/
|
2014-11-19 22:51:32 +05:30
|
|
|
if (repomode) {
|
|
|
|
plistd = xbps_rpool_get_pkg(&xh, argv[0]);
|
|
|
|
} else {
|
|
|
|
plistd = xbps_pkgdb_get_pkg(&xh, argv[0]);
|
|
|
|
}
|
2010-11-09 03:57:15 +05:30
|
|
|
if (plistd == NULL)
|
2014-11-19 22:51:32 +05:30
|
|
|
die("cannot find `%s' package", argv[0]);
|
2010-11-09 03:57:15 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the output FILE.
|
|
|
|
*/
|
2014-11-20 18:02:21 +05:30
|
|
|
if ((f = fdopen(STDOUT_FILENO, "w")) == NULL)
|
|
|
|
die("cannot open stdout");
|
2010-11-09 03:57:15 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the dot(1) graph!
|
|
|
|
*/
|
2014-11-20 18:02:21 +05:30
|
|
|
if (fulldepgraph) {
|
2014-11-20 20:54:43 +05:30
|
|
|
create_dot_graph(&xh, f, plistd, repomode, true);
|
2014-11-20 18:02:21 +05:30
|
|
|
} else {
|
2014-11-20 20:54:43 +05:30
|
|
|
create_dot_graph(&xh, f, plistd, repomode, false);
|
2014-11-20 18:02:21 +05:30
|
|
|
}
|
2010-11-09 03:57:15 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|