summaryrefslogtreecommitdiff
path: root/lib/kconfig.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-10-26 08:08:35 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-10-26 08:08:35 +0200
commitae8eef185bdfe54e12b9a6be142e8c1c7cdbf079 (patch)
treeaf8f5efc3524c573943b913aa69f084b023df3b1 /lib/kconfig.py
parentba5449d4e79689e88948655c154bc1e2cdceb05e (diff)
kconfig: enter project directory before loading kconfig
Otherwise, "source" statements will break
Diffstat (limited to 'lib/kconfig.py')
-rw-r--r--lib/kconfig.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/kconfig.py b/lib/kconfig.py
index 8481c13..164630b 100644
--- a/lib/kconfig.py
+++ b/lib/kconfig.py
@@ -8,6 +8,8 @@ import re
import shutil
import subprocess
+from contextlib import contextmanager
+
from versuchung.experiment import Experiment
from versuchung.types import String, Bool, Integer
from versuchung.files import File, Directory
@@ -15,6 +17,16 @@ 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"),
@@ -230,7 +242,8 @@ class KConfig:
from dd.autoref import BDD
kconfig_file = f"{self.cwd}/{self.kconfig}"
kconfig_hash = self.file_hash(kconfig_file)
- kconf = kconfiglib.Kconfig(kconfig_file)
+ with cd(self.cwd):
+ kconf = kconfiglib.Kconfig(kconfig_file)
pre_variables = list()
pre_expressions = list()
for choice in kconf.choices:
@@ -350,7 +363,8 @@ class KConfig:
print(f"CONFIG_{k}=y", file=f)
else:
print(f"# CONFIG_{k} is not set", file=f)
- kconf = kconfiglib.Kconfig(kconfig_file)
+ with cd(self.cwd):
+ kconf = kconfiglib.Kconfig(kconfig_file)
kconf.load_config(config_file)
int_values = list()
@@ -385,7 +399,8 @@ class KConfig:
def run_exploration_from_file(self, config_file, with_initial_config=True):
kconfig_file = f"{self.cwd}/{self.kconfig}"
kconfig_hash = self.file_hash(kconfig_file)
- kconf = kconfiglib.Kconfig(kconfig_file)
+ with cd(self.cwd):
+ kconf = kconfiglib.Kconfig(kconfig_file)
kconf.load_config(config_file)
if with_initial_config: