diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/VisualC/examples/generate.py')
-rwxr-xr-x | src/contrib/SDL-3.2.20/VisualC/examples/generate.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/VisualC/examples/generate.py b/src/contrib/SDL-3.2.20/VisualC/examples/generate.py new file mode 100755 index 0000000..e06110e --- /dev/null +++ b/src/contrib/SDL-3.2.20/VisualC/examples/generate.py | |||
@@ -0,0 +1,54 @@ | |||
1 | import os | ||
2 | import pathlib | ||
3 | import uuid | ||
4 | |||
5 | REPOSITORY_ROOT = pathlib.Path(__file__).parent.parent.parent | ||
6 | |||
7 | |||
8 | def generate(category, example_name, c_source_file): | ||
9 | guid = str(uuid.uuid4()).upper() | ||
10 | text = f""" | ||
11 | <?xml version="1.0" encoding="utf-8"?> | ||
12 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
13 | <PropertyGroup Label="Globals"> | ||
14 | <ProjectGuid>{{{guid}}}</ProjectGuid> | ||
15 | </PropertyGroup> | ||
16 | <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" /> | ||
17 | <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" /> | ||
18 | <ItemGroup> | ||
19 | <None Include="$(SolutionDir)\\..\\examples\\{category}\\{example_name}\\README.txt" /> | ||
20 | <ClCompile Include="$(SolutionDir)\\..\\examples\\{category}\\{example_name}\\{c_source_file}" /> | ||
21 | </ItemGroup> | ||
22 | <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" /> | ||
23 | </Project> | ||
24 | """.strip() | ||
25 | |||
26 | project_file = REPOSITORY_ROOT / "VisualC" / "examples" / category / example_name / f"{example_name}.vcxproj" | ||
27 | |||
28 | if project_file.exists(): | ||
29 | print("Skipping:", project_file) | ||
30 | return | ||
31 | |||
32 | print("Generating file:", project_file) | ||
33 | os.makedirs(project_file.parent, exist_ok=True) | ||
34 | with open(project_file, "w", encoding="utf-8") as f: | ||
35 | f.write(text) | ||
36 | |||
37 | |||
38 | def get_c_source_filename(example_dir: pathlib.Path): | ||
39 | """Gets the one and only C source file name in the directory of the example.""" | ||
40 | c_files = [f.name for f in example_dir.iterdir() if f.name.endswith(".c")] | ||
41 | assert len(c_files) == 1 | ||
42 | return c_files[0] | ||
43 | |||
44 | |||
45 | def main(): | ||
46 | path = REPOSITORY_ROOT / "examples" | ||
47 | for category in path.iterdir(): | ||
48 | if category.is_dir(): | ||
49 | for example in category.iterdir(): | ||
50 | generate(category.name, example.name, get_c_source_filename(example)) | ||
51 | |||
52 | |||
53 | if __name__ == "__main__": | ||
54 | main() | ||