summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-10-26 13:18:59 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-10-26 13:18:59 +0200
commitd6a19d976b699e0b230b2e6c8fdd11a0c832ae83 (patch)
tree5f098fbf57df782482914a71edc9df291474c355
parentae8eef185bdfe54e12b9a6be142e8c1c7cdbf079 (diff)
kconfig loader: load kconfig from its base directory
this ensures that source statements are handled correctly
-rw-r--r--lib/kconfig.py13
-rw-r--r--lib/loader/kconfig.py6
-rw-r--r--lib/utils.py12
3 files changed, 18 insertions, 13 deletions
diff --git a/lib/kconfig.py b/lib/kconfig.py
index 164630b..a440b81 100644
--- a/lib/kconfig.py
+++ b/lib/kconfig.py
@@ -8,8 +8,7 @@ import re
import shutil
import subprocess
-from contextlib import contextmanager
-
+from .utils import cd
from versuchung.experiment import Experiment
from versuchung.types import String, Bool, Integer
from versuchung.files import File, Directory
@@ -17,16 +16,6 @@ from versuchung.files import File, Directory
logger = logging.getLogger(__name__)
-@contextmanager
-def cd(path):
- old_dir = os.getcwd()
- os.chdir(path)
- try:
- yield
- finally:
- os.chdir(old_dir)
-
-
class AttributeExperiment(Experiment):
outputs = {
"config": File(".config"),
diff --git a/lib/loader/kconfig.py b/lib/loader/kconfig.py
index 631892f..42181c9 100644
--- a/lib/loader/kconfig.py
+++ b/lib/loader/kconfig.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
from .. import kconfiglib
+from dfatool.utils import cd
from frozendict import frozendict
import json
import os
@@ -20,7 +21,10 @@ class KConfigAttributes:
elif os.path.exists(config_path):
failed_experiments.append(config_path)
- kconf = kconfiglib.Kconfig(kconfig_path)
+ kconfig_dir = "/".join(kconfig_path.split("/")[:-1])
+
+ with cd(kconfig_dir):
+ kconf = kconfiglib.Kconfig(kconfig_path)
self.kconf = kconf
self.kconfig_hash = self.file_hash(kconfig_path)
diff --git a/lib/utils.py b/lib/utils.py
index 86829b3..10f0172 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -2,13 +2,25 @@
import json
import numpy as np
+import os
import re
import logging
+from contextlib import contextmanager
from sklearn.metrics import r2_score
logger = logging.getLogger(__name__)
+@contextmanager
+def cd(path):
+ old_dir = os.getcwd()
+ os.chdir(path)
+ try:
+ yield
+ finally:
+ os.chdir(old_dir)
+
+
class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):