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+
117import os
218import shutil
319import subprocess
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
2844def 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
5373def 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
5979if __name__ == '__main__' :
0 commit comments