-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Built-in clang-tidy
target does not build pch files required to build the sources
#13499
Comments
I am revising my outlook on this to "its a bug": it seems that custom_target had this changed, but not |
I feel ethically obliged to write down my workaround to this for whoever runs into this next. It's is a custom_target that always rebuilds that calls another ninja to build those targets manually. #!/usr/bin/env python3
import subprocess
def get_targets_of_rule(build_root: str, rule_name: str) -> list[str]:
return subprocess.check_output(['ninja', '-C', build_root, '-t', 'targets', 'rule', rule_name]).decode().strip().splitlines()
def ninja_build(build_root: str, targets: list[str]):
subprocess.check_call(['ninja', '-C', build_root, '--', *targets])
def main():
import argparse
ap = argparse.ArgumentParser(description='Builds required targets for clang-tidy')
ap.add_argument('build_root', help='Ninja build root', type=str)
args = ap.parse_args()
targets = [t for t in get_targets_of_rule(args.build_root, 'CUSTOM_COMMAND') if t.endswith('gen.hh')]
ninja_build(args.build_root, targets)
if __name__ == '__main__':
main() build_all_generated_headers = custom_target(
command : [
python,
meson.current_source_dir() / 'build_required_targets.py',
meson.global_build_root(),
],
output : 'generated_headers.stamp',
build_by_default : false,
build_always_stale : true,
)
if lix_clang_tidy_so_found
run_clang_tidy_args = [
'-load',
lix_clang_tidy_so,
'-p',
# We have to workaround a run-clang-tidy bug too, so we must give the
# directory name rather than the actual compdb file.
# https://github.com/llvm/llvm-project/issues/101440
meson.current_build_dir(),
'-quiet',
]
run_target(
'clang-tidy',
command : [
run_clang_tidy,
run_clang_tidy_args,
'-warnings-as-errors',
'*',
],
depends : [
build_all_generated_headers,
],
)
run_target(
'clang-tidy-fix',
command : [
run_clang_tidy,
run_clang_tidy_args,
'-fix',
],
depends : [
build_all_generated_headers,
],
)
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
If you run
ninja -C build clang-tidy
it will not work if you are using pch files if you have not run a full build yet, particularly with clang, since the pch files will not yet be built, and there is no dependency between the pch targets and the clang-tidy target. Furthermore, there is no way to name the pch targets in meson's DSL so custom clang-tidy target authors also have this problem.A workaround is that custom clang-tidy target authors can write horrible scripts that pull the PCH targets out of
compile_commands.json
and execute them if they are out of date.It would be possible to make meson do something like it does for test here: #1704 but I would not consider this a particularly nice solution personally, since it is a significant UX regression for users who already have a slightly stale build but with up to date PCH targets.
To Reproduce
Create a
meson.build
as follows:Create empty files
oops.cc
,pch/pch.hh
.Note to be careful if you are throwing this repro in a random subdir of another git repo: the
.cc
file needs to begit add
ed to be seen by the meson clang-tidy target.Expected behavior
I expect the clang-tidy target to depend on all the PCHes in the project, and if this is done it must be possible to create such dependencies if reimplementing clang-tidy as a custom target as well, ideally without listing every target in the project in a list by hand. There's also a design constraint of what to do of generated code that is
#include
'd into the files; it is not just PCH targets that are a problem for meson's clang-tidy targets, but pch is the most obvious one.system parameters
meson --version
: 1.5.1ninja --version
if it's a Ninja build: 1.12.1The text was updated successfully, but these errors were encountered: