From b0069c5c05dac2c910d51ef7f3bf4133721a9c49 Mon Sep 17 00:00:00 2001 From: Zach White Date: Sun, 7 Mar 2021 19:10:03 -0800 Subject: [PATCH] Begin the process of deprecating bin/qmk in favor of the global cli (#12109) * Begin the process of deprecating bin/qmk in favor of the global cli * Correctly set the qmk bin --- Makefile | 11 +++++++++-- bin/qmk | 2 ++ build_json.mk | 2 +- build_keyboard.mk | 9 ++++++--- lib/python/qmk/commands.py | 1 + lib/python/qmk/tests/test_cli_commands.py | 4 ++-- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 91ab9e4e8ea..de0a2d41530 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,13 @@ $(info QMK Firmware $(QMK_VERSION)) endif endif +# Determine which qmk cli to use +ifeq (, $(shell which qmk)) + QMK_BIN = bin/qmk +else + QMK_BIN = qmk +endif + # avoid 'Entering|Leaving directory' messages MAKEFLAGS += --no-print-directory @@ -501,8 +508,8 @@ endef %: # Check if we have the CMP tool installed cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; - # Ensure that bin/qmk works. - if ! bin/qmk hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi + # Ensure that $(QMK_BIN) works. + if ! $(QMK_BIN) hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi # Check if the submodules are dirty, and display a warning if they are ifndef SKIP_GIT if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi diff --git a/bin/qmk b/bin/qmk index a3c1be328ad..28486026f94 100755 --- a/bin/qmk +++ b/bin/qmk @@ -75,6 +75,8 @@ def main(): os.environ['ORIG_CWD'] = os.getcwd() os.chdir(qmk_dir) + print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr) + # Import the subcommands import qmk.cli # noqa diff --git a/build_json.mk b/build_json.mk index 6e2f9c4c8f2..8822be6a128 100644 --- a/build_json.mk +++ b/build_json.mk @@ -28,4 +28,4 @@ endif # Generate the keymap.c $(KEYBOARD_OUTPUT)/src/keymap.c: $(KEYMAP_JSON) - bin/qmk json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON) + $(QMK_BIN) json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON) diff --git a/build_keyboard.mk b/build_keyboard.mk index 366d1f5d2f9..74046a09474 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -12,6 +12,9 @@ endif include common.mk +# Set the qmk cli to use +QMK_BIN ?= qmk + # Set the filename for the final firmware binary KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD)) TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP) @@ -97,7 +100,7 @@ MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP) MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP) # Pull in rules from info.json -INFO_RULES_MK = $(shell bin/qmk generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk) +INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk) include $(INFO_RULES_MK) # Check for keymap.json first, so we can regenerate keymap.c @@ -294,10 +297,10 @@ endif CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h $(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) - bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h + $(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES) - bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h + $(QMK_BIN) generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 3c6f0d001d9..233d1034b4c 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -180,6 +180,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va f'VERBOSE={verbose}', f'COLOR={color}', 'SILENT=false', + 'QMK_BIN=qmk', ]) return make_command diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 82c42a20e85..bfecebdd78a 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -8,7 +8,7 @@ is_windows = 'windows' in platform.platform().lower() def check_subcommand(command, *args): - cmd = ['bin/qmk', command, *args] + cmd = ['qmk', command, *args] result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) return result @@ -17,7 +17,7 @@ def check_subcommand_stdin(file_to_read, command, *args): """Pipe content of a file to a command and return output. """ with open(file_to_read, encoding='utf-8') as my_file: - cmd = ['bin/qmk', command, *args] + cmd = ['qmk', command, *args] result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True) return result