summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-08-18 01:07:23 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-08-18 01:10:41 +0200
commitdf97bcaea2d6c24ddd62c4e9685d0db54aade092 (patch)
treec7c0e57c16dc05da7fcae8388241dfdb2c0c1893
parent3c5ae3f36cf626e79f281b80706b617b76f57060 (diff)
Revert "Fix $srctree logic for the top-level Kconfig file"
This reverts commit 8a3999bc708e8468ff79665e3cbdfccd603160e1. I realized that this should go in a major release at least, because it has the potential to break scripts that rely on the old behavior of ignoring $srctree for the filename passed to Kconfig.__init__(). A dummy release will bump the version to 9.4.2. Any future release with the change will be 10.0.0.
-rw-r--r--kconfiglib.py20
-rw-r--r--testsuite.py16
2 files changed, 21 insertions, 15 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 0714d48..68f157b 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -610,14 +610,20 @@ class Kconfig(object):
the right Kconfig is included from there (arch/$SRCARCH/Kconfig as of
writing).
- If $srctree is set, 'filename' will be looked up relative to it.
- $srctree is also used to look up source'd files within Kconfig files.
- See the class documentation.
-
If you are using Kconfiglib via 'make scriptconfig', the filename of
the base base Kconfig file will be in sys.argv[1]. It's currently
always "Kconfig" in practice.
+ The $srctree environment variable is used to look up Kconfig files
+ referenced in Kconfig files if set. See the class documentation.
+
+ Note: '(o)source' statements in Kconfig files always work relative to
+ $srctree (or the current directory if $srctree is unset), even if
+ 'filename' is a path with directories. This allows a subset of
+ Kconfig files to be loaded without breaking references to other
+ Kconfig files, e.g. by doing Kconfig("./sub/Kconfig"). sub/Kconfig
+ might expect to be sourced by ./Kconfig.
+
warn (default: True):
True if warnings related to this configuration should be generated.
This can be changed later with Kconfig.enable/disable_warnings(). It
@@ -731,7 +737,7 @@ class Kconfig(object):
self.top_node.prompt = ("Main menu", self.y)
self.top_node.parent = None
self.top_node.dep = self.y
- self.top_node.filename = filename
+ self.top_node.filename = os.path.relpath(filename, self.srctree)
self.top_node.linenr = 1
# Parse the Kconfig files
@@ -745,11 +751,11 @@ class Kconfig(object):
self._filestack = []
# The current parsing location
- self._filename = filename
+ self._filename = os.path.relpath(filename, self.srctree)
self._linenr = 0
# Open the top-level Kconfig file
- self._file = self._open(os.path.join(self.srctree, filename), "r")
+ self._file = self._open(filename, "r")
try:
# Parse everything
diff --git a/testsuite.py b/testsuite.py
index cddce68..a521128 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -895,17 +895,17 @@ comment "advanced comment"
<configuration with 14 symbols, main menu prompt "Main menu", srctree is current directory, config symbol prefix "CONFIG_", warnings disabled, printing of warnings to stderr enabled, undef. symbol assignment warnings disabled, redundant symbol assignment warnings enabled>
""")
- os.environ["srctree"] = "Kconfiglib"
+ os.environ["srctree"] = "srctree value"
os.environ["CONFIG_"] = "CONFIG_ value"
- c = Kconfig("tests/Krepr", warn=False)
+ c = Kconfig("Kconfiglib/tests/Krepr", warn=False)
c.enable_warnings()
c.disable_stderr_warnings()
c.disable_redun_warnings()
c.enable_undef_warnings()
verify_repr(c, """
-<configuration with 14 symbols, main menu prompt "Main menu", srctree "Kconfiglib", config symbol prefix "CONFIG_ value", warnings enabled, printing of warnings to stderr disabled, undef. symbol assignment warnings enabled, redundant symbol assignment warnings disabled>
+<configuration with 14 symbols, main menu prompt "Main menu", srctree "srctree value", config symbol prefix "CONFIG_ value", warnings enabled, printing of warnings to stderr disabled, undef. symbol assignment warnings enabled, redundant symbol assignment warnings disabled>
""")
os.environ.pop("srctree", None)
@@ -987,7 +987,7 @@ g
os.environ["srctree"] = srctree
# Has symbol with empty help text, so disable warnings
- c = Kconfig("tests/Klocation", warn=False)
+ c = Kconfig("Kconfiglib/tests/Klocation", warn=False)
verify_locations(c.syms["SINGLE_DEF"].nodes, "tests/Klocation:4")
@@ -1018,7 +1018,7 @@ g
# Test recursive 'source' detection
try:
- Kconfig("tests/Krecursive1")
+ Kconfig("Kconfiglib/tests/Krecursive1")
except KconfigError:
pass
except:
@@ -1030,7 +1030,7 @@ g
# TODO: Make an exception test helper
try:
- Kconfig("tests/Kmissingsource")
+ Kconfig("Kconfiglib/tests/Kmissingsource")
except KconfigError:
pass
except:
@@ -1039,7 +1039,7 @@ g
fail("'source' with missing file did not raise exception")
try:
- Kconfig("tests/Kmissingrsource")
+ Kconfig("Kconfiglib/tests/Kmissingrsource")
except KconfigError:
pass
except:
@@ -1559,7 +1559,7 @@ g
"defconfig_filename gave wrong file with $srctree unset")
os.environ["srctree"] = "Kconfiglib/tests"
- c = Kconfig("Kdefconfig_srctree")
+ c = Kconfig("Kconfiglib/tests/Kdefconfig_srctree")
verify(c.defconfig_filename == "Kconfiglib/tests/sub/defconfig_in_sub",
"defconfig_filename gave wrong file with $srctree set")