From fc2b51194c58140b096b4c953c703b7f3f6f1fbc Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sat, 1 May 2021 02:00:04 +0100 Subject: Allow .h to be optional when going data driven (#12706) * Allow .h to be optional when going data driven * Remove stub files as no longer required * Rename function * Remove include of layouts.h for now * Take advantage of type=keyboard_folder * Take advantage of type=keyboard_folder - kb should still be mandatory --- build_keyboard.mk | 6 +++- keyboards/forever65/forever65.c | 16 --------- keyboards/forever65/forever65.h | 18 ---------- lib/python/qmk/cli/generate/__init__.py | 1 + lib/python/qmk/cli/generate/keyboard_h.py | 60 +++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 35 deletions(-) delete mode 100644 keyboards/forever65/forever65.c delete mode 100644 keyboards/forever65/forever65.h create mode 100755 lib/python/qmk/cli/generate/keyboard_h.py diff --git a/build_keyboard.mk b/build_keyboard.mk index 366d1f5d2f..ec6b026c50 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -205,6 +205,7 @@ endif # # https://docs.qmk.fm/#/feature_layouts?id=tips-for-making-layouts-keyboard-agnostic # +QMK_KEYBOARD_H = $(KEYBOARD_OUTPUT)/src/default_keyboard.h ifneq ("$(wildcard $(KEYBOARD_PATH_1)/$(KEYBOARD_FOLDER_1).h)","") QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_1).h endif @@ -296,10 +297,13 @@ CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts. $(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h +$(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES) + bin/qmk generate-keyboard-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h + $(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES) bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h -generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h +generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h .INTERMEDIATE : generated-files diff --git a/keyboards/forever65/forever65.c b/keyboards/forever65/forever65.c deleted file mode 100644 index 940f3300f1..0000000000 --- a/keyboards/forever65/forever65.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright 2021 zvecr - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "forever65.h" diff --git a/keyboards/forever65/forever65.h b/keyboards/forever65/forever65.h deleted file mode 100644 index 0edfd0b456..0000000000 --- a/keyboards/forever65/forever65.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright 2021 zvecr - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include "quantum.h" \ No newline at end of file diff --git a/lib/python/qmk/cli/generate/__init__.py b/lib/python/qmk/cli/generate/__init__.py index f064649ac7..0efca0022d 100644 --- a/lib/python/qmk/cli/generate/__init__.py +++ b/lib/python/qmk/cli/generate/__init__.py @@ -3,6 +3,7 @@ from . import config_h from . import dfu_header from . import docs from . import info_json +from . import keyboard_h from . import layouts from . import rgb_breathe_table from . import rules_mk diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py new file mode 100755 index 0000000000..5a2b3656ec --- /dev/null +++ b/lib/python/qmk/cli/generate/keyboard_h.py @@ -0,0 +1,60 @@ +"""Used by the make system to generate keyboard.h from info.json. +""" +from milc import cli + +from qmk.decorators import automagic_keyboard, automagic_keymap +from qmk.info import info_json +from qmk.keyboard import keyboard_completer, keyboard_folder +from qmk.path import is_keyboard, normpath + + +def would_populate_layout_h(keyboard): + """Detect if a given keyboard is doing data driven layouts + """ + # Build the info.json file + kb_info_json = info_json(keyboard) + + for layout_name in kb_info_json['layouts']: + if kb_info_json['layouts'][layout_name]['c_macro']: + continue + + if 'matrix' not in kb_info_json['layouts'][layout_name]['layout'][0]: + cli.log.debug('%s/%s: No matrix data!', keyboard, layout_name) + continue + + return True + + return False + + +@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') +@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") +@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.h for.') +@cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True) +@automagic_keyboard +@automagic_keymap +def generate_keyboard_h(cli): + """Generates the keyboard.h file. + """ + has_layout_h = would_populate_layout_h(cli.config.generate_keyboard_h.keyboard) + + # Build the layouts.h file. + keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"'] + + if not has_layout_h: + keyboard_h_lines.append('#pragma error(".h is only optional for data driven keyboards - kb.h == bad times")') + + # Show the results + keyboard_h = '\n'.join(keyboard_h_lines) + '\n' + + if cli.args.output: + cli.args.output.parent.mkdir(parents=True, exist_ok=True) + if cli.args.output.exists(): + cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak')) + cli.args.output.write_text(keyboard_h) + + if not cli.args.quiet: + cli.log.info('Wrote keyboard_h to %s.', cli.args.output) + + else: + print(keyboard_h) -- cgit v1.2.3