blob: 477bd4688871b7f7ce0ff0c5946d3773e2eb239f [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',
Masood Malekghassemif837cc82016-05-04 11:59:22 -0700130 '-DGPR_POSIX_NO_SPECIAL_WAKEUP_FD=1',
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700131 #'-DGPR_LINUX_SOCKETUTILS=1',
Masood Malekghassemif837cc82016-05-04 11:59:22 -0700132 '-DGPR_POSIX_SOCKETUTILS=1',
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700133 '-DGPR_HAVE_UNIX_SOCKET=1',
134 '-DGPR_HAVE_IP_PKTINFO=1',
135 '-DGPR_HAVE_IPV6_RECVPKTINFO=1',
136 '-DGPR_LINUX_ENV=1',
137 '-DGPR_POSIX_FILE=1',
138 '-DGPR_POSIX_TMPFILE=1',
139 '-DGPR_POSIX_STRING=1',
140 '-DGPR_POSIX_SUBPROCESS=1',
141 '-DGPR_POSIX_SYNC=1',
142 '-DGPR_POSIX_TIME=1',
143 '-DGPR_GETPID_IN_UNISTD_H=1',
144 '-DGPR_HAVE_MSG_NOSIGNAL=1',
145 '-DGPR_ARCH_{arch}=1'.format(arch=('32' if self.arch == 'x86' else '64')),
146 ])
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100147 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700148 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100149 'tools/run_tests/build_artifact_python.sh',
150 environ=environ)
151 elif self.platform == 'windows':
152 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100153 ['tools\\run_tests\\build_artifact_python.bat',
Masood Malekghassemi751fbb02016-05-04 16:12:56 -0700154 self.python_version,
155 '32' if self.arch == 'x86' else '64'
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100156 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100157 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800158 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100159 environ['SKIP_PIP_INSTALL'] = 'TRUE'
160 return create_jobspec(self.name,
161 ['tools/run_tests/build_artifact_python.sh'],
162 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800163
164 def __str__(self):
165 return self.name
166
167
Jan Tattermusch44372132016-02-01 16:20:03 -0800168class RubyArtifact:
169 """Builds ruby native gem."""
170
171 def __init__(self, platform, arch):
172 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
173 self.platform = platform
174 self.arch = arch
175 self.labels = ['artifact', 'ruby', platform, arch]
176
177 def pre_build_jobspecs(self):
178 return []
179
180 def build_jobspec(self):
181 if self.platform == 'windows':
182 raise Exception("Not supported yet")
183 else:
184 if self.platform == 'linux':
185 environ = {}
186 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800187 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800188 return create_docker_jobspec(self.name,
189 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
190 'tools/run_tests/build_artifact_ruby.sh',
191 environ=environ)
192 else:
193 return create_jobspec(self.name,
194 ['tools/run_tests/build_artifact_ruby.sh'])
195
196
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800197class CSharpExtArtifact:
198 """Builds C# native extension library"""
199
200 def __init__(self, platform, arch):
201 self.name = 'csharp_ext_%s_%s' % (platform, arch)
202 self.platform = platform
203 self.arch = arch
204 self.labels = ['artifact', 'csharp', platform, arch]
205
206 def pre_build_jobspecs(self):
207 if self.platform == 'windows':
208 return [create_jobspec('prebuild_%s' % self.name,
209 ['tools\\run_tests\\pre_build_c.bat'],
210 shell=True,
211 flake_retries=5,
212 timeout_retries=2)]
213 else:
214 return []
215
216 def build_jobspec(self):
217 if self.platform == 'windows':
218 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
219 return create_jobspec(self.name,
220 ['tools\\run_tests\\build_artifact_csharp.bat',
221 'vsprojects\\grpc_csharp_ext.sln',
222 '/p:Configuration=Release',
223 '/p:PlatformToolset=v120',
224 '/p:Platform=%s' % msbuild_platform],
225 shell=True)
226 else:
227 environ = {'CONFIG': 'opt',
228 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800229 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800230 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
231 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800232 if self.platform == 'linux':
233 return create_docker_jobspec(self.name,
234 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800235 'tools/run_tests/build_artifact_csharp.sh',
236 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800237 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800238 archflag = _ARCH_FLAG_MAP[self.arch]
239 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
240 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800241 return create_jobspec(self.name,
242 ['tools/run_tests/build_artifact_csharp.sh'],
243 environ=environ)
244
245 def __str__(self):
246 return self.name
247
Jan Tattermusche046f712016-02-18 16:06:10 -0800248
murgatroid99673f65b2016-02-01 11:19:07 -0800249node_gyp_arch_map = {
250 'x86': 'ia32',
251 'x64': 'x64'
252}
253
254class NodeExtArtifact:
255 """Builds Node native extension"""
256
257 def __init__(self, platform, arch):
258 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
259 self.platform = platform
260 self.arch = arch
261 self.gyp_arch = node_gyp_arch_map[arch]
262 self.labels = ['artifact', 'node', platform, arch]
263
264 def pre_build_jobspecs(self):
265 return []
266
267 def build_jobspec(self):
268 if self.platform == 'windows':
269 return create_jobspec(self.name,
270 ['tools\\run_tests\\build_artifact_node.bat',
271 self.gyp_arch],
272 shell=True)
273 else:
274 if self.platform == 'linux':
275 return create_docker_jobspec(
276 self.name,
277 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
278 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
279 else:
280 return create_jobspec(self.name,
281 ['tools/run_tests/build_artifact_node.sh',
282 self.gyp_arch])
283
Stanley Cheungbf74d692016-02-23 22:39:25 -0800284class PHPArtifact:
285 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800286
287 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800288 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800289 self.platform = platform
290 self.arch = arch
291 self.labels = ['artifact', 'php', platform, arch]
292
293 def pre_build_jobspecs(self):
294 return []
295
296 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800297 if self.platform == 'linux':
298 return create_docker_jobspec(
299 self.name,
300 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
301 'tools/run_tests/build_artifact_php.sh')
302 else:
303 return create_jobspec(self.name,
304 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800305
Jan Tattermusche046f712016-02-18 16:06:10 -0800306class ProtocArtifact:
307 """Builds protoc and protoc-plugin artifacts"""
308
309 def __init__(self, platform, arch):
310 self.name = 'protoc_%s_%s' % (platform, arch)
311 self.platform = platform
312 self.arch = arch
313 self.labels = ['artifact', 'protoc', platform, arch]
314
315 def pre_build_jobspecs(self):
316 return []
317
318 def build_jobspec(self):
319 if self.platform != 'windows':
320 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800321 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
322 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800323 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800324 environ={'CONFIG': 'opt',
325 'CXXFLAGS': cxxflags,
326 'LDFLAGS': ldflags,
327 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
328 if self.platform == 'linux':
329 return create_docker_jobspec(self.name,
330 'tools/dockerfile/grpc_artifact_protoc',
331 'tools/run_tests/build_artifact_protoc.sh',
332 environ=environ)
333 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800334 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800335 return create_jobspec(self.name,
336 ['tools/run_tests/build_artifact_protoc.sh'],
337 environ=environ)
338 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800339 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
340 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
341 return create_jobspec(self.name,
342 ['tools\\run_tests\\build_artifact_protoc.bat'],
343 environ={'generator': generator,
344 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800345
346 def __str__(self):
347 return self.name
348
349
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800350def targets():
351 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800352 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800353 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800354 for platform in ('linux', 'macos', 'windows')
355 for arch in ('x86', 'x64')] +
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700356 [PythonArtifact('linux', 'x86', 'cp27-cp27m'),
357 PythonArtifact('linux', 'x86', 'cp27-cp27mu'),
358 PythonArtifact('linux', 'x64', 'cp27-cp27m'),
359 PythonArtifact('linux', 'x64', 'cp27-cp27mu'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800360 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100361 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100362 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800363 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800364 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800365 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800366 PHPArtifact('linux', 'x64'),
367 PHPArtifact('macos', 'x64')])