ee89bc90225c272193a472dd95c3dead5f8591f7
[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 = '../blender.git'
35
36 if 'cmake' in builder:
37     # cmake
38
39     # set build options
40     cmake_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
41
42     if builder.endswith('mac_x86_64_cmake'):
43         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
44     elif builder.endswith('mac_i386_cmake'):
45         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=i386')
46     elif builder.endswith('mac_ppc_cmake'):
47         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=ppc')
48
49     if 'win64' in builder:
50         cmake_options.append(['-G', '"Visual Studio 12 2013 Win64"'])
51     elif 'win32' in builder:
52         cmake_options.append(['-G', '"Visual Studio 12 2013"'])
53
54     cmake_options.append("-C../blender.git/build_files/cmake/config/blender_full.cmake")
55     if 'win32' not in builder:
56         cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=1")
57     else:
58         cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=0")
59     # configure and make
60     retcode = subprocess.call(['cmake', blender_dir] + cmake_options)
61     if retcode != 0:
62         sys.exit(retcode)
63
64     if 'win32' in builder:
65         retcode = subprocess.call(['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release'])
66     elif 'win64' in builder:
67         retcode = subprocess.call(['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release'])
68     else:
69         retcode = subprocess.call(['make', '-s', '-j4', 'install'])
70     sys.exit(retcode)
71 else:
72     python_bin = 'python'
73     if builder.find('linux') != -1:
74         python_bin = '/opt/lib/python-2.7/bin/python2.7'
75
76     # scons
77     os.chdir(blender_dir)
78     scons_cmd = [python_bin, 'scons/scons.py']
79     scons_options = ['BF_FANCY=False']
80
81     # We're using the same rules as release builder, so tweak
82     # build and install dirs
83     build_dir = os.path.join('..', 'build', builder)
84     install_dir = os.path.join('..', 'install', builder)
85
86     # Clean install directory so we'll be sure there's no
87     # residual libs and files remained from the previous install.
88     if os.path.isdir(install_dir):
89         shutil.rmtree(install_dir)
90
91     buildbot_dir = os.path.dirname(os.path.realpath(__file__))
92     config_dir = os.path.join(buildbot_dir, 'config')
93
94     if builder.find('linux') != -1:
95         configs = []
96         if builder.endswith('linux_glibc211_x86_64_scons'):
97             configs = ['user-config-player-glibc211-x86_64.py',
98                        'user-config-cuda-glibc211-x86_64.py',
99                        'user-config-glibc211-x86_64.py'
100                        ]
101             chroot_name = 'buildbot_squeeze_x86_64'
102             cuda_chroot = 'buildbot_squeeze_x86_64'
103         elif builder.endswith('linux_glibc211_i386_scons'):
104             configs = ['user-config-player-glibc211-i686.py',
105                        'user-config-cuda-glibc211-i686.py',
106                        'user-config-glibc211-i686.py']
107             chroot_name = 'buildbot_squeeze_i686'
108
109             # use 64bit cuda toolkit, so there'll be no memory limit issues
110             cuda_chroot = 'buildbot_squeeze_x86_64'
111
112         # Compilation will happen inside of chroot environment
113         prog_scons_cmd = ['schroot', '-c', chroot_name, '--'] + scons_cmd
114         cuda_scons_cmd = ['schroot', '-c', cuda_chroot, '--'] + scons_cmd
115
116         common_options = ['BF_INSTALLDIR=' + install_dir] + scons_options
117
118         for config in configs:
119             config_fpath = os.path.join(config_dir, config)
120
121             scons_options = []
122
123             if config.find('player') != -1:
124                 scons_options.append('BF_BUILDDIR=%s_player' % (build_dir))
125             elif config.find('cuda') != -1:
126                 scons_options.append('BF_BUILDDIR=%s_cuda' % (build_dir))
127             else:
128                 scons_options.append('BF_BUILDDIR=%s' % (build_dir))
129
130             scons_options += common_options
131
132             if config.find('player') != -1:
133                 scons_options.append('blenderplayer')
134                 cur_scons_cmd = prog_scons_cmd
135             elif config.find('cuda') != -1:
136                 scons_options.append('cudakernels')
137                 cur_scons_cmd = cuda_scons_cmd
138
139                 if config.find('i686') != -1:
140                     scons_options.append('BF_BITNESS=32')
141                 elif config.find('x86_64') != -1:
142                     scons_options.append('BF_BITNESS=64')
143             else:
144                 scons_options.append('blender')
145                 cur_scons_cmd = prog_scons_cmd
146
147             scons_options.append('BF_CONFIG=' + config_fpath)
148
149             retcode = subprocess.call(cur_scons_cmd + scons_options)
150             if retcode != 0:
151                 print('Error building rules with config ' + config)
152                 sys.exit(retcode)
153
154         sys.exit(0)
155     else:
156         if builder.find('win') != -1:
157             bitness = '32'
158
159             if builder.find('win64') != -1:
160                 bitness = '64'
161
162             scons_options.append('BF_INSTALLDIR=' + install_dir)
163             scons_options.append('BF_BUILDDIR=' + build_dir)
164             scons_options.append('BF_BITNESS=' + bitness)
165             scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=True')
166             scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
167             if builder.find('mingw') != -1:
168                 scons_options.append('BF_TOOLSET=mingw')
169             if builder.endswith('vc2013'):
170                 scons_options.append('MSVS_VERSION=12.0')
171                 scons_options.append('MSVC_VERSION=12.0')
172                 scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=1')
173                 scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
174             scons_options.append('BF_NUMJOBS=1')
175
176         elif builder.find('mac') != -1:
177             if builder.find('x86_64') != -1:
178                 config = 'user-config-mac-x86_64.py'
179             else:
180                 config = 'user-config-mac-i386.py'
181
182             scons_options.append('BF_CONFIG=' + os.path.join(config_dir, config))
183
184         if builder.find('win') != -1:
185             if not os.path.exists(install_dir):
186                 os.makedirs(install_dir)
187             if builder.endswith('vc2013'):
188                 dlls = ('msvcp120.dll', 'msvcr120.dll', 'vcomp120.dll')
189             if builder.find('win64') == -1:
190                 dlls_path = '..\\..\\..\\redist\\x86'
191             else:
192                 dlls_path = '..\\..\\..\\redist\\amd64'
193             for dll in dlls:
194                 shutil.copyfile(os.path.join(dlls_path, dll), os.path.join(install_dir, dll))
195
196         retcode = subprocess.call([python_bin, 'scons/scons.py'] + scons_options)
197
198         sys.exit(retcode)