summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kconfiglib.py25
-rw-r--r--tests/Kbase_dir2
-rw-r--r--testsuite.py9
3 files changed, 26 insertions, 10 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index ed1d50c..5dd53cf 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -84,7 +84,7 @@ class Config(object):
def __init__(self,
filename = "Kconfig",
- base_dir = "$srctree",
+ base_dir = None,
print_warnings = True,
print_undef_assign = False):
"""Creates a new Config object, representing a Kconfig configuration.
@@ -98,15 +98,17 @@ class Config(object):
kconfiglib via 'make scriptconfig', the filename of the base
base Kconfig file will be in sys.argv[1].
- base_dir (default: "$srctree") -- The base directory relative to which
- 'source' statements within Kconfig files will work. For the
- Linux kernel this should be the top-level directory of the
- kernel tree. $-references to environment variables will be
- expanded.
+ base_dir (default: None) -- The base directory relative to which
+ 'source' statements within Kconfig files will work. For the
+ Linux kernel this should be the top-level directory of the
+ kernel tree. $-references to existing environment variables
+ will be expanded.
- The environment variable 'srctree' is set by the Linux makefiles
- to the top-level kernel directory. A default of "." would not
- work if an alternative build directory is used.
+ If None (the default), the environment variable 'srctree' will
+ be used if set, and the current directory otherwise. 'srctree'
+ is set by the Linux makefiles to the top-level kernel
+ directory. A default of "." would not work with an alternative
+ build directory.
print_warnings (default: True) -- Set to True if warnings related to
this configuration should be printed to stderr. This can
@@ -166,7 +168,10 @@ class Config(object):
self.srctree = "."
self.filename = filename
- self.base_dir = os.path.expandvars(base_dir).rstrip("/")
+ if base_dir is None:
+ self.base_dir = self.srctree
+ else:
+ self.base_dir = os.path.expandvars(base_dir)
# The 'mainmenu' text
self.mainmenu_text = None
diff --git a/tests/Kbase_dir b/tests/Kbase_dir
new file mode 100644
index 0000000..9f8c55a
--- /dev/null
+++ b/tests/Kbase_dir
@@ -0,0 +1,2 @@
+# This will only work if 'base_dir' is set correctly
+source "empty"
diff --git a/testsuite.py b/testsuite.py
index 3407e0a..3a2ee0b 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -1234,6 +1234,15 @@ def run_selftests():
verify_value("UNAME_RELEASE", os.uname()[2])
+ # Expansion of environment variables in Config.__init__'s base_dir
+ # parameter. Just make sure we don't crash when Kbase_dir 'source's a file
+ # from the same directory.
+
+ os.environ["EnV_VaR1"] = "Kconfigl"
+ os.environ["EnV_VaR2"] = "ib/tests"
+ kconfiglib.Config("Kconfiglib/tests/Kbase_dir",
+ base_dir = "$EnV_VaR1$EnV_VaR2/")
+
#
# .config reading and writing
#