From 20de53b6a29fcfd2d91e815c5698b9b806a908f4 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 25 Aug 2018 07:21:02 +0200 Subject: Add a Kconfig.kconfig_filenames attribute Kconfig.kconfig_filenames is an ordered list of all Kconfig files included in the configuration, relative to $srctree. Can be used e.g. for custom incremental build implementations, though sync_deps() already indirectly catches any relevant changes to files. Piggyback some ' -> " quote style consistency cleanups. --- kconfiglib.py | 21 ++++++++++++++++++++- testsuite.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 3b59363..5fdd9b7 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -466,6 +466,19 @@ class Kconfig(object): A list with all comments, in the same order as they appear in the Kconfig files + kconfig_filenames: + A list with the filenames of all Kconfig files included in the + configuration, relative to $srctree (or relative to the current directory + if $srctree isn't set). + + The files are listed in the order they are source'd, starting with the + top-level Kconfig file. If a file is source'd multiple times, it will + appear multiple times. Use set() to get unique filenames. + + Note: Using this for incremental builds is redundant. Kconfig.sync_deps() + already indirectly catches any file modifications that change the + configuration output. + n/m/y: The predefined constant symbols n/m/y. Also available in const_syms. @@ -570,6 +583,7 @@ class Kconfig(object): "const_syms", "defconfig_list", "defined_syms", + "kconfig_filenames", "m", "mainmenu_text", "menus", @@ -757,6 +771,9 @@ class Kconfig(object): # Parse the Kconfig files + # Not used internally. Provided as a convenience. + self.kconfig_filenames = [filename] + # These implement a single line of "unget" for the parser self._saved_line = None self._has_tokens = False @@ -1545,6 +1562,8 @@ class Kconfig(object): # self._filename (which makes it indirectly show up in # MenuNode.filename). Equals full_filename for absolute paths. + self.kconfig_filenames.append(rel_filename) + # The parent Kconfig files are represented as a list of # (, ) tuples. # @@ -2254,7 +2273,7 @@ class Kconfig(object): self._warn("the menuconfig symbol {} has no prompt" .format(_name_and_loc(sym))) - # Tricky Python semantics: This assign prev.next before prev + # Tricky Python semantics: This assigns prev.next before prev prev.next = prev = node elif t0 in (_T_SOURCE, _T_RSOURCE, _T_OSOURCE, _T_ORSOURCE): diff --git a/testsuite.py b/testsuite.py index 1c49209..4faed1f 100644 --- a/testsuite.py +++ b/testsuite.py @@ -978,7 +978,8 @@ g """) - print("Testing locations and source/rsource/gsource/grsource") + print("Testing locations, source/rsource/gsource/grsource, and " + "Kconfig.kconfig_filenames") def verify_locations(nodes, *expected_locs): verify(len(nodes) == len(expected_locs), @@ -1034,6 +1035,22 @@ g verify_locations([c.syms["COMMENT_HOOK"].nodes[0].next], "tests/Klocation_sourced:18") + # Test Kconfig.kconfig_filenames + + verify_equal(c.kconfig_filenames, [ + "tests/Klocation", + "tests/Klocation_sourced", + "tests/sub/Klocation_rsourced", + "tests/sub/Klocation_gsourced1", + "tests/sub/Klocation_gsourced2", + "tests/sub/Klocation_gsourced1", + "tests/sub/Klocation_gsourced2", + "tests/sub/Klocation_grsourced1", + "tests/sub/Klocation_grsourced2", + "tests/sub/Klocation_grsourced1", + "tests/sub/Klocation_grsourced2" + ]) + # Test recursive 'source' detection try: @@ -1134,18 +1151,18 @@ tests/Krecursive2:1 verify_sym_path("ONE_DOWN", 5, ("Kinclude_path", 9)) verify_sym_path("TWO_DOWN", 0, - ('Kinclude_path', 4), ('Kinclude_path_sourced_1', 4)) + ("Kinclude_path", 4), ("Kinclude_path_sourced_1", 4)) verify_sym_path("TWO_DOWN", 1, - ('Kinclude_path', 4), ('Kinclude_path_sourced_1', 9)) + ("Kinclude_path", 4), ("Kinclude_path_sourced_1", 9)) verify_sym_path("TWO_DOWN", 2, - ('Kinclude_path', 9), ('Kinclude_path_sourced_1', 4)) + ("Kinclude_path", 9), ("Kinclude_path_sourced_1", 4)) verify_sym_path("TWO_DOWN", 3, - ('Kinclude_path', 9), ('Kinclude_path_sourced_1', 9)) + ("Kinclude_path", 9), ("Kinclude_path_sourced_1", 9)) verify_node_path(c.top_node) - verify_node_path(c.menus[0], ('Kinclude_path', 4), ('Kinclude_path_sourced_1', 4)) - verify_node_path(c.comments[0], ('Kinclude_path', 4), ('Kinclude_path_sourced_1', 4)) - verify_node_path(c.choices[0].nodes[0], ('Kinclude_path', 4), ('Kinclude_path_sourced_1', 4)) + verify_node_path(c.menus[0], ("Kinclude_path", 4), ("Kinclude_path_sourced_1", 4)) + verify_node_path(c.comments[0], ("Kinclude_path", 4), ("Kinclude_path_sourced_1", 4)) + verify_node_path(c.choices[0].nodes[0], ("Kinclude_path", 4), ("Kinclude_path_sourced_1", 4)) os.environ.pop("srctree", None) -- cgit v1.2.3