blob: e9267be58b4054ab4f976ca653c6f234934d22d1 [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=[]
siddharthshukla0589e532016-07-07 16:08:01 +020043 for k,v in environ.items():
Jan Tattermuschbe538a12016-01-28 14:58:15 -080044 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...
Masood Malekghassemif4c70ca2016-05-05 19:14:05 -0700116 environ['CFLAGS'] = '-DGPR_MANYLINUX1=1'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100117 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700118 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100119 'tools/run_tests/build_artifact_python.sh',
120 environ=environ)
121 elif self.platform == 'windows':
122 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100123 ['tools\\run_tests\\build_artifact_python.bat',
Masood Malekghassemi751fbb02016-05-04 16:12:56 -0700124 self.python_version,
125 '32' if self.arch == 'x86' else '64'
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100126 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100127 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800128 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100129 environ['SKIP_PIP_INSTALL'] = 'TRUE'
130 return create_jobspec(self.name,
131 ['tools/run_tests/build_artifact_python.sh'],
132 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800133
134 def __str__(self):
135 return self.name
136
137
Jan Tattermusch44372132016-02-01 16:20:03 -0800138class RubyArtifact:
139 """Builds ruby native gem."""
140
141 def __init__(self, platform, arch):
142 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
143 self.platform = platform
144 self.arch = arch
145 self.labels = ['artifact', 'ruby', platform, arch]
146
147 def pre_build_jobspecs(self):
148 return []
149
150 def build_jobspec(self):
151 if self.platform == 'windows':
152 raise Exception("Not supported yet")
153 else:
154 if self.platform == 'linux':
155 environ = {}
156 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800157 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800158 return create_docker_jobspec(self.name,
159 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
160 'tools/run_tests/build_artifact_ruby.sh',
161 environ=environ)
162 else:
163 return create_jobspec(self.name,
164 ['tools/run_tests/build_artifact_ruby.sh'])
165
166
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800167class CSharpExtArtifact:
168 """Builds C# native extension library"""
169
170 def __init__(self, platform, arch):
171 self.name = 'csharp_ext_%s_%s' % (platform, arch)
172 self.platform = platform
173 self.arch = arch
174 self.labels = ['artifact', 'csharp', platform, arch]
175
176 def pre_build_jobspecs(self):
177 if self.platform == 'windows':
178 return [create_jobspec('prebuild_%s' % self.name,
179 ['tools\\run_tests\\pre_build_c.bat'],
180 shell=True,
181 flake_retries=5,
182 timeout_retries=2)]
183 else:
184 return []
185
186 def build_jobspec(self):
187 if self.platform == 'windows':
188 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
189 return create_jobspec(self.name,
190 ['tools\\run_tests\\build_artifact_csharp.bat',
191 'vsprojects\\grpc_csharp_ext.sln',
192 '/p:Configuration=Release',
193 '/p:PlatformToolset=v120',
194 '/p:Platform=%s' % msbuild_platform],
195 shell=True)
196 else:
197 environ = {'CONFIG': 'opt',
198 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800199 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800200 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
201 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800202 if self.platform == 'linux':
203 return create_docker_jobspec(self.name,
204 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800205 'tools/run_tests/build_artifact_csharp.sh',
206 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800207 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800208 archflag = _ARCH_FLAG_MAP[self.arch]
209 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
210 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800211 return create_jobspec(self.name,
212 ['tools/run_tests/build_artifact_csharp.sh'],
213 environ=environ)
214
215 def __str__(self):
216 return self.name
217
Jan Tattermusche046f712016-02-18 16:06:10 -0800218
murgatroid99673f65b2016-02-01 11:19:07 -0800219node_gyp_arch_map = {
220 'x86': 'ia32',
221 'x64': 'x64'
222}
223
224class NodeExtArtifact:
225 """Builds Node native extension"""
226
227 def __init__(self, platform, arch):
228 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
229 self.platform = platform
230 self.arch = arch
231 self.gyp_arch = node_gyp_arch_map[arch]
232 self.labels = ['artifact', 'node', platform, arch]
233
234 def pre_build_jobspecs(self):
235 return []
236
237 def build_jobspec(self):
238 if self.platform == 'windows':
239 return create_jobspec(self.name,
240 ['tools\\run_tests\\build_artifact_node.bat',
241 self.gyp_arch],
242 shell=True)
243 else:
244 if self.platform == 'linux':
245 return create_docker_jobspec(
246 self.name,
247 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
248 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
249 else:
250 return create_jobspec(self.name,
251 ['tools/run_tests/build_artifact_node.sh',
252 self.gyp_arch])
253
Stanley Cheungbf74d692016-02-23 22:39:25 -0800254class PHPArtifact:
255 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800256
257 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800258 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800259 self.platform = platform
260 self.arch = arch
261 self.labels = ['artifact', 'php', platform, arch]
262
263 def pre_build_jobspecs(self):
264 return []
265
266 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800267 if self.platform == 'linux':
268 return create_docker_jobspec(
269 self.name,
270 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
271 'tools/run_tests/build_artifact_php.sh')
272 else:
273 return create_jobspec(self.name,
274 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800275
Jan Tattermusche046f712016-02-18 16:06:10 -0800276class ProtocArtifact:
277 """Builds protoc and protoc-plugin artifacts"""
278
279 def __init__(self, platform, arch):
280 self.name = 'protoc_%s_%s' % (platform, arch)
281 self.platform = platform
282 self.arch = arch
283 self.labels = ['artifact', 'protoc', platform, arch]
284
285 def pre_build_jobspecs(self):
286 return []
287
288 def build_jobspec(self):
289 if self.platform != 'windows':
290 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800291 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
292 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800293 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800294 environ={'CONFIG': 'opt',
295 'CXXFLAGS': cxxflags,
296 'LDFLAGS': ldflags,
297 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
298 if self.platform == 'linux':
299 return create_docker_jobspec(self.name,
300 'tools/dockerfile/grpc_artifact_protoc',
301 'tools/run_tests/build_artifact_protoc.sh',
302 environ=environ)
303 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800304 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800305 return create_jobspec(self.name,
306 ['tools/run_tests/build_artifact_protoc.sh'],
307 environ=environ)
308 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800309 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
310 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
311 return create_jobspec(self.name,
312 ['tools\\run_tests\\build_artifact_protoc.bat'],
313 environ={'generator': generator,
314 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800315
316 def __str__(self):
317 return self.name
318
319
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800320def targets():
321 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800322 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800323 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800324 for platform in ('linux', 'macos', 'windows')
325 for arch in ('x86', 'x64')] +
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700326 [PythonArtifact('linux', 'x86', 'cp27-cp27m'),
327 PythonArtifact('linux', 'x86', 'cp27-cp27mu'),
328 PythonArtifact('linux', 'x64', 'cp27-cp27m'),
329 PythonArtifact('linux', 'x64', 'cp27-cp27mu'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800330 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100331 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100332 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800333 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800334 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800335 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800336 PHPArtifact('linux', 'x64'),
337 PHPArtifact('macos', 'x64')])