Merged changes in the trunk up to revision 39368.
[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         bitness = '32'
76         # Switch to new FFmpeg library
77         if builder.find('win') != -1:
78             if builder.find('win32') != -1:
79                 LCGDIR = '#../lib/windows'
80             elif builder.find('win64') != -1:
81                 LCGDIR = '#../lib/win64'
82                 bitness = '64'
83
84             all_ffmpeg_libs = ['avcodec-53',
85                                'avdevice-53',
86                                'avformat-53',
87                                'avutil-51',
88                                'swscale-2']
89
90             ffmpeg_lib = []
91             ffmpeg_dll = []
92
93             for lib in all_ffmpeg_libs:
94                 ffmpeg_lib.append(lib + '.lib')
95                 ffmpeg_dll.append('${BF_FFMPEG_LIBPATH}/' + lib + '.dll')
96
97             scons_options.append('BF_FFMPEG=' + LCGDIR + '/ffmpeg-0.8')
98             scons_options.append('BF_FFMPEG_LIB=' + (' '.join(ffmpeg_lib)))
99             scons_options.append('BF_FFMPEG_DLL=' + (' '.join(ffmpeg_dll)))
100
101             scons_options.append('BF_BITNESS=' + bitness)
102
103         retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
104         sys.exit(retcode)
105
106 # clean release directory if it already exists
107 dir = 'release'
108
109 if os.path.exists(dir):
110     for f in os.listdir(dir):
111         if os.path.isfile(os.path.join(dir, f)):
112             os.remove(os.path.join(dir, f))
113
114 # create release package
115 try:
116     subprocess.call(['make', 'package_archive'])
117 except Exception, ex:
118     sys.stderr.write('Make package release failed' + str(ex) + '\n')
119     sys.exit(1)
120
121 # find release directory, must exist this time
122 if not os.path.exists(dir):
123     sys.stderr.write("Failed to find release directory.\n")
124     sys.exit(1)
125
126 # find release package
127 file = None
128 filepath = None
129
130 for f in os.listdir(dir):
131     rf = os.path.join(dir, f)
132     if os.path.isfile(rf) and f.startswith('blender'):
133         file = f
134         filepath = rf
135
136 if not file:
137     sys.stderr.write("Failed to find release package.\n")
138     sys.exit(1)
139
140 # create zip file
141 try:
142     upload_zip = "buildbot_upload.zip"
143     if os.path.exists(upload_zip):
144         os.remove(upload_zip)
145     z = zipfile.ZipFile(upload_zip, "w", compression=zipfile.ZIP_STORED)
146     z.write(filepath, arcname=file)
147     z.close()
148 except Exception, ex:
149     sys.stderr.write('Create buildbot_upload.zip failed' + str(ex) + '\n')
150     sys.exit(1)