8b5ae7d7c5
I noticed it when I looked at some files now used in AnkiDroid, wanting to be sure we clearly indicate that we have AGPLv3 code linked in the app
40 lines
1.2 KiB
Python
Executable File
40 lines
1.2 KiB
Python
Executable File
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import sys, subprocess, os, difflib
|
|
|
|
clang_format = sys.argv[1]
|
|
workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "")
|
|
want_fix = bool(workspace)
|
|
|
|
found_bad = False
|
|
for path in sys.argv[2:]:
|
|
with open(path) as file:
|
|
orig = file.read()
|
|
new = subprocess.check_output(
|
|
# [clang_format, "--style={'BasedOnStyle': 'google', 'IndentWidth': 4}", path]
|
|
[clang_format, "--style=google", path]
|
|
).decode("utf-8")
|
|
if orig != new:
|
|
if want_fix:
|
|
with open(os.path.join(workspace, path), "w", newline="\n") as file:
|
|
file.write(new)
|
|
print("fixed", path)
|
|
else:
|
|
print(f"Bad formatting in {path}")
|
|
print(
|
|
"\n".join(
|
|
difflib.unified_diff(
|
|
orig.splitlines(),
|
|
new.splitlines(),
|
|
fromfile="bad",
|
|
tofile="good",
|
|
lineterm="",
|
|
)
|
|
)
|
|
)
|
|
found_bad = True
|
|
|
|
if found_bad:
|
|
sys.exit(1)
|