Buildbot: Cleanup unused code
[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 = []
57     cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
58
59     if builder.startswith('mac'):
60         remove_cache = True
61         install_dir = None
62         # Set up OSX architecture
63         if builder.endswith('x86_64_10_6_cmake'):
64             cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
65         elif builder.endswith('i386_10_6_cmake'):
66             build_cubins = False
67             cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=i386')
68             # Some special options to disable usupported features
69             cmake_extra_options.append("-DWITH_CYCLES_OSL=OFF")
70             cmake_extra_options.append("-DWITH_OPENCOLLADA=OFF")
71         elif builder.endswith('ppc_10_6_cmake'):
72             cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=ppc')
73
74     elif builder.startswith('win'):
75         install_dir = None
76         if builder.startswith('win64'):
77             cmake_options.append(['-G', '"Visual Studio 12 2013 Win64"'])
78         elif builder.startswith('win32'):
79             cmake_options.append(['-G', '"Visual Studio 12 2013"'])
80             build_cubins = False
81
82     elif builder.startswith('linux'):
83         remove_cache = True
84         remove_install_dir = True
85         cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
86         cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
87         # Currently unused
88         # cmake_cuda_config_file = "build_files/buildbot/config/blender_linux_cuda.cmake"
89         if builder.endswith('x86_64_cmake'):
90             chroot_name = 'buildbot_squeeze_x86_64'
91             build_cubins = True
92             targets = ['player', 'blender']
93         elif builder.endswith('i386_cmake'):
94             chroot_name = 'buildbot_squeeze_i686'
95             build_cubins = False
96             targets = ['player', 'blender']
97
98     cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
99     cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%d" % (build_cubins))
100
101     if install_dir:
102         cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
103
104     cmake_options += cmake_extra_options
105
106     # Prepare chroot command prefix if needed
107
108     if chroot_name:
109         chroot_prefix = ['schroot', '-c', chroot_name, '--']
110     else:
111         chroot_prefix = []
112
113     # Make sure no garbage remained from the previous run
114     # (only do it if builder requested this)
115     if remove_install_dir:
116         if os.path.isdir(install_dir):
117             shutil.rmtree(install_dir)
118
119     for target in targets:
120         print("Building target %s" % (target))
121         # Construct build directory name based on the target
122         target_build_dir = build_dir
123         if target != 'blender':
124             target_build_dir += '_' + target
125         # Make sure build directory exists and enter it
126         if not os.path.isdir(target_build_dir):
127             os.mkdir(target_build_dir)
128         os.chdir(target_build_dir)
129         # Tweaking CMake options to respect the target
130         target_cmake_options = cmake_options[:]
131         if target == 'player':
132             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
133         elif target == 'cuda':
134             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_cuda_config_file))
135         # Configure the build
136         print("CMake options:")
137         print(target_cmake_options)
138         if remove_cache and os.path.exists('CMakeCache.txt'):
139             print("Removing CMake cache")
140             os.remove('CMakeCache.txt')
141         retcode = subprocess.call(chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
142         if retcode != 0:
143             print('Condifuration FAILED!')
144             sys.exit(retcode)
145
146         if 'win32' in builder:
147             command = ['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release']
148         elif 'win64' in builder:
149             command = ['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']
150         else:
151             command = chroot_prefix + ['make', '-s', '-j2', 'install']
152
153         print("Executing command:")
154         print(command)
155         retcode = subprocess.call(command)
156
157         if retcode != 0:
158             sys.exit(retcode)
159 else:
160     print("Unknown building system")
161     sys.exit(1)