Debian Codegraph @

misc/scripts/dotnet_format.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import glob
4 import os
5 import sys
6
7 if len(sys.argv) < 2:
8 print("Invalid usage of dotnet_format.py, it should be called with a path to one or multiple files.")
9 sys.exit(1)
10
11 # Create dummy generated files, if needed.
12 for path in [
13 "modules/mono/SdkPackageVersions.props",
14 ]:
15 if os.path.exists(path):
16 continue
17 os.makedirs(os.path.dirname(path), exist_ok=True)
18 with open(path, "w", encoding="utf-8", newline="\n") as f:
19 f.write("<Project />")
20
21 # Avoid importing GeneratedIncludes.props.
22 os.environ["GodotSkipGenerated"] = "true"
23
24 # Match all the input files to their respective C# project.
25 projects = {
26 path: " ".join([f for f in sys.argv[1:] if os.path.commonpath([f, path]) == path])
27 for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
28 }
29
30 # Run dotnet format on all projects with more than 0 modified files.
31 for path, files in projects.items():
32 if files:
33 os.system(f"dotnet format {path} --include {files}")