You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generateVS.py 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/local/bin/python
  2. import re
  3. import sys
  4. from os.path import join as joinpath, split as splitpath, exists as existspath, normpath, dirname, abspath, relpath, realpath
  5. import jinja2
  6. import argparse
  7. def render(tpl_path, context):
  8. path, filename = splitpath(tpl_path)
  9. return jinja2.Environment(loader=jinja2.FileSystemLoader(path or './')).get_template(filename).render(context).replace(u'\ufeff', '')
  10. def renderToFile(outfile, tpl_path, context) :
  11. res = render(tpl_path, context)
  12. with open(outfile, "w") as f:
  13. f.write(res)
  14. def getContent(file, endKeyword) :
  15. res = []
  16. for line in file :
  17. if line == endKeyword :
  18. break
  19. res.append(line)
  20. return res
  21. if __name__ == "__main__":
  22. #Arguments handling
  23. parser = argparse.ArgumentParser(description='Generate merged Visual Studio project for OpenViBE')
  24. parser.add_argument('-o', '--outsln', type=str, default="OpenViBE-Meta.sln", help='Output SLN file')
  25. parser.add_argument('-b', '--builddir', type=str, default="build", help='Build directory where Visual Studio Solutions are located')
  26. parser.add_argument('-p', '--platformtarget', type=str, default="x86", help='x86 or x64')
  27. args = parser.parse_args()
  28. build_dir = abspath(args.builddir)
  29. platform_target = args.platformtarget
  30. dist_dir = joinpath(dirname(build_dir), 'dist')
  31. outfile = args.outsln
  32. script_dir = dirname(realpath(__file__))
  33. slntpl_path = joinpath(script_dir, "OpenViBE-Meta.sln-tpl")
  34. usertpl_path = joinpath(script_dir, "vcxproj.user-tpl")
  35. designerex_path = joinpath(script_dir, "designer-extras.vcxproj-tpl")
  36. if platform_target == "x64" :
  37. platform_vs_target = "x64"
  38. else:
  39. platform_vs_target = "Win32"
  40. context = { 'proj_list' : [], 'proj_conf_platforms' : [], 'nested_projs' : {}, 'platform_target' : platform_vs_target }
  41. projects = [
  42. ('SDK', "10313F85-EFD9-42AB-BF90-643A406FDD99", normpath(joinpath(build_dir, "sdk-" + platform_target , "OpenVIBE.sln"))),
  43. ("Designer", "EEB9310A-3238-432D-9EAD-CDFCB35054D4", normpath(joinpath(build_dir, "designer-" + platform_target, "Designer.sln"))),
  44. ("Extras", "3F5EF7F3-0F10-4F2E-ACEB-3B1326E3DA48", normpath(joinpath(build_dir, "extras-" + platform_target, "OpenVIBE.sln")))]
  45. build_types = ['Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo']
  46. # Generate config file for designer-extras project
  47. ov_env = { type : (joinpath(dist_dir, "extras-" + platform_target, type, "bin", "openvibe-designer.exe"), 'OV_PATH_ROOT=' + joinpath(dist_dir, "extras-" + platform_target, type)) for type in build_types}
  48. renderToFile(joinpath(build_dir, "designer-extras.vcxproj"), designerex_path, { 'platform_target' : platform_vs_target } )
  49. renderToFile(joinpath(build_dir, "designer-extras.vcxproj.user"), usertpl_path, { 'configurations' : ov_env, 'platform_target' : platform_vs_target } )
  50. for folderName, folderId, path_sln in projects :
  51. pathprefix = relpath(dirname(path_sln), normpath(dirname(abspath(outfile))))
  52. # Sets the correct value for OV_PATH_ROOT; It should be possible to set multiple values separated by newline
  53. # Unfortunately due to a bug, this is not always possible, see https://connect.microsoft.com/VisualStudio/feedback/details/727324/msvs10-c-deu-debugger-environment-variables-missing-linefeed
  54. # (This is about german VS 2010, but this is also happening on french VS2013)
  55. ov_env = { type : (None, 'OV_PATH_ROOT=' + joinpath(dist_dir, folderName.lower() + "-" + platform_target, type.upper())) for type in build_types}
  56. if not existspath(path_sln) :
  57. print(path_sln, 'does not exist !')
  58. continue
  59. print('Parsing', path_sln)
  60. with open(path_sln, 'r') as f:
  61. for line in f :
  62. res = re.match('Project\("{([\dABCDEF-]+)}"\)\s+=\s+"([\w\-]+)",\s+"([\w\-\\\.]+)",\s+"{([\dABCDEF\-]+)}"', line)
  63. if res :
  64. slnId, projectName, projectPath, projectId = res.groups()
  65. content = getContent(f, "EndProject\n")
  66. newpath = joinpath(pathprefix, projectPath) if len(content) else projectPath
  67. tab = ['Project("{%s}") = "%s", "%s", "{%s}"\n' % (slnId, projectName, newpath, projectId)] \
  68. + content \
  69. + ["EndProject"]
  70. context['proj_list'].append(''.join(tab))
  71. context['nested_projs'][projectId] = folderId
  72. # Generate .user file
  73. projectfile = joinpath(dirname(path_sln), projectPath)
  74. userfile = projectfile + ".user"
  75. renderToFile(userfile, usertpl_path, { 'configurations' : ov_env, 'platform_target' : platform_vs_target } )
  76. elif line == "Global\n" :
  77. for line2 in f :
  78. if line2 == "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n" :
  79. context['proj_conf_platforms'] += getContent(f, "\tEndGlobalSection\n")
  80. elif line2 == "\tGlobalSection(NestedProjects) = preSolution\n" :
  81. res = getContent(f, "\tEndGlobalSection\n")
  82. for item in res :
  83. key, val = re.search('{([\dABCDEF-]+)}\s=\s{([\dABCDEF-]+)}', item).groups()
  84. context['nested_projs'][key] = val
  85. try :
  86. renderToFile(outfile, slntpl_path, context)
  87. except :
  88. print('Could not generate %s' % (outfile,))
  89. sys.exit(1)
  90. else :
  91. print('Project [%s] generated' % (outfile,))