diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-07 16:57:46 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-07 17:46:11 +0200 |
| commit | d56e9c1d4c3e6f560382ac71fa2419b2a9bef1cb (patch) | |
| tree | 6f63cb1c1ed473480789a926244dad353a083694 | |
| parent | 8de05809108aef5adbc9081975f530344c8bce62 (diff) | |
Do not require $srctree to be set for non-kernel projects.
(It was never required if you explicitly passed a 'base_dir', but it's a
bit silly to have to do that too.)
This is a bug. I expected os.path.expandvars() to replace references
non-set environment variables with nothing, but it leaves them as is.
Work around it by letting base_dir = None be special and the default. It
uses $srctree if set and the current directory otherwise. This has the
following advantages:
- It avoids having to reimplement a different version of
os.path.expandvars() and special-casing "" to mean the current
directory.
- It means '$' can appear in paths. (Though it probably never will.)
Maybe the expansion behavior could be removed too, but keep it for now
to be backwards compatible.
| -rw-r--r-- | kconfiglib.py | 25 | ||||
| -rw-r--r-- | tests/Kbase_dir | 2 | ||||
| -rw-r--r-- | testsuite.py | 9 |
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 # |
