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