Atlas - generate.py

Home / ext / SDL / VisualC / examples Lines: 1 | Size: 1791 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="$(SolutionDir)\\examples\\Examples.props" /> 17 <ItemGroup> 18 <None Include="$(SolutionDir)\\..\\examples\\{category}\\{example_name}\\README.txt" /> 19 <ClCompile Include="$(SolutionDir)\\..\\examples\\{category}\\{example_name}\\{c_source_file}" /> 20 </ItemGroup> 21 <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" /> 22</Project> 23""".strip() 24 25 project_file = REPOSITORY_ROOT / "VisualC" / "examples" / category / example_name / f"{example_name}.vcxproj" 26 27 if project_file.exists(): 28 print("Skipping:", project_file) 29 return 30 31 print("Generating file:", project_file) 32 os.makedirs(project_file.parent, exist_ok=True) 33 with open(project_file, "w", encoding="utf-8") as f: 34 f.write(text) 35 36 37def get_c_source_filename(example_dir: pathlib.Path): 38 """Gets the one and only C source file name in the directory of the example.""" 39 c_files = [f.name for f in example_dir.iterdir() if f.name.endswith(".c")] 40 assert len(c_files) == 1 41 return c_files[0] 42 43 44def main(): 45 path = REPOSITORY_ROOT / "examples" 46 for category in path.iterdir(): 47 if category.is_dir(): 48 for example in category.iterdir(): 49 if example.is_dir(): 50 generate(category.name, example.name, get_c_source_filename(example)) 51 52 53if __name__ == "__main__": 54 main() 55
[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.