Merge pull request #13916 from leandrolanzieri/pr/kconfiglib/parse_help
tools/kconfiglib: Add riot_kconfig to override default behaviours
This commit is contained in:
commit
e57b132a84
53
dist/tools/kconfiglib/riot_kconfig.py
vendored
Normal file
53
dist/tools/kconfiglib/riot_kconfig.py
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
""" RIOT customization of Kconfig """
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from kconfiglib import Kconfig, KconfigError
|
||||||
|
|
||||||
|
|
||||||
|
class RiotKconfig(Kconfig):
|
||||||
|
""" RIOT adaption of Kconfig class """
|
||||||
|
def _parse_help(self, node):
|
||||||
|
""" Parses the help section of a node, removing Doxygen markers """
|
||||||
|
doxygen_markers = ["@ref ", "@see "]
|
||||||
|
|
||||||
|
# call default parsing
|
||||||
|
super(RiotKconfig, self)._parse_help(node)
|
||||||
|
|
||||||
|
# remove Doxygen markers
|
||||||
|
for marker in doxygen_markers:
|
||||||
|
node.help = node.help.replace(marker, "")
|
||||||
|
|
||||||
|
|
||||||
|
def standard_riot_kconfig(description=None):
|
||||||
|
"""
|
||||||
|
Argument parsing helper for tools that take a single optional Kconfig file
|
||||||
|
argument (default: Kconfig). Returns the RiotKconfig instance for the parsed
|
||||||
|
configuration. Uses argparse internally.
|
||||||
|
|
||||||
|
Exits with sys.exit() (which raises SystemExit) on errors.
|
||||||
|
|
||||||
|
description (default: None):
|
||||||
|
The 'description' passed to argparse.ArgumentParser().
|
||||||
|
argparse.RawDescriptionHelpFormatter is used, so formatting is preserved.
|
||||||
|
"""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description=description)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"kconfig",
|
||||||
|
metavar="KCONFIG",
|
||||||
|
default="Kconfig",
|
||||||
|
nargs="?",
|
||||||
|
help="Kconfig file (default: Kconfig)")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Suppress backtraces for expected exceptions
|
||||||
|
try:
|
||||||
|
return RiotKconfig(args.kconfig)
|
||||||
|
except (EnvironmentError, KconfigError) as e:
|
||||||
|
# Some long exception messages have extra newlines for better
|
||||||
|
# formatting when reported as an unhandled exception. Strip them here.
|
||||||
|
sys.exit(str(e).strip())
|
||||||
10
dist/tools/kconfiglib/riot_menuconfig.py
vendored
Executable file
10
dist/tools/kconfiglib/riot_menuconfig.py
vendored
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
""" Menuconfig variant which uses RiotKconfig as base class """
|
||||||
|
import menuconfig
|
||||||
|
from riot_kconfig import standard_riot_kconfig
|
||||||
|
|
||||||
|
# keep documentation from the original tool
|
||||||
|
__doc__ = menuconfig.__doc__
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menuconfig.menuconfig(standard_riot_kconfig(__doc__))
|
||||||
@ -1,13 +1,14 @@
|
|||||||
# Define tools to use
|
# Define tools to use
|
||||||
MENUCONFIG ?= $(RIOTTOOLS)/kconfiglib/menuconfig.py
|
MENUCONFIG ?= $(RIOTTOOLS)/kconfiglib/riot_menuconfig.py
|
||||||
|
BASE_MENUCONFIG ?= $(RIOTTOOLS)/kconfiglib/menuconfig.py
|
||||||
GENCONFIG ?= $(RIOTTOOLS)/kconfiglib/genconfig.py
|
GENCONFIG ?= $(RIOTTOOLS)/kconfiglib/genconfig.py
|
||||||
MERGECONFIG ?= $(RIOTTOOLS)/kconfiglib/merge_config.py
|
MERGECONFIG ?= $(RIOTTOOLS)/kconfiglib/merge_config.py
|
||||||
|
|
||||||
$(MENUCONFIG):
|
$(BASE_MENUCONFIG):
|
||||||
@echo "[INFO] Kconfiglib not found - getting it"
|
@echo "[INFO] Kconfiglib not found - getting it"
|
||||||
@make -C $(RIOTTOOLS)/kconfiglib
|
@make -C $(RIOTTOOLS)/kconfiglib
|
||||||
@echo "[INFO] Kconfiglib downloaded"
|
@echo "[INFO] Kconfiglib downloaded"
|
||||||
|
|
||||||
$(GENCONFIG): $(MENUCONFIG)
|
$(GENCONFIG): $(BASE_MENUCONFIG)
|
||||||
|
|
||||||
$(MERGECONFIG): $(MENUCONFIG)
|
$(MERGECONFIG): $(BASE_MENUCONFIG)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user