Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests on develop #11430

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ define PARSE_KEYMAP
# Specify the variables that we are passing forward to submake
MAKE_VARS := KEYBOARD=$$(CURRENT_KB) KEYMAP=$$(CURRENT_KM) REQUIRE_PLATFORM_KEY=$$(REQUIRE_PLATFORM_KEY)
# And the first part of the make command
MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET)
MAKE_CMD := bin/qmk make -f build_keyboard.mk $$(MAKE_TARGET)
# The message to display
MAKE_MSG := $$(MSG_MAKE_KB)
# We run the command differently, depending on if we want more output or not
Expand Down
6 changes: 0 additions & 6 deletions build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,6 @@ 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

$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h

# project specific files
SRC += $(KEYBOARD_SRC) \
$(KEYMAP_C) \
Expand Down
1 change: 1 addition & 0 deletions lib/python/qmk/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . import lint
from . import list
from . import kle2json
from . import make
from . import new
from . import pyformat
from . import pytest
Expand Down
100 changes: 100 additions & 0 deletions lib/python/qmk/cli/make.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""Generate and run a make command for building a keyboard.
"""
import os
from time import time

from milc import cli

from qmk.info import find_info_json

file_stale_secs = 86400 # How many seconds old generated files are before being regenerated


def is_stale(file_path, *dependencies):
"""Checks to see if a file is stale and should be regenerated.
"""
if not os.path.exists(file_path):
return True

file_mtime = os.stat(file_path).st_mtime

# If the file is more than 24 hours old we consider it stale anyway
if time() - file_mtime > file_stale_secs:
return True

# Iterate through dependencies, if we find one that's newer return True
for dep in dependencies:
dep_mtime = os.stat(dep).st_mtime
if dep_mtime > file_mtime:
return True

return False


@cli.argument('targets', nargs='*', arg_only=True, help='Make targets to run')
@cli.argument('-f', '--makefile', arg_only=True, default='build_keyboard.mk', help="The makefile to use")
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run")
@cli.subcommand('Parse and run a QMK make command', hidden=True)
def make(cli):
"""Run a qmk make command.
"""
# Determine the keyboard
silent = False
keyboard = None
build_dir = '.build'

for target in cli.args.targets:
if target.startswith('KEYBOARD='):
keyboard = target.split('=', 1)[1]

if target.startswith('BUILD_DIR='):
build_dir = target.split('=', 1)[1]

if target == 'SILENT=true':
silent = True

if target == 'SILENT=false':
silent = False

if not keyboard:
cli.log.error('Could not identify a keyboard for this compile!')
return False

keyboard_filesafe = keyboard.replace('/', '_')
keyboard_output = f'{build_dir}/obj_{keyboard_filesafe}'

# Generate the include files
info_json_files = find_info_json(keyboard)
config_h_file = f'{keyboard_output}/src/info_config.h'
layouts_h_file = f'{keyboard_output}/src/layouts.h'

if 'clean' not in cli.args.targets:
config_h_cmd = ['bin/qmk', 'generate-config-h', '--keyboard', keyboard, '--output', config_h_file]
layouts_h_cmd = ['bin/qmk', 'generate-layouts', '--keyboard', keyboard, '--output', layouts_h_file]

if silent:
config_h_cmd.append('-q')
layouts_h_cmd.append('-q')

if is_stale(config_h_file, *info_json_files):
cli.run(config_h_cmd, capture_output=False)

if is_stale(layouts_h_file, *info_json_files):
cli.run(layouts_h_cmd, capture_output=False)

# Call make
jobs = '1'
if '-j' in os.environ.get('MAKEFLAGS', ''):
for word in os.environ['MAKEFLAGS'].split():
if word.startswith('-j'):
jobs = word[2:]
break

shell_env = os.environ.copy()
for key in ('MAKEFLAGS', 'MAKELEVEL', 'MAKE_TERMERR', 'MFLAGS'):
if key in shell_env:
del shell_env[key]

make_cmd = ['make', '-j', jobs, '-r', '-R', '-f', cli.args.makefile, *cli.args.targets]
cli.log.debug('Running: %s', ' '.join(make_cmd))
cli.run(make_cmd, capture_output=False, env=shell_env)
8 changes: 4 additions & 4 deletions tmk_core/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,27 @@ $1_CXXFLAGS = $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $
$1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS)

# Compile: create object files from C source files.
$1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h | $(BEGIN)
$1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN)
@mkdir -p $$(@D)
@$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
$$(eval CMD := $$(CC) -c $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
@$$(BUILD_CMD)

# Compile: create object files from C++ source files.
$1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h | $(BEGIN)
$1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN)
@mkdir -p $$(@D)
@$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD)
$$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
@$$(BUILD_CMD)

$1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h | $(BEGIN)
$1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN)
@mkdir -p $$(@D)
@$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD)
$$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
@$$(BUILD_CMD)

# Assemble: create object files from assembler source files.
$1/%.o : %.S $1/asflags.txt $1/compiler.txt $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h | $(BEGIN)
$1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
@mkdir -p $$(@D)
@$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
$$(eval CMD=$$(CC) -c $$($1_ASFLAGS) $$< -o $$@)
Expand Down