Further tweaks to buildbot
[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
25 # get builder name
26 if len(sys.argv) < 2:
27     sys.stderr.write("Not enough arguments, expecting builder name\n")
28     sys.exit(1)
29
30 builder = sys.argv[1]
31
32 # we run from build/ directory
33 blender_dir = '../blender'
34
35 if builder.find('cmake') != -1:
36     # cmake
37
38     # set build options
39     cmake_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
40
41     if builder.endswith('mac_x86_64_cmake'):
42         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
43     elif builder.endswith('mac_i386_cmake'):
44         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=i386')
45     elif builder.endswith('mac_ppc_cmake'):
46         cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=ppc')
47
48     # configure and make
49     retcode = subprocess.call(['cmake', blender_dir] + cmake_options)
50     if retcode != 0:
51         sys.exit(retcode)
52     retcode = subprocess.call(['make', '-s', '-j4', 'install'])
53     sys.exit(retcode)
54 else:
55     # scons
56     os.chdir(blender_dir)
57     scons_cmd = ['python', 'scons/scons.py']
58     scons_options = ['BF_FANCY=False']
59
60     if builder.find('linux') != -1:
61         import shutil
62
63         configs = []
64         if builder.endswith('linux_glibc211_x86_64_scons'):
65             configs = ['user-config-player-glibc211-x86_64.py',
66                        'user-config-cuda-glibc211-x86_64.py',
67                        'user-config-glibc211-x86_64.py'
68                        ]
69             chroot_name = 'buildbot_squeeze_x86_64'
70             cuda_chroot = 'buildbot_squeeze_x86_64'
71         elif builder.endswith('linux_glibc211_i386_scons'):
72             configs = ['user-config-player-glibc211-i686.py',
73                        'user-config-cuda-glibc211-i686.py',
74                        'user-config-glibc211-i686.py']
75             chroot_name = 'buildbot_squeeze_i686'
76
77             # use 64bit cuda toolkit, so there'll be no memory limit issues
78             cuda_chroot = 'buildbot_squeeze_x86_64'
79
80         # Compilation will happen inside of chroot environment
81         prog_scons_cmd = ['schroot', '-c', chroot_name, '--'] + scons_cmd
82         cuda_scons_cmd = ['schroot', '-c', cuda_chroot, '--'] + scons_cmd
83
84         # We're using the same rules as release builder, so tweak
85         # build and install dirs
86         build_dir = os.path.join('..', 'build', builder)
87         install_dir = os.path.join('..', 'install', builder)
88
89         common_options = ['BF_INSTALLDIR=' + install_dir] + scons_options
90
91         # Clean install directory so we'll be sure there's no
92         if os.path.isdir(install_dir):
93             shutil.rmtree(install_dir)
94
95         buildbot_dir = os.path.dirname(os.path.realpath(__file__))
96         config_dir = os.path.join(buildbot_dir, 'config')
97
98         for config in configs:
99             config_fpath = os.path.join(config_dir, config)
100
101             scons_options = []
102
103             if config.find('player') != -1:
104                 scons_options.append('BF_BUILDDIR=%s_player' % (build_dir))
105             else:
106                 scons_options.append('BF_BUILDDIR=%s' % (build_dir))
107
108             scons_options += common_options
109
110             if config.find('player') != -1:
111                 scons_options.append('blenderplayer')
112                 cur_scons_cmd = prog_scons_cmd
113             elif config.find('cuda') != -1:
114                 scons_options.append('cudakernels')
115                 cur_scons_cmd = cuda_scons_cmd
116
117                 if config.find('i686') != -1:
118                     scons_options.append('BF_BITNESS=32')
119                 elif config.find('x86_64') != -1:
120                     scons_options.append('BF_BITNESS=64')
121             else:
122                 scons_options.append('blender')
123                 cur_scons_cmd = prog_scons_cmd
124
125             scons_options.append('BF_CONFIG=' + config_fpath)
126
127             retcode = subprocess.call(cur_scons_cmd + scons_options)
128             if retcode != 0:
129                 print('Error building rules wuth config ' + config)
130                 sys.exit(retcode)
131
132         sys.exit(0)
133     else:
134         if builder.find('win') != -1:
135             bitness = '32'
136
137             if builder.find('win64') != -1:
138                 bitness = '64'
139
140             scons_options.append('BF_BITNESS=' + bitness)
141             scons_options.append('WITH_BF_CYCLES_CUDA_BINARIES=True')
142             scons_options.append('BF_CYCLES_CUDA_NVCC=nvcc.exe')
143             if builder.find('mingw') != -1:
144                 scons_options.append('BF_TOOLSET=mingw')
145
146         retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
147         sys.exit(retcode)