diff options
Diffstat (limited to 'lib/python/qmk')
-rw-r--r-- | lib/python/qmk/build_targets.py | 22 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/check.py | 26 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/make_dependencies.py | 4 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/cli/lint.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/commands.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 24 |
7 files changed, 58 insertions, 29 deletions
diff --git a/lib/python/qmk/build_targets.py b/lib/python/qmk/build_targets.py index e2df029490..df5a5ffb42 100644 --- a/lib/python/qmk/build_targets.py +++ b/lib/python/qmk/build_targets.py @@ -11,7 +11,7 @@ from qmk.commands import find_make, get_make_parallel_args, parse_configurator_j from qmk.keyboard import keyboard_folder from qmk.info import keymap_json from qmk.keymap import locate_keymap -from qmk.path import is_under_qmk_firmware, is_under_qmk_userspace +from qmk.path import is_under_qmk_firmware, is_under_qmk_userspace, unix_style_path # These must be kept in the order in which they're applied to $(TARGET) in the makefiles in order to ensure consistency. TARGET_FILENAME_MODIFIERS = ['FORCE_LAYOUT', 'CONVERT_TO'] @@ -204,11 +204,11 @@ class KeyboardKeymapBuildTarget(BuildTarget): if is_under_qmk_userspace(keymap_location) and not is_under_qmk_firmware(keymap_location): keymap_directory = keymap_location.parent compile_args.extend([ - f'MAIN_KEYMAP_PATH_1={keymap_directory}', - f'MAIN_KEYMAP_PATH_2={keymap_directory}', - f'MAIN_KEYMAP_PATH_3={keymap_directory}', - f'MAIN_KEYMAP_PATH_4={keymap_directory}', - f'MAIN_KEYMAP_PATH_5={keymap_directory}', + f'MAIN_KEYMAP_PATH_1={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_2={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_3={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_4={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_5={unix_style_path(keymap_directory)}', ]) return compile_args @@ -267,11 +267,11 @@ class JsonKeymapBuildTarget(BuildTarget): generated_files_path = intermediate_output / 'src' keymap_json = generated_files_path / 'keymap.json' compile_args.extend([ - f'MAIN_KEYMAP_PATH_1={intermediate_output}', - f'MAIN_KEYMAP_PATH_2={intermediate_output}', - f'MAIN_KEYMAP_PATH_3={intermediate_output}', - f'MAIN_KEYMAP_PATH_4={intermediate_output}', - f'MAIN_KEYMAP_PATH_5={intermediate_output}', + f'MAIN_KEYMAP_PATH_1={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_2={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_3={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_4={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_5={unix_style_path(intermediate_output)}', f'KEYMAP_JSON={keymap_json}', f'KEYMAP_PATH={generated_files_path}', ]) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 2804a1d7df..51b0f0c80a 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -54,10 +54,13 @@ def _check_arm_gcc_installation(): """Returns OK if the arm-none-eabi-gcc is fully installed and can produce binaries. """ with TemporaryDirectory() as temp_dir: - temp_file = Path(temp_dir) / 'test.elf' + temp_in = Path(temp_dir) / 'test.c' + temp_out = Path(temp_dir) / 'test.elf' - args = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-mthumb', '-mno-thumb-interwork', '--specs=nosys.specs', '--specs=nano.specs', '-x', 'c', '-o', str(temp_file), '-'] - result = cli.run(args, stdin=None, stdout=None, stderr=None, input='#include <newlib.h>\nint main() { return __NEWLIB__ * __NEWLIB_MINOR__ * __NEWLIB_PATCHLEVEL__; }') + temp_in.write_text('#include <newlib.h>\nint main() { return __NEWLIB__ * __NEWLIB_MINOR__ * __NEWLIB_PATCHLEVEL__; }', encoding='utf-8') + + args = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-mthumb', '-mno-thumb-interwork', '--specs=nosys.specs', '--specs=nano.specs', '-x', 'c', '-o', str(temp_out), str(temp_in)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully compiled using arm-none-eabi-gcc') else: @@ -65,8 +68,8 @@ def _check_arm_gcc_installation(): cli.log.error(f'Command: {" ".join(args)}') return CheckStatus.ERROR - args = ['arm-none-eabi-size', str(temp_file)] - result = cli.run(args, stdin=None, stdout=None, stderr=None) + args = ['arm-none-eabi-size', str(temp_out)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully tested arm-none-eabi-binutils using arm-none-eabi-size') else: @@ -91,10 +94,13 @@ def _check_avr_gcc_installation(): """Returns OK if the avr-gcc is fully installed and can produce binaries. """ with TemporaryDirectory() as temp_dir: - temp_file = Path(temp_dir) / 'test.elf' + temp_in = Path(temp_dir) / 'test.c' + temp_out = Path(temp_dir) / 'test.elf' + + temp_in.write_text('int main() { return 0; }', encoding='utf-8') - args = ['avr-gcc', '-mmcu=atmega32u4', '-x', 'c', '-o', str(temp_file), '-'] - result = cli.run(args, stdin=None, stdout=None, stderr=None, input='int main() { return 0; }') + args = ['avr-gcc', '-mmcu=atmega32u4', '-x', 'c', '-o', str(temp_out), str(temp_in)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully compiled using avr-gcc') else: @@ -102,8 +108,8 @@ def _check_avr_gcc_installation(): cli.log.error(f'Command: {" ".join(args)}') return CheckStatus.ERROR - args = ['avr-size', str(temp_file)] - result = cli.run(args, stdin=None, stdout=None, stderr=None) + args = ['avr-size', str(temp_out)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully tested avr-binutils using avr-size') else: diff --git a/lib/python/qmk/cli/generate/make_dependencies.py b/lib/python/qmk/cli/generate/make_dependencies.py index 331132a20f..9548187888 100755 --- a/lib/python/qmk/cli/generate/make_dependencies.py +++ b/lib/python/qmk/cli/generate/make_dependencies.py @@ -8,7 +8,7 @@ from argcomplete.completers import FilesCompleter from qmk.commands import dump_lines from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.keymap import keymap_completer, locate_keymap -from qmk.path import normpath, FileType +from qmk.path import normpath, FileType, unix_style_path @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON.') @@ -53,4 +53,4 @@ def generate_make_dependencies(cli): for file in interesting_files: check_files.append(Path('users') / cli.args.keymap / file) - dump_lines(cli.args.output, [f'generated-files: $(wildcard {found})\n' for found in check_files]) + dump_lines(cli.args.output, [f'generated-files: $(wildcard {unix_style_path(found)})\n' for found in check_files]) diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index cae9b07c3e..ef4101d77f 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -10,7 +10,7 @@ from qmk.info import info_json, get_modules from qmk.json_schema import json_load from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.commands import dump_lines, parse_configurator_json -from qmk.path import normpath, FileType +from qmk.path import normpath, unix_style_path, FileType from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE from qmk.community_modules import find_module_path, load_module_jsons @@ -63,7 +63,7 @@ def generate_modules_rules(keyboard, filename): lines.append('') lines.append('OPT_DEFS += -DCOMMUNITY_MODULES_ENABLE=TRUE') for module in modules: - module_path = find_module_path(module) + module_path = unix_style_path(find_module_path(module)) if not module_path: raise FileNotFoundError(f"Module '{module}' not found.") lines.append('') diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py index c09e377ad6..bcf905f579 100644 --- a/lib/python/qmk/cli/lint.py +++ b/lib/python/qmk/cli/lint.py @@ -317,10 +317,10 @@ def lint(cli): if isinstance(cli.config.lint.keyboard, str): # if provided via config - string not array keyboard_list = [cli.config.lint.keyboard] - elif is_all_keyboards(cli.args.keyboard[0]): + elif any(is_all_keyboards(kb) for kb in cli.args.keyboard): keyboard_list = list_keyboards() else: - keyboard_list = cli.config.lint.keyboard + keyboard_list = list(set(cli.config.lint.keyboard)) failed = [] diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 0e1876ca7a..ac1455967d 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -12,6 +12,7 @@ from qmk.constants import QMK_USERSPACE, HAS_QMK_USERSPACE from qmk.json_schema import json_load, validate from qmk.keyboard import keyboard_alias_definitions from qmk.util import maybe_exit +from qmk.path import unix_style_path def find_make(): @@ -85,7 +86,7 @@ def build_environment(args): envs = parse_env_vars(args) if HAS_QMK_USERSPACE: - envs['QMK_USERSPACE'] = Path(QMK_USERSPACE).resolve() + envs['QMK_USERSPACE'] = unix_style_path(Path(QMK_USERSPACE).resolve()) return envs diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 61daad585f..c47ed18362 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -3,7 +3,7 @@ import logging import os import argparse -from pathlib import Path +from pathlib import Path, PureWindowsPath, PurePosixPath from qmk.constants import MAX_KEYBOARD_SUBFOLDERS, QMK_FIRMWARE, QMK_USERSPACE, HAS_QMK_USERSPACE from qmk.errors import NoSuchKeyboardError @@ -146,6 +146,28 @@ def normpath(path): return Path(os.environ['ORIG_CWD']) / path +def unix_style_path(path): + """Converts a Windows-style path with drive letter to a Unix path. + + Path().as_posix() normally returns the path with drive letter and forward slashes, so is inappropriate for `Makefile` paths. + + Passes through unadulterated if the path is not a Windows-style path. + + Args: + + path + The path to convert. + + Returns: + The input path converted to Unix format. + """ + if isinstance(path, PureWindowsPath): + p = list(path.parts) + p[0] = f'/{p[0][0].lower()}' # convert from `X:/` to `/x` + path = PurePosixPath(*p) + return path + + class FileType(argparse.FileType): def __init__(self, *args, **kwargs): # Use UTF8 by default for stdin |