scripts: utils: posix: add dry-run option and improve logging
Add a `--dry-run` (or `-d`) option to the posix kconfig migration script for deprecated POSIX Kconfigs. Additionally, add a set of skipped options (e.g. `TIMER`). The `CONFIG_TIMER` option does not exist in the tree anymore and was way too generically named previously, so the false positive rate is astronomical, so it makes sense to skip it. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
2055f7d595
commit
72bc08578b
1 changed files with 21 additions and 8 deletions
|
@ -6,7 +6,7 @@ version v3.7.0 or later.
|
||||||
|
|
||||||
Usage::
|
Usage::
|
||||||
|
|
||||||
python $ZEPHYR_BASE/scripts/utils/migrate_posix_kconfigs.py -r root_path
|
python $ZEPHYR_BASE/scripts/utils/migrate_posix_kconfigs.py --root root_path --dry-run
|
||||||
|
|
||||||
The utility will process c, cpp, h, hpp, rst, conf, CMakeLists.txt,
|
The utility will process c, cpp, h, hpp, rst, conf, CMakeLists.txt,
|
||||||
yml, yaml and Kconfig files.
|
yml, yaml and Kconfig files.
|
||||||
|
@ -85,6 +85,7 @@ def process_file(path):
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
|
lineno = 1
|
||||||
for line in lines:
|
for line in lines:
|
||||||
longest = ""
|
longest = ""
|
||||||
length = 0
|
length = 0
|
||||||
|
@ -93,17 +94,24 @@ def process_file(path):
|
||||||
length = len(m)
|
length = len(m)
|
||||||
longest = m
|
longest = m
|
||||||
|
|
||||||
|
# TIMER is just way too frequent an occurrence. Skip it.
|
||||||
|
skip = {"TIMER"}
|
||||||
if length != 0:
|
if length != 0:
|
||||||
modified = True
|
if longest in skip:
|
||||||
line = line.replace(longest, REPLACEMENTS[longest])
|
pass
|
||||||
msg = MESSAGES.get(longest)
|
else:
|
||||||
if msg:
|
modified = True
|
||||||
print(
|
old = line
|
||||||
f"Notice: {longest} -> {REPLACEMENTS[longest]}: {msg}")
|
line = line.replace(longest, REPLACEMENTS[longest])
|
||||||
|
msg = MESSAGES.get(longest)
|
||||||
|
if msg:
|
||||||
|
print(f"{path}:{lineno}:old:{old.strip()}")
|
||||||
|
print(f"{path}:{lineno}:new:{line.strip()}")
|
||||||
|
|
||||||
|
lineno += 1
|
||||||
output.append(line)
|
output.append(line)
|
||||||
|
|
||||||
if modified is False:
|
if modified is False or args.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
|
@ -131,6 +139,11 @@ if __name__ == "__main__":
|
||||||
type=Path,
|
type=Path,
|
||||||
required=True,
|
required=True,
|
||||||
help="Zephyr-based project path")
|
help="Zephyr-based project path")
|
||||||
|
parser.add_argument(
|
||||||
|
"-d",
|
||||||
|
"--dry-run",
|
||||||
|
action="store_true",
|
||||||
|
help="log potential changes without modifying files")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
process_tree(args.root)
|
process_tree(args.root)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue