generate.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import pathlib
  3. import uuid
  4. REPOSITORY_ROOT = pathlib.Path(__file__).parent.parent.parent
  5. def generate(x, y):
  6. guid = str(uuid.uuid4()).upper()
  7. text = f"""
  8. <?xml version="1.0" encoding="utf-8"?>
  9. <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  10. <PropertyGroup Label="Globals">
  11. <ProjectGuid>{{{guid}}}</ProjectGuid>
  12. </PropertyGroup>
  13. <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
  14. <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" />
  15. <ItemGroup>
  16. <None Include="$(SolutionDir)\\..\\examples\\{x}\\{y}\\README.txt" />
  17. <ClCompile Include="$(SolutionDir)\\..\\examples\\{x}\\{y}\\*.c" />
  18. </ItemGroup>
  19. <Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />
  20. </Project>
  21. """.strip()
  22. file_name = REPOSITORY_ROOT / "VisualC" / "examples" / x / y / f"{y}.vcxproj"
  23. if file_name.exists():
  24. print("Skipping:", file_name)
  25. return
  26. print("Generating file:", file_name)
  27. os.makedirs(file_name.parent, exist_ok=True)
  28. with open(file_name, "w", encoding="utf-8") as f:
  29. f.write(text)
  30. def main():
  31. path = REPOSITORY_ROOT / "examples"
  32. for x in path.iterdir():
  33. if x.is_dir():
  34. for y in x.iterdir():
  35. generate(x.name, y.name)
  36. if __name__ == "__main__":
  37. main()