slave_compile.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. import os
  20. import subprocess
  21. import sys
  22. import shutil
  23. # get builder name
  24. if len(sys.argv) < 2:
  25. sys.stderr.write("Not enough arguments, expecting builder name\n")
  26. sys.exit(1)
  27. builder = sys.argv[1]
  28. # we run from build/ directory
  29. blender_dir = os.path.join('..', 'blender.git')
  30. def parse_header_file(filename, define):
  31. import re
  32. regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
  33. with open(filename, "r") as file:
  34. for l in file:
  35. match = regex.match(l)
  36. if match:
  37. return match.group(1)
  38. return None
  39. if 'cmake' in builder:
  40. # cmake
  41. # Some fine-tuning configuration
  42. blender_dir = os.path.abspath(blender_dir)
  43. build_dir = os.path.abspath(os.path.join('..', 'build', builder))
  44. install_dir = os.path.abspath(os.path.join('..', 'install', builder))
  45. targets = ['blender']
  46. command_prefix = []
  47. bits = 64
  48. # Config file to be used (relative to blender's sources root)
  49. cmake_config_file = "build_files/cmake/config/blender_release.cmake"
  50. # Set build options.
  51. cmake_options = []
  52. cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release',
  53. '-DWITH_GTESTS=ON']
  54. if builder.startswith('mac'):
  55. # Set up OSX architecture
  56. if builder.endswith('x86_64_10_9_cmake'):
  57. cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
  58. cmake_extra_options.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9')
  59. elif builder.startswith('win'):
  60. if builder.startswith('win64'):
  61. cmake_options.extend(['-G', 'Visual Studio 15 2017 Win64'])
  62. elif builder.startswith('win32'):
  63. bits = 32
  64. cmake_options.extend(['-G', 'Visual Studio 15 2017'])
  65. elif builder.startswith('linux'):
  66. cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
  67. tokens = builder.split("_")
  68. glibc = tokens[1]
  69. if glibc == 'glibc224':
  70. deb_name = "stretch"
  71. if builder.endswith('x86_64_cmake'):
  72. chroot_name = 'buildbot_' + deb_name + '_x86_64'
  73. elif builder.endswith('i686_cmake'):
  74. bits = 32
  75. chroot_name = 'buildbot_' + deb_name + '_i686'
  76. command_prefix = ['schroot', '-c', chroot_name, '--']
  77. elif glibc == 'glibc217':
  78. command_prefix = ['scl', 'enable', 'devtoolset-6', '--']
  79. cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
  80. # Prepare CMake options needed to configure cuda binaries compilation, 64bit only.
  81. if bits == 64:
  82. cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=ON")
  83. cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=ON")
  84. else:
  85. cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=OFF")
  86. cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
  87. cmake_options += cmake_extra_options
  88. # Make sure no garbage remained from the previous run
  89. if os.path.isdir(install_dir):
  90. shutil.rmtree(install_dir)
  91. for target in targets:
  92. print("Building target %s" % (target))
  93. # Construct build directory name based on the target
  94. target_build_dir = build_dir
  95. target_command_prefix = command_prefix[:]
  96. if target != 'blender':
  97. target_build_dir += '_' + target
  98. target_name = 'install'
  99. # Tweaking CMake options to respect the target
  100. target_cmake_options = cmake_options[:]
  101. # Do extra git fetch because not all platform/git/buildbot combinations
  102. # update the origin remote, causing buildinfo to detect local changes.
  103. os.chdir(blender_dir)
  104. print("Fetching remotes")
  105. command = ['git', 'fetch', '--all']
  106. print(command)
  107. retcode = subprocess.call(target_command_prefix + command)
  108. if retcode != 0:
  109. sys.exit(retcode)
  110. # Make sure build directory exists and enter it
  111. if not os.path.isdir(target_build_dir):
  112. os.mkdir(target_build_dir)
  113. os.chdir(target_build_dir)
  114. # Configure the build
  115. print("CMake options:")
  116. print(target_cmake_options)
  117. if os.path.exists('CMakeCache.txt'):
  118. print("Removing CMake cache")
  119. os.remove('CMakeCache.txt')
  120. # Remove buildinfo files to force buildbot to re-generate them.
  121. for buildinfo in ('buildinfo.h', 'buildinfo.h.txt', ):
  122. full_path = os.path.join('source', 'creator', buildinfo)
  123. if os.path.exists(full_path):
  124. print("Removing {}" . format(buildinfo))
  125. os.remove(full_path)
  126. retcode = subprocess.call(target_command_prefix + ['cmake', blender_dir] + target_cmake_options)
  127. if retcode != 0:
  128. print('Configuration FAILED!')
  129. sys.exit(retcode)
  130. if 'win32' in builder or 'win64' in builder:
  131. command = ['cmake', '--build', '.', '--target', target_name, '--config', 'Release']
  132. else:
  133. command = ['make', '-s', '-j2', target_name]
  134. print("Executing command:")
  135. print(command)
  136. retcode = subprocess.call(target_command_prefix + command)
  137. if retcode != 0:
  138. sys.exit(retcode)
  139. else:
  140. print("Unknown building system")
  141. sys.exit(1)