From 74712f2dbc3e0f04e6458c6ffe129187dd4726bf Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Tue, 31 Oct 2023 16:42:30 +0100 Subject: [PATCH] scan-build: Exclude subprojects from scan-build report When a user invokes the scan-build target that Meson generates all subprojects are included in the resulting report. This commit modifies the invocation of scan-build to exclude all bugs that scan-build finds in the subprojects from the final report. A release note has also been added describing the changed behaviour. --- .../snippets/subprojects_excluded_from_scanbuild.md | 4 ++++ mesonbuild/backend/ninjabackend.py | 2 +- mesonbuild/scripts/scanbuild.py | 9 +++++---- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 docs/markdown/snippets/subprojects_excluded_from_scanbuild.md diff --git a/docs/markdown/snippets/subprojects_excluded_from_scanbuild.md b/docs/markdown/snippets/subprojects_excluded_from_scanbuild.md new file mode 100644 index 000000000000..d740006be248 --- /dev/null +++ b/docs/markdown/snippets/subprojects_excluded_from_scanbuild.md @@ -0,0 +1,4 @@ +## Subprojects excluded from scan-build reports + +The `scan-build` target, created when using the `ninja` backend with `scan-build` +present, now excludes bugs found in subprojects from its final report. diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 41bdf4cc688e..0f630a6b6d2d 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3581,7 +3581,7 @@ def generate_scanbuild(self) -> None: if 'scan-build' in self.all_outputs: return cmd = self.environment.get_build_command() + \ - ['--internal', 'scanbuild', self.environment.source_dir, self.environment.build_dir] + \ + ['--internal', 'scanbuild', self.environment.source_dir, self.environment.build_dir, self.build.get_subproject_dir()] + \ self.environment.get_build_command() + self.get_user_option_args() elem = self.create_phony_target('scan-build', 'CUSTOM_COMMAND', 'PHONY') elem.add_item('COMMAND', cmd) diff --git a/mesonbuild/scripts/scanbuild.py b/mesonbuild/scripts/scanbuild.py index 9cfc75dc388d..be60024da329 100644 --- a/mesonbuild/scripts/scanbuild.py +++ b/mesonbuild/scripts/scanbuild.py @@ -24,12 +24,12 @@ from ast import literal_eval import os -def scanbuild(exelist: T.List[str], srcdir: Path, blddir: Path, privdir: Path, logdir: Path, args: T.List[str]) -> int: +def scanbuild(exelist: T.List[str], srcdir: Path, blddir: Path, privdir: Path, logdir: Path, subprojdir: Path, args: T.List[str]) -> int: # In case of problems leave the temp directory around # so it can be debugged. scandir = tempfile.mkdtemp(dir=str(privdir)) meson_cmd = exelist + args - build_cmd = exelist + ['-o', str(logdir)] + detect_ninja() + ['-C', scandir] + build_cmd = exelist + ['--exclude', str(subprojdir), '-o', str(logdir)] + detect_ninja() + ['-C', scandir] rc = subprocess.call(meson_cmd + [str(srcdir), scandir]) if rc != 0: return rc @@ -41,8 +41,9 @@ def scanbuild(exelist: T.List[str], srcdir: Path, blddir: Path, privdir: Path, l def run(args: T.List[str]) -> int: srcdir = Path(args[0]) bldpath = Path(args[1]) + subprojdir = srcdir / Path(args[2]) blddir = args[1] - meson_cmd = args[2:] + meson_cmd = args[3:] privdir = bldpath / 'meson-private' logdir = bldpath / 'meson-logs' / 'scanbuild' shutil.rmtree(str(logdir), ignore_errors=True) @@ -63,4 +64,4 @@ def run(args: T.List[str]) -> int: print('Could not execute scan-build "%s"' % ' '.join(exelist)) return 1 - return scanbuild(exelist, srcdir, bldpath, privdir, logdir, meson_cmd) + return scanbuild(exelist, srcdir, bldpath, privdir, logdir, subprojdir, meson_cmd)