dotnet_format.py 926 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import glob
  4. import os
  5. import sys
  6. # Create dummy generated files.
  7. for path in [
  8. "modules/mono/SdkPackageVersions.props",
  9. ]:
  10. os.makedirs(os.path.dirname(path), exist_ok=True)
  11. with open(path, "w", encoding="utf-8", newline="\n") as f:
  12. f.write("<Project />")
  13. # Avoid importing GeneratedIncludes.props.
  14. os.environ["GodotSkipGenerated"] = "true"
  15. # Match all the input files to their respective C# project.
  16. input_files = [os.path.normpath(x) for x in sys.argv]
  17. projects = {
  18. path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
  19. for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
  20. }
  21. # Run dotnet format on all projects with more than 0 modified files.
  22. for path, files in projects.items():
  23. if len(files) > 0:
  24. command = f"dotnet format {path} --include {' '.join(files)}"
  25. os.system(command)