Lines Matching refs:self
867 def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True, argument
947 self._init(filename, warn, warn_to_stderr, encoding)
959 def _init(self, filename, warn, warn_to_stderr, encoding): argument
962 self._encoding = encoding
964 self.srctree = os.getenv("srctree", "")
968 self._srctree_prefix = realpath(self.srctree) + os.sep
970 self.warn = warn
971 self.warn_to_stderr = warn_to_stderr
972 self.warn_assign_undef = os.getenv("KCONFIG_WARN_UNDEF_ASSIGN") == "y"
973 self.warn_assign_override = True
974 self.warn_assign_redun = True
975 self._warn_assign_no_prompt = True
977 self.warnings = []
979 self.config_prefix = os.getenv("CONFIG_", "CONFIG_")
981 self._set_match = _re_match(self.config_prefix + r"([^=]+)=(.*)")
982 self._unset_match = _re_match(r"# {}([^ ]+) is not set".format(
983 self.config_prefix))
985 self.config_header = os.getenv("KCONFIG_CONFIG_HEADER", "")
986 self.header_header = os.getenv("KCONFIG_AUTOHEADER_HEADER", "")
988 self.syms = {}
989 self.const_syms = {}
990 self.defined_syms = []
991 self.missing_syms = []
992 self.named_choices = {}
993 self.choices = []
994 self.menus = []
995 self.comments = []
999 sym.kconfig = self
1005 self.const_syms[nmy] = sym
1007 self.n = self.const_syms["n"]
1008 self.m = self.const_syms["m"]
1009 self.y = self.const_syms["y"]
1013 sym = self.const_syms[nmy]
1014 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
1017 self.variables = {}
1020 self._functions = {
1031 self._functions.update(
1041 self._parsing_kconfigs = True
1043 self.modules = self._lookup_sym("MODULES")
1044 self.defconfig_list = None
1046 self.top_node = MenuNode()
1047 self.top_node.kconfig = self
1048 self.top_node.item = MENU
1049 self.top_node.is_menuconfig = True
1050 self.top_node.visibility = self.y
1051 self.top_node.prompt = ("Main menu", self.y)
1052 self.top_node.parent = None
1053 self.top_node.dep = self.y
1054 self.top_node.filename = filename
1055 self.top_node.linenr = 1
1056 self.top_node.include_path = ()
1061 self.kconfig_filenames = [filename]
1062 self.env_vars = set()
1066 self._filestack = []
1067 self._include_path = ()
1070 self.filename = filename
1071 self.linenr = 0
1076 self._reuse_tokens = False
1080 self._readline = self._open(join(self.srctree, filename), "r").readline
1085 self._parse_block(None, self.top_node, self.top_node).next = None
1086 self.top_node.list = self.top_node.next
1087 self.top_node.next = None
1089 _decoding_error(e, self.filename)
1093 self._readline.__self__.close()
1095 self._parsing_kconfigs = False
1098 self._finalize_node(self.top_node, self.y)
1099 for s in self.syms.values():
1100 self._finalize_sym(s)
1102 self.unique_defined_syms = _ordered_unique(self.defined_syms)
1103 self.unique_choices = _ordered_unique(self.choices)
1106 self._check_sym_sanity()
1107 self._check_choice_sanity()
1114 self._check_undef_syms()
1117 self._build_dep()
1121 for sym in self.unique_defined_syms:
1126 self._add_choice_deps()
1129 def mainmenu_text(self): argument
1133 return self.top_node.prompt[0]
1136 def defconfig_filename(self): argument
1140 if self.defconfig_list:
1141 for filename, cond in self.defconfig_list.defaults:
1144 with self._open_config(filename.str_value) as f:
1151 def load_config(self, filename=None, replace=True, verbose=None): argument
1221 not exists(join(self.srctree, filename)):
1222 defconfig = self.defconfig_filename
1236 self._warn_assign_no_prompt = False
1241 self._load_config(filename, replace)
1245 self._warn_assign_no_prompt = True
1249 def _load_config(self, filename, replace): argument
1250 with self._open_config(filename) as f:
1252 self.missing_syms = []
1260 for sym in self.unique_defined_syms:
1263 for choice in self.unique_choices:
1267 set_match = self._set_match
1268 unset_match = self._unset_match
1269 get_sym = self.syms.get
1280 self._undef_assign(name, val, filename, linenr)
1290 self._warn("'{}' is not a valid value for the {} "
1308 self._warn("both m and y assigned to symbols "
1318 self._warn("malformed string literal in "
1334 self._warn("ignoring malformed line '{}'"
1343 self._undef_assign(name, "n", filename, linenr)
1354 self._assigned_twice(sym, val, filename, linenr)
1362 for sym in self.unique_defined_syms:
1366 for choice in self.unique_choices:
1370 def _undef_assign(self, name, val, filename, linenr): argument
1373 self.missing_syms.append((name, val))
1374 if self.warn_assign_undef:
1375 self._warn(
1379 def _assigned_twice(self, sym, new_val, filename, linenr): argument
1392 if self.warn_assign_redun:
1393 self._warn(msg, filename, linenr)
1394 elif self.warn_assign_override:
1395 self._warn(msg, filename, linenr)
1397 def load_allconfig(self, filename): argument
1417 load_allconfig(self, filename)
1419 def write_autoconf(self, filename=None, header=None): argument
1458 if self._write_if_changed(filename, self._autoconf_contents(header)):
1462 def _autoconf_contents(self, header): argument
1467 header = self.header_header
1472 for sym in self.unique_defined_syms:
1486 .format(self.config_prefix, sym.name))
1489 .format(self.config_prefix, sym.name))
1493 .format(self.config_prefix, sym.name, escape(val)))
1501 .format(self.config_prefix, sym.name, val))
1505 def write_config(self, filename=None, header=None, save_old=True, argument
1572 contents = self._config_contents(header)
1573 if self._contents_eq(filename, contents):
1579 with self._open(filename, "w") as f:
1584 def _config_contents(self, header): argument
1595 for sym in self.unique_defined_syms:
1599 header = self.config_header
1607 node = self.top_node
1621 node is not self.top_node:
1659 def write_min_config(self, filename, header=None): argument
1692 if self._write_if_changed(filename, self._min_config_contents(header)):
1696 def _min_config_contents(self, header): argument
1701 header = self.config_header
1706 for sym in self.unique_defined_syms:
1733 def sync_deps(self, path): argument
1799 self._load_old_vals(path)
1801 for sym in self.unique_defined_syms:
1840 self._write_old_vals(path)
1842 def _load_old_vals(self, path): argument
1850 for sym in self.unique_defined_syms:
1854 auto_conf = self._open(join(path, "auto.conf"), "r")
1863 match = self._set_match(line)
1870 if name in self.syms:
1871 sym = self.syms[name]
1879 self.syms[name]._old_val = val
1885 def _write_old_vals(self, path): argument
1895 self._write_if_changed(
1897 self._old_vals_contents())
1899 def _old_vals_contents(self): argument
1904 sym.config_string for sym in self.unique_defined_syms
1908 def node_iter(self, unique_syms=False): argument
1932 for sym in self.unique_defined_syms:
1935 node = self.top_node
1959 def eval_string(self, s): argument
1982 self.filename = None
1984 self._tokens = self._tokenize("if " + s)
1986 self._line = s
1987 self._tokens_i = 1 # Skip the 'if' token
1989 return expr_value(self._expect_expr_and_eol())
1991 def unset_values(self): argument
1996 self._warn_assign_no_prompt = False
2001 for sym in self.unique_defined_syms:
2004 for choice in self.unique_choices:
2007 self._warn_assign_no_prompt = True
2009 def enable_warnings(self): argument
2014 self.warn = True
2016 def disable_warnings(self): argument
2021 self.warn = False
2023 def enable_stderr_warnings(self): argument
2028 self.warn_to_stderr = True
2030 def disable_stderr_warnings(self): argument
2035 self.warn_to_stderr = False
2037 def enable_undef_warnings(self): argument
2042 self.warn_assign_undef = True
2044 def disable_undef_warnings(self): argument
2049 self.warn_assign_undef = False
2051 def enable_override_warnings(self): argument
2056 self.warn_assign_override = True
2058 def disable_override_warnings(self): argument
2063 self.warn_assign_override = False
2065 def enable_redun_warnings(self): argument
2070 self.warn_assign_redun = True
2072 def disable_redun_warnings(self): argument
2077 self.warn_assign_redun = False
2079 def __repr__(self): argument
2088 "configuration with {} symbols".format(len(self.syms)),
2089 'main menu prompt "{}"'.format(self.mainmenu_text),
2090 "srctree is current directory" if not self.srctree else
2091 'srctree "{}"'.format(self.srctree),
2092 'config symbol prefix "{}"'.format(self.config_prefix),
2093 "warnings " + status(self.warn),
2094 "printing of warnings to stderr " + status(self.warn_to_stderr),
2096 status(self.warn_assign_undef),
2098 status(self.warn_assign_override),
2100 status(self.warn_assign_redun)
2112 def _open_config(self, filename): argument
2118 return self._open(filename, "r")
2123 return self._open(join(self.srctree, filename), "r")
2135 "set to '{}'".format(self.srctree) if self.srctree
2138 def _enter_file(self, filename): argument
2148 if filename.startswith(self._srctree_prefix):
2151 rel_filename = filename[len(self._srctree_prefix):]
2156 self.kconfig_filenames.append(rel_filename)
2172 self._filestack.append((self._include_path, self._readline))
2176 self._include_path += ((self.filename, self.linenr),)
2179 for name, _ in self._include_path:
2185 .format(self.filename, self.linenr, rel_filename,
2187 for name, linenr in self._include_path)))
2190 self._readline = self._open(filename, "r").readline
2195 .format(self.filename, self.linenr, filename,
2196 self._line.strip(),
2199 self.filename = rel_filename
2200 self.linenr = 0
2202 def _leave_file(self): argument
2207 self.filename, self.linenr = self._include_path[-1]
2209 self._readline.__self__.close() # __self__ fetches the 'file' object
2210 self._include_path, self._readline = self._filestack.pop()
2212 def _next_line(self): argument
2218 if self._reuse_tokens:
2219 self._reuse_tokens = False
2227 line = self._readline()
2230 self.linenr += 1
2234 line = line[:-2] + self._readline()
2235 self.linenr += 1
2237 self._tokens = self._tokenize(line)
2240 self._tokens_i = 1
2244 def _line_after_help(self, line): argument
2255 line = line[:-2] + self._readline()
2256 self.linenr += 1
2258 self._tokens = self._tokenize(line)
2259 self._reuse_tokens = True
2261 def _write_if_changed(self, filename, contents): argument
2274 if self._contents_eq(filename, contents):
2276 with self._open(filename, "w") as f:
2280 def _contents_eq(self, filename, contents): argument
2285 with self._open(filename, "r") as f:
2298 def _lookup_sym(self, name): argument
2303 if name in self.syms:
2304 return self.syms[name]
2307 sym.kconfig = self
2311 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
2313 if self._parsing_kconfigs:
2314 self.syms[name] = sym
2316 self._warn("no symbol {} in configuration".format(name))
2320 def _lookup_const_sym(self, name): argument
2323 if name in self.const_syms:
2324 return self.const_syms[name]
2327 sym.kconfig = self
2331 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
2333 if self._parsing_kconfigs:
2334 self.const_syms[name] = sym
2338 def _tokenize(self, s): argument
2350 self._line = s # Used for error reporting
2357 self._parse_error("unknown token at start of line")
2374 self._parse_assignment(s)
2408 name, s, i = self._expand_name(s, i)
2412 token = self.const_syms[name] if name in STR_TO_TRI else \
2413 self._lookup_sym(name)
2429 self._warn("style: quotes recommended around '{}' in '{}'"
2430 .format(name, self._line.strip()),
2431 self.filename, self.linenr)
2449 self._parse_error("unterminated string")
2454 s, end_i = self._expand_str(s, i)
2474 else self._lookup_const_sym(val)
2528 self._parse_error("unknown tokens in line")
2550 def _expect_sym(self): argument
2551 token = self._tokens[self._tokens_i]
2552 self._tokens_i += 1
2555 self._parse_error("expected symbol")
2559 def _expect_nonconst_sym(self): argument
2562 token = self._tokens[1]
2563 self._tokens_i = 2
2566 self._parse_error("expected nonconstant symbol")
2570 def _expect_str_and_eol(self): argument
2571 token = self._tokens[self._tokens_i]
2572 self._tokens_i += 1
2575 self._parse_error("expected string")
2577 if self._tokens[self._tokens_i] is not None:
2578 self._trailing_tokens_error()
2582 def _expect_expr_and_eol(self): argument
2583 expr = self._parse_expr(True)
2585 if self._tokens[self._tokens_i] is not None:
2586 self._trailing_tokens_error()
2590 def _check_token(self, token): argument
2593 if self._tokens[self._tokens_i] is token:
2594 self._tokens_i += 1
2602 def _parse_assignment(self, s): argument
2614 s, i = self._expand_macro(s, i, ())
2630 self._parse_error("syntax error")
2635 if name in self.variables:
2637 var = self.variables[name]
2641 var.kconfig = self
2644 self.variables[name] = var
2656 var.value = self._expand_whole(val, ())
2661 self._expand_whole(val, ()))
2663 def _expand_whole(self, s, args): argument
2675 s, i = self._expand_macro(s, i, args)
2678 def _expand_name(self, s, i): argument
2685 s, end_i = self._expand_name_iter(s, i)
2691 self._parse_error("macro expanded to blank string")
2699 def _expand_name_iter(self, s, i): argument
2710 s, i = self._expand_macro(s, match.start(), ())
2712 def _expand_str(self, s, i): argument
2724 self._parse_error("unterminated string")
2739 s, i = self._expand_macro(s, match.start(), ())
2745 def _expand_macro(self, s, i, args): argument
2763 self._parse_error("missing end parenthesis in macro expansion")
2790 res += self._fn_val(new_args)
2805 s, i = self._expand_macro(s, match.start(), args)
2807 def _fn_val(self, args): argument
2814 if fn in self.variables:
2815 var = self.variables[fn]
2820 self._parse_error("Preprocessor variable {} recursively "
2825 self._parse_error("Preprocessor function {} seems stuck "
2829 res = self._expand_whole(self.variables[fn].value, args)
2833 if fn in self._functions:
2836 py_fn, min_arg, max_arg = self._functions[fn]
2850 .format(self.filename, self.linenr, fn,
2853 return py_fn(self, *args)
2857 self.env_vars.add(fn)
2866 def _make_and(self, e1, e2): argument
2869 if e1 is self.y:
2872 if e2 is self.y:
2875 if e1 is self.n or e2 is self.n:
2876 return self.n
2880 def _make_or(self, e1, e2): argument
2883 if e1 is self.n:
2886 if e2 is self.n:
2889 if e1 is self.y or e2 is self.y:
2890 return self.y
2894 def _parse_block(self, end_token, parent, prev): argument
2917 while self._next_line():
2918 t0 = self._tokens[0]
2922 sym = self._tokens[1]
2925 self._parse_error("missing or bad symbol name")
2927 if self._tokens[2] is not None:
2928 self._trailing_tokens_error()
2930 self.defined_syms.append(sym)
2933 node.kconfig = self
2939 node.filename = self.filename
2940 node.linenr = self.linenr
2941 node.include_path = self._include_path
2945 self._parse_props(node)
2949 node.dep != self.y or
2953 self._parse_error("configdefault can only contain `default`")
2956 self._warn("the menuconfig symbol {} has no prompt"
2972 pattern = self._expect_str_and_eol()
2976 pattern = join(dirname(self.filename), pattern)
2986 filenames = sorted(iglob(join(self._srctree_prefix, pattern)))
2994 .format(self.filename, self.linenr, pattern,
2995 self._line.strip(),
2996 "set to '{}'".format(self.srctree)
2997 if self.srctree else "unset or blank"))
3000 self._enter_file(filename)
3002 prev = self._parse_block(None, parent, prev)
3004 self._leave_file()
3010 if self._tokens[1] is not None:
3011 self._trailing_tokens_error()
3020 node.dep = self._expect_expr_and_eol()
3022 self._parse_block(_T_ENDIF, node, node)
3029 node.kconfig = self
3032 node.prompt = (self._expect_str_and_eol(), self.y)
3033 node.visibility = self.y
3035 node.filename = self.filename
3036 node.linenr = self.linenr
3037 node.include_path = self._include_path
3039 self.menus.append(node)
3041 self._parse_props(node)
3042 self._parse_block(_T_ENDMENU, node, node)
3049 node.kconfig = self
3052 node.prompt = (self._expect_str_and_eol(), self.y)
3055 node.filename = self.filename
3056 node.linenr = self.linenr
3057 node.include_path = self._include_path
3059 self.comments.append(node)
3061 self._parse_props(node)
3066 if self._tokens[1] is None:
3068 choice.direct_dep = self.n
3071 name = self._expect_str_and_eol()
3072 choice = self.named_choices.get(name)
3076 choice.direct_dep = self.n
3077 self.named_choices[name] = choice
3079 self.choices.append(choice)
3082 node.kconfig = choice.kconfig = self
3087 node.filename = self.filename
3088 node.linenr = self.linenr
3089 node.include_path = self._include_path
3093 self._parse_props(node)
3094 self._parse_block(_T_ENDCHOICE, node, node)
3100 self.top_node.prompt = (self._expect_str_and_eol(), self.y)
3105 self._parse_error(
3119 self.filename))
3123 def _parse_cond(self): argument
3127 expr = self._parse_expr(True) if self._check_token(_T_IF) else self.y
3129 if self._tokens[self._tokens_i] is not None:
3130 self._trailing_tokens_error()
3134 def _parse_props(self, node): argument
3153 node.dep = self.y
3155 while self._next_line():
3156 t0 = self._tokens[0]
3160 self._set_type(node.item, t0)
3161 if self._tokens[1] is not None:
3162 self._parse_prompt(node)
3165 if not self._check_token(_T_ON):
3166 self._parse_error("expected 'on' after 'depends'")
3168 node.dep = self._make_and(node.dep,
3169 self._expect_expr_and_eol())
3172 self._parse_help(node)
3176 self._parse_error("only symbols can select")
3178 node.selects.append((self._expect_nonconst_sym(),
3179 self._parse_cond()))
3186 node.defaults.append((self._parse_expr(False),
3187 self._parse_cond()))
3190 self._set_type(node.item, _DEF_TOKEN_TO_TYPE[t0])
3191 node.defaults.append((self._parse_expr(False),
3192 self._parse_cond()))
3195 self._parse_prompt(node)
3198 node.ranges.append((self._expect_sym(), self._expect_sym(),
3199 self._parse_cond()))
3203 self._parse_error("only symbols can imply")
3205 node.implies.append((self._expect_nonconst_sym(),
3206 self._parse_cond()))
3209 if not self._check_token(_T_IF):
3210 self._parse_error("expected 'if' after 'visible'")
3212 node.visibility = self._make_and(node.visibility,
3213 self._expect_expr_and_eol())
3216 if self._check_token(_T_ENV):
3217 if not self._check_token(_T_EQUAL):
3218 self._parse_error("expected '=' after 'env'")
3220 env_var = self._expect_str_and_eol()
3225 (self._lookup_const_sym(os.environ[env_var]),
3226 self.y))
3228 self._warn("{1} has 'option env=\"{0}\"', "
3231 self.filename, self.linenr)
3234 self._warn("Kconfiglib expands environment variables "
3241 self.filename, self.linenr)
3243 elif self._check_token(_T_DEFCONFIG_LIST):
3244 if not self.defconfig_list:
3245 self.defconfig_list = node.item
3247 self._warn("'option defconfig_list' set on multiple "
3249 "used.".format(self.defconfig_list.name,
3251 self.filename, self.linenr)
3253 elif self._check_token(_T_MODULES):
3259 if node.item is not self.modules:
3260 self._warn("the 'modules' option is not supported. "
3268 self.filename, self.linenr)
3270 elif self._check_token(_T_ALLNOCONFIG_Y):
3272 self._parse_error("the 'allnoconfig_y' option is only "
3278 self._parse_error("unrecognized option")
3282 self._parse_error('"optional" is only valid for choices')
3288 self._reuse_tokens = True
3291 def _set_type(self, sc, new_type): argument
3296 self._warn("{} defined with multiple types, {} will be used"
3301 def _parse_prompt(self, node): argument
3307 self._warn(node.item.name_and_loc +
3310 prompt = self._tokens[1]
3311 self._tokens_i = 2
3314 self._parse_error("expected prompt string")
3317 self._warn(node.item.name_and_loc +
3324 node.prompt = (prompt, self._parse_cond())
3326 def _parse_help(self, node): argument
3328 self._warn(node.item.name_and_loc + " defined with more than "
3332 readline = self._readline
3339 self.linenr += 1
3341 self._empty_help(node, line)
3354 self._empty_help(node, line)
3378 self.linenr += len_(lines)
3381 self._line_after_help(line)
3383 def _empty_help(self, node, line): argument
3384 self._warn(node.item.name_and_loc +
3388 self._line_after_help(line)
3390 def _parse_expr(self, transform_m): argument
3423 and_expr = self._parse_and_expr(transform_m)
3428 return and_expr if not self._check_token(_T_OR) else \
3429 (OR, and_expr, self._parse_expr(transform_m))
3431 def _parse_and_expr(self, transform_m): argument
3432 factor = self._parse_factor(transform_m)
3437 return factor if not self._check_token(_T_AND) else \
3438 (AND, factor, self._parse_and_expr(transform_m))
3440 def _parse_factor(self, transform_m): argument
3441 token = self._tokens[self._tokens_i]
3442 self._tokens_i += 1
3447 if self._tokens[self._tokens_i] not in _RELATIONS:
3452 if transform_m and token is self.m:
3453 return (AND, self.m, self.modules)
3461 self._tokens_i += 1
3462 return (self._tokens[self._tokens_i - 1], token,
3463 self._expect_sym())
3467 return (token, self._parse_factor(transform_m))
3470 expr_parse = self._parse_expr(transform_m)
3471 if self._check_token(_T_CLOSE_PAREN):
3474 self._parse_error("malformed expression")
3480 def _build_dep(self): argument
3494 for sym in self.unique_defined_syms:
3529 for choice in self.unique_choices:
3541 def _add_choice_deps(self): argument
3551 for choice in self.unique_choices:
3555 def _invalidate_all(self): argument
3559 for sym in self.unique_defined_syms:
3562 for choice in self.unique_choices:
3569 def _finalize_sym(self, sym): argument
3583 default = (d[0], self._make_and(sym.direct_dep, d[1]))
3587 def _finalize_node(self, node, visible_if): argument
3614 self._add_props_to_sym(node)
3622 self._finalize_node(cur.next, visible_if)
3637 visible_if = self._make_and(visible_if, node.visibility)
3643 self._propagate_deps(node, visible_if)
3648 self._finalize_node(cur, visible_if)
3663 choice.direct_dep = self._make_or(choice.direct_dep, node.dep)
3668 def _propagate_deps(self, node, visible_if): argument
3682 dep = cur.dep = self._make_and(cur.dep, basedep)
3688 self._make_and(
3690 self._make_and(visible_if, dep)))
3694 cur.defaults = [(default, self._make_and(cond, dep))
3699 cur.ranges = [(low, high, self._make_and(cond, dep))
3704 cur.selects = [(target, self._make_and(cond, dep))
3709 cur.implies = [(target, self._make_and(cond, dep))
3716 self._make_and(cur.prompt[1], dep))
3720 def _add_props_to_sym(self, node): argument
3741 sym.direct_dep = self._make_or(sym.direct_dep, node.dep)
3750 target.rev_dep = self._make_or(
3752 self._make_and(sym, cond))
3757 target.weak_rev_dep = self._make_or(
3759 self._make_and(sym, cond))
3765 def _check_sym_sanity(self): argument
3780 for sym in self.unique_defined_syms:
3787 self._warn("{} selects the {} symbol {}, which is not "
3795 self._warn("{} implies the {} symbol {}, which is not "
3817 self._warn("style: quotes recommended around "
3822 self._warn("the {0} symbol {1} has a non-{0} default {2}"
3828 self._warn("the {} symbol {} has selects or implies"
3833 self._warn("{} defined without a type"
3839 self._warn(
3848 self._warn("the {0} symbol {1} has a non-{0} "
3855 def _check_choice_sanity(self): argument
3868 self._warn(msg)
3870 for choice in self.unique_choices:
3872 self._warn("{} defined with type {}"
3880 self._warn(choice.name_and_loc + " defined without a prompt")
3889 self._warn("the default selection {} of {} is not "
3896 self._warn("default on the choice symbol {} will have "
3909 self._warn("the choice symbol {} has no prompt"
3913 self._warn("the choice symbol {} is defined with a "
3917 def _parse_error(self, msg): argument
3919 "" if self.filename is None else
3920 "{}:{}: ".format(self.filename, self.linenr),
3921 self._line.strip(), msg))
3923 def _trailing_tokens_error(self): argument
3924 self._parse_error("extra tokens at end of line")
3926 def _open(self, filename, mode): argument
3961 open(filename, mode, encoding=self._encoding)
3963 def _check_undef_syms(self): argument
3990 for sym in (self.syms.viewvalues if _IS_PY2 else self.syms.values)():
4002 for node in self.node_iter():
4006 self._warn(msg)
4008 def _warn(self, msg, filename=None, linenr=None): argument
4011 if not self.warn:
4018 self.warnings.append(msg)
4019 if self.warn_to_stderr:
4314 def type(self): argument
4318 if self.orig_type is TRISTATE and \
4319 (self.choice and self.choice.tri_value == 2 or
4320 not self.kconfig.modules.tri_value):
4324 return self.orig_type
4327 def str_value(self): argument
4331 if self._cached_str_val is not None:
4332 return self._cached_str_val
4334 if self.orig_type in _BOOL_TRISTATE:
4336 self._cached_str_val = TRI_TO_STR[self.tri_value]
4337 return self._cached_str_val
4342 if not self.orig_type: # UNKNOWN
4343 self._cached_str_val = self.name
4344 return self.name
4349 vis = self.visibility
4351 self._write_to_conf = vis != 0
4353 if self.orig_type in _INT_HEX:
4359 base = _TYPE_TO_BASE[self.orig_type]
4362 for low_expr, high_expr, cond in self.ranges:
4381 if vis and self.user_value:
4382 user_val = int(self.user_value, base)
4385 self.kconfig._warn(
4389 .format(num2str(user_val), TYPE_TO_STR[self.orig_type],
4390 self.name_and_loc,
4396 val = self.user_value
4405 for sym, cond in self.defaults:
4407 has_default = self._write_to_conf = True
4432 if self.orig_type is INT else \
4437 self.kconfig._warn(
4440 .format(val_num, self.name_and_loc,
4444 elif self.orig_type is STRING:
4445 if vis and self.user_value is not None:
4447 val = self.user_value
4450 for sym, cond in self.defaults:
4453 self._write_to_conf = True
4461 if self.env_var is not None or self is self.kconfig.defconfig_list:
4462 self._write_to_conf = False
4464 self._cached_str_val = val
4468 def tri_value(self): argument
4472 if self._cached_tri_val is not None:
4473 return self._cached_tri_val
4475 if self.orig_type not in _BOOL_TRISTATE:
4476 if self.orig_type: # != UNKNOWN
4478 self.kconfig._warn(
4481 .format(TYPE_TO_STR[self.orig_type], self.name_and_loc))
4483 self._cached_tri_val = 0
4488 vis = self.visibility
4489 self._write_to_conf = vis != 0
4493 if not self.choice:
4496 if vis and self.user_value is not None:
4498 val = min(self.user_value, vis)
4504 for default, cond in self.defaults:
4509 self._write_to_conf = True
4514 dep_val = expr_value(self.weak_rev_dep)
4515 if dep_val and expr_value(self.direct_dep):
4517 self._write_to_conf = True
4520 dep_val = expr_value(self.rev_dep)
4522 if expr_value(self.direct_dep) < dep_val:
4523 self._warn_select_unsatisfied_deps()
4526 self._write_to_conf = True
4531 (self.type is BOOL or expr_value(self.weak_rev_dep) == 2):
4538 val = 2 if self.choice.selection is self else 0
4540 elif vis and self.user_value:
4544 self._cached_tri_val = val
4548 def assignable(self): argument
4552 if self._cached_assignable is None:
4553 self._cached_assignable = self._assignable()
4554 return self._cached_assignable
4557 def visibility(self): argument
4561 if self._cached_vis is None:
4562 self._cached_vis = _visibility(self)
4563 return self._cached_vis
4566 def config_string(self): argument
4572 val = self.str_value
4573 if not self._write_to_conf:
4576 if self.orig_type in _BOOL_TRISTATE:
4578 .format(self.kconfig.config_prefix, self.name, val) \
4581 .format(self.kconfig.config_prefix, self.name)
4583 if self.orig_type in _INT_HEX:
4585 .format(self.kconfig.config_prefix, self.name, val)
4589 .format(self.kconfig.config_prefix, self.name, escape(val))
4592 def name_and_loc(self): argument
4596 return self.name + " " + _locs(self)
4598 def set_value(self, value): argument
4638 if self.orig_type in _BOOL_TRISTATE and value in STR_TO_TRI:
4648 if value == self.user_value and not self.choice:
4649 self._was_set = True
4653 if not (self.orig_type is BOOL and value in (2, 0) or
4654 self.orig_type is TRISTATE and value in TRI_TO_STR or
4656 (self.orig_type is STRING or
4657 self.orig_type is INT and _is_base_n(value, 10) or
4658 self.orig_type is HEX and _is_base_n(value, 16)
4662 self.kconfig._warn(
4667 self.name_and_loc, TYPE_TO_STR[self.orig_type]))
4671 self.user_value = value
4672 self._was_set = True
4674 if self.choice and value == 2:
4679 self.choice.user_selection = self
4680 self.choice._was_set = True
4681 self.choice._rec_invalidate()
4683 self._rec_invalidate_if_has_prompt()
4687 def unset_value(self): argument
4692 if self.user_value is not None:
4693 self.user_value = None
4694 self._rec_invalidate_if_has_prompt()
4697 def referenced(self): argument
4701 return {item for node in self.nodes for item in node.referenced}
4704 def orig_defaults(self): argument
4708 return [d for node in self.nodes for d in node.orig_defaults]
4711 def orig_selects(self): argument
4715 return [s for node in self.nodes for s in node.orig_selects]
4718 def orig_implies(self): argument
4722 return [i for node in self.nodes for i in node.orig_implies]
4725 def orig_ranges(self): argument
4729 return [r for node in self.nodes for r in node.orig_ranges]
4731 def __repr__(self): argument
4737 fields = ["symbol " + self.name, TYPE_TO_STR[self.type]]
4740 for node in self.nodes:
4745 add("value " + (self.str_value if self.orig_type in _BOOL_TRISTATE
4746 else '"{}"'.format(self.str_value)))
4748 if not self.is_constant:
4751 if self.user_value is not None:
4753 add("user value " + (TRI_TO_STR[self.user_value]
4754 if self.orig_type in _BOOL_TRISTATE
4755 else '"{}"'.format(self.user_value)))
4757 add("visibility " + TRI_TO_STR[self.visibility])
4759 if self.choice:
4762 if self.is_allnoconfig_y:
4765 if self is self.kconfig.defconfig_list:
4768 if self.env_var is not None:
4769 add("from environment variable " + self.env_var)
4771 if self is self.kconfig.modules:
4774 add("direct deps " + TRI_TO_STR[expr_value(self.direct_dep)])
4776 if self.nodes:
4777 for node in self.nodes:
4780 add("constant" if self.is_constant else "undefined")
4784 def __str__(self): argument
4798 return self.custom_str(standard_sc_expr_str)
4800 def custom_str(self, sc_expr_str_fn): argument
4806 for node in self.nodes)
4812 def __init__(self): argument
4828 self.orig_type = self._visited = 0
4830 self.nodes = []
4832 self.defaults = []
4833 self.selects = []
4834 self.implies = []
4835 self.ranges = []
4837 self.user_value = \
4838 self.choice = \
4839 self.env_var = \
4840 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4841 self._cached_assignable = None
4846 self.is_allnoconfig_y = \
4847 self._was_set = \
4848 self._write_to_conf = False
4851 self._dependents = set()
4853 def _assignable(self): argument
4856 if self.orig_type not in _BOOL_TRISTATE:
4861 vis = self.visibility
4865 rev_dep_val = expr_value(self.rev_dep)
4868 if self.choice:
4872 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4881 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4890 return (0, 1) if expr_value(self.weak_rev_dep) != 2 else (0, 2)
4899 def _invalidate(self): argument
4902 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4903 self._cached_assignable = None
4905 def _rec_invalidate(self): argument
4908 if self is self.kconfig.modules:
4910 self.kconfig._invalidate_all()
4912 self._invalidate()
4914 for item in self._dependents:
4936 def _rec_invalidate_if_has_prompt(self): argument
4949 for node in self.nodes:
4951 self._rec_invalidate()
4954 if self.kconfig._warn_assign_no_prompt:
4955 self.kconfig._warn(self.name_and_loc + " has no prompt, meaning "
4958 def _str_default(self): argument
4964 if self.orig_type in _BOOL_TRISTATE:
4968 if not self.choice:
4969 for default, cond in self.defaults:
4975 val = max(expr_value(self.rev_dep),
4976 expr_value(self.weak_rev_dep),
4981 if val == 1 and self.type is BOOL:
4986 if self.orig_type: # STRING/INT/HEX
4987 for default, cond in self.defaults:
4993 def _warn_select_unsatisfied_deps(self): argument
5001 .format(self.name_and_loc, expr_str(self.direct_dep),
5002 TRI_TO_STR[expr_value(self.direct_dep)],
5003 TRI_TO_STR[expr_value(self.rev_dep)])
5006 for select in split_expr(self.rev_dep, OR):
5007 if expr_value(select) <= expr_value(self.direct_dep):
5029 self.kconfig._warn(msg)
5214 def type(self): argument
5218 if self.orig_type is TRISTATE and not self.kconfig.modules.tri_value:
5220 return self.orig_type
5223 def str_value(self): argument
5227 return TRI_TO_STR[self.tri_value]
5230 def tri_value(self): argument
5237 val = 0 if self.is_optional else 1
5239 if self.user_value is not None:
5240 val = max(val, self.user_value)
5244 val = min(val, self.visibility)
5247 return 2 if val == 1 and self.type is BOOL else val
5250 def assignable(self): argument
5254 if self._cached_assignable is None:
5255 self._cached_assignable = self._assignable()
5256 return self._cached_assignable
5259 def visibility(self): argument
5263 if self._cached_vis is None:
5264 self._cached_vis = _visibility(self)
5265 return self._cached_vis
5268 def name_and_loc(self): argument
5273 return standard_sc_expr_str(self) + " " + _locs(self)
5276 def selection(self): argument
5280 if self._cached_selection is _NO_CACHED_SELECTION:
5281 self._cached_selection = self._selection()
5282 return self._cached_selection
5284 def set_value(self, value): argument
5300 if value == self.user_value:
5303 self._was_set = True
5306 if not (self.orig_type is BOOL and value in (2, 0) or
5307 self.orig_type is TRISTATE and value in TRI_TO_STR):
5310 self.kconfig._warn(
5315 self.name_and_loc, TYPE_TO_STR[self.orig_type]))
5319 self.user_value = value
5320 self._was_set = True
5321 self._rec_invalidate()
5325 def unset_value(self): argument
5330 if self.user_value is not None or self.user_selection:
5331 self.user_value = self.user_selection = None
5332 self._rec_invalidate()
5335 def referenced(self): argument
5339 return {item for node in self.nodes for item in node.referenced}
5342 def orig_defaults(self): argument
5346 return [d for node in self.nodes for d in node.orig_defaults]
5348 def __repr__(self): argument
5353 fields = ["choice " + self.name if self.name else "choice",
5354 TYPE_TO_STR[self.type]]
5357 for node in self.nodes:
5361 add("mode " + self.str_value)
5363 if self.user_value is not None:
5364 add('user mode {}'.format(TRI_TO_STR[self.user_value]))
5366 if self.selection:
5367 add("{} selected".format(self.selection.name))
5369 if self.user_selection:
5371 .format(self.user_selection.name)
5373 if self.selection is not self.user_selection:
5378 add("visibility " + TRI_TO_STR[self.visibility])
5380 if self.is_optional:
5383 for node in self.nodes:
5388 def __str__(self): argument
5399 return self.custom_str(standard_sc_expr_str)
5401 def custom_str(self, sc_expr_str_fn): argument
5407 for node in self.nodes)
5413 def __init__(self): argument
5425 self.orig_type = self._visited = 0
5427 self.nodes = []
5429 self.syms = []
5430 self.defaults = []
5432 self.name = \
5433 self.user_value = self.user_selection = \
5434 self._cached_vis = self._cached_assignable = None
5436 self._cached_selection = _NO_CACHED_SELECTION
5440 self.is_constant = self.is_optional = False
5443 self._dependents = set()
5445 def _assignable(self): argument
5450 vis = self.visibility
5456 if not self.is_optional:
5457 return (2,) if self.type is BOOL else (1, 2)
5458 return (0, 2) if self.type is BOOL else (0, 1, 2)
5462 return (0, 1) if self.is_optional else (1,)
5464 def _selection(self): argument
5469 if self.tri_value != 2:
5474 if self.user_selection and self.user_selection.visibility:
5475 return self.user_selection
5478 return self._selection_from_defaults()
5480 def _selection_from_defaults(self): argument
5482 for sym, cond in self.defaults:
5488 for sym in self.syms:
5495 def _invalidate(self): argument
5496 self._cached_vis = self._cached_assignable = None
5497 self._cached_selection = _NO_CACHED_SELECTION
5499 def _rec_invalidate(self): argument
5502 self._invalidate()
5504 for item in self._dependents:
5674 def __init__(self): argument
5678 self.defaults = []
5679 self.selects = []
5680 self.implies = []
5681 self.ranges = []
5684 def orig_prompt(self): argument
5688 if not self.prompt:
5690 return (self.prompt[0], self._strip_dep(self.prompt[1]))
5693 def orig_defaults(self): argument
5697 return [(default, self._strip_dep(cond))
5698 for default, cond in self.defaults]
5701 def orig_selects(self): argument
5705 return [(select, self._strip_dep(cond))
5706 for select, cond in self.selects]
5709 def orig_implies(self): argument
5713 return [(imply, self._strip_dep(cond))
5714 for imply, cond in self.implies]
5717 def orig_ranges(self): argument
5721 return [(low, high, self._strip_dep(cond))
5722 for low, high, cond in self.ranges]
5725 def referenced(self): argument
5731 res = expr_items(self.dep)
5733 if self.prompt:
5734 res |= expr_items(self.prompt[1])
5736 if self.item is MENU:
5737 res |= expr_items(self.visibility)
5739 for value, cond in self.defaults:
5743 for value, cond in self.selects:
5747 for value, cond in self.implies:
5751 for low, high, cond in self.ranges:
5758 def __repr__(self): argument
5766 if self.item.__class__ is Symbol:
5767 add("menu node for symbol " + self.item.name)
5769 elif self.item.__class__ is Choice:
5771 if self.item.name is not None:
5772 s += " " + self.item.name
5775 elif self.item is MENU:
5781 if self.prompt:
5783 self.prompt[0], TRI_TO_STR[expr_value(self.prompt[1])]))
5785 if self.item.__class__ is Symbol and self.is_menuconfig:
5788 add("deps " + TRI_TO_STR[expr_value(self.dep)])
5790 if self.item is MENU:
5791 add("'visible if' deps " + TRI_TO_STR[expr_value(self.visibility)])
5793 if self.item.__class__ in _SYMBOL_CHOICE and self.help is not None:
5796 if self.list:
5799 if self.next:
5802 add("{}:{}".format(self.filename, self.linenr))
5806 def __str__(self): argument
5823 return self.custom_str(standard_sc_expr_str)
5825 def custom_str(self, sc_expr_str_fn): argument
5830 return self._menu_comment_node_str(sc_expr_str_fn) \
5831 if self.item in _MENU_COMMENT else \
5832 self._sym_choice_node_str(sc_expr_str_fn)
5834 def _menu_comment_node_str(self, sc_expr_str_fn): argument
5835 s = '{} "{}"'.format("menu" if self.item is MENU else "comment",
5836 self.prompt[0])
5838 if self.dep is not self.kconfig.y:
5839 s += "\n\tdepends on {}".format(expr_str(self.dep, sc_expr_str_fn))
5841 if self.item is MENU and self.visibility is not self.kconfig.y:
5842 s += "\n\tvisible if {}".format(expr_str(self.visibility,
5847 def _sym_choice_node_str(self, sc_expr_str_fn): argument
5852 if cond is not self.kconfig.y:
5856 sc = self.item
5859 if self.is_menuconfig:
5861 elif self.is_configdefault:
5869 if sc.orig_type and not self.prompt: # sc.orig_type != UNKNOWN
5874 if self.prompt:
5881 indent_add_cond(prefix + ' "{}"'.format(escape(self.prompt[0])),
5882 self.orig_prompt[1])
5897 for low, high, cond in self.orig_ranges:
5903 for default, cond in self.orig_defaults:
5911 for select, cond in self.orig_selects:
5914 for imply, cond in self.orig_implies:
5917 if self.dep is not sc.kconfig.y:
5918 indent_add("depends on " + expr_str(self.dep, sc_expr_str_fn))
5920 if self.help is not None:
5922 for line in self.help.splitlines():
5927 def _strip_dep(self, expr): argument
5933 if self.dep is expr:
5934 return self.kconfig.y
5937 if expr.__class__ is tuple and expr[0] is AND and expr[2] is self.dep:
5976 def expanded_value(self): argument
5980 return self.expanded_value_w_args()
5982 def expanded_value_w_args(self, *args): argument
5989 return self.kconfig._fn_val((self.name,) + args)
5991 def __repr__(self): argument
5993 .format(self.name,
5994 "recursive" if self.is_recursive else "immediate",
5995 self.value)
6020 def __init__(self, ioerror, msg): argument
6021 self.msg = msg
6022 super(_KconfigIOError, self).__init__(
6025 def __str__(self): argument
6026 return self.msg