Skip to content

Commit bdb2ac1

Browse files
committed
gen_defines.py: add option to remove inline comments
Add an option to remove inline comments from the #define lines. This allows including the generated files in C++ code, which does not elide the comments when performing macro expansion. Signed-off-by: Luca Burelli <[email protected]>
1 parent 1481a8b commit bdb2ac1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/dts/gen_defines.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
def main():
3333
global header_file
3434
global flash_area_num
35+
global no_inline_comments
3536

3637
args = parse_args()
38+
no_inline_comments = args.no_inline_comments
3739

3840
edtlib_logger.setup_edtlib_logging()
3941

@@ -136,6 +138,8 @@ def parse_args() -> argparse.Namespace:
136138
help="path to write header to")
137139
parser.add_argument("--edt-pickle",
138140
help="path to read pickled edtlib.EDT object from")
141+
parser.add_argument("--no-inline-comments", action="store_true",
142+
help="remove comments from #define lines")
139143

140144
return parser.parse_args()
141145

@@ -1016,6 +1020,9 @@ def out_define(
10161020

10171021
warn = fr' __WARN("{deprecation_msg}")' if deprecation_msg else ""
10181022

1023+
if no_inline_comments:
1024+
val = re.sub("\\s*/\\*.*?\\*/\\s*", "", str(val))
1025+
10191026
if width:
10201027
s = f"#define {macro.ljust(width)}{warn} {val}"
10211028
else:

0 commit comments

Comments
 (0)