From 04d323e9a77957b83344a386329dd0686d7a5570 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sat, 20 Mar 2021 11:28:21 +0100 Subject: [PATCH] distromatic.c: add a sources file with the list of number of requirements per package to detect leaves (package that can be removed without breaking deps) --- src/distromatic.c | 34 ++++++++++++++++++++++++++++++++++ src/headerlist.c | 2 ++ src/include/headerlist.h | 1 + src/reports.c | 21 ++++++++++++++++----- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/distromatic.c b/src/distromatic.c index 91c1dbf..f90fc0a 100644 --- a/src/distromatic.c +++ b/src/distromatic.c @@ -1264,6 +1264,40 @@ main(int argc, char *argv[]) currheadersourcelist = currheadersourcelist->next; } } + + // write list of left packages (not required by any other package) + char allsources_filename[PATH_MAX]; + FILE *afs; + snprintf(allsources_filename, PATH_MAX, "%ssources", configtag->html_dir); + afs=fopen(allsources_filename,"w"); + if (!afs) { + fprintf(stderr, "Error: can't open file for writing: %s. Aborting.\n", allsources_filename); + exit(1); + } + currheadersourcelist = configtag->headersourcelist; + long tot; + fprintf(afs,"# Number of times each source and related builds are internally required\n# src"); + for (i = 0; i < ARCHS_MAX && configtag->arch[i]; i++) { + tot += currheadersourcelist->childrenrequiredcount[i]; + fprintf(afs," %s", configtag->arch[i]); + } + fprintf(afs," tot\n"); + while (currheadersourcelist != NULL) { + tot = 0; + fprintf(afs,"%s:", currheadersourcelist->name); + for (i = 0; i < ARCHS_MAX && configtag->arch[i]; i++) { + tot += currheadersourcelist->childrenrequiredcount[i]; + if (currheadersourcelist->firstchild[i]) + fprintf(afs," %ld", + currheadersourcelist->childrenrequiredcount[i]); + else + fprintf(afs," -"); + } + fprintf(afs," %ld\n", tot); + currheadersourcelist = currheadersourcelist->next; + } + fclose(afs); + } // if (genheader_mode) if (mode & MODE_SQLITE3) { diff --git a/src/headerlist.c b/src/headerlist.c index c75dbee..dabf987 100644 --- a/src/headerlist.c +++ b/src/headerlist.c @@ -1084,6 +1084,7 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) { newheadersourcelist->next = NULL; for (arch = 0; arch < ARCHS_MAX; arch++) { newheadersourcelist->firstchild[arch] = NULL; + newheadersourcelist->childrenrequiredcount[arch] = 0; } newheadersourcelist->updatingparent = NULL; newheadersourcelist->altrepository = altrepository; @@ -1231,6 +1232,7 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) { newheadersourcelist->next = NULL; for (arch = 0; arch < ARCHS_MAX; arch++) { newheadersourcelist->firstchild[arch] = NULL; + newheadersourcelist->childrenrequiredcount[arch] = 0; } newheadersourcelist->updatingparent = NULL; newheadersourcelist->altrepository = altrepository; diff --git a/src/include/headerlist.h b/src/include/headerlist.h index cd4afaa..e73af3b 100644 --- a/src/include/headerlist.h +++ b/src/include/headerlist.h @@ -140,6 +140,7 @@ struct headerSourceList { struct warningList *firstwarning; struct headerSourceList *updatingparent; struct rebuildList *firstrebuild; + long childrenrequiredcount[ARCHS_MAX]; long id; }; diff --git a/src/reports.c b/src/reports.c index e55975f..3ded699 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1760,9 +1760,9 @@ int print_datatables(struct configTag *ct, int arch) { logmsg(LOG_DEBUG,"writing deps files (1)"); struct providedList* provided = ct->providedlist_idx[arch][0]; while (provided) { - if (!strncmp("debuginfo(build-id)", provided->name, 20)) { - provided = provided->next; - continue; + if (!strncmp("debuginfo(build-id)", provided->name, 20)) { + provided = provided->next; + continue; } nonobsoletednumproviders=0; for (i = 0; i < provided->numproviders; i++) { @@ -1849,18 +1849,23 @@ int print_datatables(struct configTag *ct, int arch) { strcmp(currheaderlist->require[i-1]->resolved->provider[0]->name, currheaderlist->require[i]->resolved->provider[0]->name)) && strcmp(currheaderlist->name, - currheaderlist->require[i]->resolved->provider[0]->name)) + currheaderlist->require[i]->resolved->provider[0]->name)) { fprintf(fd,"%s ",currheaderlist->require[i]->resolved->provider[0]->name); + } } else { if (i == 0 || !currheaderlist->require[i-1]->resolved || !currheaderlist->require[i-1]->resolved->numproviders || strcmp(currheaderlist->require[i-1]->resolved->name, - currheaderlist->require[i]->resolved->name)) { + currheaderlist->require[i]->resolved->name)) { fprintf_depstable_filtered_var(fd,currheaderlist->require[i]->resolved->name); fprintf(fd," "); } } + for (int j = 0; j < currheaderlist->require[i]->resolved->numproviders; j++) { + if (currheaderlist->require[i]->resolved->provider[j]->sourceheader != currheaderlist->sourceheader) + currheaderlist->require[i]->resolved->provider[j]->sourceheader->childrenrequiredcount[arch]++; + } } } fprintf(fd,"\n"); @@ -1874,6 +1879,12 @@ int print_datatables(struct configTag *ct, int arch) { strncmp("debuginfo(build-id)",currheaderlist->sourceheader->require[i]->name,20)) { fprintf(fbd," "); fprintf_depstable_filtered_var(fbd,currheaderlist->sourceheader->require[i]->name); + if (currheaderlist->sourceheader->require[i]->resolved) { + for (int j = 0; j < currheaderlist->sourceheader->require[i]->resolved->numproviders; j++) { + if (currheaderlist->sourceheader->require[i]->resolved->provider[j]->sourceheader != currheaderlist->sourceheader) + currheaderlist->sourceheader->require[i]->resolved->provider[j]->sourceheader->childrenrequiredcount[arch]++; + } + } } }