summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-01-05 22:27:21 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-01-05 22:55:10 +0100
commitd331e92f806eb0e3f4a86523a847bfac5501084f (patch)
tree791d53c98650abc1996c48788bf61d795cc102e0 /kconfiglib.py
parent5d693b2e66451aedfd694ffde4dba7d4b74afa46 (diff)
Formatting and comment nits
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py60
1 files changed, 37 insertions, 23 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 05cc172..afc57cb 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -829,23 +829,27 @@ class Kconfig(object):
def write_autoconf(self, filename,
header="/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */\n"):
r"""
- Writes out symbol values as a C header file.
+ Writes out symbol values as a C header file, matching the format used
+ by include/generated/autoconf.h in the kernel (though possibly with a
+ different ordering of the #defines, as the order in the C
+ implementation depends on the hash table implementation as of writing).
filename:
Self-explanatory.
header (default: "/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */\n"):
Text that will be inserted verbatim at the beginning of the file. You
- would usually want it enclosed in "/* */" to make it a C comment,
+ would usually want it enclosed in '/* */' to make it a C comment,
and include a final terminating newline.
"""
with open(filename, "w") as f:
# Small optimization
write = f.write
+
write(header)
- # Avoid duplicates
+ # Avoid duplicates -- see write_config()
for sym in self.defined_syms:
sym._written = False
@@ -856,31 +860,41 @@ class Kconfig(object):
while 1:
item = node.item
- if isinstance(item, Symbol):
- if not item._written:
- # Force caculation of the value by means of the hidden
- # call triggered by accessing str_value
- val = item.str_value
- if item._write_to_conf:
- if item.orig_type in (BOOL, TRISTATE) and val != "n":
- suffix = "_MODULE" if val == "m" else ""
+ if isinstance(item, Symbol) and not item._written:
+ # Note: _write_to_conf is determined when the value is
+ # calculated. This is a hidden function call due to
+ # property magic.
+ val = item.str_value
+ if item._write_to_conf:
+ if item.orig_type in (BOOL, TRISTATE):
+ if val != "n":
write("#define {}{}{} 1\n"
.format(self.config_prefix, item.name,
- suffix))
- elif item.orig_type == STRING:
- write('#define {}{} "{}"\n'
- .format(self.config_prefix, item.name,
- escape(val)))
- elif item.orig_type in (INT, HEX):
- if item.orig_type == HEX and not val.startswith(("0x", "0X")):
- val = "0x" + val
- write("#define {}{} {}\n"
- .format(self.config_prefix, item.name,
- val))
+ "_MODULE" if val == "m" else ""))
- item._written = True
+ elif item.orig_type == STRING:
+ write('#define {}{} "{}"\n'
+ .format(self.config_prefix, item.name,
+ escape(val)))
+
+ elif item.orig_type in (INT, HEX):
+ if item.orig_type == HEX and \
+ not val.startswith(("0x", "0X")):
+ val = "0x" + val
+
+ write("#define {}{} {}\n"
+ .format(self.config_prefix, item.name,
+ val))
+
+ else:
+ _internal_error("Internal error while creating C "
+ 'header: unknown type "{}".'
+ .format(item.orig_type))
+
+ item._written = True
# Iterative tree walk using parent pointers
+
if node.list:
node = node.list
elif node.next: