ab58af577a93e2069588aa9612a125420e9c411d
[blender.git] / build_files / buildbot / slave_compile.py
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
19 # <pep8 compliant>
20
21 import os
22 import subprocess
23 import sys
24 import shutil
25
26 # get builder name
27 if len(sys.argv) < 2:
28     sys.stderr.write("Not enough arguments, expecting builder name\n")
29     sys.exit(1)
30
31 builder = sys.argv[1]
32
33 # we run from build/ directory
34 blender_dir = os.path.join('..', 'blender.git')
35
36 if 'cmake' in builder:
37     # cmake
38
39     # Some fine-tuning configuration
40     blender_dir = os.path.join('..', blender_dir)
41     build_dir = os.path.abspath(os.path.join('..', 'build', builder))
42     install_dir = os.path.abspath(os.path.join('..', 'install', builder))
43     targets = ['blender']
44
45     chroot_name = None  # If not None command will be delegated to that chroot
46     build_cubins = True  # Whether to build Cycles CUDA kernels
47     remove_cache = False  # Remove CMake cache to be sure config is totally up-to-date
48     remove_install_dir = False  # Remove installation folder before building
49
50     # Config file to be used (relative to blender's sources root)
51     cmake_config_file = "build_files/cmake/config/blender_full.cmake"
52     cmake_player_config_file = None
53     cmake_cuda_config_file = None
54
55     # Set build options.
56     cmake_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
57
58     if builder.startswith('mac'):
59         # Set up OSX architecture
60         if builder.endswith('x86_64_cmake'):
61             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
62         elif builder.endswith('i386_cmake'):
63             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=i386')
64         elif builder.endswith('ppc_cmake'):
65             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=ppc')
66
67     elif builder.startswith('win'):
68         install_dir = None
69         if builder.startswith('win64'):
70             cmake_options.append(['-G', '"Visual Studio 12 2013 Win64"'])
71         elif builder.startswith('win32'):
72             cmake_options.append(['-G', '"Visual Studio 12 2013"'])
73             build_cubins = False
74
75     elif builder.startswith('linux'):
76         remove_cache = True
77         remove_install_dir = True
78         cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
79         cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
80         # Currently unused
81         # cmake_cuda_config_file = "build_files/buildbot/config/blender_linux_cuda.cmake"
82         if builder.endswith('x86_64_cmake'):
83             chroot_name = 'buildbot_squeeze_x86_64'
84             build_cubins = True
85             targets = ['player', 'blender']
86         elif builder.endswith('i386_cmake'):
87             chroot_name = 'buildbot_squeeze_i686'
88             build_cubins = False
89             targets = ['player', 'blender']
90
91     cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%d" % (build_cubins))
92
93     if install_dir:
94         cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
95
96     cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
97
98     # Prepare chroot command prefix if needed
99
100     if chroot_name:
101         chroot_prefix = ['schroot', '-c', chroot_name, '--']
102     else:
103         chroot_prefix = []
104
105     # Make sure no garbage remained from the previous run
106     # (only do it if builder requested this)
107     if remove_install_dir:
108         if os.path.isdir(install_dir):
109             shutil.rmtree(install_dir)
110
111     for target in targets:
112         print("Building target %s" % (target))
113         # Construct build directory name based on the target
114         target_build_dir = build_dir
115         if target != 'blender':
116             target_build_dir += '_' + target
117         # Make sure build directory exists and enter it
118         if not os.path.isdir(target_build_dir):
119             os.mkdir(target_build_dir)
120         os.chdir(target_build_dir)
121         # Tweaking CMake options to respect the target
122         target_cmake_options = cmake_options[:]
123         if target == 'player':
124             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
125         elif target == 'cuda':
126             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_cuda_config_file))
127         # Configure the build
128         print("CMake options:")
129         print(target_cmake_options)
130         if remove_cache and os.path.exists('CMakeCache.txt'):
131             print("Removing CMake cache")
132             os.remove('CMakeCache.txt')
133         retcode = subprocess.call(chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
134         if retcode != 0:
135             print('Condifuration FAILED!')
136             sys.exit(retcode)
137
138         if 'win32' in builder:
139             command = ['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release']
140         elif 'win64' in builder:
141             command = ['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']
142         else:
143             command = chroot_prefix + ['make', '-s', '-j2', 'install']
144
145         print("Executing command:")
146         print(command)
147         retcode = subprocess.call(command)
148
149         if retcode != 0:
150             sys.exit(retcode)
151 else:
152     python_bin = 'python'
153
154     # scons
155     os.chdir(blender_dir)
156     scons_cmd = [python_bin, 'scons/scons.py']
157     scons_options = ['BF_FANCY=False']
158
159     # We're using the same rules as release builder, so tweak
160     # build and install dirs
161     build_dir = os.path.join('..', 'build', builder)
162     install_dir = os.path.join('..', 'install', builder)
163
164     # Clean install directory so we'll be sure there's no
165     # residual libs and files remained from the previous install.
166     if os.path.isdir(install_dir):
167         shutil.rmtree(install_dir)
168
169     buildbot_dir = os.path.dirname(os.path.realpath(__file__))
170     config_dir = os.path.join(buildbot_dir, 'config')
171
172     if builder.find('win') != -1:
173         bitness = '32'
174
175         if builder.find('win64') != -1:
176             bitness = '64'
177
178         scons_options.append('BF_INSTALLDIR=' + install_dir)
179         scons_options.append('BF_BUILDDIR=' + build_dir)
180         scons_options.append('BF_BITNESS=' + bitness)
181         scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=True')
182         scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
183         if builder.find('mingw') != -1:
184             scons_options.append('BF_TOOLSET=mingw')
185         if builder.endswith('vc2013'):
186             scons_options.append('MSVS_VERSION=12.0')
187             scons_options.append('MSVC_VERSION=12.0')
188             scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=1')
189             scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
190         scons_options.append('BF_NUMJOBS=1')
191
192     elif builder.find('mac') != -1:
193         if builder.find('x86_64') != -1:
194             config = 'user-config-mac-x86_64.py'
195         else:
196             config = 'user-config-mac-i386.py'
197
198         scons_options.append('BF_CONFIG=' + os.path.join(config_dir, config))
199
200     if builder.find('win') != -1:
201         if not os.path.exists(install_dir):
202             os.makedirs(install_dir)
203         if builder.endswith('vc2013'):
204             dlls = ('msvcp120.dll', 'msvcr120.dll', 'vcomp120.dll')
205         if builder.find('win64') == -1:
206             dlls_path = '..\\..\\..\\redist\\x86'
207         else:
208             dlls_path = '..\\..\\..\\redist\\amd64'
209         for dll in dlls:
210             shutil.copyfile(os.path.join(dlls_path, dll), os.path.join(install_dir, dll))
211
212     retcode = subprocess.call([python_bin, 'scons/scons.py'] + scons_options)
213
214     sys.exit(retcode)