summaryrefslogtreecommitdiffstats
path: root/misc/scripts/dotnet_format.py
blob: de414bbe3028a6b54a161259ccca89291728632b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import glob
import os
import sys

# Create dummy generated files.
for path in [
    "modules/mono/SdkPackageVersions.props",
]:
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, "w") as f:
        f.write("<Project />")

# Avoid importing GeneratedIncludes.props.
os.environ["GodotSkipGenerated"] = "true"

# Match all the input files to their respective C# project.
input_files = [os.path.normpath(x) for x in sys.argv]
projects = {
    path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
    for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
}

# Run dotnet format on all projects with more than 0 modified files.
for path, files in projects.items():
    if len(files) > 0:
        command = f"dotnet format {path} --include {' '.join(files)}"
        os.system(command)