aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/scripts
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-03-10 08:41:54 -0500
committerXavier Claessens <xclaesse@gmail.com>2021-03-16 21:01:54 -0400
commit0638e38bfc8ef969c7ea9e2005ff051c14dab0f9 (patch)
tree41bb16d587cd02728f2bddd6c31e9a425674d95b /mesonbuild/scripts
parentf55868927721f273640a3ba7a8e703d418a352b6 (diff)
downloadmeson-0638e38bfc8ef969c7ea9e2005ff051c14dab0f9.zip
meson-0638e38bfc8ef969c7ea9e2005ff051c14dab0f9.tar.gz
meson-0638e38bfc8ef969c7ea9e2005ff051c14dab0f9.tar.bz2
clangformat: Add clang-format-check target
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r--mesonbuild/scripts/clangformat.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py
index 2cf757f..ceb36ac 100644
--- a/mesonbuild/scripts/clangformat.py
+++ b/mesonbuild/scripts/clangformat.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import argparse
import subprocess
import itertools
import fnmatch
@@ -34,15 +35,17 @@ def parse_pattern_file(fname: Path) -> T.List[str]:
pass
return patterns
-def run_clang_format(exelist: T.List[str], fname: Path) -> subprocess.CompletedProcess:
+def run_clang_format(exelist: T.List[str], fname: Path, check: bool) -> subprocess.CompletedProcess:
before = fname.stat().st_mtime
ret = subprocess.run(exelist + ['-style=file', '-i', str(fname)])
after = fname.stat().st_mtime
if before != after:
print('File reformatted: ', fname)
+ if check:
+ ret.returncode = 1
return ret
-def clangformat(exelist: T.List[str], srcdir: Path, builddir: Path) -> int:
+def clangformat(exelist: T.List[str], srcdir: Path, builddir: Path, check: bool) -> int:
patterns = parse_pattern_file(srcdir / '.clang-format-include')
if not patterns:
patterns = ['**/*']
@@ -61,17 +64,23 @@ def clangformat(exelist: T.List[str], srcdir: Path, builddir: Path) -> int:
if f.is_dir() or f.suffix not in suffixes or \
any(fnmatch.fnmatch(strf, i) for i in ignore):
continue
- futures.append(e.submit(run_clang_format, exelist, f))
+ futures.append(e.submit(run_clang_format, exelist, f, check))
returncode = max([x.result().returncode for x in futures])
return returncode
def run(args: T.List[str]) -> int:
- srcdir = Path(args[0])
- builddir = Path(args[1])
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--check', action='store_true')
+ parser.add_argument('sourcedir')
+ parser.add_argument('builddir')
+ options = parser.parse_args(args)
+
+ srcdir = Path(options.sourcedir)
+ builddir = Path(options.builddir)
exelist = detect_clangformat()
if not exelist:
print('Could not execute clang-format "%s"' % ' '.join(exelist))
return 1
- return clangformat(exelist, srcdir, builddir)
+ return clangformat(exelist, srcdir, builddir, options.check)