builddist.py 5.3 KB

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