summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-05-27 16:43:10 +0000
committerQMK Bot <hello@qmk.fm>2021-05-27 16:43:10 +0000
commitc1a3060431cd8bf96ed182680c46f1e0d3314ab0 (patch)
treef4b32975305881d5dafdab198cba59faff4d88be
parentb769b362027faa10cf5b920be709cf69587a4c97 (diff)
parent84883d340045c50ce6c200c9087461c1db853898 (diff)
Merge remote-tracking branch 'origin/master' into develop
-rw-r--r--lib/python/qmk/cli/c2json.py9
-rw-r--r--lib/python/qmk/errors.py7
-rw-r--r--lib/python/qmk/keymap.py6
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/python/qmk/cli/c2json.py b/lib/python/qmk/cli/c2json.py
index e66b0a1b58..43110a9387 100644
--- a/lib/python/qmk/cli/c2json.py
+++ b/lib/python/qmk/cli/c2json.py
@@ -9,6 +9,7 @@ import qmk.keymap
import qmk.path
from qmk.json_encoders import InfoJSONEncoder
from qmk.keyboard import keyboard_completer, keyboard_folder
+from qmk.errors import CppError
@cli.argument('--no-cpp', arg_only=True, action='store_false', help='Do not use \'cpp\' on keymap.c')
@@ -37,7 +38,13 @@ def c2json(cli):
cli.args.output = None
# Parse the keymap.c
- keymap_json = qmk.keymap.c2json(cli.args.keyboard, cli.args.keymap, cli.args.filename, use_cpp=cli.args.no_cpp)
+ try:
+ keymap_json = qmk.keymap.c2json(cli.args.keyboard, cli.args.keymap, cli.args.filename, use_cpp=cli.args.no_cpp)
+ except CppError as e:
+ if cli.config.general.verbose:
+ cli.log.debug('The C pre-processor ran into a fatal error: %s', e)
+ cli.log.error('Something went wrong. Try to use --no-cpp.\nUse the CLI in verbose mode to find out more.')
+ return False
# Generate the keymap.json
try:
diff --git a/lib/python/qmk/errors.py b/lib/python/qmk/errors.py
index 4a8a91556b..1317687821 100644
--- a/lib/python/qmk/errors.py
+++ b/lib/python/qmk/errors.py
@@ -3,3 +3,10 @@ class NoSuchKeyboardError(Exception):
"""
def __init__(self, message):
self.message = message
+
+
+class CppError(Exception):
+ """Raised when 'cpp' cannot process a file.
+ """
+ def __init__(self, message):
+ self.message = message
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py
index ac7951082e..2d5921e7a8 100644
--- a/lib/python/qmk/keymap.py
+++ b/lib/python/qmk/keymap.py
@@ -13,6 +13,7 @@ from pygments import lex
import qmk.path
from qmk.keyboard import find_keyboard_from_dir, rules_mk
+from qmk.errors import CppError
# The `keymap.c` template to use when a keyboard doesn't have its own
DEFAULT_KEYMAP_C = """#include QMK_KEYBOARD_H
@@ -372,7 +373,10 @@ def _c_preprocess(path, stdin=DEVNULL):
"""
cmd = ['cpp', str(path)] if path else ['cpp']
pre_processed_keymap = cli.run(cmd, stdin=stdin)
-
+ if 'fatal error' in pre_processed_keymap.stderr:
+ for line in pre_processed_keymap.stderr.split('\n'):
+ if 'fatal error' in line:
+ raise (CppError(line))
return pre_processed_keymap.stdout