shuriken: Add lint command

This commit is contained in:
Lexi / Zoe 2026-05-11 01:41:25 +02:00
parent 7b8aac69fb
commit d256de19c5
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232

View file

@ -3,7 +3,7 @@
############################################
# shuriken - A ninja-based C++ build tool
# ------------------------------------------
# Version: 0.1.0
# Version: 0.1.0 (modified)
# Author: binaryDiv
# License: MIT License
# https://git.0xbd.space/binaryDiv/shuriken
@ -186,8 +186,8 @@ class ShurikenArgumentParser:
help='Print generated Ninja file to stdout instead of writing to a file',
)
subparser_build = subparsers.add_parser('build', help='Build project (default command)')
subparser_compdb = subparsers.add_parser('compdb', help='Generate compilation database')
_subparser_build = subparsers.add_parser('build', help='Build project (default command)')
_subparser_compdb = subparsers.add_parser('compdb', help='Generate compilation database')
subparser_run = subparsers.add_parser('run', help='Build and run project')
subparser_run.add_argument(
@ -196,6 +196,13 @@ class ShurikenArgumentParser:
help='Arguments that are passed to the application',
)
subparser_lint = subparsers.add_parser('lint', help='Lint the project')
subparser_lint.add_argument(
'lint_files',
nargs='*',
help='Files to lint (defaults to all source files)',
)
subparser_clean = subparsers.add_parser('clean', help='Remove all build files of the current target')
subparser_clean.add_argument(
'--all',
@ -204,11 +211,11 @@ class ShurikenArgumentParser:
help='Remove all generated files from all targets',
)
subparser_dump_config = subparsers.add_parser(
_subparser_dump_config = subparsers.add_parser(
'dump-config',
help='Dumps the parsed config as well as the effective build target config (for debugging)',
)
subparser_dyndep = subparsers.add_parser(
_subparser_dyndep = subparsers.add_parser(
'p1689-to-dyndeps',
help='(Internal command) Parse p1689 file and generate Ninja dyndeps',
)
@ -298,6 +305,9 @@ class ShurikenCli:
case 'run':
self.run_project(selected_target)
case 'lint':
self.lint_project(selected_target)
case 'clean':
if self.args.clean_all:
self.log_info('Cleaning up *all* build targets')
@ -413,6 +423,26 @@ class ShurikenCli:
except KeyboardInterrupt:
self.log_info('Keyboard interrupt')
def lint_project(self, target: str) -> None:
# Build project using Ninja (necessary before linting)
self.build_project(target)
# Collect files to lint
if self.args.lint_files:
files_args = shlex.join(self.args.lint_files)
else:
files_args = f"$(find {self.config.source_dir} -name '*.cpp' -or -name '*.cppm')"
self.log_info('Running clangd-tidy')
run_result = subprocess.run(
f'clangd-tidy -p {self.config.build_dir} --allow-extensions cpp,cppm {files_args}',
shell=True,
)
if run_result.returncode > 0:
self.log_error(f'clangd-tidy exited with return code {run_result.returncode}')
exit(1)
def clean_project(self, target: str) -> None:
ninja_file_path = self.config.get_ninja_file_path(target)