Lines Matching full:the

12 See the homepage at https://github.com/ulfalizer/Kconfiglib for a longer
15 Since Kconfiglib 12.0.0, the library version is available in
20 Using Kconfiglib on the Linux kernel with the Makefile targets
23 For the Linux kernel, a handy interface is provided by the
25 the 'patch' utility:
30 Warning: Not passing -p1 to patch will cause the wrong file to be patched.
32 Please tell me if the patch does not apply. It should be trivial to apply
33 manually, as it's just a block of text that needs to be inserted near the other
36 Look further down for a motivation for the Makefile patch and for instructions
39 If you do not wish to install Kconfiglib via pip, the Makefile patch is set up
40 so that you can also just clone Kconfiglib into the kernel root:
45 Warning: The directory name Kconfiglib/ is significant in this case, because
46 it's added to PYTHONPATH by the new targets in makefile.patch.
48 The targets added by the Makefile patch are described in the following
55 This target runs the curses menuconfig interface with Python 3. As of
63 This target runs the Tkinter menuconfig interface. Both Python 2 and Python 3
64 are supported. To change the Python interpreter used, pass
65 PYTHONCMD=<executable> to 'make'. The default is 'python'.
72 been preloaded and is available in 'kconf'. To change the Python interpreter
73 used, pass PYTHONCMD=<executable> to 'make'. The default is 'python'.
75 To get a feel for the API, try evaluating and printing the symbols in
76 kconf.defined_syms, and explore the MenuNode menu tree starting at
79 The item contained in a menu node is found in MenuNode.item (note that this can
80 be one of the constants kconfiglib.MENU and kconfiglib.COMMENT), and all
85 If you want to look up a symbol by name, use the kconf.syms dictionary.
91 This target runs the Python script given by the SCRIPT parameter on the
92 configuration. sys.argv[1] holds the name of the top-level Kconfig file
93 (currently always "Kconfig" in practice), and sys.argv[2] holds the SCRIPT_ARG
96 See the examples/ subdirectory for example scripts.
102 This target prints a list of all environment variables referenced from the
103 Kconfig files, together with their values. See the
106 Only environment variables that are referenced via the Kconfig preprocessor
107 $(FOO) syntax are included. The preprocessor was added in Linux 4.18.
110 Using Kconfiglib without the Makefile targets
113 The make targets are only needed to pick up environment variables exported from
114 the Kbuild makefiles and referenced inside Kconfig files, via e.g.
133 command is added by the Makefile patch.
135 To run Kconfiglib without the Makefile patch, set the environment variables
142 Search the top-level Makefile for "Additional ARCH settings" to see other
149 Kconfiglib has the same assignment semantics as the C implementation.
151 Any symbol can be assigned a value by the user (via Kconfig.load_config() or
152 Symbol.set_value()), but this user value is only respected if the symbol is
153 visible, which corresponds to it (currently) being visible in the menuconfig
156 For symbols with prompts, the visibility of the symbol is determined by the
157 condition on the prompt. Symbols without prompts are never visible, so setting
193 In this example, A && B && C && D (the prompt condition) needs to be non-n for
194 FOO to be visible (assignable). If its value is m, the symbol can only be
195 assigned the value m: The visibility sets an upper bound on the value that can
196 be assigned by the user, and any higher user value will be truncated down.
198 'default' properties are independent of the visibility, though a 'default' will
199 often get the same condition as the prompt due to dependency propagation.
200 'default' properties are used if the symbol is not visible or has no user
204 no (active) 'default' default to n for bool/tristate symbols, and to the empty
207 'select' works similarly to symbol visibility, but sets a lower bound on the
208 value of the symbol. The lower bound is determined by the value of the
212 For non-bool/tristate symbols, it only matters whether the visibility is n or
213 non-n: m visibility acts the same as y visibility.
215 Conditions on 'default' and 'select' work in mostly intuitive ways. If the
216 condition is n, the 'default' or 'select' is disabled. If it is m, the
217 'default' or 'select' value (the value of the selecting symbol) is truncated
223 matches the .config format produced by the C implementations down to the
231 The point is to remember the user n selection (which might differ from the
232 default value the symbol would get), while at the same sticking to the rule
233 that undefined corresponds to n (.config uses Makefile format, making the line
234 above a comment). When the .config file is read back in, this line will be
235 treated the same as the following assignment:
239 In Kconfiglib, the set of (currently) assignable values for a bool/tristate
241 sym.visibility is non-0 (non-n) to see whether the user value will have an
245 Intro to the menu tree
248 The menu structure, as seen in e.g. menuconfig, is represented by a tree of
249 MenuNode objects. The top node of the configuration corresponds to an implicit
250 top-level menu, the title of which is shown at the top in the standard
251 menuconfig interface. (The title is also available in Kconfig.mainmenu_text in
254 The top node is found in Kconfig.top_node. From there, you can visit child menu
255 nodes by following the 'list' pointer, and any following menu nodes by
256 following the 'next' pointer. Usually, a non-None 'list' pointer indicates a
260 MenuNode.item is either a Symbol or a Choice object, or one of the constants
261 MENU and COMMENT. The prompt of the menu node can be found in MenuNode.prompt,
262 which also holds the title for menus and comments. For Symbol and Choice,
263 MenuNode.help holds the help text (if any, otherwise None).
266 locations will have one menu node for each location. The list of menu nodes for
267 a Symbol or Choice can be found in the Symbol/Choice.nodes attribute.
270 menu node(s) rather than in the Symbol or Choice objects themselves. This makes
272 help text in each location. To get the help text or prompt for a symbol with a
274 The prompt is a (text, condition) tuple, where condition determines the
277 This organization mirrors the C implementation. MenuNode is called
283 As a convenience, the properties added at a particular definition location are
284 available on the MenuNode itself, in e.g. MenuNode.defaults. This is helpful
286 locations can be shown with the correct properties at each location.
292 Expressions can be evaluated with the expr_value() function and printed with
293 the expr_str() function (these are used internally as well). Evaluating an
297 The following table should help you figure out how expressions are represented.
298 A, B, C, ... are symbols (Symbol instances), NOT is the kconfiglib.NOT
319 represented as constant symbols, so the only values that appear in expressions
320 are symbols***. This mirrors the C implementation.
322 ***For choice symbols, the parent Choice will appear in expressions as well,
323 but it's usually invisible as the value interfaces of Symbol and Choice are
324 identical. This mirrors the C implementation and makes different choice modes
329 - The value of A && B is min(A.tri_value, B.tri_value)
331 - The value of A || B is max(A.tri_value, B.tri_value)
333 - The value of !A is 2 - A.tri_value
335 - The value of A = B is 2 (y) if A.str_value == B.str_value, and 0 (n)
338 For constant (as well as undefined) symbols, str_value matches the name of
339 the symbol. This mirrors the C implementation and explains why
342 n/m/y are automatically converted to the corresponding constant symbols
347 If a condition is missing (e.g., <cond> when the 'if <cond>' is removed from
348 'default A if <cond>'), it is actually Kconfig.y. The standard __str__()
360 The 'rsource' statement sources Kconfig files with a path relative to directory
361 of the Kconfig file containing the 'rsource' statement, instead of relative to
362 the project root.
389 If an absolute path is given to 'rsource', it acts the same as 'source'.
402 For example, the following statement might source sub1/foofoofoo and
407 The glob patterns accepted are the same as for the standard glob.glob()
411 pattern to match no files: 'osource' and 'orsource' (the o is for "optional").
413 For example, the following statements will be no-ops if neither "foo" nor any
429 default at the same time.
438 references to undefined symbols within Kconfig files. The only gotcha is
442 Some projects (e.g. the Linux kernel) use multiple Kconfig trees with many
454 This warning can also be enabled/disabled via the Kconfig.warn_assign_undef
467 sys.path can be customized via PYTHONPATH, and includes the directory of the
470 If the KCONFIG_FUNCTIONS environment variable is set, it gives a different
473 The imported module is expected to define a global dictionary named 'functions'
481 # Name of the user-defined function ("my-fn"). Think argv[0].
484 # Arguments passed to the function from Kconfig (strings)
486 # Returns a string to be substituted as the result of calling the
501 <min.args> and <max.args> are the minimum and maximum number of arguments
502 expected by the function (excluding the implicit 'name' argument). If
503 <max.args> is None, there is no upper limit to the number of arguments. Passing
506 Functions can access the current parsing location as kconf.filename/linenr.
507 Accessing other fields of the Kconfig object is not safe. See the warning
511 called only when 'foo' is expanded. If 'fn' uses the parsing location and the
512 intent is to use the location of the assignment, you want 'foo := $(fn)'
513 instead, which calls the function immediately.
515 Once defined, user functions can be called from Kconfig in the same way as
532 time, before all Kconfig files have been processed, and before the menu tree
534 the menu tree via the 'kconf' parameter will work, and it could potentially
544 service, or open a ticket on the GitHub page.
577 Represents a Kconfig configuration, e.g. for x86 or ARM. This is the set of
578 symbols, choices, and menu nodes appearing in the configuration. Creating
582 The following attributes are available. They should be treated as
586 A dictionary with all symbols in the configuration, indexed by name. Also
591 the 'Intro to the menu tree' section in the module docstring.
600 A list with all defined symbols, in the same order as they appear in the
608 A list like 'defined_syms', but with duplicates removed. Just the first
618 A list with all choices, in the same order as they appear in the Kconfig
629 A list with all menus, in the same order as they appear in the Kconfig
633 A list with all comments, in the same order as they appear in the Kconfig
637 A list with the filenames of all Kconfig files included in the
638 configuration, relative to $srctree (or relative to the current directory
642 The files are listed in the order they are source'd, starting with the
650 A set() with the names of all environment variables referenced in the
653 Only environment variables referenced with the preprocessor $(FOO) syntax
654 will be registered. The older $FOO syntax is only supported for backwards
657 Also note that $(FOO) won't be registered unless the environment variable
659 preprocessor variable (which gives the empty string).
661 Another gotcha is that environment variables referenced in the values of
663 only be registered if the variable is actually used (expanded) somewhere.
665 The note from the 'kconfig_filenames' documentation applies here too.
668 The predefined constant symbols n/m/y. Also available in const_syms.
671 The Symbol instance for the modules symbol. Currently hardcoded to
676 'modules' is never None. If the MODULES symbol is not explicitly defined,
680 (provided the MODULES symbol is defined and visible). Modules are
681 disabled by default in the kernel Kconfig files as of writing, though
685 The Symbol instance for the 'option defconfig_list' symbol, or None if no
686 defconfig_list symbol exists. The defconfig filename derived from this
690 The filename given by the defconfig_list symbol. This is taken from the
691 first 'default' with a satisfied condition where the specified file
693 not found and $srctree was set when the Kconfig was created,
697 or if the defconfig_list symbol has no 'default' with a satisfied
702 overrides the defconfig_list symbol, meaning defconfig_filename might not
706 The menu node (see the MenuNode class) of the implicit top-level menu.
707 Acts as the root of the menu tree.
710 The prompt (title) of the top menu (top_node). Defaults to "Main menu".
711 Can be changed with the 'mainmenu' statement (see kconfig-language.txt).
714 A dictionary with all preprocessor variables, indexed by name. See the
721 When 'warn' is False, the values of the other warning-related variables
724 This variable as well as the other warn* variables can be read to check
725 the current warning settings.
735 This variable is False by default unless the KCONFIG_WARN_UNDEF_ASSIGN
736 environment variable was set to 'y' when the Kconfig instance was
741 to the same symbol in configuration files, where the assignments set
742 different values (e.g. CONFIG_FOO=m followed by CONFIG_FOO=y, where the
750 to the same value.
759 See the 'warn_to_stderr' parameter to Kconfig.__init__() and the
764 will get added to Kconfig.warnings. See the various Kconfig.warn*
769 within the most recently loaded .config file(s). 'name' is the symbol
770 name without the 'CONFIG_' prefix. 'value' is a string that gives the
771 right-hand side of the assignment verbatim.
776 The value the $srctree environment variable had when the Kconfig instance
777 was created, or the empty string if $srctree wasn't set. This gives nice
778 behavior with os.path.join(), which treats "" as the current directory,
783 are not found in the current directory. This is used to support
784 out-of-tree builds. The C tools use this environment variable in the same
787 Changing $srctree after creating the Kconfig instance has no effect. Only
788 the value when the configuration is loaded matters. This avoids surprises
792 The value the CONFIG_ environment variable had when the Kconfig instance
793 was created, or "CONFIG_" if CONFIG_ wasn't set. This is the prefix used
795 the same way in the C tools.
798 The value the KCONFIG_CONFIG_HEADER environment variable had when the
799 Kconfig instance was created, or the empty string if
800 KCONFIG_CONFIG_HEADER wasn't set. This string is inserted verbatim at the
804 The value the KCONFIG_AUTOHEADER_HEADER environment variable had when the
805 Kconfig instance was created, or the empty string if
807 the beginning of header files. See write_autoconf().
810 The current parsing location, for use in Python preprocessor functions.
811 See the module docstring.
871 Note that Kconfig files are not the same as .config files (which store
874 See the module docstring for some environment variables that influence
887 The Kconfig file to load. For the Linux kernel, you'll want "Kconfig"
888 from the top-level directory, as environment variables will make sure
889 the right Kconfig is included from there (arch/$SRCARCH/Kconfig as of
894 See the class documentation.
896 If you are using Kconfiglib via 'make scriptconfig', the filename of
897 the base base Kconfig file will be in sys.argv[1]. It's currently
906 See the other Kconfig.warn_* variables as well, which enable or
909 All generated warnings are added to the Kconfig.warnings list. See
910 the class documentation.
920 The encoding to use when reading and writing files, and when decoding
921 output from commands run via $(shell). If None, the encoding
922 specified in the current locale will be used.
924 The "utf-8" default avoids exceptions on systems that are configured
925 to use the C locale, which implies an ASCII encoding.
936 generated during parsing is caught, the exception message is printed
937 to stderr together with the command name, and sys.exit(1) is called
940 This hides the Python traceback for "expected" errors like syntax
967 # because it assumes symlink/../foo is the same as foo/.
1058 # Parse the Kconfig files
1064 # Keeps track of the location in the parent Kconfig files. Kconfig
1069 # The current parsing location
1074 # part of the construct currently being parsed. This is kinda like an
1078 # Open the top-level Kconfig file. Store the readline() method directly
1083 # Parse the Kconfig files. Returns the last node, which we
1091 # Close the top-level Kconfig file. __self__ fetches the 'file' object
1092 # for the method.
1129 See the class documentation.
1136 See the class documentation.
1151 Loads symbol values from a file in the .config format. Equivalent to
1152 calling Symbol.set_value() to set each of the values.
1154 "# CONFIG_FOO is not set" within a .config file sets the user value of
1155 FOO to n. The C tools work the same way.
1157 For each symbol, the Symbol.user_value attribute holds the value the
1158 symbol was assigned in the .config file (if any). The user value might
1161 Calling this function also updates the Kconfig.missing_syms attribute
1162 with a list of all assignments to undefined symbols within the
1164 True, and appended to otherwise. See the documentation for
1167 See the Kconfig.__init__() docstring for raised exceptions
1172 (see the class documentation).
1174 If 'filename' is None (the default), the configuration file to load
1175 (if any) is calculated automatically, giving the behavior you'd
1178 1. If the KCONFIG_CONFIG environment variable is set, it gives the
1179 path to the configuration file to load. Otherwise, ".config" is
1182 2. If the path from (1.) doesn't exist, the configuration file
1184 derived from the 'option defconfig_list' symbol.
1190 See the return value as well.
1193 If True, all existing user values will be cleared before loading the
1209 print(kconf.load_config()). The returned message distinguishes between
1232 # Disable the warning about assigning to symbols without prompts. This
1252 # If we're replacing the configuration, keep track of which
1253 # symbols and choices got set so that we can unset the rest
1270 # The C tools ignore trailing whitespace
1282 # The C implementation only checks the first character
1283 # to the right of '=', for whatever reason
1288 self._warn("'{}' is not a valid value for the {} "
1298 # During .config loading, we infer the mode of the
1299 # choice from the kind of values that are assigned
1300 # to the choice symbols
1307 "within the same choice",
1310 # Set the choice's mode
1349 # Done parsing the assignment. Set the value.
1357 # If we're replacing the configuration, unset the symbols that
1374 "attempt to assign the value '{}' to the undefined symbol {}"
1380 # Use strings for bool/tristate user values in the warning
1397 Helper for all*config. Loads (merges) the configuration file specified
1399 the Linux kernel.
1402 for the duration of the call
1404 the previous warning settings at the end. The KCONFIG_ALLCONFIG
1408 an error to stderr if KCONFIG_ALLCONFIG is set but the configuration
1419 Writes out symbol values as a C header file, matching the format used
1420 by include/generated/autoconf.h in the kernel.
1422 The ordering of the #defines matches the one generated by
1423 write_config(). The order in the C implementation depends on the hash
1428 like the modification time and possibly triggering redundant work in
1434 If None (the default), the path in the environment variable
1436 otherwise. This is compatible with the C tools.
1439 Text inserted verbatim at the beginning of the file. You would
1443 If None (the default), the value of the environment variable
1444 KCONFIG_AUTOHEADER_HEADER had when the Kconfig instance was created
1445 will be used if it was set, and no header otherwise. See the
1448 Returns a string with a message saying that the header got saved, or
1461 # write_autoconf() helper. Returns the contents to write as a string,
1462 # with 'header' or KCONFIG_AUTOHEADER_HEADER at the beginning.
1471 # _write_to_conf is determined when the value is calculated. This
1475 # instead, to avoid accessing the internal _write_to_conf variable
1506 Writes out symbol values in the .config format. The format matches the
1509 Symbols appear in the same order in generated .config files as they do
1510 in the Kconfig files. For symbols defined in multiple locations, a
1511 single assignment is written out corresponding to the first location
1512 where the symbol is defined.
1514 See the 'Intro to symbol values' section in the module docstring to
1519 like the modification time and possibly triggering redundant work in
1522 See the Kconfig.__init__() docstring for raised exceptions
1528 If None (the default), the path in the environment variable
1533 Text inserted verbatim at the beginning of the file. You would
1537 if None (the default), the value of the environment variable
1538 KCONFIG_CONFIG_HEADER had when the Kconfig instance was created will
1539 be used if it was set, and no header otherwise. See the
1544 <filename>.old in the same directory before the new configuration is
1584 # write_config() helper. Returns the contents to write as a string,
1585 # with 'header' or KCONFIG_CONFIG_HEADER at the beginning.
1587 # More memory friendly would be to 'yield' the strings and
1608 # Jump to the next node with an iterative tree walk
1631 # Generate configuration output for the node
1645 # Add a blank line before the first symbol printed after an
1661 matches their default value. The format matches the one produced by
1664 The resulting configuration file is incomplete, but a complete
1670 See the Kconfig.__init__() docstring for raised exceptions
1677 Text inserted verbatim at the beginning of the file. You would
1681 if None (the default), the value of the environment variable
1682 KCONFIG_CONFIG_HEADER had when the Kconfig instance was created will
1683 be used if it was set, and no header otherwise. See the
1686 Returns a string with a message saying the minimal configuration got
1696 # write_min_config() helper. Returns the contents to write as a string,
1697 # with 'header' or KCONFIG_CONFIG_HEADER at the beginning.
1718 # choice, unless the choice is optional or the symbol type
1719 # isn't bool (it might be possible to set the choice mode
1720 # to n or the symbol to m in those cases).
1735 doing a full rebuild whenever the configuration is changed, mirroring
1736 include/config/ in the kernel.
1741 See the Kconfig.__init__() docstring for raised exceptions
1747 sync_deps(path) does the following:
1749 1. If the directory <path> does not exist, it is created.
1752 which are then compared against the current symbol values. If a
1754 autoconf.h compared to before), the change is signaled by
1755 touch'ing a file corresponding to the symbol.
1757 The first time sync_deps() is run on a directory, <path>/auto.conf
1759 logically has the same effect as updating the entire
1762 The path to a symbol's file is calculated from the symbol's name
1763 by replacing all '_' with '/' and appending '.h'. For example, the
1764 symbol FOO_BAR_BAZ gets the file <path>/foo/bar/baz.h, and FOO
1765 gets the file <path>/foo.h.
1767 This scheme matches the C tools. The point is to avoid having a
1768 single directory with a huge number of files, which the underlying
1771 3. A new auto.conf with the current symbol values is written, to keep
1772 track of them for the next build.
1776 metadata like the modification time and possibly triggering
1780 The last piece of the puzzle is knowing what symbols each source file
1782 to the files corresponding to the symbols they depends on. The source
1783 file will then get recompiled (only) when the symbol value changes
1786 The tool in the kernel that extracts symbol dependencies from source
1788 to "not changed", which fixdep deals with by using the $(wildcard) Make
1791 In case you need a different scheme for your project, the sync_deps()
1801 # _write_to_conf is determined when the value is calculated. This
1805 # instead, to avoid accessing the internal _write_to_conf variable
1816 # No old value (the symbol was missing or n), new value n.
1825 # The symbol wouldn't appear in autoconf.h (because
1834 # Remember the current values as the "new old" values.
1836 # This call could go anywhere after the call to _load_old_vals(), but
1845 # The extra field could be avoided with some trickery involving dumping
1847 # faster. The C tools also use a dedicated field for this purpose.
1880 # Flag that the symbol no longer exists, in
1887 # '# CONFIG_FOO is not set' comments). The format matches the C
1888 # implementation, though the ordering is arbitrary there (depends on
1889 # the hash table implementation).
1899 # _write_old_vals() helper. Returns the contents to write as a string.
1909 Returns a generator for iterating through all MenuNode's in the Kconfig
1910 tree. The iteration is done in Kconfig definition order (each node is
1911 visited before its children, and the children of a node are visited
1912 before the next node).
1914 The Kconfig.top_node menu node is skipped. It contains an implicit menu
1915 that holds the top-level items.
1917 As an example, the following code will produce a list equal to
1924 If True, only the first MenuNode will be included for symbols defined
1927 Using kconf.node_iter(True) in the example above would give a list
1936 # Jump to the next node with an iterative tree walk
1960 Returns the tristate value of the expression 's', represented as 0, 1,
1965 which has the value y, then eval_string("y && (FOO || BAR)") returns
1968 To get the string value of non-bool/tristate symbols, use
1970 all non-bool/tristate symbols have the tristate value 0 (n).
1972 The expression parsing is consistent with how parsing works for
1973 conditional ('if ...') expressions in the configuration, and matches
1974 the C implementation. m is rewritten to 'm && MODULES', so
1977 # The parser is optimized to be fast when parsing Kconfig files (where
1978 # an expression can never appear at the beginning of a line). We have
1986 self._tokens_i = 1 # Skip the 'if' token
2080 Returns a string with information about the Kconfig object when it is
2081 evaluated on e.g. the interactive Python prompt.
2113 # '$srctree/filename' if $srctree was set when the configuration was
2119 # This will try opening the same file twice if $srctree is unset,
2125 # the try block:
2127 # https://docs.python.org/3/reference/compound_stmts.html#the-try-statement
2131 e, "Could not open '{}' ({}: {}). Check that the $srctree "
2138 # Jumps to the beginning of a sourced Kconfig file, saving the previous
2157 # The parent Kconfig files are represented as a list of
2161 # (<filename>, <linenr>) tuples, giving the locations of the 'source'
2162 # statements in the parent Kconfig files. The current include path is
2165 # The point of this redundant setup is to allow Kconfig._include_path
2170 # before entering the file
2173 # _include_path is a tuple, so this rebinds the variable instead of
2191 # We already know that the file exists
2202 # Returns from a Kconfig file to the file that sourced it. See
2208 self._readline.__self__.close() # __self__ fetches the 'file' object
2212 # Fetches and tokenizes the next line from the current Kconfig file.
2225 # texts at the end of files (see _line_after_help())
2244 # Tokenizes a line after a help text. This case is special in that the
2245 # line has already been fetched (to discover that it isn't part of the
2261 # Writes 'contents' into 'filename', but only if it differs from the
2262 # current contents of the file.
2264 # Another variant would be write a temporary file on the same
2265 # filesystem, compare the files, and rename() the temporary file if it
2270 # Returns True if the file has changed and is updated, and False
2280 # Returns True if the contents of 'filename' is 'contents' (a string),
2289 # If the error here would prevent writing the file as well, we'll
2298 # Fetches the symbol 'name' from the symbol table, creating and
2340 # regexes and string operations where possible. This is the biggest
2345 # janky versions of the C tools complicate things though.
2349 # Initial token on the line
2357 # to the previous token. See _STRING_LEX for why this is needed.
2360 # Backwards compatibility with old versions of the C tools, which
2362 # This was fixed in the C tools by commit c2264564 ("kconfig: warn
2368 # If the first token is not a keyword (and not a weird help token),
2375 # The current index in the string being tokenized
2378 # Main tokenization loop (for tokens past the first one)
2380 # Test for an identifier/keyword first. This is the most common
2387 # new symbols for us the first time we see them. Note that
2388 # 'token' still refers to the previous token.
2400 # into the corresponding constant symbols, like the C
2413 # It's a case of missing quotes. For example, the
2437 # assume that s[i] is the start of a token here.
2442 # Fast path for lines without $ and \. Find the
2453 # os.path.expandvars() and the $UNAME_RELEASE replace()
2458 # The preprocessor functionality changed how
2466 # This is the only place where we don't survive with a
2533 # Add the token
2536 # None-terminating the token list makes token fetching simpler/faster
2541 # Helpers for syntax checking and token fetching. See the
2544 # More of these could be added, but the single-use cases are inlined as an
2557 # Used for 'select' and 'imply' only. We know the token indices.
2588 # If the next token is 'token', removes it and returns True
2600 # Parses a preprocessor variable assignment, registering the variable
2604 # Expand any macros in the left-hand side of the assignment (the
2655 # += does immediate expansion if the variable was last set
2662 # have to worry about delimiters. See _expand_macro() re. the 'args'
2665 # Returns the expanded string.
2678 # Returns the expanded name, the expanded 's' (including the part
2679 # before the name), and the index of the first character in the next
2680 # token after the name.
2699 # Returns the expanded 's' (including the part before the name) and the
2700 # index of the first character after the expanded name in 's'.
2713 # Returns the expanded 's' (including the part before the string) and
2714 # the index of the first character after the expanded string in 's'.
2725 # Found the end of the string
2729 # Replace '\x' with 'x'. 'i' ends up pointing to the character
2735 # A macro call within the string
2744 # from the expansion of another macro, 'args' holds the arguments
2747 # Returns the expanded 's' (including the part before the macro) and
2748 # the index of the first character after the expanded macro in 's'.
2773 # Found the end of the macro
2777 # $(1) is replaced by the first argument to the function, etc.,
2781 # Does the macro look like an integer, with a corresponding
2782 # argument? If so, expand it to the value of the argument.
2786 # and also go through the function value path
2796 # Found the end of a macro argument
2801 # A nested macro call within the macro
2805 # Returns the result of calling the function args[0] with the arguments
2892 # Parses a block, which is the contents of either a file or an if,
2896 # The token that ends the block, e.g. _T_ENDIF ("endif") for ifs.
2900 # The parent menu node, corresponding to a menu, Choice, or 'if'.
2904 # The previous menu node. New nodes will be added after this one (by
2908 # Choice): After parsing the children, the 'next' pointer is assigned
2909 # to the 'list' pointer to "tilt up" the children above the node.
2911 # Returns the final menu node in the block (or 'prev' if the block is
2918 # The tokenizer allocates Symbol objects for us
2944 self._warn("the menuconfig symbol {} has no prompt"
2952 # due to tricky Python semantics. The order matters.
2971 # - Sort the glob results to ensure a consistent ordering of
2981 "environment variables expand to the empty string."
2993 # Reached the end of the block. Terminate the final node and
3089 # A valid endchoice/endif/endmenu is caught by the 'end_token'
3097 # End of file reached. Return the last node.
3110 # Parses an optional 'if <expr>' construct and returns the parsed
3111 # <expr>, or self.y if the next token is not _T_IF
3121 # Parses and adds properties to the MenuNode 'node' (type, 'prompt',
3135 # The menu node we're parsing properties on
3137 # Dependencies from 'depends on'. Will get propagated to the properties
3215 "but the environment variable {0} is not "
3223 "For compatibility with the C tools, "
3224 "rename {} to {} (so that the symbol name "
3225 "matches the environment variable name)."
3243 # modules besides the kernel yet, and there it's likely to
3246 self._warn("the 'modules' option is not supported. "
3250 "Kconfiglib just assumes the symbol name "
3251 "MODULES, like older versions of the C "
3258 self._parse_error("the 'allnoconfig_y' option is only "
3273 # Reuse the tokens for the non-property line later
3278 # Sets the type of 'sc' (symbol or choice) to 'new_type'
3289 # a symbol, but additional prompts can be added by defining the symbol
3315 "one help text -- only the last one will be used")
3335 # any tabs people might've put deliberately into the first line after
3336 # the help text
3343 # The help text goes on till the first non-blank line with less indent
3344 # than the first line
3346 # Add the first line
3353 # No need to preserve the exact whitespace in these
3377 # Parses an expression from the tokens in Kconfig._tokens using a
3378 # simple top-down approach. See the module docstring for the expression
3382 # True if m should be rewritten to m && MODULES. See the
3393 # It helps to think of the 'expr: and_expr' case as a single-operand OR
3394 # (no ||), and of the 'and_expr: factor' case as a single-operand AND
3398 # work as well. The straightforward implementation there gives a
3404 # recursion too). If we also try to optimize the list representation by
3412 # Otherwise, parse the expression on the right and make an OR node.
3421 # Otherwise, parse the right operand and make an AND node. This turns
3445 # _T_EQUAL, _T_UNEQUAL, etc., deliberately have the same values as
3446 # EQUAL, UNEQUAL, etc., so we can just use the token directly
3467 # Populates the Symbol/Choice._dependents sets, which contain all other
3468 # items (symbols and choices) that immediately depend on the item in
3469 # the sense that changing the value of the item might affect the value
3470 # of the dependent items. This is used for caching/invalidation.
3472 # The calculated sets might be larger than necessary as we don't do any
3473 # complex analysis of the expressions.
3481 # Symbols depend on the following:
3483 # The prompt conditions
3488 # The default values and their conditions
3493 # The reverse and weak reverse dependencies
3497 # The ranges along with their conditions
3503 # The direct dependencies. This is usually redundant, as the direct
3505 # invalidation solid for 'imply', which only checks the direct
3510 # In addition to the above, choice symbols depend on the choice
3511 # they're in, but that's handled automatically since the Choice is
3512 # propagated to the conditions of the properties before
3516 # Choices depend on the following:
3518 # The prompt conditions
3523 # The default symbol conditions
3528 # Choices also depend on the choice symbols themselves, because the
3529 # y-mode selection of the choice might change if a choice symbol's
3533 # The invalidation algorithm can handle the resulting
3570 # menu_finalize() in the C implementation is similar.
3573 # The menu node to finalize. This node and its children will have
3574 # been finalized when the function returns, and any implicit menus
3579 # the prompts of symbols and choices.
3582 # Copy defaults, ranges, selects, and implies to the Symbol
3585 # Find any items that should go in an implicit menu rooted at the
3603 # The menu node is a choice, menu, or if. Finalize each child node.
3608 # Propagate the menu node's dependencies to each child menu node.
3610 # This needs to go before the recursive _finalize_node() call so
3614 # Finalize the children
3622 # to finalize this "level" in the menu tree.
3629 # Add the node's non-node-specific properties to the choice, like
3640 # If the parent node holds a Choice, we use the Choice itself as the
3641 # parent dependency. This makes sense as the value (mode) of the choice
3642 # limits the visibility of the contained choice symbols. The C
3643 # implementation works the same way.
3645 # Due to the similar interface, Choice works as a drop-in replacement
3654 # Propagate 'visible if' and dependencies to the prompt
3682 # Propagate dependencies to the prompt. 'visible if' is only
3690 # Copies properties from the menu node 'node' up to its contained
3695 # traverses the menu tree roughly breadth-first, meaning properties on
3696 # symbols defined in multiple locations could end up in the wrong
3701 # See the Symbol class docstring
3709 # Modify the reverse dependencies of the selected symbol
3715 # Modify the weak reverse dependencies of the implied
3731 # Returns True if the (possibly constant) symbol 'sym' is valid as a value
3748 self._warn("{} selects the {} symbol {}, which is not "
3756 self._warn("{} implies the {} symbol {}, which is not "
3766 "the {} symbol {} has a malformed default {} -- "
3775 # reference or someone leaving out the quotes. Guess that
3776 # the quotes were left out if 'foo' isn't all-uppercase
3783 self._warn("the {0} symbol {1} has a non-{0} default {2}"
3789 self._warn("the {} symbol {} has selects or implies"
3801 "the {} symbol {} has ranges, but is not int or hex"
3809 self._warn("the {0} symbol {1} has a non-{0} "
3821 msg = "the choice symbol {} is {} by the following symbols, but " \
3850 self._warn("the default selection {} of {} is not "
3851 "contained in the choice"
3857 self._warn("default on the choice symbol {} will have "
3870 self._warn("the choice symbol {} has no prompt"
3874 self._warn("the choice symbol {} is defined with a "
3875 "prompt outside the choice"
3891 # interoperability between Linux and Windows. It's already the
3894 # The "U" flag would currently work for both Python 2 and 3, but it's
3918 # - For Python 3, force the encoding. Forcing the encoding on Python 2
3925 # Prints warnings for all references to undefined symbols within the
3929 # Returns True if the string 's' looks like a number.
3935 # Otherwise, symbols whose names happen to contain only the letters A-F
3952 # - sym.nodes empty means the symbol is undefined (has no
3958 # - The MODULES symbol always exists
3991 The following attributes are available. They should be viewed as read-only,
3995 Note: Prompts, help texts, and locations are stored in the Symbol's
3996 MenuNode(s) rather than in the Symbol itself. Check the MenuNode class and
3997 the Symbol.nodes attribute. This organization matches the C tools.
4000 The name of the symbol, e.g. "FOO" for 'config FOO'.
4003 The type of the symbol. One of BOOL, TRISTATE, STRING, INT, HEX, UNKNOWN.
4007 When running without modules (MODULES having the value n), TRISTATE
4009 within choices in "y" mode. This matches the C tools, and makes sense for
4013 The type as given in the Kconfig file, without any magic applied. Used
4014 when printing the symbol.
4017 The tristate value of the symbol as an integer. One of 0, 1, 2,
4020 This is the symbol value that's used outside of relation expressions
4024 The value of the symbol as a string. Gives the value for string/int/hex
4027 This is the symbol value that's used in relational expressions
4030 Gotcha: For int/hex symbols, the exact format of the value is often
4033 int(hex_sym.str_value, 16) to get the integer value.
4036 The user value of the symbol. None if no user value has been assigned
4039 Holds 0, 1, or 2 for bool/tristate symbols, and a string for the other
4046 A tuple containing the tristate user values that can currently be
4047 assigned to the symbol (that would be respected), ordered from lowest (0,
4048 representing n) to highest (2, representing y). This corresponds to the
4049 selections available in the menuconfig interface. The set of assignable
4050 values is calculated from the symbol's visibility and selects/implies.
4052 Returns the empty set for non-bool/tristate symbols and for symbols with
4053 visibility n. The other possible values are (0, 2), (0, 1, 2), (1, 2),
4054 (1,), and (2,). A (1,) or (2,) result means the symbol is visible but
4055 "locked" to m or y through a select, perhaps in combination with the
4059 instead to determine if the value can be changed.
4065 # What's the highest value it can be assigned? [-1] in Python
4066 # gives the last element.
4069 # The lowest?
4072 # Can the symbol be set to at least m?
4076 # Can the symbol be set to m?
4081 The visibility of the symbol. One of 0, 1, 2, representing n, m, y. See
4082 the module documentation for an overview of symbol values and visibility.
4085 The .config assignment string that would get written out for the symbol
4086 by Kconfig.write_config(). Returns the empty string if no .config
4093 Symbols with the (no longer needed) 'option env=...' option generate no
4094 configuration output, and neither does the special
4098 even for non-.config-like formats. To write just the symbols that would
4104 This is a superset of the symbols written out by write_autoconf().
4116 , giving the name of the symbol and its definition location(s).
4118 If the symbol is undefined, the location is given as "(undefined)".
4126 Holds the parent Choice for choice symbols, and None for non-choice
4130 List of (default, cond) tuples for the symbol's 'default' properties. For
4139 List of (symbol, cond) tuples for the symbol's 'select' properties. For
4150 List of (low, high, cond) tuples for the symbol's 'range' properties. For
4159 value, so this works out. The C tools work the same way.
4165 See the corresponding attributes on the MenuNode class.
4170 with the selecting symbol.
4179 The direct ('depends on') dependencies for the symbol, or self.kconfig.y
4183 Those get propagated to the direct dependencies, and the resulting direct
4184 dependencies in turn get propagated to the conditions of all properties.
4186 If the symbol is defined in multiple locations, the dependencies from the
4190 A set() with all symbols and choices referenced in the properties and
4191 property conditions of the symbol.
4194 get propagated to the symbol (see the 'Intro to symbol values' section in
4195 the module docstring).
4197 Choices appear in the dependencies of choice symbols.
4199 For the following definitions, only B and not C appears in A's
4214 See the Symbol.direct_dep attribute if you're only interested in the
4215 direct dependencies of the symbol (its 'depends on'). You can extract the
4216 symbols in it with the global expr_items() function.
4219 If the Symbol has an 'option env="FOO"' option, this contains the name
4220 ("FOO") of the environment variable. None for symbols without no
4223 'option env="FOO"' acts like a 'default' property whose value is the
4227 they are visible. env_var corresponds to a flag called SYMBOL_AUTO in the
4231 True if the symbol has 'option allnoconfig_y' set on it. This has no
4236 True if the symbol is a constant (quoted) symbol.
4239 The Kconfig instance this symbol is from.
4276 See the class documentation.
4289 See the class documentation.
4295 # Also calculates the visibility, so invalidation safe
4301 # FOO has the value "bar".
4314 # The C implementation checks the user value against the range in a
4326 # The zeros are from the C implementation running strtoll()
4337 # Defaults are used if the symbol is invisible, lacks a user value,
4346 "user value {} on the {} symbol {} ignored due to "
4347 "being outside the active range ([{}, {}]) -- falling "
4353 # If the user value is well-formed and satisfies range
4354 # contraints, it is stored in exactly the same form as
4355 # specified in the assignment (with or without "0x", etc.)
4362 # Used to implement the warning below
4389 # The value is rewritten to a standard form if it is
4399 "being outside the active range ([{}, {}])"
4406 # If the symbol is visible and has a user value, use that
4416 # env_var corresponds to SYMBOL_AUTO in the C implementation, and is
4417 # also set on the defconfig_list symbol there. Test for the
4419 # env_var setting and the defconfig_list symbol being printed
4430 See the class documentation.
4437 # Would take some work to give the location here
4439 "The {} symbol {} is being evaluated in a logical context "
4457 # If the symbol is visible and has a user value, use that
4495 # Visible choice symbol in y-mode choice. The choice mode limits
4496 # the visibility of choice symbols, so it's sufficient to just
4497 # check the visibility of the choice symbols themselves.
4510 See the class documentation.
4519 See the class documentation.
4528 See the class documentation.
4530 # _write_to_conf is determined when the value is calculated. This is a
4554 See the class documentation.
4560 Sets the user value of the symbol.
4562 Equal in effect to assigning the value to the symbol within a .config
4563 file. For bool and tristate symbols, use the 'assignable' attribute to
4568 Setting a choice symbol to 2 (y) sets Choice.user_selection to the
4570 Choice.user_selection is considered when the choice is in y mode (the
4574 automatically recalculated to reflect the assigned value.
4577 The user value to give to the symbol. For bool and tristate symbols,
4578 n/m/y can be specified either as 0/1/2 (the usual format for tristate
4579 values in Kconfiglib) or as one of the strings "n", "m", or "y". For
4582 Note that the value for an int/hex symbol is passed as a string, e.g.
4583 "123" or "0x0123". The format of this string is preserved in the
4586 Values that are invalid for the type (such as "foo" or 1 (m) for a
4591 Returns True if the value is valid for the type of the symbol, and
4592 False otherwise. This only looks at the form of the value. For BOOL and
4593 TRISTATE symbols, check the Symbol.assignable attribute to see what
4594 values are currently in range and would actually be reflected in the
4595 value of the symbol. For other symbol types, check whether the
4601 # If the new user value matches the old, nothing changes, and we can
4605 # symbol's user value to y might change the state of the choice, so it
4606 # wouldn't be safe (symbol user values always match the values set in a
4612 # Check if the value is valid for our type
4621 # Display tristate values as n, m, y in the warning
4623 "the value {} is invalid for {}, which has type {} -- "
4635 # Setting a choice symbol to y makes it the user selection of the
4636 # choice. Like for symbol user values, the user selection is not
4637 # guaranteed to match the actual selection of the choice, as
4649 Removes any user value from the symbol, as if the symbol had never
4659 See the class documentation.
4666 See the class documentation.
4673 See the class documentation.
4680 See the class documentation.
4687 See the class documentation.
4693 Returns a string with information about the symbol (including its name,
4694 value, visibility, and location(s)) when it is evaluated on e.g. the
4726 add("is the defconfig_list symbol")
4732 add("is the modules symbol")
4746 Returns a string representation of the symbol when it is printed.
4747 Matches the Kconfig format, with any parent dependencies propagated to
4748 the 'depends on' condition.
4750 The string is constructed by joining the strings returned by
4751 MenuNode.__str__() for each of the symbol's menu nodes, so symbols
4755 The returned string does not end in a newline. An empty string is
4777 # These attributes are always set on the instance from outside and
4803 # _write_to_conf is calculated along with the value. If True, the
4814 # Worker function for the 'assignable' attribute
4860 # Marks the symbol as needing to be recalculated
4866 # Invalidates the symbol and all items that (possibly) depend on it
4883 # stop the invalidation at symbols with _cached_vis None.
4887 # (even when you already have a list of all the dependent
4891 # for choices, where the choice depends on the choice symbols
4897 # Invalidates the symbol and its dependent symbols, but only if the
4905 # Prints a warning if the symbol has no prompt. In some contexts (e.g.
4907 # normal and expected, so the warning can be disabled.
4919 # write_min_config() helper function. Returns the value the symbol
4921 # the same algorithm as the C implementation (though a bit cleaned up),
4960 "currently being {}-selected by the following symbols:" \
4965 # The reverse dependencies from each select are ORed together
4968 # Only include selects that exceed the direct dependencies
4974 # In both cases, we can split on AND and pick the first operand
5000 The following attributes are available on Choice instances. They should be
5004 Note: Prompts, help texts, and locations are stored in the Choice's
5005 MenuNode(s) rather than in the Choice itself. Check the MenuNode class and
5006 the Choice.nodes attribute. This organization matches the C tools.
5009 The name of the choice, e.g. "FOO" for 'choice FOO', or None if the
5013 The type of the choice. One of BOOL, TRISTATE, UNKNOWN. UNKNOWN is for
5014 choices defined without a type where none of the contained symbols have a
5015 type either (otherwise the choice inherits the type of the first symbol
5019 magically change type to BOOL. This matches the C tools, and makes sense
5023 The type as given in the Kconfig file, without any magic applied. Used
5024 when printing the choice.
5027 The tristate value (mode) of the choice. A choice can be in one of three
5030 0 (n) - The choice is disabled and no symbols can be selected. For
5032 the 'optional' flag set (see kconfig-language.txt).
5034 1 (m) - Any number of choice symbols can be set to m, the rest will
5037 2 (y) - One symbol will be y, the rest n.
5039 Only tristate choices can be in m mode. The visibility of the choice is
5040 an upper bound on the mode, and the mode in turn is an upper bound on the
5041 visibility of the choice symbols.
5043 To change the mode, use Choice.set_value().
5046 The C tools internally represent choices as a type of symbol, with
5048 similarity to Symbol. The value (mode) of a choice is really just a
5050 lower bound to m for visible non-optional choices (the reverse
5053 Symbols within choices get the choice propagated as a dependency to
5054 their properties. This turns the mode of the choice into an upper bound
5055 on e.g. the visibility of choice symbols, and explains the gotcha
5056 related to printing choice symbols mentioned in the module docstring.
5058 Kconfiglib uses a separate Choice class only because it makes the code
5060 Corresponding attributes have the same name in the Symbol and Choice
5064 Like choice.tri_value, but gives the value as one of the strings
5068 The value (mode) selected by the user through Choice.set_value(). Either
5069 0, 1, or 2, or None if the user hasn't selected a mode. See
5076 See the symbol class documentation. Gives the assignable values (modes).
5079 The Symbol instance of the currently selected symbol. None if the Choice
5084 sym.set_value(2) on the choice symbol you want to select instead.
5087 The symbol selected by the user (by setting it to y). Ignored if the
5088 choice is not in y mode, but still remembered so that the choice "snaps
5089 back" to the user selection if the mode is changed back to y. This might
5093 sym.set_value(2) on the choice symbol to be selected instead.
5096 See the Symbol class documentation. Acts on the value (mode).
5103 , giving the name of the choice and its definition location(s). If the
5105 be shown as "<choice>" before the list of locations (always a single one
5109 List of symbols contained in the choice.
5111 Obscure gotcha: If a symbol depends on the previous symbol within a
5116 A list of MenuNodes for this choice. In practice, the list will probably
5121 List of (symbol, cond) tuples for the choice's 'defaults' properties. For
5129 See the corresponding attribute on the MenuNode class.
5135 A set() with all symbols referenced in the properties and property
5136 conditions of the choice.
5139 get propagated to the choice (see the 'Intro to symbol values' section in
5140 the module docstring).
5143 True if the choice has the 'optional' flag set on it and can be in
5147 The Kconfig instance this choice is from.
5176 Returns the type of the choice. See Symbol.type.
5185 See the class documentation.
5192 See the class documentation.
5195 # non-optional choices, which is how the C implementation does it
5212 See the class documentation.
5221 See the class documentation.
5230 See the class documentation.
5232 # Reuse the expression format, which is '<choice (name, if any)>'.
5238 See the class documentation.
5246 Sets the user value (mode) of the choice. Like for Symbol.set_value(),
5247 the visibility might truncate the value. Choices without the 'optional'
5252 Returns True if the value is valid for the type of the choice, and
5253 False otherwise. This only looks at the form of the value. Check the
5255 and would actually be reflected in the mode of the choice.
5261 # We know the value must be valid if it was successfully set
5269 # Display tristate values as n, m, y in the warning
5271 "the value {} is invalid for {}, which has type {} -- "
5287 Resets the user value (mode) and user selection of the Choice, as if
5288 the user had never touched the mode or any of the choice symbols.
5297 See the class documentation.
5304 See the class documentation.
5310 Returns a string with information about the choice when it is evaluated
5311 on e.g. the interactive Python prompt.
5350 Returns a string representation of the choice when it is printed.
5351 Matches the Kconfig format (though without the contained choice
5352 symbols), with any parent dependencies propagated to the 'depends on'
5355 The returned string does not end in a newline.
5378 # These attributes are always set on the instance from outside and
5406 # Worker function for the 'assignable' attribute
5425 # Worker function for the 'selection' attribute
5433 # Use the user selection if it's visible
5443 # The default symbol must be visible too
5447 # Otherwise, pick the first visible symbol, if any
5471 Represents a menu node in the configuration. This corresponds to an entry
5472 in e.g. the 'make menuconfig' interface, though non-visible choices, menus,
5476 The top-level menu node, corresponding to the implicit top-level menu, is
5479 The menu nodes for a Symbol or Choice can be found in the
5481 menu nodes, with their text stored in the prompt attribute (prompt[0]).
5482 This mirrors the C implementation.
5484 The following attributes are available on MenuNode instances. They should
5488 Either a Symbol, a Choice, or one of the constants MENU and COMMENT.
5490 (matching the C implementation) and do not appear in the final menu tree.
5493 The following menu node. None if there is no following node.
5496 The first child menu node. None if there are no children.
5503 The parent menu node. None if there is no parent.
5506 A (string, cond) tuple with the prompt for the menu node and its
5510 For symbols and choices, the prompt is stored in the MenuNode rather than
5511 the Symbol or Choice instance. For menus and comments, the prompt holds
5512 the text.
5515 The 'default' properties for this particular menu node. See
5537 These work the like the corresponding attributes without orig_*, but omit
5538 any dependencies propagated from 'depends on' and surrounding 'if's (the
5542 showing the direct dependencies in one place.
5545 The help text for the menu node for Symbols and Choices. None if there is
5546 no help text. Always stored in the node rather than the Symbol or Choice.
5550 Trailing whitespace (including a final newline) is stripped from the help
5551 text. This was not the case before Kconfiglib 10.21.0, where the format
5555 The direct ('depends on') dependencies for the menu node, or
5559 Those get propagated to the direct dependencies, and the resulting direct
5560 dependencies in turn get propagated to the conditions of all properties.
5562 If a symbol or choice is defined in multiple locations, only the
5563 properties defined at a particular location get the corresponding
5567 The 'visible if' dependencies for the menu node (which must represent a
5569 'visible if' dependencies are recursively propagated to the prompts of
5570 symbols and choices within the menu.
5573 A set() with all symbols and choices referenced in the properties and
5574 property conditions of the menu node.
5577 Choices appear in the dependencies of choice symbols.
5580 Set to True if the children of the menu node should be displayed in a
5581 separate menu. This is the case for the following items:
5587 - Symbols defined with the 'menuconfig' keyword. The children come from
5591 'is_menuconfig' is just a hint on how to display the menu node. It's
5595 The location where the menu node appears. The filename is relative to
5596 $srctree (or to the current directory if $srctree isn't set), except
5600 A tuple of (filename, linenr) tuples, giving the locations of the
5601 'source' statements via which the Kconfig file containing this menu node
5602 was included. The first element is the location of the 'source' statement
5603 in the top-level Kconfig file passed to Kconfig.__init__(), etc.
5605 Note that the Kconfig file of the menu node itself isn't included. Check
5609 The Kconfig instance the menu node is from.
5645 See the class documentation.
5654 See the class documentation.
5662 See the class documentation.
5670 See the class documentation.
5678 See the class documentation.
5686 See the class documentation.
5719 Returns a string with information about the menu node when it is
5720 evaluated on e.g. the interactive Python prompt.
5767 Returns a string representation of the menu node. Matches the Kconfig
5768 format, with any parent dependencies propagated to the 'depends on'
5771 The output could (almost) be fed back into a Kconfig parser to redefine
5772 the object associated with the menu node. See the module documentation
5780 The returned string does not end in a newline.
5824 # If there's a prompt, we'll use the '<type> "prompt"' shorthand
5884 # copied, and (2) the direct dependencies always appear at the end.
5901 The following attributes are available:
5904 The name of the variable.
5907 The unexpanded value of the variable.
5910 The expanded value of the variable. For simple variables (those defined
5912 KconfigError if the expansion seems to be stuck in a loop.
5914 Accessing this field is the same as calling expanded_value_w_args() with
5919 True if the variable is recursive (defined with =).
5932 See the class documentation.
5938 Returns the expanded value of the variable/function. Any arguments
5941 Raises a KconfigError if the expansion seems to be stuck in a loop.
5956 KconfigError and KconfigSyntaxError are the same class. The
5970 # "[Errno <errno>] <strerror>", ignoring any custom message passed to the
5990 Evaluates the expression 'expr' to a tristate value. Returns 0 (n), 1 (m),
6004 # Short-circuit the n case as an optimization (~5% faster
6010 # Short-circuit the y case as an optimization
6033 # Fall back on a lexicographic comparison if the operands don't
6062 Returns the string representation of the expression 'expr', as in a Kconfig
6069 the expression, with the symbol/choice as the argument. It is expected to
6070 return a string to be used for the symbol/choice.
6073 documentation, or for printing the value of each symbol/choice after it.
6106 Returns a set() of all items (symbols and choices) that appear in the
6133 Returns a list containing the top-level AND or OR operands in the
6134 expression 'expr', in the same (left-to-right) order as they appear in
6135 the expression.
6155 # Second || is not at the top level
6158 # Parentheses don't matter as long as we stay at the top level (don't
6178 Escapes the string 's' in the same fashion as is done for display in
6188 Unescapes the string 's'. \ followed by any character is replaced with just
6200 argument (default: Kconfig). Returns the Kconfig instance for the parsed
6206 The 'description' passed to argparse.ArgumentParser().
6227 Helper for tools. Returns the value of KCONFIG_CONFIG (which specifies the
6230 Calling load_config() with filename=None might give the behavior you want,
6247 # "Upcasts" a _KconfigIOError to an IOError, removing the custom
6248 # __str__() message. The standard message is better here.
6251 # but it's probably not a big deal. The distinction is shaky (see
6288 # the values a user can set for them, corresponding to the visibility in
6289 # e.g. 'make menuconfig'. This function calculates the visibility for the
6290 # Symbol or Choice 'sc' -- the logic is nearly identical.
6373 # the C implementation.
6379 # If sym_name is MY_SYM_NAME, touches my/sym/name.h. See the sync_deps()
6387 # A kind of truncating touch, mirroring the C tools
6425 # Symbol/Choice.name_and_loc helper. Returns the "(defined at ...)" part of
6426 # the string. 'sc' is a Symbol or Choice.
6448 # Check for one of the following:
6480 # with no unexpected "jumps" in the indentation.
6484 # looks confusing, and the menuconfig already shows all choice symbols if
6485 # you enter the choice at some location with a prompt.
6507 # which are assumed to already have been flattened. The C implementation
6508 # doesn't bother to do this, but we expose the menu tree directly, and it
6527 # due to tricky Python semantics. The order matters.
6532 # Finalizes a choice, marking each symbol whose menu node has the choice as
6533 # the parent as a choice symbol, and automatically determining types if not
6545 # If no type is specified for the choice, its type is that of
6546 # the first choice item with a specified type
6553 # Each choice item of UNKNOWN type gets the type of the choice
6560 # Detects dependency loops using depth-first search on the dependency graph
6568 # "visited, potentially part of a dependency loop". The recursive
6569 # search then continues from the symbol/choice.
6572 # there's a dependency loop. The loop is found on the call stack by
6573 # recording symbols while returning ("on the way back") until X is seen
6581 # This saves work if we run into the symbol/choice again in later calls
6586 # X, we visit all choice symbols from the choice except X, and prevent
6587 # immediately revisiting the choice with a flag (ignore_choice).
6589 # Maybe there's a better way to handle this (different flags or the
6598 # Choices show up in Symbol._dependents when the choice has the
6602 # Since we aren't entering the choice via a choice symbol, all
6603 # choice symbols need to be checked, hence the None.
6618 # The symbol is not part of a dependency loop
6625 # The symbol was checked earlier and is already known to not be part of
6629 # sym._visited == 1, found a dependency loop. Return the symbol as the
6645 # Prevent the choice from being immediately re-entered via the
6652 # The choice is not part of a dependency loop
6659 # The choice was checked earlier and is already known to not be part of
6663 # choice._visited == 1, found a dependency loop. Return the choice as the
6669 # Called "on the way back" when we know we have a loop
6671 # Is the symbol/choice 'cur' where the loop started?
6673 # Nope, it's just a part of the loop
6676 # Yep, we have the entire loop. Throw an exception that shows it.
6685 msg += "the choice symbol "
6690 # Small wart: Since we reuse the already calculated
6718 # Gives the filename and context for UnicodeDecodeError's, which are a pain
6719 # to debug otherwise. 'e' is the UnicodeDecodeError object.
6721 # If the decoding error is for the output of a $(shell,...) command,
6722 # macro_linenr holds the line number where it was run (the exact line
6742 "Kconfiglib 12.0.0, the message is returned from {0}() instead, "
6745 "stdout. The old API required ugly hacks to reuse messages in "
6804 # On Python 3 versions before 3.6, it's not possible to specify the
6805 # encoding when passing universal_newlines=True to Popen() (the 'encoding'
6840 # The token and type constants below are safe to test with 'is', which is a bit
6843 # caches small integer objects). The constants end up pointing to unique
6844 # integer objects, and since we consistently refer to them via the names below,
6845 # we always get the same object.
6904 # Keyword to token map, with the get() method assigned directly as a small
6952 # The constants below match the value of the corresponding tokens to remove the
6998 # Used in comparisons. 0 means the base is inferred from the format of the
7109 # Helper functions for getting compiled regular expressions, with the needed
7112 # Use ASCII regex matching on Python 3. It's already the default on Python 2.
7125 # The initial token on a line. Also eats leading and trailing whitespace, so
7126 # that we can jump straight to the next token (or to the end of the line if
7132 # expansions in the left-hand side.
7135 # An identifier/keyword after the first token. Also eats trailing whitespace.
7139 # A fragment in the left-hand side of a preprocessor variable assignment. These
7140 # are the portions between macro expansions ($(foo)). Macros are supported in
7141 # the LHS (variable name).
7144 # The assignment operator and value (right-hand side) in a preprocessor
7155 # end-of-line, in case the macro is the last thing on the line.
7159 # file, including escaped characters. Extracts the contents.