builddist.py 5.6 KB

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