Cleanup: remove unused buildbot code.
[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 = os.path.join('..', 'blender.git')
35
36
37 def parse_header_file(filename, define):
38     import re
39     regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
40     with open(filename, "r") as file:
41         for l in file:
42             match = regex.match(l)
43             if match:
44                 return match.group(1)
45     return None
46
47 if 'cmake' in builder:
48     # cmake
49
50     # Some fine-tuning configuration
51     blender_dir = os.path.abspath(blender_dir)
52     build_dir = os.path.abspath(os.path.join('..', 'build', builder))
53     install_dir = os.path.abspath(os.path.join('..', 'install', builder))
54     targets = ['blender']
55
56     chroot_name = None  # If not None command will be delegated to that chroot
57     build_cubins = True  # Whether to build Cycles CUDA kernels
58     bits = 64
59
60     # Config file to be used (relative to blender's sources root)
61     cmake_config_file = "build_files/cmake/config/blender_release.cmake"
62     cmake_player_config_file = None
63
64     # Set build options.
65     cmake_options = []
66     cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
67
68     if builder.startswith('mac'):
69         # Set up OSX architecture
70         if builder.endswith('x86_64_10_9_cmake'):
71             cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
72         cmake_extra_options.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9')
73
74     elif builder.startswith('win'):
75         if builder.startswith('win64'):
76             cmake_options.extend(['-G', 'Visual Studio 15 2017 Win64'])
77         elif builder.startswith('win32'):
78             bits = 32
79             cmake_options.extend(['-G', 'Visual Studio 15 2017'])
80
81     elif builder.startswith('linux'):
82         tokens = builder.split("_")
83         glibc = tokens[1]
84         if glibc == 'glibc224':
85             deb_name = "stretch"
86         elif glibc == 'glibc219':
87             deb_name = "jessie"
88         elif glibc == 'glibc211':
89             deb_name = "squeeze"
90         cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
91         cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
92         if builder.endswith('x86_64_cmake'):
93             chroot_name = 'buildbot_' + deb_name + '_x86_64'
94             targets = ['player', 'blender']
95         elif builder.endswith('i686_cmake'):
96             bits = 32
97             chroot_name = 'buildbot_' + deb_name + '_i686'
98             targets = ['player', 'blender']
99         if deb_name != "stretch":
100             cmake_extra_options.extend(["-DCMAKE_C_COMPILER=/usr/bin/gcc-7",
101                                         "-DCMAKE_CXX_COMPILER=/usr/bin/g++-7"])
102
103     cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
104
105     # Prepare CMake options needed to configure cuda binaries compilation, 64bit only.
106     if bits == 64 and build_cubins:
107         cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=ON")
108         cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=ON")
109     else:
110         cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=OFF")
111
112     cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
113
114     cmake_options += cmake_extra_options
115
116     # Prepare chroot command prefix if needed
117     if chroot_name:
118         chroot_prefix = ['schroot', '-c', chroot_name, '--']
119     else:
120         chroot_prefix = []
121
122     # Make sure no garbage remained from the previous run
123     if os.path.isdir(install_dir):
124         shutil.rmtree(install_dir)
125
126     for target in targets:
127         print("Building target %s" % (target))
128         # Construct build directory name based on the target
129         target_build_dir = build_dir
130         target_chroot_prefix = chroot_prefix[:]
131         if target != 'blender':
132             target_build_dir += '_' + target
133         target_name = 'install'
134         # Tweaking CMake options to respect the target
135         target_cmake_options = cmake_options[:]
136         if target == 'player':
137             target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
138         # Do extra git fetch because not all platform/git/buildbot combinations
139         # update the origin remote, causing buildinfo to detect local changes.
140         os.chdir(blender_dir)
141         print("Fetching remotes")
142         command = ['git', 'fetch', '--all']
143         print(command)
144         retcode = subprocess.call(target_chroot_prefix + command)
145         if retcode != 0:
146             sys.exit(retcode)
147         # Make sure build directory exists and enter it
148         if not os.path.isdir(target_build_dir):
149             os.mkdir(target_build_dir)
150         os.chdir(target_build_dir)
151         # Configure the build
152         print("CMake options:")
153         print(target_cmake_options)
154         if os.path.exists('CMakeCache.txt'):
155             print("Removing CMake cache")
156             os.remove('CMakeCache.txt')
157         retcode = subprocess.call(target_chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
158         if retcode != 0:
159             print('Configuration FAILED!')
160             sys.exit(retcode)
161
162         if 'win32' in builder or 'win64' in builder:
163             command = ['cmake', '--build', '.', '--target', target_name, '--config', 'Release']
164         else:
165             command = ['make', '-s', '-j2', target_name]
166
167         print("Executing command:")
168         print(command)
169         retcode = subprocess.call(target_chroot_prefix + command)
170
171         if retcode != 0:
172             sys.exit(retcode)
173
174 else:
175     print("Unknown building system")
176     sys.exit(1)