builddist.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/python
  2. import subprocess
  3. import os
  4. import sys
  5. import getopt
  6. import traceback
  7. import shutil
  8. import re
  9. def Usage(args):
  10. print sys.argv[0] + ' [-hp] [-r revision]'
  11. print ''
  12. print ' -r\t: Specify RmlUi internal revision number'
  13. print ' -s\t: Include full source code and build files'
  14. print ' -h\t: This help screen'
  15. print ''
  16. sys.exit()
  17. def CheckVSVars():
  18. if 'VCINSTALLDIR' in os.environ:
  19. return
  20. if not 'VS90COMNTOOLS' in os.environ:
  21. print "Unable to find VS9 install - check your VS90COMNTOOLS environment variable"
  22. sys.exit()
  23. path = os.environ['VS90COMNTOOLS']
  24. subprocess.call('"' + path + 'vsvars32.bat" > NUL && ' + ' '.join(sys.argv))
  25. sys.exit()
  26. def ProcessOptions(args):
  27. options = {'RMLUI_VERSION': 'custom', 'FULL_SOURCE': False, 'ARCHIVE_NAME': 'RmlUi-sdk'}
  28. try:
  29. optlist, args = getopt.getopt(args, 'r:phs')
  30. except getopt.GetoptError, e:
  31. print '\nError: ' + str(e) + '\n'
  32. Usage(args)
  33. for opt in optlist:
  34. if opt[0] == '-h':
  35. Usage(args)
  36. if opt[0] == '-r':
  37. options['RMLUI_VERSION'] = opt[1]
  38. if opt[0] == '-s':
  39. options['FULL_SOURCE'] = True
  40. options['ARCHIVE_NAME'] = 'RmlUi-source'
  41. return options
  42. def Build(project, configs, defines = {}):
  43. old_cl = ''
  44. if 'CL' in os.environ:
  45. old_cl = os.environ['CL']
  46. else:
  47. os.environ['CL'] = ''
  48. for name, value in defines.iteritems():
  49. os.environ['CL'] = os.environ['CL'] + ' /D' + name + '=' + value
  50. for config in configs:
  51. cmd = '"' + os.environ['VCINSTALLDIR'] + '\\vcpackages\\vcbuild.exe" /rebuild ' + project + '.vcproj "' + config + '|Win32"'
  52. ret = subprocess.call(cmd)
  53. if ret != 0:
  54. print "Failed to build " + project
  55. sys.exit()
  56. os.environ['CL'] = old_cl
  57. def DelTree(path):
  58. if not os.path.exists(path):
  59. return
  60. print 'Deleting ' + path + '...'
  61. for root, dirs, files in os.walk(path, topdown=False):
  62. for name in files:
  63. os.remove(os.path.join(root, name))
  64. for name in dirs:
  65. os.rmdir(os.path.join(root, name))
  66. def CopyFiles(source_path, destination_path, file_list = [], exclude_list = [], preserve_paths = True):
  67. working_directory = os.getcwd()
  68. source_directory = os.path.abspath(os.path.join(working_directory, os.path.normpath(source_path)))
  69. destination_directory = os.path.abspath(os.path.join(working_directory, os.path.normpath(destination_path)))
  70. print "Copying " + source_directory + " to " + destination_directory + " ..."
  71. if not os.path.exists(source_directory):
  72. print "Warning: Source directory " + source_directory + " doesn't exist."
  73. return False
  74. for root, directories, files in os.walk(source_directory, False):
  75. for file in files:
  76. # Skip files not in the include list.
  77. if len(file_list) > 0:
  78. included = False
  79. for include in file_list:
  80. if re.search(include, file):
  81. included = True
  82. break;
  83. if not included:
  84. continue
  85. # Determine our subdirectory.
  86. subdir = root.replace(source_directory, "")
  87. if subdir[:1] == os.path.normcase('/'):
  88. subdir = subdir[1:]
  89. # Skip paths in the exclude list
  90. excluded = False
  91. for exclude in exclude_list:
  92. if re.search(exclude, file):
  93. excluded = True
  94. break
  95. if excluded:
  96. continue
  97. # Build up paths
  98. source_file = os.path.join(root, file)
  99. destination_subdir = destination_directory
  100. if preserve_paths:
  101. destination_subdir = os.path.join(destination_directory, subdir)
  102. if not os.path.exists(destination_subdir):
  103. os.makedirs(destination_subdir)
  104. destination_file = os.path.join(destination_subdir, file)
  105. # Copy files
  106. try:
  107. shutil.copy(source_file, destination_file)
  108. except:
  109. print "Failed copying " + source_file + " to " + destination_file
  110. traceback.print_exc()
  111. return True
  112. def Archive(archive_name, path):
  113. cwd = os.getcwd()
  114. os.chdir(path + '/..')
  115. file_name = archive_name + '.zip'
  116. if os.path.exists(file_name):
  117. os.unlink(file_name)
  118. os.system('zip -r ' + file_name + ' ' + path[path.rfind('/')+1:])
  119. os.chdir(cwd)
  120. def main():
  121. CheckVSVars()
  122. options = ProcessOptions(sys.argv[1:])
  123. Build('RmlCore', ['Debug', 'Release'], {'RMLUI_VERSION': '\\"' + options['RMLUI_VERSION'] + '\\"'})
  124. Build('RmlControls', ['Debug', 'Release'])
  125. Build('RmlDebugger', ['Debug', 'Release'])
  126. DelTree('../Distribution/RmlUi')
  127. CopyFiles('../Include', '../Distribution/RmlUi/Include')
  128. CopyFiles('../Build', '../Distribution/RmlUi/Build', ['\.dll$', '^[^_].*\.lib$', '\.py$', '\.pyd$'])
  129. CopyFiles('../Samples', '../Distribution/RmlUi/Samples', ['\.h$', '\.cpp$', '\.vcproj$', '\.sln$', '\.vcproj\.user$', '\.rml$', '\.rcss$', '\.tga$', '\.py$', '\.otf$', '\.txt$'])
  130. if options['FULL_SOURCE']:
  131. CopyFiles('../Build', '../Distribution/RmlUi/Build', ['\.vcproj$', '\.sln$', '\.vsprops$', '\.py$'])
  132. CopyFiles('../Source', '../Distribution/RmlUi/Source', ['\.cpp$', '\.h$', '\.inl$'])
  133. shutil.copyfile('../changelog.txt', '../Distribution/RmlUi/changelog.txt')
  134. Archive(options['ARCHIVE_NAME'] + '-' + options['RMLUI_VERSION'], '../Distribution/RmlUi');
  135. if __name__ == '__main__':
  136. main()