summaryrefslogtreecommitdiff
path: root/bin/analyze-kconfig.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2022-04-26 09:31:23 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2022-04-26 09:31:23 +0200
commitab47cdc202d4432dc17b204ceab094f93734401e (patch)
treebd91bc8ed6d34090d88574d9f50736da0f4ff987 /bin/analyze-kconfig.py
parentd29b176cb372405d92a37b7fe68b2b4b01facce8 (diff)
analyze-kconfig: more robust kconfig-webconf export
Diffstat (limited to 'bin/analyze-kconfig.py')
-rwxr-xr-xbin/analyze-kconfig.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py
index 6ec0ca3..a0c04cc 100755
--- a/bin/analyze-kconfig.py
+++ b/bin/analyze-kconfig.py
@@ -8,6 +8,7 @@ Only boolean variables are supported at the moment.
"""
import argparse
+import hashlib
import json
import kconfiglib
import logging
@@ -304,8 +305,22 @@ def main():
dfatool.cli.print_model_size(model)
if args.export_webconf:
- with open("nfpkeys.json", "r") as f:
- nfpkeys = json.load(f)
+ attributes = KConfigAttributes(args.kconfig_path, None)
+ try:
+ with open(f"{attributes.kconfig_root}/nfpkeys.json", "r") as f:
+ nfpkeys = json.load(f)
+ except FileNotFoundError:
+ logging.error(
+ f"{attributes.kconfig_root}/nfpkeys.json is missing, webconf model will be incomplete"
+ )
+ nfpkeys = None
+ kconfig_hasher = hashlib.sha256()
+ with open(args.kconfig_path, "rb") as f:
+ kconfig_data = f.read()
+ while len(kconfig_data) > 0:
+ kconfig_hasher.update(kconfig_data)
+ kconfig_data = f.read()
+ kconfig_hash = str(kconfig_hasher.hexdigest())
complete_json_model = model.to_json(
with_param_name=True, param_names=parameter_names
)
@@ -313,9 +328,18 @@ def main():
for name, attribute_data in complete_json_model["name"].items():
for attribute, data in attribute_data.items():
json_model[attribute] = data.copy()
- json_model[attribute].update(nfpkeys[name][attribute])
+ if nfpkeys:
+ json_model[attribute].update(nfpkeys[name][attribute])
+ out_model = {
+ "model": json_model,
+ "modelType": "dfatool-kconfig",
+ "project": "tbd",
+ "kconfigHash": kconfig_hash,
+ "symbols": attributes.symbol_names,
+ "choices": attributes.choice_names,
+ }
with open(args.export_webconf, "w") as f:
- json.dump(json_model, f, sort_keys=True, cls=dfatool.utils.NpEncoder)
+ json.dump(out_model, f, sort_keys=True, cls=dfatool.utils.NpEncoder)
if args.export_dot:
dfatool.cli.export_dot(model, args.export_dot)