Skip to content

Commit 1ccb271

Browse files
pevikmasahir0y
authored andcommitted
kconfig: make "Selected by:" and "Implied by:" readable
Reverse dependency expressions can get rather unwieldy, especially if a symbol is selected by more than a handful of other symbols. I.e. it's possible to have near endless expressions like: A && B && !C || D || F && (G || H) || [...] Chop these expressions into actually readable chunks: - A && B && !C - D - F && (G || H) - [...] I.e. transform the top level OR tokens into newlines and prepend each line with a minus. This makes the "Selected by:" and "Implied by:" blurb much easier to read. This is done only if there is more than one top level OR. "Depends on:" and "Range :" were deliberately left as they are. Based on idea from Paul Bolle. Suggested-by: Paul Bolle <pebolle@tiscali.nl> Signed-off-by: Petr Vorel <petr.vorel@gmail.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 312ee68 commit 1ccb271

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

scripts/kconfig/expr.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2)
11761176
return expr_get_leftmost_symbol(ret);
11771177
}
11781178

1179-
void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
1179+
static void __expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken, bool revdep)
11801180
{
11811181
if (!e) {
11821182
fn(data, NULL, "y");
@@ -1231,9 +1231,14 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
12311231
fn(data, e->right.sym, e->right.sym->name);
12321232
break;
12331233
case E_OR:
1234-
expr_print(e->left.expr, fn, data, E_OR);
1235-
fn(data, NULL, " || ");
1236-
expr_print(e->right.expr, fn, data, E_OR);
1234+
if (revdep && e->left.expr->type != E_OR)
1235+
fn(data, NULL, "\n - ");
1236+
__expr_print(e->left.expr, fn, data, E_OR, revdep);
1237+
if (revdep)
1238+
fn(data, NULL, "\n - ");
1239+
else
1240+
fn(data, NULL, " || ");
1241+
__expr_print(e->right.expr, fn, data, E_OR, revdep);
12371242
break;
12381243
case E_AND:
12391244
expr_print(e->left.expr, fn, data, E_AND);
@@ -1266,6 +1271,11 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
12661271
fn(data, NULL, ")");
12671272
}
12681273

1274+
void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
1275+
{
1276+
__expr_print(e, fn, data, prevtoken, false);
1277+
}
1278+
12691279
static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
12701280
{
12711281
xfwrite(str, strlen(str), 1, data);
@@ -1310,3 +1320,13 @@ void expr_gstr_print(struct expr *e, struct gstr *gs)
13101320
{
13111321
expr_print(e, expr_print_gstr_helper, gs, E_NONE);
13121322
}
1323+
1324+
/*
1325+
* Transform the top level "||" tokens into newlines and prepend each
1326+
* line with a minus. This makes expressions much easier to read.
1327+
* Suitable for reverse dependency expressions.
1328+
*/
1329+
void expr_gstr_print_revdep(struct expr *e, struct gstr *gs)
1330+
{
1331+
__expr_print(e, expr_print_gstr_helper, gs, E_NONE, true);
1332+
}

scripts/kconfig/expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2);
310310
void expr_fprint(struct expr *e, FILE *out);
311311
struct gstr; /* forward */
312312
void expr_gstr_print(struct expr *e, struct gstr *gs);
313+
void expr_gstr_print_revdep(struct expr *e, struct gstr *gs);
313314

314315
static inline int expr_is_yes(struct expr *e)
315316
{

scripts/kconfig/menu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,14 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym,
828828
get_symbol_props_str(r, sym, P_SELECT, _(" Selects: "));
829829
if (sym->rev_dep.expr) {
830830
str_append(r, _(" Selected by: "));
831-
expr_gstr_print(sym->rev_dep.expr, r);
831+
expr_gstr_print_revdep(sym->rev_dep.expr, r);
832832
str_append(r, "\n");
833833
}
834834

835835
get_symbol_props_str(r, sym, P_IMPLY, _(" Implies: "));
836836
if (sym->implied.expr) {
837837
str_append(r, _(" Implied by: "));
838-
expr_gstr_print(sym->implied.expr, r);
838+
expr_gstr_print_revdep(sym->implied.expr, r);
839839
str_append(r, "\n");
840840
}
841841

0 commit comments

Comments
 (0)