blob: ec44e3746c9ad6fa96151210894b50d6e899c445 [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
33import jobset
34
35
36def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={},
37 flake_retries=0, timeout_retries=0):
38 """Creates jobspec for a task running under docker."""
39 environ = environ.copy()
40 environ['RUN_COMMAND'] = shell_command
41
42 docker_args=[]
43 for k,v in environ.iteritems():
44 docker_args += ['-e', '%s=%s' % (k, v)]
45 docker_env = {'DOCKERFILE_DIR': dockerfile_dir,
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070046 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
Jan Tattermuschbe538a12016-01-28 14:58:15 -080047 'OUTPUT_DIR': 'artifacts'}
48 jobspec = jobset.JobSpec(
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070049 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080050 environ=docker_env,
51 shortname='build_artifact.%s' % (name),
52 timeout_seconds=30*60,
53 flake_retries=flake_retries,
54 timeout_retries=timeout_retries)
55 return jobspec
56
57
58def create_jobspec(name, cmdline, environ=None, shell=False,
59 flake_retries=0, timeout_retries=0):
60 """Creates jobspec."""
61 jobspec = jobset.JobSpec(
62 cmdline=cmdline,
63 environ=environ,
64 shortname='build_artifact.%s' % (name),
Jan Tattermusch5b762b62016-02-09 08:18:02 -080065 timeout_seconds=30*60,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080066 flake_retries=flake_retries,
67 timeout_retries=timeout_retries,
68 shell=shell)
69 return jobspec
70
71
Jan Tattermusche046f712016-02-18 16:06:10 -080072_MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7'
73
74_ARCH_FLAG_MAP = {
75 'x86': '-m32',
76 'x64': '-m64'
77}
Jan Tattermuschbe538a12016-01-28 14:58:15 -080078
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010079python_version_arch_map = {
80 'x86': 'Python27_32bits',
81 'x64': 'Python27'
82}
83
Jan Tattermusch8640f922016-02-01 18:58:46 -080084class PythonArtifact:
85 """Builds Python artifacts."""
86
Masood Malekghassemi010eb482016-05-03 15:59:40 -070087 def __init__(self, platform, arch, manylinux_build=None):
88 if manylinux_build:
89 self.name = 'python_%s_%s_%s' % (platform, arch, manylinux_build)
90 else:
91 self.name = 'python_%s_%s' % (platform, arch)
Jan Tattermusch8640f922016-02-01 18:58:46 -080092 self.platform = platform
93 self.arch = arch
94 self.labels = ['artifact', 'python', platform, arch]
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010095 self.python_version = python_version_arch_map[arch]
Masood Malekghassemi010eb482016-05-03 15:59:40 -070096 self.manylinux_build = manylinux_build
Jan Tattermusch8640f922016-02-01 18:58:46 -080097
98 def pre_build_jobspecs(self):
99 return []
100
101 def build_jobspec(self):
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100102 environ = {}
103 if self.platform == 'linux':
104 if self.arch == 'x86':
105 environ['SETARCH_CMD'] = 'linux32'
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700106 # Inside the manylinux container, the python installations are located in
107 # special places...
108 environ['PYTHON'] = '/opt/python/{}/bin/python'.format(self.manylinux_build)
109 environ['PIP'] = '/opt/python/{}/bin/pip'.format(self.manylinux_build)
110 # Our docker image has all the prerequisites pip-installed already.
111 environ['SKIP_PIP_INSTALL'] = '1'
112 # Platform autodetection for the manylinux1 image breaks so we set the
113 # defines ourselves.
114 # TODO(atash) get better platform-detection support in core so we don't
115 # need to do this manually...
116 environ['CFLAGS'] = " ".join([
117 '-DGPR_NO_AUTODETECT_PLATFORM',
118 '-DGPR_PLATFORM_STRING=\\"manylinux\\"',
119 '-DGPR_POSIX_CRASH_HANDLER=1',
120 '-DGPR_CPU_LINUX=1',
121 '-DGPR_GCC_ATOMIC=1',
122 '-DGPR_GCC_TLS=1',
123 '-DGPR_LINUX=1',
124 '-DGPR_LINUX_LOG=1',
125 #'-DGPR_LINUX_MULTIPOLL_WITH_EPOLL=1',
126 '-DGPR_POSIX_SOCKET=1',
127 '-DGPR_POSIX_WAKEUP_FD=1',
128 '-DGPR_POSIX_SOCKETADDR=1',
129 #'-DGPR_LINUX_EVENTFD=1',
130 #'-DGPR_LINUX_SOCKETUTILS=1',
131 '-DGPR_HAVE_UNIX_SOCKET=1',
132 '-DGPR_HAVE_IP_PKTINFO=1',
133 '-DGPR_HAVE_IPV6_RECVPKTINFO=1',
134 '-DGPR_LINUX_ENV=1',
135 '-DGPR_POSIX_FILE=1',
136 '-DGPR_POSIX_TMPFILE=1',
137 '-DGPR_POSIX_STRING=1',
138 '-DGPR_POSIX_SUBPROCESS=1',
139 '-DGPR_POSIX_SYNC=1',
140 '-DGPR_POSIX_TIME=1',
141 '-DGPR_GETPID_IN_UNISTD_H=1',
142 '-DGPR_HAVE_MSG_NOSIGNAL=1',
143 '-DGPR_ARCH_{arch}=1'.format(arch=('32' if self.arch == 'x86' else '64')),
144 ])
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100145 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700146 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100147 'tools/run_tests/build_artifact_python.sh',
148 environ=environ)
149 elif self.platform == 'windows':
150 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100151 ['tools\\run_tests\\build_artifact_python.bat',
152 self.python_version
153 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100154 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800155 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100156 environ['SKIP_PIP_INSTALL'] = 'TRUE'
157 return create_jobspec(self.name,
158 ['tools/run_tests/build_artifact_python.sh'],
159 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800160
161 def __str__(self):
162 return self.name
163
164
Jan Tattermusch44372132016-02-01 16:20:03 -0800165class RubyArtifact:
166 """Builds ruby native gem."""
167
168 def __init__(self, platform, arch):
169 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
170 self.platform = platform
171 self.arch = arch
172 self.labels = ['artifact', 'ruby', platform, arch]
173
174 def pre_build_jobspecs(self):
175 return []
176
177 def build_jobspec(self):
178 if self.platform == 'windows':
179 raise Exception("Not supported yet")
180 else:
181 if self.platform == 'linux':
182 environ = {}
183 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800184 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800185 return create_docker_jobspec(self.name,
186 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
187 'tools/run_tests/build_artifact_ruby.sh',
188 environ=environ)
189 else:
190 return create_jobspec(self.name,
191 ['tools/run_tests/build_artifact_ruby.sh'])
192
193
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800194class CSharpExtArtifact:
195 """Builds C# native extension library"""
196
197 def __init__(self, platform, arch):
198 self.name = 'csharp_ext_%s_%s' % (platform, arch)
199 self.platform = platform
200 self.arch = arch
201 self.labels = ['artifact', 'csharp', platform, arch]
202
203 def pre_build_jobspecs(self):
204 if self.platform == 'windows':
205 return [create_jobspec('prebuild_%s' % self.name,
206 ['tools\\run_tests\\pre_build_c.bat'],
207 shell=True,
208 flake_retries=5,
209 timeout_retries=2)]
210 else:
211 return []
212
213 def build_jobspec(self):
214 if self.platform == 'windows':
215 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
216 return create_jobspec(self.name,
217 ['tools\\run_tests\\build_artifact_csharp.bat',
218 'vsprojects\\grpc_csharp_ext.sln',
219 '/p:Configuration=Release',
220 '/p:PlatformToolset=v120',
221 '/p:Platform=%s' % msbuild_platform],
222 shell=True)
223 else:
224 environ = {'CONFIG': 'opt',
225 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800226 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800227 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
228 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800229 if self.platform == 'linux':
230 return create_docker_jobspec(self.name,
231 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800232 'tools/run_tests/build_artifact_csharp.sh',
233 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800234 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800235 archflag = _ARCH_FLAG_MAP[self.arch]
236 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
237 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800238 return create_jobspec(self.name,
239 ['tools/run_tests/build_artifact_csharp.sh'],
240 environ=environ)
241
242 def __str__(self):
243 return self.name
244
Jan Tattermusche046f712016-02-18 16:06:10 -0800245
murgatroid99673f65b2016-02-01 11:19:07 -0800246node_gyp_arch_map = {
247 'x86': 'ia32',
248 'x64': 'x64'
249}
250
251class NodeExtArtifact:
252 """Builds Node native extension"""
253
254 def __init__(self, platform, arch):
255 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
256 self.platform = platform
257 self.arch = arch
258 self.gyp_arch = node_gyp_arch_map[arch]
259 self.labels = ['artifact', 'node', platform, arch]
260
261 def pre_build_jobspecs(self):
262 return []
263
264 def build_jobspec(self):
265 if self.platform == 'windows':
266 return create_jobspec(self.name,
267 ['tools\\run_tests\\build_artifact_node.bat',
268 self.gyp_arch],
269 shell=True)
270 else:
271 if self.platform == 'linux':
272 return create_docker_jobspec(
273 self.name,
274 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
275 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
276 else:
277 return create_jobspec(self.name,
278 ['tools/run_tests/build_artifact_node.sh',
279 self.gyp_arch])
280
Stanley Cheungbf74d692016-02-23 22:39:25 -0800281class PHPArtifact:
282 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800283
284 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800285 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800286 self.platform = platform
287 self.arch = arch
288 self.labels = ['artifact', 'php', platform, arch]
289
290 def pre_build_jobspecs(self):
291 return []
292
293 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800294 if self.platform == 'linux':
295 return create_docker_jobspec(
296 self.name,
297 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
298 'tools/run_tests/build_artifact_php.sh')
299 else:
300 return create_jobspec(self.name,
301 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800302
Jan Tattermusche046f712016-02-18 16:06:10 -0800303class ProtocArtifact:
304 """Builds protoc and protoc-plugin artifacts"""
305
306 def __init__(self, platform, arch):
307 self.name = 'protoc_%s_%s' % (platform, arch)
308 self.platform = platform
309 self.arch = arch
310 self.labels = ['artifact', 'protoc', platform, arch]
311
312 def pre_build_jobspecs(self):
313 return []
314
315 def build_jobspec(self):
316 if self.platform != 'windows':
317 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800318 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
319 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800320 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800321 environ={'CONFIG': 'opt',
322 'CXXFLAGS': cxxflags,
323 'LDFLAGS': ldflags,
324 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
325 if self.platform == 'linux':
326 return create_docker_jobspec(self.name,
327 'tools/dockerfile/grpc_artifact_protoc',
328 'tools/run_tests/build_artifact_protoc.sh',
329 environ=environ)
330 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800331 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800332 return create_jobspec(self.name,
333 ['tools/run_tests/build_artifact_protoc.sh'],
334 environ=environ)
335 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800336 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
337 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
338 return create_jobspec(self.name,
339 ['tools\\run_tests\\build_artifact_protoc.bat'],
340 environ={'generator': generator,
341 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800342
343 def __str__(self):
344 return self.name
345
346
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800347def targets():
348 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800349 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800350 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800351 for platform in ('linux', 'macos', 'windows')
352 for arch in ('x86', 'x64')] +
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700353 [PythonArtifact('linux', 'x86', 'cp27-cp27m'),
354 PythonArtifact('linux', 'x86', 'cp27-cp27mu'),
355 PythonArtifact('linux', 'x64', 'cp27-cp27m'),
356 PythonArtifact('linux', 'x64', 'cp27-cp27mu'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800357 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100358 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100359 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800360 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800361 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800362 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800363 PHPArtifact('linux', 'x64'),
364 PHPArtifact('macos', 'x64')])