From d56e9c1d4c3e6f560382ac71fa2419b2a9bef1cb Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 7 Jun 2015 16:57:46 +0200 Subject: 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. --- kconfiglib.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'kconfiglib.py') 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 -- cgit v1.2.3