Skip to content

Commit

Permalink
scripts: Use avr-gcc and specify MAKEFILE_KEYBOARD_LAYOUT macro.
Browse files Browse the repository at this point in the history
The avr-gcc cross-compiler should be used as some includes are
specific to the AVR target and fail when using a GCC for the host.
Also, expose any failure when running the GCC command; previously such
errors would only manifest themselves later in a more confusing
fashion (see: benblazak#97).  Finally, the MAKEFILE_KEYBOARD_LAYOUT macro needs
to be specified for the GCC command to succeed.

* build-scripts/gen-ui-info.py
(gen_mappings.parse_layout_file): Use subprocess.check_output.
Replace 'gcc' with 'avr-gcc'.  Specify the MAKEFILE_KEYBOARD_LAYOUT
macro.

Fixes: benblazak#97
  • Loading branch information
Apteryks committed Sep 19, 2023
1 parent 1ef8a1f commit ce1e2c2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build-scripts/gen-ui-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import argparse
import json
import os
import pathlib
import re
import subprocess
import sys
Expand Down Expand Up @@ -260,6 +261,7 @@ def gen_mappings(matrix_file_path, layout_file_path):
# normalize paths
matrix_file_path = os.path.abspath(matrix_file_path)
layout_file_path = os.path.abspath(layout_file_path)
layout_name = pathlib.Path(layout_file_path).with_suffix('').name

def parse_matrix_file(matrix_file_path):
match = re.search( # find the whole 'KB_MATRIX_LAYER' macro
Expand All @@ -275,9 +277,12 @@ def parse_matrix_file(matrix_file_path):
}

def parse_layout_file(layout_file_path):
output = subprocess.check_output(
['avr-gcc', f'-DMAKEFILE_KEYBOARD_LAYOUT={layout_name}',
'-E', layout_file_path], encoding='UTF-8')
match = re.findall( # find each whole '_kb_layout*' matrix definition
r"(_kb_layout\w*)[^=]*=((?:[^{}]*\{){3}[^=]*(?:[^{}]*\}){3})",
subprocess.getoutput("gcc -E '" + layout_file_path + "'"),
output,
)

layout = {}
Expand Down

0 comments on commit ce1e2c2

Please sign in to comment.