qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
18.38k stars 39.59k forks source link

[Bug] FORCE_LAYOUT ignored with qmk command when using external userspace #22815

Open byronclark opened 11 months ago

byronclark commented 11 months ago

Describe the Bug

According to https://github.com/qmk/qmk_firmware/blob/master/docs/feature_layouts.md the FORCE_LAYOUT variable can be used to specify a specific layout for a keyboard and keymap that support more than one layout.

For example:

To this point, everything is working as expected.

But I would like to be able to build with the qmk compile command like I do for my other keyboards that don't have this multiple layout issue. I would expect the following command to work: qmk compile -kb beekeeb/piantor -km manna-harbour_miryoku -e FORCE_LAYOUT=split_3x6_3.

Unfortunately, that command seems to always build the split_3x5_3 layout. Here's what the dry-run output shows:

❯ qmk compile -kb beekeeb/piantor -km manna-harbour_miryoku -e FORCE_LAYOUT=split_3x6_3 -n
Ψ Compiling keymap with gmake -r -R -f builddefs/build_keyboard.mk -s KEYBOARD=beekeeb/piantor KEYMAP=manna-harbour_miryoku KEYBOARD_FILESAFE=beekeeb_piantor TARGET=beekeeb_piantor_manna-harbour_miryoku INTERMEDIATE_OUTPUT=.build/obj_beekeeb_piantor_manna-harbour_miryoku VERBOSE=false COLOR=true SILENT=false QMK_BIN="qmk" FORCE_LAYOUT=split_3x6_3 QMK_USERSPACE=/home/byron/sandbox/current/qmk_userspace MAIN_KEYMAP_PATH_1=/home/byron/sandbox/current/qmk_userspace/layouts/split_3x5_3/manna-harbour_miryoku MAIN_KEYMAP_PATH_2=/home/byron/sandbox/current/qmk_userspace/layouts/split_3x5_3/manna-harbour_miryoku MAIN_KEYMAP_PATH_3=/home/byron/sandbox/current/qmk_userspace/layouts/split_3x5_3/manna-harbour_miryoku MAIN_KEYMAP_PATH_4=/home/byron/sandbox/current/qmk_userspace/layouts/split_3x5_3/manna-harbour_miryoku MAIN_KEYMAP_PATH_5=/home/byron/sandbox/current/qmk_userspace/layouts/split_3x5_3/manna-harbour_miryoku

The MAIN_KEYMAP_PATH_ variables are only set when using external userspace and seem to be overriding the FORCE_LAYOUT setting.

Keyboard Used

beekeeb/piantor

Link to product page (if applicable)

No response

Operating System

Linux

qmk doctor Output

Ψ QMK Doctor is checking your environment.
Ψ CLI version: 1.1.2
Ψ QMK home: /home/byron/sandbox/current/qmk_firmware
Ψ Detected Linux (Fedora Linux 39 (Workstation Edition)).
⚠ Missing or outdated udev rules for 'atmel-dfu' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'kiibohd' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'stm32-dfu' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'apm32-dfu' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'gd32v-dfu' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'wb32-dfu' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'bootloadhid' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'usbasploader' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'usbtinyisp' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'md-boot' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.
⚠ Missing or outdated udev rules for 'caterina' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
⚠ Missing or outdated udev rules for 'hid-bootloader' boards. Run 'sudo cp /home/byron/sandbox/current/qmk_firmware/util/udev/50-qmk.rules /etc/udev/rules.d/'.
Ψ Testing userspace candidate: /home/byron/sandbox/current/qmk_userspace -- Valid `qmk.json`
Ψ QMK userspace: /home/byron/sandbox/current/qmk_userspace
Ψ Userspace enabled: True
Ψ Git branch: user/byronclark
Ψ Repo version: 0.23.2
Ψ - Latest user/byronclark: 2023-12-21 09:32:19 +1100 (2661ee282a) -- [Bugfix] Manipulate deferred executor slot only if tokens match (#22722)
Ψ - Latest upstream/master: 2023-12-29 17:17:20 +0100 (fc20e0b014) -- Waffling60 iso rev e (#22733)
Ψ - Latest upstream/develop: 2023-12-29 16:17:49 +0000 (a081fc7301) -- Merge remote-tracking branch 'origin/master' into develop
Ψ - Common ancestor with upstream/master: 2023-12-21 09:32:19 +1100 (2661ee282a) -- [Bugfix] Manipulate deferred executor slot only if tokens match (#22722)
Ψ - Common ancestor with upstream/develop: 2023-12-21 09:32:19 +1100 (2661ee282a) -- [Bugfix] Manipulate deferred executor slot only if tokens match (#22722)
Ψ CLI installed in virtualenv.
☒ Can't find dfu-programmer in your path.
Would you like to install dependencies? [Y/n] n
Ψ Found arm-none-eabi-gcc version 13.1.0
Ψ Found avr-gcc version 13.1.0
⚠ We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.
Ψ Found avrdude version 6.4
⚠ Unknown version for dfu-programmer
Ψ Found dfu-util version 0.11
Ψ Submodules are up to date.
Ψ Submodule status:
Ψ - lib/chibios: 2023-04-15 13:48:04 +0000 --  (11edb1610)
Ψ - lib/chibios-contrib: 2023-07-17 11:39:05 +0200 --  (da78eb37)
Ψ - lib/googletest: 2021-06-11 06:37:43 -0700 --  (e2239ee6)
Ψ - lib/lufa: 2022-08-26 12:09:55 +1000 --  (549b97320)
Ψ - lib/vusb: 2022-06-13 09:18:17 +1000 --  (819dbc1)
Ψ - lib/printf: 2022-06-29 23:59:58 +0300 --  (c2e3b4e)
Ψ - lib/pico-sdk: 2023-02-12 20:19:37 +0100 --  (a3398d8)
Ψ - lib/lvgl: 2022-04-11 04:44:53 -0600 --  (e19410f8)
Ψ Major problems detected, please fix these problems before proceeding.
Ψ Check out the FAQ (https://docs.qmk.fm/#/faq_build) or join the QMK Discord (https://discord.gg/Uq7gcHh) for help.

Is AutoHotKey / Karabiner installed

Other keyboard-related software installed

No response

Additional Context

No response

zvecr commented 11 months ago

Due to some of the various ways the CLI processes layouts, and the multiple entrypoints it passes through, there is a somewhat inconsistent problem to unpick.

However a somewhat gross implementation of a fix, that will work in most (all?) scenarios:

diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index d95ff5f923..e59b49ae6d 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -81,6 +81,10 @@ def build_environment(args):
     if HAS_QMK_USERSPACE:
         envs['QMK_USERSPACE'] = Path(QMK_USERSPACE).resolve()

+    # Handle FORCE_LAYOUT
+    if envs.get('FORCE_LAYOUT'):
+        os.environ['FORCE_LAYOUT'] = envs['FORCE_LAYOUT']
+
     return envs

diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 5500ecdd19..acc9ad701f 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -192,6 +192,12 @@ def info_json(keyboard):
     # Merge in data from <keyboard.c>
     info_data = _extract_led_config(info_data, str(keyboard))

+    from os import environ
+    force_community = environ.get('FORCE_LAYOUT')
+    community_layouts = info_data.get("community_layouts", [])
+    if force_community in community_layouts:
+        info_data["community_layouts"] = [force_community]
+
     # Validate
     _validate(keyboard, info_data)

(Avoids chaining state everywhere by using environment to consistently stash the FORCE_LAYOUT value)