Buildbot: attempt to solve packing on windows
[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_player_linux.cmake"
80         cmake_cuda_config_file = "build_files/buildbot/config/blender_cuda_linux.cmake"
81         if builder.endswith('x86_64_cmake'):
82             chroot_name = 'buildbot_squeeze_x86_64'
83             build_cubins = False
84             targets = ['player', 'blender']
85         elif builder.endswith('i386_cmake'):
86             chroot_name = 'buildbot_squeeze_i686'
87             build_cubins = False
88             targets = ['player', 'blender']
89
90     cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%d" % (build_cubins))
91
92     if install_dir:
93         cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
94
95     cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
96
97     # Prepare chroot command prefix if needed
98
99     if chroot_name:
100         chroot_prefix = ['schroot', '-c', chroot_name, '--']
101     else:
102         chroot_prefix = []
103
104     # Make sure no garbage remained from the previous run
105     # (only do it if builder requested this)
106     if remove_install_dir:
107         if os.path.isdir(install_dir):
108             shutil.rmtree(install_dir)
109
110     for target in targets:
111         print("Building target %s" % (target))
112         # Construct build directory name based on the target
113         target_build_dir = build_dir
114         if target != 'blender':
115             target_build_dir += '_' + target
116         # Make sure build directory exists and enter it
117         if not os.path.isdir(target_build_dir):
118             os.mkdir(target_build_dir)
119         os.chdir(target_build_dir)
120         # Tweaking CMake options to respect the target
121         target_cmake_options = cmake_options[:]
122         if target == 'player':
123             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
124         elif target == 'cuda':
125             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_cuda_config_file))
126         # Configure the build
127         print("CMake options:")
128         print(target_cmake_options)
129         if remove_cache and os.path.exists('CMakeCache.txt'):
130             print("Removing CMake cache")
131             os.remove('CMakeCache.txt')
132         retcode = subprocess.call(chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
133         if retcode != 0:
134             print('Condifuration FAILED!')
135             sys.exit(retcode)
136
137         if 'win32' in builder:
138             command = ['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release']
139         elif 'win64' in builder:
140             command = ['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']
141         else:
142             command = chroot_prefix + ['make', '-s', '-j2', 'install']
143
144         print("Executing command:")
145         print(command)
146         retcode = subprocess.call(command)
147
148         if retcode != 0:
149             sys.exit(retcode)
150 else:
151     python_bin = 'python'
152     if builder.find('linux') != -1:
153         python_bin = '/opt/lib/python-2.7/bin/python2.7'
154
155     # scons
156     os.chdir(blender_dir)
157     scons_cmd = [python_bin, 'scons/scons.py']
158     scons_options = ['BF_FANCY=False']
159
160     # We're using the same rules as release builder, so tweak
161     # build and install dirs
162     build_dir = os.path.join('..', 'build', builder)
163     install_dir = os.path.join('..', 'install', builder)
164
165     # Clean install directory so we'll be sure there's no
166     # residual libs and files remained from the previous install.
167     if os.path.isdir(install_dir):
168         shutil.rmtree(install_dir)
169
170     buildbot_dir = os.path.dirname(os.path.realpath(__file__))
171     config_dir = os.path.join(buildbot_dir, 'config')
172
173     if builder.find('linux') != -1:
174         configs = []
175         if builder.endswith('linux_glibc211_x86_64_scons'):
176             configs = ['user-config-player-glibc211-x86_64.py',
177                        'user-config-cuda-glibc211-x86_64.py',
178                        'user-config-glibc211-x86_64.py'
179                        ]
180             chroot_name = 'buildbot_squeeze_x86_64'
181             cuda_chroot = 'buildbot_squeeze_x86_64'
182         elif builder.endswith('linux_glibc211_i386_scons'):
183             configs = ['user-config-player-glibc211-i686.py',
184                        'user-config-cuda-glibc211-i686.py',
185                        'user-config-glibc211-i686.py']
186             chroot_name = 'buildbot_squeeze_i686'
187
188             # use 64bit cuda toolkit, so there'll be no memory limit issues
189             cuda_chroot = 'buildbot_squeeze_x86_64'
190
191         # Compilation will happen inside of chroot environment
192         prog_scons_cmd = ['schroot', '-c', chroot_name, '--'] + scons_cmd
193         cuda_scons_cmd = ['schroot', '-c', cuda_chroot, '--'] + scons_cmd
194
195         common_options = ['BF_INSTALLDIR=' + install_dir] + scons_options
196
197         for config in configs:
198             config_fpath = os.path.join(config_dir, config)
199
200             scons_options = []
201
202             if config.find('player') != -1:
203                 scons_options.append('BF_BUILDDIR=%s_player' % (build_dir))
204             elif config.find('cuda') != -1:
205                 scons_options.append('BF_BUILDDIR=%s_cuda' % (build_dir))
206             else:
207                 scons_options.append('BF_BUILDDIR=%s' % (build_dir))
208
209             scons_options += common_options
210
211             if config.find('player') != -1:
212                 scons_options.append('blenderplayer')
213                 cur_scons_cmd = prog_scons_cmd
214             elif config.find('cuda') != -1:
215                 scons_options.append('cudakernels')
216                 cur_scons_cmd = cuda_scons_cmd
217
218                 if config.find('i686') != -1:
219                     scons_options.append('BF_BITNESS=32')
220                 elif config.find('x86_64') != -1:
221                     scons_options.append('BF_BITNESS=64')
222             else:
223                 scons_options.append('blender')
224                 cur_scons_cmd = prog_scons_cmd
225
226             scons_options.append('BF_CONFIG=' + config_fpath)
227
228             retcode = subprocess.call(cur_scons_cmd + scons_options)
229             if retcode != 0:
230                 print('Error building rules with config ' + config)
231                 sys.exit(retcode)
232
233         sys.exit(0)
234     else:
235         if builder.find('win') != -1:
236             bitness = '32'
237
238             if builder.find('win64') != -1:
239                 bitness = '64'
240
241             scons_options.append('BF_INSTALLDIR=' + install_dir)
242             scons_options.append('BF_BUILDDIR=' + build_dir)
243             scons_options.append('BF_BITNESS=' + bitness)
244             scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=True')
245             scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
246             if builder.find('mingw') != -1:
247                 scons_options.append('BF_TOOLSET=mingw')
248             if builder.endswith('vc2013'):
249                 scons_options.append('MSVS_VERSION=12.0')
250                 scons_options.append('MSVC_VERSION=12.0')
251                 scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=1')
252                 scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
253             scons_options.append('BF_NUMJOBS=1')
254
255         elif builder.find('mac') != -1:
256             if builder.find('x86_64') != -1:
257                 config = 'user-config-mac-x86_64.py'
258             else:
259                 config = 'user-config-mac-i386.py'
260
261             scons_options.append('BF_CONFIG=' + os.path.join(config_dir, config))
262
263         if builder.find('win') != -1:
264             if not os.path.exists(install_dir):
265                 os.makedirs(install_dir)
266             if builder.endswith('vc2013'):
267                 dlls = ('msvcp120.dll', 'msvcr120.dll', 'vcomp120.dll')
268             if builder.find('win64') == -1:
269                 dlls_path = '..\\..\\..\\redist\\x86'
270             else:
271                 dlls_path = '..\\..\\..\\redist\\amd64'
272             for dll in dlls:
273                 shutil.copyfile(os.path.join(dlls_path, dll), os.path.join(install_dir, dll))
274
275         retcode = subprocess.call([python_bin, 'scons/scons.py'] + scons_options)
276
277         sys.exit(retcode)