Enable 'keyboard.json' as a build target (#22891)
This commit is contained in:
		
							parent
							
								
									c5225ab500
								
							
						
					
					
						commit
						9f4a9d5826
					
				
					 12 changed files with 53 additions and 45 deletions
				
			
		| 
						 | 
				
			
			@ -18,10 +18,11 @@ from qmk.path import normpath, FileType
 | 
			
		|||
@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
 | 
			
		||||
@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
 | 
			
		||||
def generate_make_dependencies(cli):
 | 
			
		||||
    """Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard.
 | 
			
		||||
    """Generates the list of dependent config files for a keyboard.
 | 
			
		||||
    """
 | 
			
		||||
    interesting_files = [
 | 
			
		||||
        'info.json',
 | 
			
		||||
        'keyboard.json',
 | 
			
		||||
        'rules.mk',
 | 
			
		||||
        'post_rules.mk',
 | 
			
		||||
        'config.h',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -251,7 +251,7 @@ def new_keyboard(cli):
 | 
			
		|||
 | 
			
		||||
    # merge in infos
 | 
			
		||||
    community_info = Path(COMMUNITY / f'{default_layout}/info.json')
 | 
			
		||||
    augment_community_info(community_info, keyboard(kb_name) / community_info.name)
 | 
			
		||||
    augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
 | 
			
		||||
 | 
			
		||||
    cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
 | 
			
		||||
    cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -863,7 +863,17 @@ def unknown_processor_rules(info_data, rules):
 | 
			
		|||
def merge_info_jsons(keyboard, info_data):
 | 
			
		||||
    """Return a merged copy of all the info.json files for a keyboard.
 | 
			
		||||
    """
 | 
			
		||||
    for info_file in find_info_json(keyboard):
 | 
			
		||||
    config_files = find_info_json(keyboard)
 | 
			
		||||
 | 
			
		||||
    # keyboard.json can only exist at the deepest part of the tree
 | 
			
		||||
    keyboard_json_count = 0
 | 
			
		||||
    for index, info_file in enumerate(config_files):
 | 
			
		||||
        if Path(info_file).name == 'keyboard.json':
 | 
			
		||||
            keyboard_json_count += 1
 | 
			
		||||
            if index != 0 or keyboard_json_count > 1:
 | 
			
		||||
                _log_error(info_data, f'Invalid keyboard.json location detected: {info_file}.')
 | 
			
		||||
 | 
			
		||||
    for info_file in config_files:
 | 
			
		||||
        # Load and validate the JSON data
 | 
			
		||||
        new_info_data = json_load(info_file)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -921,7 +931,7 @@ def find_info_json(keyboard):
 | 
			
		|||
    base_path = Path('keyboards')
 | 
			
		||||
    keyboard_path = base_path / keyboard
 | 
			
		||||
    keyboard_parent = keyboard_path.parent
 | 
			
		||||
    info_jsons = [keyboard_path / 'info.json']
 | 
			
		||||
    info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']
 | 
			
		||||
 | 
			
		||||
    # Add DEFAULT_FOLDER before parents, if present
 | 
			
		||||
    rules = rules_mk(keyboard)
 | 
			
		||||
| 
						 | 
				
			
			@ -933,6 +943,7 @@ def find_info_json(keyboard):
 | 
			
		|||
        if keyboard_parent == base_path:
 | 
			
		||||
            break
 | 
			
		||||
        info_jsons.append(keyboard_parent / 'info.json')
 | 
			
		||||
        info_jsons.append(keyboard_parent / 'keyboard.json')
 | 
			
		||||
        keyboard_parent = keyboard_parent.parent
 | 
			
		||||
 | 
			
		||||
    # Return a list of the info.json files that actually exist
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -166,9 +166,9 @@ def keyboard_folder_or_all(keyboard):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def _find_name(path):
 | 
			
		||||
    """Determine the keyboard name by stripping off the base_path and rules.mk.
 | 
			
		||||
    """Determine the keyboard name by stripping off the base_path and filename.
 | 
			
		||||
    """
 | 
			
		||||
    return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "")
 | 
			
		||||
    return path.replace(base_path, "").rsplit(os.path.sep, 1)[0]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def keyboard_completer(prefix, action, parser, parsed_args):
 | 
			
		||||
| 
						 | 
				
			
			@ -181,8 +181,10 @@ def list_keyboards(resolve_defaults=True):
 | 
			
		|||
    """Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
 | 
			
		||||
    """
 | 
			
		||||
    # We avoid pathlib here because this is performance critical code.
 | 
			
		||||
    kb_wildcard = os.path.join(base_path, "**", "rules.mk")
 | 
			
		||||
    paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
 | 
			
		||||
    paths = []
 | 
			
		||||
    for marker in ['rules.mk', 'keyboard.json']:
 | 
			
		||||
        kb_wildcard = os.path.join(base_path, "**", marker)
 | 
			
		||||
        paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
 | 
			
		||||
 | 
			
		||||
    found = map(_find_name, paths)
 | 
			
		||||
    if resolve_defaults:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,9 @@ def is_keyboard(keyboard_name):
 | 
			
		|||
    if keyboard_name:
 | 
			
		||||
        keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
 | 
			
		||||
        rules_mk = keyboard_path / 'rules.mk'
 | 
			
		||||
        keyboard_json = keyboard_path / 'keyboard.json'
 | 
			
		||||
 | 
			
		||||
        return rules_mk.exists()
 | 
			
		||||
        return rules_mk.exists() or keyboard_json.exists()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue