diff options
author | Erovia <erovia@users.noreply.github.com> | 2019-10-14 18:35:12 +0200 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2020-02-15 15:19:03 -0800 |
commit | d257a98cb80a90f116072c882753039b10a5e042 (patch) | |
tree | c6635d64ad97562998e863a8a3c19e3958e54123 /lib/python/qmk/makefile.py | |
parent | f8002828cac83272e5804bf705e20d07ac64e7a0 (diff) | |
download | qmk_firmware-d257a98cb80a90f116072c882753039b10a5e042.tar.gz qmk_firmware-d257a98cb80a90f116072c882753039b10a5e042.zip |
Fix regex for parsing rules.mk files
I don't know why it couldn't put it together before... ¯\_(ツ)_/¯
Diffstat (limited to 'lib/python/qmk/makefile.py')
-rw-r--r-- | lib/python/qmk/makefile.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py index ce64431f9..dc498adc8 100644 --- a/lib/python/qmk/makefile.py +++ b/lib/python/qmk/makefile.py | |||
@@ -16,20 +16,15 @@ def parse_rules_mk(file_path): | |||
16 | Returns: | 16 | Returns: |
17 | a dictionary with the file's content | 17 | a dictionary with the file's content |
18 | """ | 18 | """ |
19 | # regex to match lines with comment at the end | 19 | # regex to match lines uncommented lines and get the data |
20 | # group(1) = option's name | 20 | # group(1) = option's name |
21 | # group(2) = operator (eg.: '=', '+=') | 21 | # group(2) = operator (eg.: '=', '+=') |
22 | # group(3) = value(s) | 22 | # group(3) = value(s) |
23 | commented_regex = re.compile(r"^\s*(\w+)\s*([\:\+\-]?=)\s*(.*?)(?=\s*\#)") | 23 | rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))") |
24 | # regex to match lines without comment at the end | ||
25 | # group(1) = option's name | ||
26 | # group(2) = operator (eg.: '=', '+=') | ||
27 | # group(3) = value(s) | ||
28 | uncommented_regex = re.compile(r"^\s*(\w+)\s*([\:\+\-]?=)\s*(.*?)(?=\s*$)") | ||
29 | mk_content = qmk.path.unicode_lines(file_path) | 24 | mk_content = qmk.path.unicode_lines(file_path) |
30 | parsed_file = dict() | 25 | parsed_file = dict() |
31 | for line in mk_content: | 26 | for line in mk_content: |
32 | found = commented_regex.search(line) if "#" in line else uncommented_regex.search(line) | 27 | found = rules_mk_regex.search(line) |
33 | if found: | 28 | if found: |
34 | parsed_file[found.group(1)] = dict(operator = found.group(2), value = found.group(3)) | 29 | parsed_file[found.group(1)] = dict(operator = found.group(2), value = found.group(3)) |
35 | return parsed_file | 30 | return parsed_file |