3781: Only use correct clang-format version r=heinrich5991 a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-04-17 19:46:19 +00:00 committed by GitHub
commit 4cb65aa2d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,11 +26,27 @@ def filter_cpp(filenames):
return [filename for filename in filenames return [filename for filename in filenames
if any(filename.endswith(ext) for ext in ".c .cpp .h".split())] if any(filename.endswith(ext) for ext in ".c .cpp .h".split())]
def find_clang_format(version):
for binary in (
"clang-format",
"clang-format-{}".format(version),
"/opt/clang-format-static/clang-format-{}".format(version)):
try:
out = subprocess.check_output([binary, "--version"])
except FileNotFoundError:
continue
if "clang-format version {}.".format(version) in out.decode("utf-8"):
return binary
print("Found no clang-format {}".format(version))
sys.exit(-1)
clang_format_bin = find_clang_format(10)
def reformat(filenames): def reformat(filenames):
subprocess.check_call(["clang-format", "-i"] + filenames) subprocess.check_call([clang_format_bin, "-i"] + filenames)
def warn(filenames): def warn(filenames):
return subprocess.call(["clang-format", "-Werror", "--dry-run"] + filenames) return subprocess.call([clang_format_bin, "-Werror", "--dry-run"] + filenames)
def main(): def main():
p = argparse.ArgumentParser(description="Check and fix style of changed files") p = argparse.ArgumentParser(description="Check and fix style of changed files")