fd3ff1fbee74b794029c2a918c6ebe9ac49a8a6c
[blender.git] / build_files / buildbot / slave_pack.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 # Runs on buildbot slave, creating a release package using the build
22 # system and zipping it into buildbot_upload.zip. This is then uploaded
23 # to the master in the next buildbot step.
24
25 import os
26 import subprocess
27 import sys
28 import zipfile
29
30 # get builder name
31 if len(sys.argv) < 2:
32     sys.stderr.write("Not enough arguments, expecting builder name\n")
33     sys.exit(1)
34
35 builder = sys.argv[1]
36 branch = ''
37
38 if len(sys.argv) >= 3:
39     branch = sys.argv[2]
40
41 # scons does own packaging
42 if builder.find('scons') != -1:
43     os.chdir('../blender')
44     scons_options = ['BF_QUICK=slnt', 'BUILDBOT_BRANCH=' + branch, 'buildslave']
45
46     if builder.find('linux') != -1:
47         buildbot_dir = os.path.dirname(os.path.realpath(__file__))
48         config_dir = os.path.join(buildbot_dir, 'config')
49         build_dir = os.path.join('..', 'build', builder)
50         install_dir = os.path.join('..', 'install', builder)
51
52         scons_options += ['WITH_BF_NOBLENDER=True', 'WITH_BF_PLAYER=False',
53             'BF_BUILDDIR=' + build_dir,
54             'BF_INSTALLDIR=' + install_dir,
55             'WITHOUT_BF_INSTALL=True']
56
57         config = None
58
59         if builder.endswith('linux_x86_64_scons'):
60             config = 'user-config-x86_64.py'
61         elif builder.endswith('linux_i386_scons'):
62             config = 'user-config-x86_64.py'
63
64         if config is not None:
65             config_fpath = os.path.join(config_dir, config)
66             scons_options.append('BF_CONFIG=' + config_fpath)
67
68         blender = os.path.join(install_dir, 'blender')
69         blenderplayer = os.path.join(install_dir, 'blenderplayer')
70         subprocess.call(['strip', '--strip-all', blender, blenderplayer])
71
72         retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
73         sys.exit(retcode)
74     else:
75         # Switch to new FFmpeg library
76         if builder.find('win') != -1:
77             if builder.find('win32') != -1:
78                 LCGDIR = '#../lib/windows'
79             elif builder.find('win64') != -1:
80                 LCGDIR = '#../lib/win64'
81
82             all_ffmpeg_libs = ['avcodec-53',
83                                'avdevice-53',
84                                'avformat-53',
85                                'avutil-51',
86                                'swscale-2']
87
88             ffmpeg_lib = []
89             ffmpeg_dll = []
90
91             for lib in all_ffmpeg_libs:
92                 ffmpeg_lib.append(lib + '.lib')
93                 ffmpeg_dll.append('${BF_FFMPEG_LIBPATH}/' + lib + '.dll')
94
95             scons_options.append('BF_FFMPEG=' + LCGDIR + '/ffmpeg-0.8')
96             scons_options.append('BF_FFMPEG_LIB=' + (' '.join(ffmpeg_lib)))
97             scons_options.append('BF_FFMPEG_DLL=' + (' '.join(ffmpeg_dll)))
98
99         retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
100         sys.exit(retcode)
101
102 # clean release directory if it already exists
103 dir = 'release'
104
105 if os.path.exists(dir):
106     for f in os.listdir(dir):
107         if os.path.isfile(os.path.join(dir, f)):
108             os.remove(os.path.join(dir, f))
109
110 # create release package
111 try:
112     subprocess.call(['make', 'package_archive'])
113 except Exception, ex:
114     sys.stderr.write('Make package release failed' + str(ex) + '\n')
115     sys.exit(1)
116
117 # find release directory, must exist this time
118 if not os.path.exists(dir):
119     sys.stderr.write("Failed to find release directory.\n")
120     sys.exit(1)
121
122 # find release package
123 file = None
124 filepath = None
125
126 for f in os.listdir(dir):
127     rf = os.path.join(dir, f)
128     if os.path.isfile(rf) and f.startswith('blender'):
129         file = f
130         filepath = rf
131
132 if not file:
133     sys.stderr.write("Failed to find release package.\n")
134     sys.exit(1)
135
136 # create zip file
137 try:
138     upload_zip = "buildbot_upload.zip"
139     if os.path.exists(upload_zip):
140         os.remove(upload_zip)
141     z = zipfile.ZipFile(upload_zip, "w", compression=zipfile.ZIP_STORED)
142     z.write(filepath, arcname=file)
143     z.close()
144 except Exception, ex:
145     sys.stderr.write('Create buildbot_upload.zip failed' + str(ex) + '\n')
146     sys.exit(1)