fast_build.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python
  2. # Builds all projects in the provided solution in a parallel way.
  3. # Usage: "fast_build $Solution $Configuration $Platform"
  4. # Where: $Solution - Path to a .sln file, e.g. Banshee.sln
  5. # Where: $Configuration - e.g. Debug, OptimizedDebug, Release
  6. # Where: $Platform - x86, x64
  7. # Usage example: fast_build Banshee.sln Debug x64
  8. # msbuild must be available in the PATH variable, or the script must be ran from VS or VS Command Prompt
  9. import sys
  10. import os
  11. import multiprocessing
  12. import re
  13. slnPath = sys.argv[1]
  14. configuration = sys.argv[2]
  15. platform = sys.argv[3]
  16. slnDir = os.path.dirname(slnPath)
  17. # Triggers compile for a single project
  18. def compileWorker(projectPath):
  19. if not os.path.isabs(projectPath):
  20. projectPath = os.path.join(slnDir, projectPath)
  21. os.system("msbuild {0} /t:ClCompile /p:Configuration={1};Platform={2}".format(projectPath, configuration, platform))
  22. return
  23. # Since we'll be running this script using multiple processes, ensure this bit only runs on the main process
  24. if __name__ == '__main__':
  25. # Parse the solution file to find all C++ projects
  26. slnContents = open(slnPath, 'r').read()
  27. projects = re.findall(r"Project\(\".*\"\) = \".*\", \"(.*\.vcxproj)\", \".*\"\n", slnContents);
  28. # Launch a compile thread for every project
  29. pool = multiprocessing.Pool(multiprocessing.cpu_count())
  30. pool.map(compileWorker, projects)