diff options
| author | Chris Dornsife <chris@dornsife.com> | 2017-02-13 12:06:17 -0800 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2017-02-14 18:14:12 +0100 |
| commit | 45f87b9d86951f8d2d73dd68e43de11d56ad7a3c (patch) | |
| tree | 5778043b65aaa6f3f6dc8dfcf13d82d0068d4212 /kconfiglib.py | |
| parent | 0b544365784e13277f1641c8eaa596c9ef8ff003 (diff) | |
Add support for the CONFIG_ environment variable
Makes the prefix used in .config files configurable.
Also add pip installation note to README.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index e2a8763..9bc89f3 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -175,6 +175,12 @@ class Config(object): self.arch = os.environ.get("ARCH") self.srcarch = os.environ.get("SRCARCH") + # If you set CONFIG_ in the environment, Kconfig will prefix all symbols + # with its value when saving the configuration, instead of using the default, "CONFIG_". + self.config_prefix = os.environ.get("CONFIG_") + if self.config_prefix is None: + self.config_prefix = "CONFIG_" + # See Config.__init__(). We need this for get_defconfig_filename(). self.srctree = os.environ.get("srctree") if self.srctree is None: @@ -390,6 +396,10 @@ class Config(object): replace (default: True): True if the configuration should replace the old configuration; False if it should add to it.""" + # Regular expressions for parsing .config files + _set_re_match = re.compile(r"{}(\w+)=(.*)".format(self.config_prefix)).match + _unset_re_match = re.compile(r"# {}(\w+) is not set".format(self.config_prefix)).match + # Put this first so that a missing file doesn't screw up our state filename = os.path.expandvars(filename) line_feeder = _FileFeed(filename) @@ -2437,17 +2447,17 @@ class Symbol(Item): return if self.type == BOOL or self.type == TRISTATE: - append_fn("CONFIG_{0}={1}".format(self.name, val) + append_fn("{0}{1}={2}".format(self.config.config_prefix, self.name, val) if val == "y" or val == "m" else - "# CONFIG_{0} is not set".format(self.name)) + "# {0}{1} is not set".format(self.config.config_prefix, self.name)) elif self.type == INT or self.type == HEX: - append_fn("CONFIG_{0}={1}".format(self.name, val)) + append_fn("{0}{1}={2}".format(self.config.config_prefix, self.name, val)) elif self.type == STRING: # Escape \ and " - append_fn('CONFIG_{0}="{1}"' - .format(self.name, + append_fn('{0}{1}="{2}"' + .format(self.config.config_prefix, self.name, val.replace("\\", "\\\\").replace('"', '\\"'))) else: @@ -3417,10 +3427,6 @@ _initial_token_re_match = re.compile(r"[^\w]*(\w+)\s*").match # trailing whitespace as an optimization. _id_keyword_re_match = re.compile(r"\s*([\w./-]+)\s*").match -# Regular expressions for parsing .config files -_set_re_match = re.compile(r"CONFIG_(\w+)=(.*)").match -_unset_re_match = re.compile(r"# CONFIG_(\w+) is not set").match - # Regular expression for finding $-references to symbols in strings _sym_ref_re_search = re.compile(r"\$[A-Za-z0-9_]+").search |
