kconfig: improve the recursive dependency report
[carl9170fw.git] / config / symbol.c
index 2460648a581aee4a9c8d41a6661dfd29627b8ff3..703b9b899ee9c6fd0b2f2de9411d8be5b4413cbe 100644 (file)
@@ -76,15 +76,6 @@ struct property *sym_get_choice_prop(struct symbol *sym)
        return NULL;
 }
 
-struct property *sym_get_env_prop(struct symbol *sym)
-{
-       struct property *prop;
-
-       for_all_properties(sym, prop, P_ENV)
-               return prop;
-       return NULL;
-}
-
 static struct property *sym_get_default_prop(struct symbol *sym)
 {
        struct property *prop;
@@ -463,7 +454,7 @@ void sym_calc_value(struct symbol *sym)
                }
        }
 
-       if (sym->flags & SYMBOL_AUTO)
+       if (sym->flags & SYMBOL_NO_WRITE)
                sym->flags &= ~SYMBOL_WRITE;
 
        if (sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES)
@@ -879,59 +870,6 @@ struct symbol *sym_find(const char *name)
        return symbol;
 }
 
-/*
- * Expand symbol's names embedded in the string given in argument. Symbols'
- * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to
- * the empty string.
- */
-char *sym_expand_string_value(const char *in)
-{
-       const char *src;
-       char *res;
-       size_t reslen;
-
-       /*
-        * Note: 'in' might come from a token that's about to be
-        * freed, so make sure to always allocate a new string
-        */
-       reslen = strlen(in) + 1;
-       res = xmalloc(reslen);
-       res[0] = '\0';
-
-       while ((src = strchr(in, '$'))) {
-               char *p, name[SYMBOL_MAXLENGTH];
-               const char *symval = "";
-               struct symbol *sym;
-               size_t newlen;
-
-               strncat(res, in, src - in);
-               src++;
-
-               p = name;
-               while (isalnum(*src) || *src == '_')
-                       *p++ = *src++;
-               *p = '\0';
-
-               sym = sym_find(name);
-               if (sym != NULL) {
-                       sym_calc_value(sym);
-                       symval = sym_get_string_value(sym);
-               }
-
-               newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
-               if (newlen > reslen) {
-                       reslen = newlen;
-                       res = xrealloc(res, reslen);
-               }
-
-               strcat(res, symval);
-               in = src;
-       }
-       strcat(res, in);
-
-       return res;
-}
-
 const char *sym_escape_string_value(const char *in)
 {
        const char *p;
@@ -1073,7 +1011,7 @@ static struct dep_stack {
        struct dep_stack *prev, *next;
        struct symbol *sym;
        struct property *prop;
-       struct expr *expr;
+       struct expr **expr;
 } *check_top;
 
 static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
@@ -1138,31 +1076,42 @@ static void sym_check_print_recursive(struct symbol *last_sym)
                        fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
                                prop->file->name, prop->lineno);
 
-               if (stack->expr) {
-                       fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
-                               prop->file->name, prop->lineno,
+               if (sym_is_choice(sym)) {
+                       fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
+                               menu->file->name, menu->lineno,
+                               sym->name ? sym->name : "<choice>",
+                               next_sym->name ? next_sym->name : "<choice>");
+               } else if (sym_is_choice_value(sym)) {
+                       fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
+                               menu->file->name, menu->lineno,
                                sym->name ? sym->name : "<choice>",
-                               prop_get_type_name(prop->type),
                                next_sym->name ? next_sym->name : "<choice>");
-               } else if (stack->prop) {
+               } else if (stack->expr == &sym->dir_dep.expr) {
                        fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
                                prop->file->name, prop->lineno,
                                sym->name ? sym->name : "<choice>",
                                next_sym->name ? next_sym->name : "<choice>");
-               } else if (sym_is_choice(sym)) {
-                       fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
-                               menu->file->name, menu->lineno,
+               } else if (stack->expr == &sym->rev_dep.expr) {
+                       fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
+                               prop->file->name, prop->lineno,
                                sym->name ? sym->name : "<choice>",
                                next_sym->name ? next_sym->name : "<choice>");
-               } else if (sym_is_choice_value(sym)) {
-                       fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
-                               menu->file->name, menu->lineno,
+               } else if (stack->expr == &sym->implied.expr) {
+                       fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n",
+                               prop->file->name, prop->lineno,
                                sym->name ? sym->name : "<choice>",
                                next_sym->name ? next_sym->name : "<choice>");
+               } else if (stack->expr) {
+                       fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
+                               prop->file->name, prop->lineno,
+                               sym->name ? sym->name : "<choice>",
+                               prop_get_type_name(prop->type),
+                               next_sym->name ? next_sym->name : "<choice>");
                } else {
-                       fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
+                       fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
                                prop->file->name, prop->lineno,
                                sym->name ? sym->name : "<choice>",
+                               prop_get_type_name(prop->type),
                                next_sym->name ? next_sym->name : "<choice>");
                }
        }
@@ -1219,12 +1168,26 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 
        dep_stack_insert(&stack, sym);
 
+       stack.expr = &sym->dir_dep.expr;
+       sym2 = sym_check_expr_deps(sym->dir_dep.expr);
+       if (sym2)
+               goto out;
+
+       stack.expr = &sym->rev_dep.expr;
        sym2 = sym_check_expr_deps(sym->rev_dep.expr);
        if (sym2)
                goto out;
 
+       stack.expr = &sym->implied.expr;
+       sym2 = sym_check_expr_deps(sym->implied.expr);
+       if (sym2)
+               goto out;
+
+       stack.expr = NULL;
+
        for (prop = sym->prop; prop; prop = prop->next) {
-               if (prop->type == P_CHOICE || prop->type == P_SELECT)
+               if (prop->type == P_CHOICE || prop->type == P_SELECT ||
+                   prop->type == P_IMPLY)
                        continue;
                stack.prop = prop;
                sym2 = sym_check_expr_deps(prop->visible.expr);
@@ -1232,7 +1195,7 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
                        break;
                if (prop->type != P_DEFAULT || sym_is_choice(sym))
                        continue;
-               stack.expr = prop->expr;
+               stack.expr = &prop->expr;
                sym2 = sym_check_expr_deps(prop->expr);
                if (sym2)
                        break;
@@ -1310,9 +1273,6 @@ struct symbol *sym_check_deps(struct symbol *sym)
                sym->flags &= ~SYMBOL_CHECK;
        }
 
-       if (sym2 && sym2 == sym)
-               sym2 = NULL;
-
        return sym2;
 }
 
@@ -1351,8 +1311,6 @@ const char *prop_get_type_name(enum prop_type type)
        switch (type) {
        case P_PROMPT:
                return "prompt";
-       case P_ENV:
-               return "env";
        case P_COMMENT:
                return "comment";
        case P_MENU: