keymapviz
keymapviz copied to clipboard
Multi-threaded QMK compilation breaks the script
I have the following code block at the top of my keymap rules.mk
:
# Automatically update the keymap visualization when compiling
.PHONY: %
%:
keymapviz -k dactyl_manuform5x6 -t fancy -r keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c -c keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymapviz.toml > /dev/null
This lets me automatically update the keymap visualizations any time I run qmk compile
or qmk flash
which is awesome. However, this only works if I use a single thread for compiling my keymap. If I use the -j
/--jobs
option of the qmk
CLI with any value above 1, keymapviz often throws an error and thus aborts the entire compilation operation. Although in some rare cases, the script works fine and the compilation is not aborted; clear sign of a race condition.
The error that keymapviz throws is the following:
Making handwired/dactyl_manuform/5x6 with keymap precondition
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
Traceback (most recent call last):
File "/home/vern/.local/bin/keymapviz", line 8, in <module>
sys.exit(main())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 91, in main
output_keymap_c(arg.keymap_c.name, kmvz.keymap_c())
File "/home/vern/.local/lib/python3.8/site-packages/keymapviz/keymapviz.py", line 79, in output_keymap_c
os.rename(output_filename, output_filename + ".bac")
FileNotFoundError: [Errno 2] No such file or directory: 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c' -> 'keyboards/handwired/dactyl_manuform/5x6/keymaps/precondition/keymap.c.bac'
make[1]: *** No rule to make target '.build/obj_handwired_dactyl_manuform_5x6_precondition/quantum/keymap_common.d', needed by '.build/obj_handwired_dactyl_manuform_5x6_precondition/quantum/keymap_common.o'. Stop.
make[1]: *** Waiting for unfinished jobs....
avr-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Make finished with errors
make: *** [Makefile:535: handwired/dactyl_manuform/5x6:precondition] Error 1
Honestly, I'm not sure whether the problem has to be solved within keymapviz itself, within my particular .PHONY
block or within the QMK CLI.
PS: I use keymapviz 1.7.0