Skip to content

Commit 1d3e779

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[format] Add formatting check to presubmit.py
Bug: 430616180 Change-Id: I6784d3f4232e11b272cbb7a345713edff05c7426 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9156216 Commit-Queue: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Michael Achenbach <machenbach@google.com>
1 parent 96773db commit 1d3e779

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

Tools/presubmit.py

100644100755
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
117
import os
218
import shutil
319
import subprocess
@@ -13,7 +29,7 @@
1329
"ast.proto"
1430
]
1531

16-
def check_git_clean():
32+
def check_git_clean(info):
1733
"""Check that the git repository does not have any uncommitted changes."""
1834
result = subprocess.run(
1935
["git", "diff", "--name-only"],
@@ -23,15 +39,15 @@ def check_git_clean():
2339
output = result.stdout.decode().strip()
2440
if output != "":
2541
diff_result = subprocess.run(["git", "diff"], cwd=BASE_DIR, capture_output=True, check=True)
26-
assert False, f"Unexpected modified files: {output}\n== Diff ==\n{diff_result.stdout.decode()}"
42+
assert False, f"Unexpected modified files {info}: {output}\n== Diff ==\n{diff_result.stdout.decode()}"
2743

2844
def check_proto():
2945
"""Check that program.proto is up-to-date."""
3046
print("Checking generated protobuf files...")
3147
proto_dir = BASE_DIR / "Sources/Fuzzilli/Protobuf"
3248
subprocess.run(["python3", "./gen_programproto.py"], cwd=proto_dir, check=True)
3349
# gen_programproto.py should be a no-op.
34-
check_git_clean()
50+
check_git_clean("after running gen_programproto.py")
3551

3652
if not shutil.which("protoc"):
3753
print("Skipping protobuf validation as protoc is not available.")
@@ -48,12 +64,16 @@ def check_proto():
4864
cmd = ["protoc", "--swift_opt=Visibility=Public", "--swift_out=."] + KNOWN_PROTO_FILES
4965
subprocess.run(cmd, cwd=proto_dir, check=True, env=env)
5066
# Regenerating the protobuf files should be a no-op.
51-
check_git_clean()
67+
check_git_clean("after regenerating protobuf files")
68+
69+
def check_formatting():
70+
subprocess.run(["swift", "format", BASE_DIR, "--recursive", "--parallel", "--in-place"], check=True)
71+
check_git_clean("after auto-formatting")
5272

5373
def main():
54-
check_git_clean()
74+
check_git_clean("before any checks")
5575
check_proto()
56-
# TODO(mliedtke): Ensure formatting delta is zero once we enable automated formatting.
76+
check_formatting()
5777

5878

5979
if __name__ == '__main__':

0 commit comments

Comments
 (0)