Atlas - generate.py

Home / ext / SDL / VisualC / examples Lines: 1 | Size: 1857 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1import os 2import pathlib 3import uuid 4 5REPOSITORY_ROOT = pathlib.Path(__file__).parent.parent.parent 6 7 8def 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 38def 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 45def main(): 46 path = REPOSITORY_ROOT / "examples" 47 for category in path.iterdir(): 48 if category.is_dir(): 49 for example in category.iterdir(): 50 if example.is_dir(): 51 generate(category.name, example.name, get_c_source_filename(example)) 52 53 54if __name__ == "__main__": 55 main() 56
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.