ff7fb873835ac219e23fe7f38f71f90d7b32dcbc
[blender-staging.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         remove_cache = True
60         install_dir = None
61         # Set up OSX architecture
62         if builder.endswith('x86_64_10_6_cmake'):
63             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
64         elif builder.endswith('i386_10_6_cmake'):
65             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=i386')
66             # Some special options to disable usupported features
67             cmake_options.append("-DWITH_CYCLES_OSL=OFF")
68             cmake_options.append("-DWITH_OPENCOLLADA=OFF")
69         elif builder.endswith('ppc_10_6_cmake'):
70             cmake_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=ppc')
71
72     elif builder.startswith('win'):
73         install_dir = None
74         if builder.startswith('win64'):
75             cmake_options.append(['-G', '"Visual Studio 12 2013 Win64"'])
76         elif builder.startswith('win32'):
77             cmake_options.append(['-G', '"Visual Studio 12 2013"'])
78             build_cubins = False
79
80     elif builder.startswith('linux'):
81         remove_cache = True
82         remove_install_dir = True
83         cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
84         cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
85         # Currently unused
86         # cmake_cuda_config_file = "build_files/buildbot/config/blender_linux_cuda.cmake"
87         if builder.endswith('x86_64_cmake'):
88             chroot_name = 'buildbot_squeeze_x86_64'
89             build_cubins = True
90             targets = ['player', 'blender']
91         elif builder.endswith('i386_cmake'):
92             chroot_name = 'buildbot_squeeze_i686'
93             build_cubins = False
94             targets = ['player', 'blender']
95
96     cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%d" % (build_cubins))
97
98     if install_dir:
99         cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
100
101     cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
102
103     # Prepare chroot command prefix if needed
104
105     if chroot_name:
106         chroot_prefix = ['schroot', '-c', chroot_name, '--']
107     else:
108         chroot_prefix = []
109
110     # Make sure no garbage remained from the previous run
111     # (only do it if builder requested this)
112     if remove_install_dir:
113         if os.path.isdir(install_dir):
114             shutil.rmtree(install_dir)
115
116     for target in targets:
117         print("Building target %s" % (target))
118         # Construct build directory name based on the target
119         target_build_dir = build_dir
120         if target != 'blender':
121             target_build_dir += '_' + target
122         # Make sure build directory exists and enter it
123         if not os.path.isdir(target_build_dir):
124             os.mkdir(target_build_dir)
125         os.chdir(target_build_dir)
126         # Tweaking CMake options to respect the target
127         target_cmake_options = cmake_options[:]
128         if target == 'player':
129             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
130         elif target == 'cuda':
131             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_cuda_config_file))
132         # Configure the build
133         print("CMake options:")
134         print(target_cmake_options)
135         if remove_cache and os.path.exists('CMakeCache.txt'):
136             print("Removing CMake cache")
137             os.remove('CMakeCache.txt')
138         retcode = subprocess.call(chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
139         if retcode != 0:
140             print('Condifuration FAILED!')
141             sys.exit(retcode)
142
143         if 'win32' in builder:
144             command = ['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release']
145         elif 'win64' in builder:
146             command = ['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']
147         else:
148             command = chroot_prefix + ['make', '-s', '-j2', 'install']
149
150         print("Executing command:")
151         print(command)
152         retcode = subprocess.call(command)
153
154         if retcode != 0:
155             sys.exit(retcode)
156 else:
157     python_bin = 'python'
158
159     # scons
160     os.chdir(blender_dir)
161     scons_cmd = [python_bin, 'scons/scons.py']
162     scons_options = ['BF_FANCY=False']
163
164     # We're using the same rules as release builder, so tweak
165     # build and install dirs
166     build_dir = os.path.join('..', 'build', builder)
167     install_dir = os.path.join('..', 'install', builder)
168
169     # Clean install directory so we'll be sure there's no
170     # residual libs and files remained from the previous install.
171     if os.path.isdir(install_dir):
172         shutil.rmtree(install_dir)
173
174     buildbot_dir = os.path.dirname(os.path.realpath(__file__))
175     config_dir = os.path.join(buildbot_dir, 'config')
176
177     if builder.find('mac') != -1:
178         if builder.find('x86_64') != -1:
179             config = 'user-config-mac-x86_64.py'
180         else:
181             config = 'user-config-mac-i386.py'
182
183         scons_options.append('BF_CONFIG=' + os.path.join(config_dir, config))
184
185     retcode = subprocess.call([python_bin, 'scons/scons.py'] + scons_options)
186
187     sys.exit(retcode)