blob: 4a4297f1998e4237298e3b6a30854dd572edf29a [file] [log] [blame]
Nathaniel Manistacbf21da2016-02-02 22:17:44 +00001#!/usr/bin/env python2.7
Jan Tattermuschbe538a12016-01-28 14:58:15 -08002# Copyright 2016, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31"""Definition of targets to build artifacts."""
32
Masood Malekghassemi0e128752016-07-15 14:36:54 -070033import os.path
34import sys
35
Jan Tattermuschbe538a12016-01-28 14:58:15 -080036import jobset
37
38
39def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={},
40 flake_retries=0, timeout_retries=0):
41 """Creates jobspec for a task running under docker."""
42 environ = environ.copy()
43 environ['RUN_COMMAND'] = shell_command
44
45 docker_args=[]
46 for k,v in environ.iteritems():
47 docker_args += ['-e', '%s=%s' % (k, v)]
48 docker_env = {'DOCKERFILE_DIR': dockerfile_dir,
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070049 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
Jan Tattermuschbe538a12016-01-28 14:58:15 -080050 'OUTPUT_DIR': 'artifacts'}
51 jobspec = jobset.JobSpec(
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070052 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080053 environ=docker_env,
54 shortname='build_artifact.%s' % (name),
55 timeout_seconds=30*60,
56 flake_retries=flake_retries,
57 timeout_retries=timeout_retries)
58 return jobspec
59
60
61def create_jobspec(name, cmdline, environ=None, shell=False,
62 flake_retries=0, timeout_retries=0):
63 """Creates jobspec."""
64 jobspec = jobset.JobSpec(
65 cmdline=cmdline,
66 environ=environ,
67 shortname='build_artifact.%s' % (name),
Jan Tattermusch5b762b62016-02-09 08:18:02 -080068 timeout_seconds=30*60,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080069 flake_retries=flake_retries,
70 timeout_retries=timeout_retries,
71 shell=shell)
72 return jobspec
73
74
Jan Tattermusche046f712016-02-18 16:06:10 -080075_MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7'
76
77_ARCH_FLAG_MAP = {
78 'x86': '-m32',
79 'x64': '-m64'
80}
Jan Tattermuschbe538a12016-01-28 14:58:15 -080081
Masood Malekghassemi0e128752016-07-15 14:36:54 -070082python_windows_version_arch_map = {
83 ('x86', '2.7'): 'Python27_32bits',
84 ('x64', '2.7'): 'Python27',
85 ('x86', '3.4'): 'Python34_32bits',
86 ('x64', '3.4'): 'Python34',
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010087}
88
Jan Tattermusch8640f922016-02-01 18:58:46 -080089class PythonArtifact:
90 """Builds Python artifacts."""
91
Masood Malekghassemi0e128752016-07-15 14:36:54 -070092 def __init__(self, platform, arch, python_version, manylinux_build=None):
Masood Malekghassemi010eb482016-05-03 15:59:40 -070093 if manylinux_build:
Masood Malekghassemi0e128752016-07-15 14:36:54 -070094 self.name = 'python%s_%s_%s_%s' % (python_version, platform, arch, manylinux_build)
Masood Malekghassemi010eb482016-05-03 15:59:40 -070095 else:
Masood Malekghassemi0e128752016-07-15 14:36:54 -070096 self.name = 'python%s_%s_%s' % (python_version, platform, arch)
Jan Tattermusch8640f922016-02-01 18:58:46 -080097 self.platform = platform
98 self.arch = arch
Masood Malekghassemi0e128752016-07-15 14:36:54 -070099 self.labels = ['artifact', 'python', python_version, platform, arch]
100 self.python_version = python_version
101 self.python_windows_prefix = python_windows_version_arch_map[arch, python_version]
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700102 self.manylinux_build = manylinux_build
Jan Tattermusch8640f922016-02-01 18:58:46 -0800103
104 def pre_build_jobspecs(self):
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700105 return []
Jan Tattermusch8640f922016-02-01 18:58:46 -0800106
107 def build_jobspec(self):
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100108 environ = {}
109 if self.platform == 'linux':
110 if self.arch == 'x86':
111 environ['SETARCH_CMD'] = 'linux32'
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700112 # Inside the manylinux container, the python installations are located in
113 # special places...
114 environ['PYTHON'] = '/opt/python/{}/bin/python'.format(self.manylinux_build)
115 environ['PIP'] = '/opt/python/{}/bin/pip'.format(self.manylinux_build)
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700116 environ['SKIP_PIP_INSTALL'] = '1'
117 # Platform autodetection for the manylinux1 image breaks so we set the
118 # defines ourselves.
119 # TODO(atash) get better platform-detection support in core so we don't
120 # need to do this manually...
Masood Malekghassemif4c70ca2016-05-05 19:14:05 -0700121 environ['CFLAGS'] = '-DGPR_MANYLINUX1=1'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100122 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700123 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100124 'tools/run_tests/build_artifact_python.sh',
125 environ=environ)
126 elif self.platform == 'windows':
127 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100128 ['tools\\run_tests\\build_artifact_python.bat',
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700129 self.python_windows_prefix,
Masood Malekghassemi751fbb02016-05-04 16:12:56 -0700130 '32' if self.arch == 'x86' else '64'
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100131 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100132 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800133 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100134 environ['SKIP_PIP_INSTALL'] = 'TRUE'
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700135 environ['PYTHON'] = 'python{}'.format(self.python_version)
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100136 return create_jobspec(self.name,
137 ['tools/run_tests/build_artifact_python.sh'],
138 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800139
140 def __str__(self):
141 return self.name
142
143
Jan Tattermusch44372132016-02-01 16:20:03 -0800144class RubyArtifact:
145 """Builds ruby native gem."""
146
147 def __init__(self, platform, arch):
148 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
149 self.platform = platform
150 self.arch = arch
151 self.labels = ['artifact', 'ruby', platform, arch]
152
153 def pre_build_jobspecs(self):
154 return []
155
156 def build_jobspec(self):
157 if self.platform == 'windows':
158 raise Exception("Not supported yet")
159 else:
160 if self.platform == 'linux':
161 environ = {}
162 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800163 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800164 return create_docker_jobspec(self.name,
165 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
166 'tools/run_tests/build_artifact_ruby.sh',
167 environ=environ)
168 else:
169 return create_jobspec(self.name,
170 ['tools/run_tests/build_artifact_ruby.sh'])
171
172
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800173class CSharpExtArtifact:
174 """Builds C# native extension library"""
175
176 def __init__(self, platform, arch):
177 self.name = 'csharp_ext_%s_%s' % (platform, arch)
178 self.platform = platform
179 self.arch = arch
180 self.labels = ['artifact', 'csharp', platform, arch]
181
182 def pre_build_jobspecs(self):
183 if self.platform == 'windows':
184 return [create_jobspec('prebuild_%s' % self.name,
185 ['tools\\run_tests\\pre_build_c.bat'],
186 shell=True,
187 flake_retries=5,
188 timeout_retries=2)]
189 else:
190 return []
191
192 def build_jobspec(self):
193 if self.platform == 'windows':
194 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
195 return create_jobspec(self.name,
196 ['tools\\run_tests\\build_artifact_csharp.bat',
197 'vsprojects\\grpc_csharp_ext.sln',
198 '/p:Configuration=Release',
199 '/p:PlatformToolset=v120',
200 '/p:Platform=%s' % msbuild_platform],
201 shell=True)
202 else:
203 environ = {'CONFIG': 'opt',
204 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800205 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800206 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
207 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800208 if self.platform == 'linux':
209 return create_docker_jobspec(self.name,
210 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800211 'tools/run_tests/build_artifact_csharp.sh',
212 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800213 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800214 archflag = _ARCH_FLAG_MAP[self.arch]
215 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
216 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800217 return create_jobspec(self.name,
218 ['tools/run_tests/build_artifact_csharp.sh'],
219 environ=environ)
220
221 def __str__(self):
222 return self.name
223
Jan Tattermusche046f712016-02-18 16:06:10 -0800224
murgatroid99673f65b2016-02-01 11:19:07 -0800225node_gyp_arch_map = {
226 'x86': 'ia32',
227 'x64': 'x64'
228}
229
230class NodeExtArtifact:
231 """Builds Node native extension"""
232
233 def __init__(self, platform, arch):
234 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
235 self.platform = platform
236 self.arch = arch
237 self.gyp_arch = node_gyp_arch_map[arch]
238 self.labels = ['artifact', 'node', platform, arch]
239
240 def pre_build_jobspecs(self):
241 return []
242
243 def build_jobspec(self):
244 if self.platform == 'windows':
245 return create_jobspec(self.name,
246 ['tools\\run_tests\\build_artifact_node.bat',
247 self.gyp_arch],
248 shell=True)
249 else:
250 if self.platform == 'linux':
251 return create_docker_jobspec(
252 self.name,
253 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
254 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
255 else:
256 return create_jobspec(self.name,
257 ['tools/run_tests/build_artifact_node.sh',
258 self.gyp_arch])
259
Stanley Cheungbf74d692016-02-23 22:39:25 -0800260class PHPArtifact:
261 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800262
263 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800264 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800265 self.platform = platform
266 self.arch = arch
267 self.labels = ['artifact', 'php', platform, arch]
268
269 def pre_build_jobspecs(self):
270 return []
271
272 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800273 if self.platform == 'linux':
274 return create_docker_jobspec(
275 self.name,
276 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
277 'tools/run_tests/build_artifact_php.sh')
278 else:
279 return create_jobspec(self.name,
280 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800281
Jan Tattermusche046f712016-02-18 16:06:10 -0800282class ProtocArtifact:
283 """Builds protoc and protoc-plugin artifacts"""
284
285 def __init__(self, platform, arch):
286 self.name = 'protoc_%s_%s' % (platform, arch)
287 self.platform = platform
288 self.arch = arch
289 self.labels = ['artifact', 'protoc', platform, arch]
290
291 def pre_build_jobspecs(self):
292 return []
293
294 def build_jobspec(self):
295 if self.platform != 'windows':
296 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800297 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
298 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800299 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800300 environ={'CONFIG': 'opt',
301 'CXXFLAGS': cxxflags,
302 'LDFLAGS': ldflags,
303 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
304 if self.platform == 'linux':
305 return create_docker_jobspec(self.name,
306 'tools/dockerfile/grpc_artifact_protoc',
307 'tools/run_tests/build_artifact_protoc.sh',
308 environ=environ)
309 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800310 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800311 return create_jobspec(self.name,
312 ['tools/run_tests/build_artifact_protoc.sh'],
313 environ=environ)
314 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800315 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
316 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
317 return create_jobspec(self.name,
318 ['tools\\run_tests\\build_artifact_protoc.bat'],
319 environ={'generator': generator,
320 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800321
322 def __str__(self):
323 return self.name
324
325
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800326def targets():
327 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800328 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800329 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800330 for platform in ('linux', 'macos', 'windows')
331 for arch in ('x86', 'x64')] +
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700332 [PythonArtifact('linux', 'x86', '2.7', 'cp27-cp27m'),
333 PythonArtifact('linux', 'x86', '2.7', 'cp27-cp27mu'),
334 PythonArtifact('linux', 'x64', '2.7', 'cp27-cp27m'),
335 PythonArtifact('linux', 'x64', '2.7', 'cp27-cp27mu'),
336 PythonArtifact('macos', 'x64', '2.7'),
337 PythonArtifact('windows', 'x86', '2.7'),
338 PythonArtifact('windows', 'x64', '2.7'),
339 PythonArtifact('linux', 'x86', '3.4', 'cp34-cp34m'),
340 PythonArtifact('linux', 'x64', '3.4', 'cp34-cp34m'),
341 PythonArtifact('macos', 'x64', '3.4'),
342 PythonArtifact('windows', 'x86', '3.4'),
343 PythonArtifact('windows', 'x64', '3.4'),
murgatroid9941a9e832016-02-03 09:47:35 -0800344 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800345 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800346 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800347 PHPArtifact('linux', 'x64'),
348 PHPArtifact('macos', 'x64')])