Lines Matching full:self
779 def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True, argument
841 self.srctree = os.environ.get("srctree", "")
842 self.config_prefix = os.environ.get("CONFIG_", "CONFIG_")
845 self._set_match = _re_match(self.config_prefix + r"([^=]+)=(.*)")
846 self._unset_match = \
847 _re_match(r"# {}([^ ]+) is not set".format(self.config_prefix))
850 self.warnings = []
852 self._warnings_enabled = warn
853 self._warn_to_stderr = warn_to_stderr
854 self._warn_for_undef_assign = \
856 self._warn_for_redun_assign = self._warn_for_override = True
859 self._encoding = encoding
862 self.syms = {}
863 self.const_syms = {}
864 self.defined_syms = []
866 self.named_choices = {}
867 self.choices = []
869 self.menus = []
870 self.comments = []
874 sym.kconfig = self
880 self.const_syms[nmy] = sym
882 self.n = self.const_syms["n"]
883 self.m = self.const_syms["m"]
884 self.y = self.const_syms["y"]
888 sym = self.const_syms[nmy]
889 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
893 self.variables = {}
896 self._functions = {
907 self._functions.update(
918 self._parsing_kconfigs = True
920 self.modules = self._lookup_sym("MODULES")
921 self.defconfig_list = None
923 self.top_node = MenuNode()
924 self.top_node.kconfig = self
925 self.top_node.item = MENU
926 self.top_node.is_menuconfig = True
927 self.top_node.visibility = self.y
928 self.top_node.prompt = ("Main menu", self.y)
929 self.top_node.parent = None
930 self.top_node.dep = self.y
931 self.top_node.filename = filename
932 self.top_node.linenr = 1
933 self.top_node.include_path = ()
938 self.kconfig_filenames = [filename]
939 self.env_vars = set()
944 self._reuse_tokens = False
948 self._filestack = []
949 self._include_path = ()
952 self._filename = filename
953 self._linenr = 0
957 self._readline = \
958 self._open(os.path.join(self.srctree, filename), "r").readline
962 self._parse_block(None, self.top_node, self.top_node)
964 _decoding_error(e, self._filename)
968 self._readline.__self__.close()
970 self.top_node.list = self.top_node.next
971 self.top_node.next = None
973 self._parsing_kconfigs = False
975 self.unique_defined_syms = _ordered_unique(self.defined_syms)
976 self.unique_choices = _ordered_unique(self.choices)
979 self._finalize_tree(self.top_node, self.y)
983 self._check_sym_sanity()
984 self._check_choice_sanity()
991 self._check_undef_syms()
995 self._build_dep()
999 for sym in self.unique_defined_syms:
1004 self._add_choice_deps()
1007 self._warn_for_no_prompt = True
1009 self.mainmenu_text = self.top_node.prompt[0]
1012 def defconfig_filename(self): argument
1016 if self.defconfig_list:
1017 for filename, cond in self.defconfig_list.defaults:
1020 with self._open_config(filename.str_value) as f:
1027 def load_config(self, filename=None, replace=True, verbose=True): argument
1089 filename = self.defconfig_filename
1103 self._warn_for_no_prompt = False
1107 self._load_config(filename, replace)
1111 self._warn_for_no_prompt = True
1115 def _load_config(self, filename, replace): argument
1116 with self._open_config(filename) as f:
1124 for sym in self.unique_defined_syms:
1127 for choice in self.unique_choices:
1131 set_match = self._set_match
1132 unset_match = self._unset_match
1133 syms = self.syms
1143 self._warn_undef_assign_load(name, val, filename,
1149 self._warn_undef_assign_load(name, val, filename,
1160 self._warn("'{}' is not a valid value for the {} "
1178 self._warn("both m and y assigned to symbols "
1188 self._warn("malformed string literal in "
1204 self._warn("ignoring malformed line '{}'"
1212 self._warn_undef_assign_load(name, "n", filename,
1236 self._warn_redun_assign(msg, filename, linenr)
1238 self._warn_override(msg, filename, linenr)
1246 for sym in self.unique_defined_syms:
1250 for choice in self.unique_choices:
1254 def write_autoconf(self, filename, argument
1265 Self-explanatory.
1272 with self._open(filename, "w") as f:
1275 for sym in self.unique_defined_syms:
1284 .format(self.config_prefix, sym.name,
1289 .format(self.config_prefix, sym.name,
1298 .format(self.config_prefix, sym.name, val))
1300 def write_config(self, filename=None, argument
1349 with self._open(filename, "w") as f:
1352 for node in self.node_iter(unique_syms=True):
1367 def write_min_config(self, filename, argument
1381 Self-explanatory.
1388 with self._open(filename, "w") as f:
1391 for sym in self.unique_defined_syms:
1416 def sync_deps(self, path): argument
1480 self._sync_deps()
1484 def _sync_deps(self): argument
1486 self._load_old_vals()
1488 for sym in self.unique_defined_syms:
1524 self._write_old_vals()
1526 def _write_old_vals(self): argument
1536 with self._open("auto.conf", "w") as f:
1537 for sym in self.unique_defined_syms:
1541 def _load_old_vals(self): argument
1549 for sym in self.unique_defined_syms:
1556 with self._open("auto.conf", "r") as f:
1558 match = self._set_match(line)
1565 if name in self.syms:
1566 sym = self.syms[name]
1574 self.syms[name]._old_val = val
1580 def node_iter(self, unique_syms=False): argument
1604 for sym in self.unique_defined_syms:
1607 node = self.top_node
1631 def eval_string(self, s): argument
1654 self._filename = None
1658 self._line = s
1659 self._tokens = self._tokenize("if " + s)
1660 self._tokens_i = 1 # Skip the 'if' token
1662 return expr_value(self._expect_expr_and_eol())
1664 def unset_values(self): argument
1669 self._warn_for_no_prompt = False
1674 for sym in self.unique_defined_syms:
1677 for choice in self.unique_choices:
1680 self._warn_for_no_prompt = True
1682 def enable_warnings(self): argument
1686 self._warnings_enabled = True
1688 def disable_warnings(self): argument
1692 self._warnings_enabled = False
1694 def enable_stderr_warnings(self): argument
1698 self._warn_to_stderr = True
1700 def disable_stderr_warnings(self): argument
1704 self._warn_to_stderr = False
1706 def enable_undef_warnings(self): argument
1712 self._warn_for_undef_assign = True
1714 def disable_undef_warnings(self): argument
1718 self._warn_for_undef_assign = False
1720 def enable_override_warnings(self): argument
1729 self._warn_for_override = True
1731 def disable_override_warnings(self): argument
1735 self._warn_for_override = False
1737 def enable_redun_warnings(self): argument
1745 self._warn_for_redun_assign = True
1747 def disable_redun_warnings(self): argument
1751 self._warn_for_redun_assign = False
1753 def __repr__(self): argument
1759 "configuration with {} symbols".format(len(self.syms)),
1760 'main menu prompt "{}"'.format(self.mainmenu_text),
1761 "srctree is current directory" if not self.srctree else
1762 'srctree "{}"'.format(self.srctree),
1763 'config symbol prefix "{}"'.format(self.config_prefix),
1765 ("enabled" if self._warnings_enabled else "disabled"),
1767 ("enabled" if self._warn_to_stderr else "disabled"),
1769 ("enabled" if self._warn_for_undef_assign else "disabled"),
1771 ("enabled" if self._warn_for_redun_assign else "disabled")
1783 def _open_config(self, filename): argument
1789 return self._open(filename, "r")
1794 return self._open(os.path.join(self.srctree, filename), "r")
1805 self._srctree_hint()),
1808 def _enter_file(self, full_filename, rel_filename): argument
1817 # self._filename (which makes it indirectly show up in
1820 self.kconfig_filenames.append(rel_filename)
1836 self._filestack.append((self._include_path, self._readline))
1840 self._include_path += ((self._filename, self._linenr),)
1843 for name, _ in self._include_path:
1849 .format(self._filename, self._linenr, rel_filename,
1851 for name, linenr in self._include_path)))
1856 self._readline = self._open(full_filename, "r").readline
1860 .format(self._filename, self._linenr, full_filename,
1863 self._filename = rel_filename
1864 self._linenr = 0
1866 def _leave_file(self): argument
1871 self._readline.__self__.close()
1873 self._filename, self._linenr = self._include_path[-1]
1875 self._include_path, self._readline = self._filestack.pop()
1877 def _next_line(self): argument
1883 if self._reuse_tokens:
1884 self._reuse_tokens = False
1885 # self._tokens_i is known to be 1 here, because _parse_properties()
1892 line = self._readline()
1895 self._linenr += 1
1899 line = line[:-2] + self._readline()
1900 self._linenr += 1
1902 self._line = line # Used for error reporting
1903 self._tokens = self._tokenize(line)
1905 # and _parse_properties(). They immediately fetch self._tokens[0].
1906 self._tokens_i = 1
1910 def _line_after_help(self, line): argument
1921 line = line[:-2] + self._readline()
1922 self._linenr += 1
1924 self._line = line
1925 self._tokens = self._tokenize(line)
1926 self._reuse_tokens = True
1933 def _lookup_sym(self, name): argument
1938 if name in self.syms:
1939 return self.syms[name]
1942 sym.kconfig = self
1945 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
1947 if self._parsing_kconfigs:
1948 self.syms[name] = sym
1950 self._warn("no symbol {} in configuration".format(name))
1954 def _lookup_const_sym(self, name): argument
1957 if name in self.const_syms:
1958 return self.const_syms[name]
1961 sym.kconfig = self
1964 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
1966 if self._parsing_kconfigs:
1967 self.const_syms[name] = sym
1971 def _tokenize(self, s): argument
1988 self._parse_error("unknown token at start of line")
2005 self._parse_assignment(s)
2039 name, s, i = self._expand_name(s, i)
2043 token = self.const_syms[name] \
2045 self._lookup_sym(name)
2073 self._parse_error("unterminated string")
2078 s, end_i = self._expand_str(s, i)
2098 else self._lookup_const_sym(val)
2152 self._parse_error("unknown tokens in line")
2174 def _expect_sym(self): argument
2175 token = self._tokens[self._tokens_i]
2176 self._tokens_i += 1
2179 self._parse_error("expected symbol")
2183 def _expect_nonconst_sym(self): argument
2186 token = self._tokens[1]
2187 self._tokens_i = 2
2190 self._parse_error("expected nonconstant symbol")
2194 def _expect_str_and_eol(self): argument
2195 token = self._tokens[self._tokens_i]
2196 self._tokens_i += 1
2199 self._parse_error("expected string")
2201 if self._tokens[self._tokens_i] is not None:
2202 self._trailing_tokens_error()
2206 def _expect_expr_and_eol(self): argument
2207 expr = self._parse_expr(True)
2209 if self._tokens[self._tokens_i] is not None:
2210 self._trailing_tokens_error()
2214 def _check_token(self, token): argument
2217 if self._tokens[self._tokens_i] is token:
2218 self._tokens_i += 1
2227 def _parse_assignment(self, s): argument
2239 s, i = self._expand_macro(s, i, ())
2255 self._parse_error("syntax error")
2260 if name in self.variables:
2262 var = self.variables[name]
2266 var.kconfig = self
2269 self.variables[name] = var
2281 var.value = self._expand_whole(val, ())
2286 self._expand_whole(val, ()))
2288 def _expand_whole(self, s, args): argument
2300 s, i = self._expand_macro(s, i, args)
2303 def _expand_name(self, s, i): argument
2310 s, end_i = self._expand_name_iter(s, i)
2316 self._parse_error("macro expanded to blank string")
2324 def _expand_name_iter(self, s, i): argument
2334 s, i = self._expand_macro(s, match.start(), ())
2338 def _expand_str(self, s, i): argument
2350 self._parse_error("unterminated string")
2365 s, i = self._expand_macro(s, match.start(), ())
2371 def _expand_macro(self, s, i, args): argument
2391 self._parse_error("missing end parenthesis in macro expansion")
2411 prefix += self._fn_val(new_args)
2423 s, i = self._expand_macro(s, match.start(), args)
2425 def _fn_val(self, args): argument
2432 if fn in self.variables:
2433 var = self.variables[fn]
2438 self._parse_error("Preprocessor variable {} recursively "
2443 self._parse_error("Preprocessor function {} seems stuck "
2447 res = self._expand_whole(self.variables[fn].value, args)
2451 if fn in self._functions:
2454 py_fn, min_arg, max_arg = self._functions[fn]
2468 .format(self._filename, self._linenr, fn,
2471 return py_fn(self, *args)
2475 self.env_vars.add(fn)
2485 def _make_and(self, e1, e2): argument
2488 if e1 is self.y:
2491 if e2 is self.y:
2494 if e1 is self.n or e2 is self.n:
2495 return self.n
2499 def _make_or(self, e1, e2): argument
2502 if e1 is self.n:
2505 if e2 is self.n:
2508 if e1 is self.y or e2 is self.y:
2509 return self.y
2513 def _parse_block(self, end_token, parent, prev): argument
2536 while self._next_line():
2537 t0 = self._tokens[0]
2541 sym = self._tokens[1]
2544 self._parse_error("missing or bad symbol name")
2546 if self._tokens[2] is not None:
2547 self._trailing_tokens_error()
2549 self.defined_syms.append(sym)
2552 node.kconfig = self
2557 node.filename = self._filename
2558 node.linenr = self._linenr
2559 node.include_path = self._include_path
2563 self._parse_properties(node)
2566 self._warn("the menuconfig symbol {} has no prompt"
2582 pattern = self._expect_str_and_eol()
2591 pattern = os.path.join(os.path.dirname(self._filename),
2598 sorted(glob.iglob(os.path.join(self.srctree, pattern)))
2603 self._filename, self._linenr, pattern,
2604 self._srctree_hint()),
2608 self._enter_file(
2616 os.path.relpath(filename, self.srctree))
2618 prev = self._parse_block(None, parent, prev)
2620 self._leave_file()
2626 if self._tokens[1] is not None:
2627 self._trailing_tokens_error()
2636 node.dep = self._expect_expr_and_eol()
2638 self._parse_block(_T_ENDIF, node, node)
2645 node.kconfig = self
2648 node.prompt = (self._expect_str_and_eol(), self.y)
2649 node.visibility = self.y
2651 node.filename = self._filename
2652 node.linenr = self._linenr
2653 node.include_path = self._include_path
2655 self.menus.append(node)
2657 self._parse_properties(node)
2658 self._parse_block(_T_ENDMENU, node, node)
2665 node.kconfig = self
2668 node.prompt = (self._expect_str_and_eol(), self.y)
2671 node.filename = self._filename
2672 node.linenr = self._linenr
2673 node.include_path = self._include_path
2675 self.comments.append(node)
2677 self._parse_properties(node)
2682 if self._tokens[1] is None:
2684 choice.direct_dep = self.n
2687 name = self._expect_str_and_eol()
2688 choice = self.named_choices.get(name)
2692 choice.direct_dep = self.n
2693 self.named_choices[name] = choice
2695 self.choices.append(choice)
2697 choice.kconfig = self
2700 node.kconfig = self
2705 node.filename = self._filename
2706 node.linenr = self._linenr
2707 node.include_path = self._include_path
2711 self._parse_properties(node)
2712 self._parse_block(_T_ENDCHOICE, node, node)
2718 self.top_node.prompt = (self._expect_str_and_eol(), self.y)
2719 self.top_node.filename = self._filename
2720 self.top_node.linenr = self._linenr
2725 self._parse_error(
2739 self._filename))
2744 def _parse_cond(self): argument
2746 # <expr>, or self.y if the next token is not _T_IF
2748 expr = self._parse_expr(True) if self._check_token(_T_IF) else self.y
2750 if self._tokens[self._tokens_i] is not None:
2751 self._trailing_tokens_error()
2755 def _parse_properties(self, node): argument
2774 node.dep = self.y
2776 while self._next_line():
2777 t0 = self._tokens[0]
2780 self._set_type(node, t0)
2781 if self._tokens[1] is not None:
2782 self._parse_prompt(node)
2785 if not self._check_token(_T_ON):
2786 self._parse_error("expected 'on' after 'depends'")
2788 node.dep = self._make_and(node.dep,
2789 self._expect_expr_and_eol())
2792 self._parse_help(node)
2796 self._parse_error("only symbols can select")
2798 node.selects.append((self._expect_nonconst_sym(),
2799 self._parse_cond()))
2806 node.defaults.append((self._parse_expr(False),
2807 self._parse_cond()))
2810 self._set_type(node, t0)
2811 node.defaults.append((self._parse_expr(False),
2812 self._parse_cond()))
2815 self._parse_prompt(node)
2818 node.ranges.append((self._expect_sym(), self._expect_sym(),
2819 self._parse_cond()))
2823 self._parse_error("only symbols can imply")
2825 node.implies.append((self._expect_nonconst_sym(),
2826 self._parse_cond()))
2829 if not self._check_token(_T_IF):
2830 self._parse_error("expected 'if' after 'visible'")
2832 node.visibility = self._make_and(node.visibility,
2833 self._expect_expr_and_eol())
2836 if self._check_token(_T_ENV):
2837 if not self._check_token(_T_EQUAL):
2838 self._parse_error("expected '=' after 'env'")
2840 env_var = self._expect_str_and_eol()
2845 (self._lookup_const_sym(os.environ[env_var]),
2846 self.y))
2848 self._warn("{1} has 'option env=\"{0}\"', "
2851 self._filename, self._linenr)
2854 self._warn("Kconfiglib expands environment variables "
2861 self._filename, self._linenr)
2863 elif self._check_token(_T_DEFCONFIG_LIST):
2864 if not self.defconfig_list:
2865 self.defconfig_list = node.item
2867 self._warn("'option defconfig_list' set on multiple "
2869 "used.".format(self.defconfig_list.name,
2871 self._filename, self._linenr)
2873 elif self._check_token(_T_MODULES):
2879 if node.item is not self.modules:
2880 self._warn("the 'modules' option is not supported. "
2888 self._filename, self._linenr)
2890 elif self._check_token(_T_ALLNOCONFIG_Y):
2892 self._parse_error("the 'allnoconfig_y' option is only "
2898 self._parse_error("unrecognized option")
2902 self._parse_error('"optional" is only valid for choices')
2908 self._reuse_tokens = True
2911 def _set_type(self, node, type_token): argument
2919 self._warn("{} defined with multiple types, {} will be used"
2925 def _parse_prompt(self, node): argument
2931 self._warn(_name_and_loc(node.item) +
2934 prompt = self._tokens[1]
2935 self._tokens_i = 2
2938 self._parse_error("expected prompt string")
2941 self._warn(_name_and_loc(node.item) +
2948 node.prompt = (prompt, self._parse_cond())
2950 def _parse_help(self, node): argument
2952 self._warn(_name_and_loc(node.item) + " defined with more than "
2956 readline = self._readline
2963 self._linenr += 1
2965 self._empty_help(node, line)
2978 self._empty_help(node, line)
3002 self._linenr += len_(lines)
3005 self._line_after_help(line)
3007 def _empty_help(self, node, line): argument
3008 self._warn(_name_and_loc(node.item) +
3012 self._line_after_help(line)
3014 def _parse_expr(self, transform_m): argument
3047 and_expr = self._parse_and_expr(transform_m)
3053 if not self._check_token(_T_OR) else \
3054 (OR, and_expr, self._parse_expr(transform_m))
3056 def _parse_and_expr(self, transform_m): argument
3057 factor = self._parse_factor(transform_m)
3063 if not self._check_token(_T_AND) else \
3064 (AND, factor, self._parse_and_expr(transform_m))
3066 def _parse_factor(self, transform_m): argument
3067 token = self._tokens[self._tokens_i]
3068 self._tokens_i += 1
3073 if self._tokens[self._tokens_i] not in _RELATIONS:
3078 if transform_m and token is self.m:
3079 return (AND, self.m, self.modules)
3087 self._tokens_i += 1
3088 return (self._tokens[self._tokens_i - 1], token,
3089 self._expect_sym())
3093 return (token, self._parse_factor(transform_m))
3096 expr_parse = self._parse_expr(transform_m)
3097 if self._check_token(_T_CLOSE_PAREN):
3100 self._parse_error("malformed expression")
3106 def _build_dep(self): argument
3120 for sym in self.unique_defined_syms:
3155 for choice in self.unique_choices:
3167 def _add_choice_deps(self): argument
3177 for choice in self.unique_choices:
3181 def _invalidate_all(self): argument
3185 for sym in self.unique_defined_syms:
3188 for choice in self.unique_choices:
3197 def _finalize_tree(self, node, visible_if): argument
3218 visible_if = self._make_and(visible_if, node.visibility)
3226 self._propagate_deps(node, visible_if)
3231 self._finalize_tree(cur, visible_if)
3237 self._add_props_to_sym(node)
3246 self._finalize_tree(cur.next, visible_if)
3270 choice.direct_dep = self._make_or(choice.direct_dep, node.dep)
3275 def _propagate_deps(self, node, visible_if): argument
3289 cur.dep = dep = self._make_and(cur.dep, basedep)
3294 self._make_and(cur.prompt[1], dep))
3300 self._make_and(cur.prompt[1], visible_if))
3304 cur.defaults = [(default, self._make_and(cond, dep))
3309 cur.ranges = [(low, high, self._make_and(cond, dep))
3314 cur.selects = [(target, self._make_and(cond, dep))
3319 cur.implies = [(target, self._make_and(cond, dep))
3325 def _add_props_to_sym(self, node): argument
3338 sym.direct_dep = self._make_or(sym.direct_dep, node.dep)
3347 target.rev_dep = self._make_or(
3349 self._make_and(sym, cond))
3354 target.weak_rev_dep = self._make_or(
3356 self._make_and(sym, cond))
3363 def _check_sym_sanity(self): argument
3378 for sym in self.unique_defined_syms:
3385 self._warn("{} selects the {} symbol {}, which is not "
3393 self._warn("{} implies the {} symbol {}, which is not "
3415 self._warn("style: quotes recommended around "
3420 self._warn("the {0} symbol {1} has a non-{0} default {2}"
3426 self._warn("the {} symbol {} has selects or implies"
3431 self._warn("{} defined without a type"
3437 self._warn(
3446 self._warn("the {0} symbol {1} has a non-{0} "
3453 def _check_choice_sanity(self): argument
3466 self._warn(msg)
3468 for choice in self.unique_choices:
3470 self._warn("{} defined with type {}"
3478 self._warn(_name_and_loc(choice) + " defined without a prompt")
3487 self._warn("the default selection {} of {} is not "
3494 self._warn("default on the choice symbol {} will have "
3507 self._warn("the choice symbol {} has no prompt"
3511 self._warn("the choice symbol {} is defined with a "
3515 def _parse_error(self, msg): argument
3517 "" if self._filename is None else
3518 "{}:{}: ".format(self._filename, self._linenr),
3519 self._line.strip(), msg))
3521 def _trailing_tokens_error(self): argument
3522 self._parse_error("extra tokens at end of line")
3524 def _open(self, filename, mode): argument
3559 open(filename, mode, encoding=self._encoding)
3561 def _check_undef_syms(self): argument
3588 for sym in (self.syms.viewvalues if _IS_PY2 else self.syms.values)():
3601 for node in self.node_iter():
3606 self._warn(msg)
3608 def _warn(self, msg, filename=None, linenr=None): argument
3611 if self._warnings_enabled:
3616 self.warnings.append(msg)
3617 if self._warn_to_stderr:
3620 def _warn_undef_assign(self, msg, filename, linenr): argument
3623 if self._warn_for_undef_assign:
3624 self._warn(msg, filename, linenr)
3626 def _warn_undef_assign_load(self, name, val, filename, linenr): argument
3629 self._warn_undef_assign(
3633 def _warn_override(self, msg, filename, linenr): argument
3636 if self._warn_for_override:
3637 self._warn(msg, filename, linenr)
3639 def _warn_redun_assign(self, msg, filename, linenr): argument
3642 if self._warn_for_redun_assign:
3643 self._warn(msg, filename, linenr)
3645 def _srctree_hint(self): argument
3653 .format("set to '{}'".format(self.srctree) if self.srctree
3796 self.kconfig.y.
3804 condition was given, 'cond' is self.kconfig.y.
3815 condition, 'cond' is self.config.y.
3840 implied symbol has expr_value(self.direct_dep) != 0. 'depends on' and
3907 def type(self): argument
3911 if self.orig_type is TRISTATE and \
3912 ((self.choice and self.choice.tri_value == 2) or
3913 not self.kconfig.modules.tri_value):
3917 return self.orig_type
3920 def str_value(self): argument
3924 if self._cached_str_val is not None:
3925 return self._cached_str_val
3927 if self.orig_type in _BOOL_TRISTATE:
3929 self._cached_str_val = TRI_TO_STR[self.tri_value]
3930 return self._cached_str_val
3935 if not self.orig_type: # UNKNOWN
3936 self._cached_str_val = self.name
3937 return self.name
3942 vis = self.visibility
3944 self._write_to_conf = (vis != 0)
3946 if self.orig_type in _INT_HEX:
3952 base = _TYPE_TO_BASE[self.orig_type]
3955 for low_expr, high_expr, cond in self.ranges:
3974 if vis and self.user_value:
3975 user_val = int(self.user_value, base)
3978 self.kconfig._warn(
3982 .format(num2str(user_val), TYPE_TO_STR[self.orig_type],
3983 _name_and_loc(self),
3989 val = self.user_value
3998 for sym, cond in self.defaults:
4000 has_default = self._write_to_conf = True
4025 if self.orig_type is INT else \
4030 self.kconfig._warn(
4033 .format(val_num, _name_and_loc(self),
4037 elif self.orig_type is STRING:
4038 if vis and self.user_value is not None:
4040 val = self.user_value
4043 for sym, cond in self.defaults:
4046 self._write_to_conf = True
4054 if self.env_var is not None or self is self.kconfig.defconfig_list:
4055 self._write_to_conf = False
4057 self._cached_str_val = val
4061 def tri_value(self): argument
4065 if self._cached_tri_val is not None:
4066 return self._cached_tri_val
4068 if self.orig_type not in _BOOL_TRISTATE:
4069 if self.orig_type: # != UNKNOWN
4071 self.kconfig._warn(
4074 .format(TYPE_TO_STR[self.orig_type], _name_and_loc(self)))
4076 self._cached_tri_val = 0
4081 vis = self.visibility
4082 self._write_to_conf = (vis != 0)
4086 if not self.choice:
4089 if vis and self.user_value is not None:
4091 val = min(self.user_value, vis)
4097 for default, cond in self.defaults:
4102 self._write_to_conf = True
4107 dep_val = expr_value(self.weak_rev_dep)
4108 if dep_val and expr_value(self.direct_dep):
4110 self._write_to_conf = True
4113 dep_val = expr_value(self.rev_dep)
4115 if expr_value(self.direct_dep) < dep_val:
4116 self._warn_select_unsatisfied_deps()
4119 self._write_to_conf = True
4124 (self.type is BOOL or expr_value(self.weak_rev_dep) == 2):
4131 val = 2 if self.choice.selection is self else 0
4133 elif vis and self.user_value:
4137 self._cached_tri_val = val
4141 def assignable(self): argument
4145 if self._cached_assignable is None:
4146 self._cached_assignable = self._assignable()
4148 return self._cached_assignable
4151 def visibility(self): argument
4155 if self._cached_vis is None:
4156 self._cached_vis = _visibility(self)
4158 return self._cached_vis
4161 def config_string(self): argument
4167 val = self.str_value
4168 if not self._write_to_conf:
4171 if self.orig_type in _BOOL_TRISTATE:
4173 .format(self.kconfig.config_prefix, self.name, val) \
4176 .format(self.kconfig.config_prefix, self.name)
4178 if self.orig_type in _INT_HEX:
4180 .format(self.kconfig.config_prefix, self.name, val)
4184 .format(self.kconfig.config_prefix, self.name, escape(val))
4186 def set_value(self, value): argument
4229 if value == self.user_value and not self.choice:
4230 self._was_set = True
4234 if not (self.orig_type is BOOL and value in (2, 0, "y", "n") or
4235 self.orig_type is TRISTATE and value in (2, 1, 0, "y", "m", "n") or
4237 (self.orig_type is STRING or
4238 self.orig_type is INT and _is_base_n(value, 10) or
4239 self.orig_type is HEX and _is_base_n(value, 16)
4243 self.kconfig._warn(
4248 _name_and_loc(self), TYPE_TO_STR[self.orig_type]))
4252 if self.orig_type in _BOOL_TRISTATE and value in ("y", "m", "n"):
4255 self.user_value = value
4256 self._was_set = True
4258 if self.choice and value == 2:
4263 self.choice.user_selection = self
4264 self.choice._was_set = True
4265 self.choice._rec_invalidate()
4267 self._rec_invalidate_if_has_prompt()
4271 def unset_value(self): argument
4276 if self.user_value is not None:
4277 self.user_value = None
4278 self._rec_invalidate_if_has_prompt()
4281 def referenced(self): argument
4286 for node in self.nodes:
4291 def __repr__(self): argument
4299 fields.append("symbol " + self.name)
4300 fields.append(TYPE_TO_STR[self.type])
4302 for node in self.nodes:
4308 (self.str_value
4309 if self.orig_type in _BOOL_TRISTATE else
4310 '"{}"'.format(self.str_value)))
4312 if not self.is_constant:
4315 if self.user_value is not None:
4318 (TRI_TO_STR[self.user_value]
4319 if self.orig_type in _BOOL_TRISTATE else
4320 '"{}"'.format(self.user_value)))
4322 fields.append("visibility " + TRI_TO_STR[self.visibility])
4324 if self.choice:
4327 if self.is_allnoconfig_y:
4330 if self is self.kconfig.defconfig_list:
4333 if self.env_var is not None:
4334 fields.append("from environment variable " + self.env_var)
4336 if self is self.kconfig.modules:
4340 TRI_TO_STR[expr_value(self.direct_dep)])
4342 if self.nodes:
4343 for node in self.nodes:
4346 if self.is_constant:
4353 def __str__(self): argument
4366 return self.custom_str(standard_sc_expr_str)
4368 def custom_str(self, sc_expr_str_fn): argument
4374 for node in self.nodes)
4380 def __init__(self): argument
4394 self.orig_type = UNKNOWN
4395 self.defaults = []
4396 self.selects = []
4397 self.implies = []
4398 self.ranges = []
4400 self.nodes = []
4402 self.user_value = \
4403 self.choice = \
4404 self.env_var = \
4405 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4406 self._cached_assignable = None
4411 self.is_allnoconfig_y = \
4412 self._was_set = \
4413 self._write_to_conf = False
4416 self._dependents = set()
4420 self._visited = 0
4422 def _assignable(self): argument
4425 if self.orig_type not in _BOOL_TRISTATE:
4430 vis = self.visibility
4435 rev_dep_val = expr_value(self.rev_dep)
4438 if self.choice:
4442 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4451 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4460 return (0, 1) if expr_value(self.weak_rev_dep) != 2 else (0, 2)
4469 def _invalidate(self): argument
4472 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4473 self._cached_assignable = None
4475 def _rec_invalidate(self): argument
4478 if self is self.kconfig.modules:
4480 self.kconfig._invalidate_all()
4482 self._invalidate()
4484 for item in self._dependents:
4506 def _rec_invalidate_if_has_prompt(self): argument
4519 for node in self.nodes:
4521 self._rec_invalidate()
4524 if self.kconfig._warn_for_no_prompt:
4525 self.kconfig._warn(_name_and_loc(self) + " has no prompt, meaning "
4528 def _str_default(self): argument
4534 if self.orig_type in _BOOL_TRISTATE:
4538 if not self.choice:
4539 for default, cond in self.defaults:
4545 val = max(expr_value(self.rev_dep),
4546 expr_value(self.weak_rev_dep),
4551 if val == 1 and self.type is BOOL:
4556 if self.orig_type in _STRING_INT_HEX:
4557 for default, cond in self.defaults:
4563 def _warn_select_unsatisfied_deps(self): argument
4571 .format(_name_and_loc(self), expr_str(self.direct_dep),
4572 TRI_TO_STR[expr_value(self.direct_dep)],
4573 TRI_TO_STR[expr_value(self.rev_dep)])
4576 for select in split_expr(self.rev_dep, OR):
4577 if expr_value(select) <= expr_value(self.direct_dep):
4599 self.kconfig._warn(msg)
4718 there is no condition, 'cond' is self.config.y.
4764 def type(self): argument
4768 if self.orig_type is TRISTATE and not self.kconfig.modules.tri_value:
4771 return self.orig_type
4774 def str_value(self): argument
4778 return TRI_TO_STR[self.tri_value]
4781 def tri_value(self): argument
4788 val = 0 if self.is_optional else 1
4790 if self.user_value is not None:
4791 val = max(val, self.user_value)
4795 val = min(val, self.visibility)
4798 return 2 if val == 1 and self.type is BOOL else val
4801 def assignable(self): argument
4805 if self._cached_assignable is None:
4806 self._cached_assignable = self._assignable()
4808 return self._cached_assignable
4811 def visibility(self): argument
4815 if self._cached_vis is None:
4816 self._cached_vis = _visibility(self)
4818 return self._cached_vis
4821 def selection(self): argument
4825 if self._cached_selection is _NO_CACHED_SELECTION:
4826 self._cached_selection = self._selection()
4828 return self._cached_selection
4830 def set_value(self, value): argument
4843 if value == self.user_value:
4846 self._was_set = True
4849 if not ((self.orig_type is BOOL and value in (2, 0, "y", "n") ) or
4850 (self.orig_type is TRISTATE and value in (2, 1, 0, "y", "m", "n"))):
4853 self.kconfig._warn(
4858 _name_and_loc(self),
4859 TYPE_TO_STR[self.orig_type]))
4866 self.user_value = value
4867 self._was_set = True
4868 self._rec_invalidate()
4872 def unset_value(self): argument
4877 if self.user_value is not None or self.user_selection:
4878 self.user_value = self.user_selection = None
4879 self._rec_invalidate()
4882 def referenced(self): argument
4887 for node in self.nodes:
4892 def __repr__(self): argument
4899 fields.append("choice " + self.name if self.name else "choice")
4900 fields.append(TYPE_TO_STR[self.type])
4902 for node in self.nodes:
4906 fields.append("mode " + self.str_value)
4908 if self.user_value is not None:
4909 fields.append('user mode {}'.format(TRI_TO_STR[self.user_value]))
4911 if self.selection:
4912 fields.append("{} selected".format(self.selection.name))
4914 if self.user_selection:
4916 .format(self.user_selection.name)
4918 if self.selection is not self.user_selection:
4923 fields.append("visibility " + TRI_TO_STR[self.visibility])
4925 if self.is_optional:
4928 for node in self.nodes:
4933 def __str__(self): argument
4943 return self.custom_str(standard_sc_expr_str)
4945 def custom_str(self, sc_expr_str_fn): argument
4951 for node in self.nodes)
4957 def __init__(self): argument
4967 self.orig_type = UNKNOWN
4968 self.syms = []
4969 self.defaults = []
4971 self.nodes = []
4973 self.name = \
4974 self.user_value = self.user_selection = \
4975 self._cached_vis = self._cached_assignable = None
4977 self._cached_selection = _NO_CACHED_SELECTION
4981 self.is_constant = self.is_optional = False
4984 self._dependents = set()
4987 self._visited = 0
4989 def _assignable(self): argument
4994 vis = self.visibility
5000 if not self.is_optional:
5001 return (2,) if self.type is BOOL else (1, 2)
5002 return (0, 2) if self.type is BOOL else (0, 1, 2)
5006 return (0, 1) if self.is_optional else (1,)
5008 def _selection(self): argument
5013 if self.tri_value != 2:
5018 if self.user_selection and self.user_selection.visibility:
5019 return self.user_selection
5022 return self._get_selection_from_defaults()
5024 def _get_selection_from_defaults(self): argument
5026 for sym, cond in self.defaults:
5032 for sym in self.syms:
5039 def _invalidate(self): argument
5040 self._cached_vis = self._cached_assignable = None
5041 self._cached_selection = _NO_CACHED_SELECTION
5043 def _rec_invalidate(self): argument
5046 self._invalidate()
5048 for item in self._dependents:
5090 conditional expression (which is self.kconfig.y if there is no
5126 The 'depends on' dependencies for the menu node, or self.kconfig.y if
5137 menu), or self.kconfig.y if there are no 'visible if' dependencies.
5202 def __init__(self): argument
5206 self.defaults = []
5207 self.selects = []
5208 self.implies = []
5209 self.ranges = []
5212 def referenced(self): argument
5216 # self.dep is included to catch dependencies from a lone 'depends on'
5218 res = expr_items(self.dep)
5220 if self.prompt:
5221 res |= expr_items(self.prompt[1])
5223 if self.item is MENU:
5224 res |= expr_items(self.visibility)
5226 for value, cond in self.defaults:
5230 for value, cond in self.selects:
5234 for value, cond in self.implies:
5238 for low, high, cond in self.ranges:
5245 def __repr__(self): argument
5252 if self.item.__class__ is Symbol:
5253 fields.append("menu node for symbol " + self.item.name)
5255 elif self.item.__class__ is Choice:
5257 if self.item.name is not None:
5258 s += " " + self.item.name
5261 elif self.item is MENU:
5264 else: # self.item is COMMENT
5267 if self.prompt:
5269 .format(self.prompt[0],
5270 TRI_TO_STR[expr_value(self.prompt[1])]))
5272 if self.item.__class__ is Symbol and self.is_menuconfig:
5275 fields.append("deps " + TRI_TO_STR[expr_value(self.dep)])
5277 if self.item is MENU:
5279 TRI_TO_STR[expr_value(self.visibility)])
5281 if self.item.__class__ in _SYMBOL_CHOICE and self.help is not None:
5284 if self.list:
5287 if self.next:
5290 fields.append("{}:{}".format(self.filename, self.linenr))
5294 def __str__(self): argument
5310 return self.custom_str(standard_sc_expr_str)
5312 def custom_str(self, sc_expr_str_fn): argument
5317 return self._menu_comment_node_str(sc_expr_str_fn) \
5318 if self.item in _MENU_COMMENT else \
5319 self._sym_choice_node_str(sc_expr_str_fn)
5321 def _menu_comment_node_str(self, sc_expr_str_fn): argument
5322 s = '{} "{}"'.format("menu" if self.item is MENU else "comment",
5323 self.prompt[0])
5325 if self.dep is not self.kconfig.y:
5326 s += "\n\tdepends on {}".format(expr_str(self.dep, sc_expr_str_fn))
5328 if self.item is MENU and self.visibility is not self.kconfig.y:
5329 s += "\n\tvisible if {}".format(expr_str(self.visibility,
5334 def _sym_choice_node_str(self, sc_expr_str_fn): argument
5341 if cond is not self.kconfig.y:
5345 sc = self.item
5349 ("menuconfig " if self.is_menuconfig else "config ")
5357 if self.prompt:
5359 'prompt "{}"'.format(escape(self.prompt[0])),
5360 self.prompt[1])
5375 for low, high, cond in self.ranges:
5381 for default, cond in self.defaults:
5389 for select, cond in self.selects:
5392 for imply, cond in self.implies:
5395 if self.dep is not sc.kconfig.y:
5396 indent_add("depends on " + expr_str(self.dep, sc_expr_str_fn))
5398 if self.help is not None:
5400 for line in self.help.splitlines():
5438 def expanded_value(self): argument
5442 return self.expanded_value_w_args()
5444 def expanded_value_w_args(self, *args): argument
5451 return self.kconfig._fn_val((self.name,) + args)
5453 def __repr__(self): argument
5455 .format(self.name,
5456 "recursive" if self.is_recursive else "immediate",
5457 self.value)
5474 def __init__(self, ioerror, msg): argument
5475 self.msg = msg
5476 super(_KconfigIOError, self).__init__(
5479 def __str__(self): argument
5480 return self.msg