Skip to content

Commit cabb7d6

Browse files
de-nordiccarlescufi
authored andcommitted
scripts: runners: Copy load_dot_config to BuildConfiguration.get()
The body of load_dot_config method has been reimplemented in BuildConfiguration.get(), replacing the previous code. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 185d695 commit cabb7d6

File tree

1 file changed

+26
-16
lines changed
  • scripts/west_commands/runners

1 file changed

+26
-16
lines changed

scripts/west_commands/runners/core.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import shutil
2222
import signal
2323
import subprocess
24+
import re
2425
from typing import Dict, List, NamedTuple, NoReturn, Optional, Set, Type, \
2526
Union
2627

@@ -144,23 +145,32 @@ def _init(self):
144145
self._parse(self.path)
145146

146147
def _parse(self, filename: str):
147-
with open(filename, 'r') as f:
148-
for line in f:
149-
line = line.strip()
150-
if not line or line.startswith('#'):
151-
continue
152-
option, value = line.split('=', 1)
153-
self.options[option] = self._parse_value(value)
154-
155-
@staticmethod
156-
def _parse_value(value):
157-
if value.startswith('"') or value.startswith("'"):
158-
return value.split()
159-
try:
160-
return int(value, 0)
161-
except ValueError:
162-
return value
148+
opt_value = re.compile('^(?P<option>CONFIG_[A-Za-z0-9_]+)=(?P<value>.*)$')
149+
not_set = re.compile('^# (?P<option>CONFIG_[A-Za-z0-9_]+) is not set$')
163150

151+
with open(filename, 'r') as f:
152+
lines = f.readlines()
153+
154+
for line in lines:
155+
match = opt_value.match(line)
156+
if match:
157+
value = match.group('value').rstrip()
158+
if value.startswith('"') and value.endswith('"'):
159+
value = value[1:-1]
160+
else:
161+
try:
162+
base = 16 if value.startswith('0x') else 10
163+
self.options[match.group('option')] = int(value, base=base)
164+
continue
165+
except ValueError:
166+
pass
167+
168+
self.options[match.group('option')] = value
169+
continue
170+
171+
match = not_set.match(line)
172+
if match:
173+
self.options[match.group('option')] = 'n'
164174

165175
class MissingProgram(FileNotFoundError):
166176
'''FileNotFoundError subclass for missing program dependencies.

0 commit comments

Comments
 (0)