From c4fa87692547a25f772b3da336147b4eb9114f64 Mon Sep 17 00:00:00 2001 From: Bernd Busse Date: Sat, 3 Oct 2020 19:58:55 +0200 Subject: [PATCH] Never run clang-format / clang-tidy against directories `pathlib.Path.glob()` also returns directories that match source filenames (i.e. a directory named `test.h/`), but `clang-format` and `clang-tidy` fail when handed a directory. We manually skip calling `clang-format` and `clang-tidy` on those directories. --- mesonbuild/scripts/clangformat.py | 2 ++ mesonbuild/scripts/clangtidy.py | 2 ++ run_unittests.py | 2 ++ test cases/unit/54 clang-format/dummydir.h/dummy.dat | 1 + test cases/unit/70 clang-tidy/dummydir.h/dummy.dat | 1 + 5 files changed, 8 insertions(+) create mode 100644 test cases/unit/54 clang-format/dummydir.h/dummy.dat create mode 100644 test cases/unit/70 clang-tidy/dummydir.h/dummy.dat diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py index 19ea5ec2f..e7a3ff850 100644 --- a/mesonbuild/scripts/clangformat.py +++ b/mesonbuild/scripts/clangformat.py @@ -27,6 +27,8 @@ def clangformat(exelist: T.List[str], srcdir_name: str, builddir_name: str) -> i futures = [] with ThreadPoolExecutor() as e: for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff)): + if f.is_dir(): + continue strf = str(f) if strf.startswith(builddir_name): continue diff --git a/mesonbuild/scripts/clangtidy.py b/mesonbuild/scripts/clangtidy.py index 11174ea25..03aa8c77f 100644 --- a/mesonbuild/scripts/clangtidy.py +++ b/mesonbuild/scripts/clangtidy.py @@ -28,6 +28,8 @@ def manual_clangformat(srcdir_name: str, builddir_name: str) -> int: returncode = 0 with ThreadPoolExecutor() as e: for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff)): + if f.is_dir(): + continue strf = str(f) if strf.startswith(builddir_name): continue diff --git a/run_unittests.py b/run_unittests.py index 1fd436d55..038540404 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4212,9 +4212,11 @@ recommended as it is not supported on some platforms''') if is_osx(): raise unittest.SkipTest('Apple ships a broken clang-tidy that chokes on -pipe.') testdir = os.path.join(self.unit_test_dir, '70 clang-tidy') + dummydir = os.path.join(testdir, 'dummydir.h') self.init(testdir, override_envvars={'CXX': 'c++'}) out = self.run_target('clang-tidy') self.assertIn('cttest.cpp:4:20', out) + self.assertNotIn(dummydir, out) def test_identity_cross(self): testdir = os.path.join(self.unit_test_dir, '71 cross') diff --git a/test cases/unit/54 clang-format/dummydir.h/dummy.dat b/test cases/unit/54 clang-format/dummydir.h/dummy.dat new file mode 100644 index 000000000..80c6165f3 --- /dev/null +++ b/test cases/unit/54 clang-format/dummydir.h/dummy.dat @@ -0,0 +1 @@ +Placeholder to track enclosing directory in git. Not to be analyzed. diff --git a/test cases/unit/70 clang-tidy/dummydir.h/dummy.dat b/test cases/unit/70 clang-tidy/dummydir.h/dummy.dat new file mode 100644 index 000000000..80c6165f3 --- /dev/null +++ b/test cases/unit/70 clang-tidy/dummydir.h/dummy.dat @@ -0,0 +1 @@ +Placeholder to track enclosing directory in git. Not to be analyzed.