blob: b145e0392cef31864c2abf3dc1accf41a64ea1f3 [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={},
Masood Malekghassemi027835f2016-07-15 22:31:50 -070040 flake_retries=0, timeout_retries=0, timeout_seconds=30*60):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080041 """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),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070055 timeout_seconds=timeout_seconds,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080056 flake_retries=flake_retries,
57 timeout_retries=timeout_retries)
58 return jobspec
59
60
61def create_jobspec(name, cmdline, environ=None, shell=False,
Masood Malekghassemi027835f2016-07-15 22:31:50 -070062 flake_retries=0, timeout_retries=0, timeout_seconds=30*60):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080063 """Creates jobspec."""
64 jobspec = jobset.JobSpec(
65 cmdline=cmdline,
66 environ=environ,
67 shortname='build_artifact.%s' % (name),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070068 timeout_seconds=timeout_seconds,
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',
Masood Malekghassemi027835f2016-07-15 22:31:50 -0700125 environ=environ,
126 timeout_seconds=60*60)
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100127 elif self.platform == 'windows':
128 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100129 ['tools\\run_tests\\build_artifact_python.bat',
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700130 self.python_windows_prefix,
Masood Malekghassemi751fbb02016-05-04 16:12:56 -0700131 '32' if self.arch == 'x86' else '64'
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100132 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100133 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800134 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100135 environ['SKIP_PIP_INSTALL'] = 'TRUE'
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700136 environ['PYTHON'] = 'python{}'.format(self.python_version)
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100137 return create_jobspec(self.name,
138 ['tools/run_tests/build_artifact_python.sh'],
139 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800140
141 def __str__(self):
142 return self.name
143
144
Jan Tattermusch44372132016-02-01 16:20:03 -0800145class RubyArtifact:
146 """Builds ruby native gem."""
147
148 def __init__(self, platform, arch):
149 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
150 self.platform = platform
151 self.arch = arch
152 self.labels = ['artifact', 'ruby', platform, arch]
153
154 def pre_build_jobspecs(self):
155 return []
156
157 def build_jobspec(self):
158 if self.platform == 'windows':
159 raise Exception("Not supported yet")
160 else:
161 if self.platform == 'linux':
162 environ = {}
163 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800164 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800165 return create_docker_jobspec(self.name,
166 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
167 'tools/run_tests/build_artifact_ruby.sh',
168 environ=environ)
169 else:
170 return create_jobspec(self.name,
171 ['tools/run_tests/build_artifact_ruby.sh'])
172
173
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800174class CSharpExtArtifact:
175 """Builds C# native extension library"""
176
177 def __init__(self, platform, arch):
178 self.name = 'csharp_ext_%s_%s' % (platform, arch)
179 self.platform = platform
180 self.arch = arch
181 self.labels = ['artifact', 'csharp', platform, arch]
182
183 def pre_build_jobspecs(self):
184 if self.platform == 'windows':
185 return [create_jobspec('prebuild_%s' % self.name,
186 ['tools\\run_tests\\pre_build_c.bat'],
187 shell=True,
188 flake_retries=5,
189 timeout_retries=2)]
190 else:
191 return []
192
193 def build_jobspec(self):
194 if self.platform == 'windows':
195 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
196 return create_jobspec(self.name,
197 ['tools\\run_tests\\build_artifact_csharp.bat',
198 'vsprojects\\grpc_csharp_ext.sln',
199 '/p:Configuration=Release',
200 '/p:PlatformToolset=v120',
201 '/p:Platform=%s' % msbuild_platform],
202 shell=True)
203 else:
204 environ = {'CONFIG': 'opt',
205 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800206 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800207 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
208 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800209 if self.platform == 'linux':
210 return create_docker_jobspec(self.name,
211 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800212 'tools/run_tests/build_artifact_csharp.sh',
213 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800214 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800215 archflag = _ARCH_FLAG_MAP[self.arch]
216 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
217 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800218 return create_jobspec(self.name,
219 ['tools/run_tests/build_artifact_csharp.sh'],
220 environ=environ)
221
222 def __str__(self):
223 return self.name
224
Jan Tattermusche046f712016-02-18 16:06:10 -0800225
murgatroid99673f65b2016-02-01 11:19:07 -0800226node_gyp_arch_map = {
227 'x86': 'ia32',
228 'x64': 'x64'
229}
230
231class NodeExtArtifact:
232 """Builds Node native extension"""
233
234 def __init__(self, platform, arch):
235 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
236 self.platform = platform
237 self.arch = arch
238 self.gyp_arch = node_gyp_arch_map[arch]
239 self.labels = ['artifact', 'node', platform, arch]
240
241 def pre_build_jobspecs(self):
242 return []
243
244 def build_jobspec(self):
245 if self.platform == 'windows':
246 return create_jobspec(self.name,
247 ['tools\\run_tests\\build_artifact_node.bat',
248 self.gyp_arch],
249 shell=True)
250 else:
251 if self.platform == 'linux':
252 return create_docker_jobspec(
253 self.name,
254 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
255 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
256 else:
257 return create_jobspec(self.name,
258 ['tools/run_tests/build_artifact_node.sh',
259 self.gyp_arch])
260
Stanley Cheungbf74d692016-02-23 22:39:25 -0800261class PHPArtifact:
262 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800263
264 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800265 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800266 self.platform = platform
267 self.arch = arch
268 self.labels = ['artifact', 'php', platform, arch]
269
270 def pre_build_jobspecs(self):
271 return []
272
273 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800274 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_php.sh')
279 else:
280 return create_jobspec(self.name,
281 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800282
Jan Tattermusche046f712016-02-18 16:06:10 -0800283class ProtocArtifact:
284 """Builds protoc and protoc-plugin artifacts"""
285
286 def __init__(self, platform, arch):
287 self.name = 'protoc_%s_%s' % (platform, arch)
288 self.platform = platform
289 self.arch = arch
290 self.labels = ['artifact', 'protoc', platform, arch]
291
292 def pre_build_jobspecs(self):
293 return []
294
295 def build_jobspec(self):
296 if self.platform != 'windows':
297 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800298 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
299 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800300 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800301 environ={'CONFIG': 'opt',
302 'CXXFLAGS': cxxflags,
303 'LDFLAGS': ldflags,
304 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
305 if self.platform == 'linux':
306 return create_docker_jobspec(self.name,
307 'tools/dockerfile/grpc_artifact_protoc',
308 'tools/run_tests/build_artifact_protoc.sh',
309 environ=environ)
310 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800311 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800312 return create_jobspec(self.name,
313 ['tools/run_tests/build_artifact_protoc.sh'],
314 environ=environ)
315 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800316 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
317 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
318 return create_jobspec(self.name,
319 ['tools\\run_tests\\build_artifact_protoc.bat'],
320 environ={'generator': generator,
321 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800322
323 def __str__(self):
324 return self.name
325
326
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800327def targets():
328 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800329 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800330 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800331 for platform in ('linux', 'macos', 'windows')
332 for arch in ('x86', 'x64')] +
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700333 [PythonArtifact('linux', 'x86', '2.7', 'cp27-cp27m'),
334 PythonArtifact('linux', 'x86', '2.7', 'cp27-cp27mu'),
335 PythonArtifact('linux', 'x64', '2.7', 'cp27-cp27m'),
336 PythonArtifact('linux', 'x64', '2.7', 'cp27-cp27mu'),
337 PythonArtifact('macos', 'x64', '2.7'),
338 PythonArtifact('windows', 'x86', '2.7'),
339 PythonArtifact('windows', 'x64', '2.7'),
340 PythonArtifact('linux', 'x86', '3.4', 'cp34-cp34m'),
341 PythonArtifact('linux', 'x64', '3.4', 'cp34-cp34m'),
342 PythonArtifact('macos', 'x64', '3.4'),
343 PythonArtifact('windows', 'x86', '3.4'),
344 PythonArtifact('windows', 'x64', '3.4'),
murgatroid9941a9e832016-02-03 09:47:35 -0800345 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800346 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800347 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800348 PHPArtifact('linux', 'x64'),
349 PHPArtifact('macos', 'x64')])