2011-03-22 13:05:05 +00:00
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
2011-03-27 05:23:14 +00:00
# <pep8 compliant>
2011-03-22 13:05:05 +00:00
import os
import subprocess
import sys
2013-03-11 09:11:46 +00:00
import shutil
2011-03-22 13:05:05 +00:00
# get builder name
if len ( sys . argv ) < 2 :
sys . stderr . write ( " Not enough arguments, expecting builder name \n " )
sys . exit ( 1 )
builder = sys . argv [ 1 ]
# we run from build/ directory
2015-12-02 18:09:06 +05:00
blender_dir = os . path . join ( ' .. ' , ' blender.git ' )
2011-03-22 13:05:05 +00:00
2016-02-15 19:12:46 +01:00
def parse_header_file ( filename , define ) :
import re
regex = re . compile ( " ^# \ s*define \ s+ %s \ s+(.*) " % define )
with open ( filename , " r " ) as file :
for l in file :
match = regex . match ( l )
if match :
return match . group ( 1 )
return None
2014-11-11 11:22:49 +01:00
if ' cmake ' in builder :
2011-03-22 13:05:05 +00:00
# cmake
2015-12-02 18:09:06 +05:00
# Some fine-tuning configuration
blender_dir = os . path . join ( ' .. ' , blender_dir )
build_dir = os . path . abspath ( os . path . join ( ' .. ' , ' build ' , builder ) )
install_dir = os . path . abspath ( os . path . join ( ' .. ' , ' install ' , builder ) )
targets = [ ' blender ' ]
chroot_name = None # If not None command will be delegated to that chroot
2016-02-15 19:12:46 +01:00
cuda_chroot_name = None # If not None cuda compilationcommand will be delegated to that chroot
2015-12-02 18:09:06 +05:00
build_cubins = True # Whether to build Cycles CUDA kernels
2016-02-15 19:12:46 +01:00
bits = 64
2015-12-02 18:09:06 +05:00
# Config file to be used (relative to blender's sources root)
cmake_config_file = " build_files/cmake/config/blender_full.cmake "
cmake_player_config_file = None
cmake_cuda_config_file = None
# Set build options.
2015-12-20 15:32:59 +05:00
cmake_options = [ ]
cmake_extra_options = [ ' -DCMAKE_BUILD_TYPE:STRING=Release ' ]
2016-02-15 19:12:46 +01:00
cuda_cmake_options = [ ]
2011-03-22 13:05:05 +00:00
2015-12-02 18:09:06 +05:00
if builder . startswith ( ' mac ' ) :
# Set up OSX architecture
2015-12-20 14:12:43 +05:00
if builder . endswith ( ' x86_64_10_6_cmake ' ) :
2015-12-20 15:32:59 +05:00
cmake_extra_options . append ( ' -DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 ' )
2016-03-29 19:46:10 +02:00
cmake_extra_options . append ( ' -DCUDA_NVCC_EXECUTABLE=/usr/local/cuda-hack/bin/nvcc ' )
2015-12-02 18:09:06 +05:00
elif builder . startswith ( ' win ' ) :
2016-05-31 15:27:07 +02:00
if builder . endswith ( ' _vc2015 ' ) :
2016-05-31 14:42:18 +02:00
if builder . startswith ( ' win64 ' ) :
2016-06-04 12:36:21 +02:00
cmake_options . extend ( [ ' -G ' , ' Visual Studio 14 2015 Win64 ' , b ' -DCUDA_NVCC_FLAGS= " -ccbin \\ " C: \\ Program Files (x86) \\ Microsoft Visual Studio 12.0 \\ VC \\ bin \\ amd64 \\ " " ' ] )
2016-05-31 14:42:18 +02:00
elif builder . startswith ( ' win32 ' ) :
bits = 32
2016-06-04 12:36:21 +02:00
cmake_options . extend ( [ ' -G ' , ' Visual Studio 14 2015 ' , b ' -DCUDA_NVCC_FLAGS= " -ccbin \\ " C: \\ Program Files (x86) \\ Microsoft Visual Studio 12.0 \\ VC \\ bin \\ " " ' ] )
2016-05-31 14:42:18 +02:00
else :
2015-12-02 18:18:58 +05:00
if builder . startswith ( ' win64 ' ) :
2016-05-31 15:27:07 +02:00
cmake_options . extend ( [ ' -G ' , ' Visual Studio 12 2013 Win64 ' ] )
2015-12-02 18:09:06 +05:00
elif builder . startswith ( ' win32 ' ) :
2016-02-15 19:12:46 +01:00
bits = 32
2016-05-31 15:27:07 +02:00
cmake_options . extend ( [ ' -G ' , ' Visual Studio 12 2013 ' ] )
2015-12-02 18:09:06 +05:00
elif builder . startswith ( ' linux ' ) :
2016-02-27 13:09:12 +01:00
tokens = builder . split ( " _ " )
glibc = tokens [ 1 ]
if glibc == ' glibc219 ' :
deb_name = " jessie "
elif glibc == ' glibc211 ' :
deb_name = " squeeze "
2015-12-02 18:09:06 +05:00
cmake_config_file = " build_files/buildbot/config/blender_linux.cmake "
2015-12-03 22:24:27 +05:00
cmake_player_config_file = " build_files/buildbot/config/blender_linux_player.cmake "
2015-12-02 18:09:06 +05:00
if builder . endswith ( ' x86_64_cmake ' ) :
2016-02-27 13:09:12 +01:00
chroot_name = ' buildbot_ ' + deb_name + ' _x86_64 '
2015-12-02 18:09:06 +05:00
targets = [ ' player ' , ' blender ' ]
2016-02-27 14:05:40 +01:00
elif builder . endswith ( ' i686_cmake ' ) :
2016-02-15 19:12:46 +01:00
bits = 32
2016-02-27 13:09:12 +01:00
chroot_name = ' buildbot_ ' + deb_name + ' _i686 '
cuda_chroot_name = ' buildbot_ ' + deb_name + ' _x86_64 '
2016-02-15 19:12:46 +01:00
targets = [ ' player ' , ' blender ' , ' cuda ' ]
2015-12-02 18:09:06 +05:00
2015-12-20 15:32:59 +05:00
cmake_options . append ( " -C " + os . path . join ( blender_dir , cmake_config_file ) )
2016-02-15 19:12:46 +01:00
# Prepare CMake options needed to configure cuda binaries compilation.
cuda_cmake_options . append ( " -DWITH_CYCLES_CUDA_BINARIES= %s " % ( ' ON ' if build_cubins else ' OFF ' ) )
if build_cubins or ' cuda ' in targets :
if bits == 32 :
cuda_cmake_options . append ( " -DCUDA_64_BIT_DEVICE_CODE=OFF " )
else :
cuda_cmake_options . append ( " -DCUDA_64_BIT_DEVICE_CODE=ON " )
# Only modify common cmake options if cuda doesn't require separate target.
if ' cuda ' not in targets :
cmake_options + = cuda_cmake_options
2015-12-02 18:09:06 +05:00
2016-05-09 17:29:31 +02:00
cmake_options . append ( " -DCMAKE_INSTALL_PREFIX= %s " % ( install_dir ) )
2015-12-02 18:09:06 +05:00
2015-12-20 15:32:59 +05:00
cmake_options + = cmake_extra_options
2015-12-02 18:09:06 +05:00
# Prepare chroot command prefix if needed
if chroot_name :
chroot_prefix = [ ' schroot ' , ' -c ' , chroot_name , ' -- ' ]
2014-11-11 11:22:49 +01:00
else :
2015-12-02 18:09:06 +05:00
chroot_prefix = [ ]
2016-02-15 19:12:46 +01:00
if cuda_chroot_name :
cuda_chroot_prefix = [ ' schroot ' , ' -c ' , cuda_chroot_name , ' -- ' ]
else :
cuda_chroot_prefix = chroot_prefix [ : ]
2015-12-02 18:09:06 +05:00
# Make sure no garbage remained from the previous run
2016-05-09 17:29:31 +02:00
if os . path . isdir ( install_dir ) :
shutil . rmtree ( install_dir )
2015-12-02 18:09:06 +05:00
for target in targets :
print ( " Building target %s " % ( target ) )
# Construct build directory name based on the target
target_build_dir = build_dir
2016-02-15 19:12:46 +01:00
target_chroot_prefix = chroot_prefix [ : ]
2015-12-02 18:09:06 +05:00
if target != ' blender ' :
target_build_dir + = ' _ ' + target
2016-02-15 19:12:46 +01:00
target_name = ' install '
2015-12-02 18:09:06 +05:00
# Make sure build directory exists and enter it
if not os . path . isdir ( target_build_dir ) :
os . mkdir ( target_build_dir )
os . chdir ( target_build_dir )
# Tweaking CMake options to respect the target
target_cmake_options = cmake_options [ : ]
if target == ' player ' :
target_cmake_options . append ( " -C " + os . path . join ( blender_dir , cmake_player_config_file ) )
elif target == ' cuda ' :
2016-02-15 19:12:46 +01:00
target_cmake_options + = cuda_cmake_options
target_chroot_prefix = cuda_chroot_prefix [ : ]
target_name = ' cycles_kernel_cuda '
# If cuda binaries are compiled as a separate target, make sure
# other targets don't compile cuda binaries.
if ' cuda ' in targets and target != ' cuda ' :
target_cmake_options . append ( " -DWITH_CYCLES_CUDA_BINARIES=OFF " )
2015-12-02 18:09:06 +05:00
# Configure the build
print ( " CMake options: " )
print ( target_cmake_options )
2016-02-17 15:29:13 +01:00
if os . path . exists ( ' CMakeCache.txt ' ) :
print ( " Removing CMake cache " )
os . remove ( ' CMakeCache.txt ' )
2016-02-15 19:12:46 +01:00
retcode = subprocess . call ( target_chroot_prefix + [ ' cmake ' , blender_dir ] + target_cmake_options )
2015-12-02 18:09:06 +05:00
if retcode != 0 :
print ( ' Condifuration FAILED! ' )
sys . exit ( retcode )
if ' win32 ' in builder :
command = [ ' msbuild ' , ' INSTALL.vcxproj ' , ' /Property:PlatformToolset=v120_xp ' , ' /p:Configuration=Release ' ]
elif ' win64 ' in builder :
command = [ ' msbuild ' , ' INSTALL.vcxproj ' , ' /p:Configuration=Release ' ]
else :
2016-02-15 19:12:46 +01:00
command = target_chroot_prefix + [ ' make ' , ' -s ' , ' -j2 ' , target_name ]
2015-12-02 18:09:06 +05:00
print ( " Executing command: " )
print ( command )
retcode = subprocess . call ( command )
if retcode != 0 :
sys . exit ( retcode )
2016-02-15 19:12:46 +01:00
if builder . startswith ( ' linux ' ) and target == ' cuda ' :
2016-04-24 22:42:41 +10:00
blender_h = os . path . join ( blender_dir , " source " , " blender " , " blenkernel " , " BKE_blender_version.h " )
2016-02-15 19:12:46 +01:00
blender_version = int ( parse_header_file ( blender_h , ' BLENDER_VERSION ' ) )
blender_version = " %d . %d " % ( blender_version / / 100 , blender_version % 100 )
kernels = os . path . join ( target_build_dir , ' intern ' , ' cycles ' , ' kernel ' )
install_kernels = os . path . join ( install_dir , blender_version , ' scripts ' , ' addons ' , ' cycles ' , ' lib ' )
os . mkdir ( install_kernels )
print ( " Copying cuda binaries from %s to %s " % ( kernels , install_kernels ) )
os . system ( ' cp %s /*.cubin %s ' % ( kernels , install_kernels ) )
2011-03-22 13:05:05 +00:00
else :
2015-12-20 15:44:53 +05:00
print ( " Unknown building system " )
sys . exit ( 1 )