blob: 8648ceb1f3dc3a11acee9d608ec1d13c70f04bd6 [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
Ken Payson5998cd72016-08-10 15:39:43 -070034import random
35import string
Masood Malekghassemi0e128752016-07-15 14:36:54 -070036import sys
37
Jan Tattermusch5c79a312016-12-20 11:02:50 +010038sys.path.insert(0, os.path.abspath('..'))
39import python_utils.jobset as jobset
Jan Tattermuschbe538a12016-01-28 14:58:15 -080040
41
42def create_docker_jobspec(name, dockerfile_dir, shell_command, environ={},
Ken Payson626fb452017-02-17 22:52:27 -080043 flake_retries=0, timeout_retries=0, timeout_seconds=30*60,
44 docker_base_image=None):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080045 """Creates jobspec for a task running under docker."""
46 environ = environ.copy()
47 environ['RUN_COMMAND'] = shell_command
48
49 docker_args=[]
siddharthshukla0589e532016-07-07 16:08:01 +020050 for k,v in environ.items():
Jan Tattermuschbe538a12016-01-28 14:58:15 -080051 docker_args += ['-e', '%s=%s' % (k, v)]
52 docker_env = {'DOCKERFILE_DIR': dockerfile_dir,
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070053 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
Jan Tattermuschbe538a12016-01-28 14:58:15 -080054 'OUTPUT_DIR': 'artifacts'}
Ken Payson626fb452017-02-17 22:52:27 -080055
56 if docker_base_image is not None:
57 docker_env['DOCKER_BASE_IMAGE'] = docker_base_image
Jan Tattermuschbe538a12016-01-28 14:58:15 -080058 jobspec = jobset.JobSpec(
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070059 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080060 environ=docker_env,
61 shortname='build_artifact.%s' % (name),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070062 timeout_seconds=timeout_seconds,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080063 flake_retries=flake_retries,
64 timeout_retries=timeout_retries)
65 return jobspec
66
67
68def create_jobspec(name, cmdline, environ=None, shell=False,
Masood Malekghassemi027835f2016-07-15 22:31:50 -070069 flake_retries=0, timeout_retries=0, timeout_seconds=30*60):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080070 """Creates jobspec."""
71 jobspec = jobset.JobSpec(
72 cmdline=cmdline,
73 environ=environ,
74 shortname='build_artifact.%s' % (name),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070075 timeout_seconds=timeout_seconds,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080076 flake_retries=flake_retries,
77 timeout_retries=timeout_retries,
78 shell=shell)
79 return jobspec
80
81
Jan Tattermusche046f712016-02-18 16:06:10 -080082_MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7'
83
84_ARCH_FLAG_MAP = {
85 'x86': '-m32',
86 'x64': '-m64'
87}
Jan Tattermuschbe538a12016-01-28 14:58:15 -080088
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010089
Jan Tattermusch8640f922016-02-01 18:58:46 -080090class PythonArtifact:
91 """Builds Python artifacts."""
92
Ken Payson5998cd72016-08-10 15:39:43 -070093 def __init__(self, platform, arch, py_version):
94 self.name = 'python_%s_%s_%s' % (platform, arch, py_version)
Jan Tattermusch8640f922016-02-01 18:58:46 -080095 self.platform = platform
96 self.arch = arch
Ken Payson5998cd72016-08-10 15:39:43 -070097 self.labels = ['artifact', 'python', platform, arch, py_version]
98 self.py_version = py_version
Jan Tattermusch8640f922016-02-01 18:58:46 -080099
100 def pre_build_jobspecs(self):
Masood Malekghassemi0e128752016-07-15 14:36:54 -0700101 return []
Jan Tattermusch8640f922016-02-01 18:58:46 -0800102
103 def build_jobspec(self):
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100104 environ = {}
105 if self.platform == 'linux':
106 if self.arch == 'x86':
107 environ['SETARCH_CMD'] = 'linux32'
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700108 # Inside the manylinux container, the python installations are located in
109 # special places...
Ken Payson5998cd72016-08-10 15:39:43 -0700110 environ['PYTHON'] = '/opt/python/{}/bin/python'.format(self.py_version)
111 environ['PIP'] = '/opt/python/{}/bin/pip'.format(self.py_version)
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700112 # 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'
Masood Malekghassemiaff69362016-09-21 15:10:36 -0700117 environ['GRPC_BUILD_GRPCIO_TOOLS_DEPENDENTS'] = 'TRUE'
118 environ['GRPC_BUILD_MANYLINUX_WHEEL'] = 'TRUE'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100119 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700120 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100121 'tools/run_tests/artifacts/build_artifact_python.sh',
Masood Malekghassemi027835f2016-07-15 22:31:50 -0700122 environ=environ,
Ken Payson626fb452017-02-17 22:52:27 -0800123 timeout_seconds=60*60,
124 docker_base_image='quay.io/pypa/manylinux1_i686' if self.arch == 'x86' else 'quay.io/pypa/manylinux1_x86_64')
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100125 elif self.platform == 'windows':
Ken Payson5998cd72016-08-10 15:39:43 -0700126 if 'Python27' in self.py_version or 'Python34' in self.py_version:
127 environ['EXT_COMPILER'] = 'mingw32'
128 else:
129 environ['EXT_COMPILER'] = 'msvc'
130 # For some reason, the batch script %random% always runs with the same
131 # seed. We create a random temp-dir here
132 dir = ''.join(random.choice(string.ascii_uppercase) for _ in range(10))
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100133 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100134 ['tools\\run_tests\\artifacts\\build_artifact_python.bat',
Ken Payson5998cd72016-08-10 15:39:43 -0700135 self.py_version,
136 '32' if self.arch == 'x86' else '64',
137 dir
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100138 ],
Ken Payson5998cd72016-08-10 15:39:43 -0700139 environ=environ,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100140 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800141 else:
Ken Payson5998cd72016-08-10 15:39:43 -0700142 environ['PYTHON'] = self.py_version
143 environ['SKIP_PIP_INSTALL'] = 'TRUE'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100144 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100145 ['tools/run_tests/artifacts/build_artifact_python.sh'],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100146 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800147
148 def __str__(self):
149 return self.name
150
151
Jan Tattermusch44372132016-02-01 16:20:03 -0800152class RubyArtifact:
153 """Builds ruby native gem."""
154
155 def __init__(self, platform, arch):
156 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
157 self.platform = platform
158 self.arch = arch
159 self.labels = ['artifact', 'ruby', platform, arch]
160
161 def pre_build_jobspecs(self):
162 return []
163
164 def build_jobspec(self):
165 if self.platform == 'windows':
166 raise Exception("Not supported yet")
167 else:
168 if self.platform == 'linux':
169 environ = {}
170 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800171 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800172 return create_docker_jobspec(self.name,
173 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100174 'tools/run_tests/artifacts/build_artifact_ruby.sh',
Jan Tattermusch44372132016-02-01 16:20:03 -0800175 environ=environ)
176 else:
177 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100178 ['tools/run_tests/artifacts/build_artifact_ruby.sh'])
Jan Tattermusch44372132016-02-01 16:20:03 -0800179
180
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800181class CSharpExtArtifact:
182 """Builds C# native extension library"""
183
184 def __init__(self, platform, arch):
185 self.name = 'csharp_ext_%s_%s' % (platform, arch)
186 self.platform = platform
187 self.arch = arch
188 self.labels = ['artifact', 'csharp', platform, arch]
189
190 def pre_build_jobspecs(self):
191 if self.platform == 'windows':
192 return [create_jobspec('prebuild_%s' % self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100193 ['tools\\run_tests\\helper_scripts\\pre_build_c.bat'],
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800194 shell=True,
195 flake_retries=5,
196 timeout_retries=2)]
197 else:
198 return []
199
200 def build_jobspec(self):
201 if self.platform == 'windows':
202 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
203 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100204 ['tools\\run_tests\\artifacts\\build_artifact_csharp.bat',
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800205 'vsprojects\\grpc_csharp_ext.sln',
206 '/p:Configuration=Release',
207 '/p:PlatformToolset=v120',
208 '/p:Platform=%s' % msbuild_platform],
209 shell=True)
210 else:
211 environ = {'CONFIG': 'opt',
212 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800213 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800214 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
215 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800216 if self.platform == 'linux':
217 return create_docker_jobspec(self.name,
218 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100219 'tools/run_tests/artifacts/build_artifact_csharp.sh',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800220 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800221 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800222 archflag = _ARCH_FLAG_MAP[self.arch]
223 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
224 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800225 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100226 ['tools/run_tests/artifacts/build_artifact_csharp.sh'],
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800227 environ=environ)
228
229 def __str__(self):
230 return self.name
231
Jan Tattermusche046f712016-02-18 16:06:10 -0800232
murgatroid99673f65b2016-02-01 11:19:07 -0800233node_gyp_arch_map = {
234 'x86': 'ia32',
235 'x64': 'x64'
236}
237
238class NodeExtArtifact:
239 """Builds Node native extension"""
240
241 def __init__(self, platform, arch):
242 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
243 self.platform = platform
244 self.arch = arch
245 self.gyp_arch = node_gyp_arch_map[arch]
246 self.labels = ['artifact', 'node', platform, arch]
247
248 def pre_build_jobspecs(self):
249 return []
250
251 def build_jobspec(self):
252 if self.platform == 'windows':
253 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100254 ['tools\\run_tests\\artifacts\\build_artifact_node.bat',
murgatroid99673f65b2016-02-01 11:19:07 -0800255 self.gyp_arch],
256 shell=True)
257 else:
258 if self.platform == 'linux':
259 return create_docker_jobspec(
260 self.name,
261 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100262 'tools/run_tests/artifacts/build_artifact_node.sh {}'.format(self.gyp_arch))
murgatroid99673f65b2016-02-01 11:19:07 -0800263 else:
264 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100265 ['tools/run_tests/artifacts/build_artifact_node.sh',
murgatroid99673f65b2016-02-01 11:19:07 -0800266 self.gyp_arch])
267
Stanley Cheungbf74d692016-02-23 22:39:25 -0800268class PHPArtifact:
269 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800270
271 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800272 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800273 self.platform = platform
274 self.arch = arch
275 self.labels = ['artifact', 'php', platform, arch]
276
277 def pre_build_jobspecs(self):
278 return []
279
280 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800281 if self.platform == 'linux':
282 return create_docker_jobspec(
283 self.name,
284 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100285 'tools/run_tests/artifacts/build_artifact_php.sh')
Stanley Cheung80db5be2016-02-24 21:35:56 -0800286 else:
287 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100288 ['tools/run_tests/artifacts/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800289
Jan Tattermusche046f712016-02-18 16:06:10 -0800290class ProtocArtifact:
291 """Builds protoc and protoc-plugin artifacts"""
292
293 def __init__(self, platform, arch):
294 self.name = 'protoc_%s_%s' % (platform, arch)
295 self.platform = platform
296 self.arch = arch
297 self.labels = ['artifact', 'protoc', platform, arch]
298
299 def pre_build_jobspecs(self):
300 return []
301
302 def build_jobspec(self):
303 if self.platform != 'windows':
304 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800305 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
306 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800307 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800308 environ={'CONFIG': 'opt',
309 'CXXFLAGS': cxxflags,
310 'LDFLAGS': ldflags,
311 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
312 if self.platform == 'linux':
313 return create_docker_jobspec(self.name,
314 'tools/dockerfile/grpc_artifact_protoc',
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100315 'tools/run_tests/artifacts/build_artifact_protoc.sh',
Jan Tattermusche046f712016-02-18 16:06:10 -0800316 environ=environ)
317 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800318 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800319 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100320 ['tools/run_tests/artifacts/build_artifact_protoc.sh'],
Jan Tattermusche046f712016-02-18 16:06:10 -0800321 environ=environ)
322 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800323 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
324 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
325 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100326 ['tools\\run_tests\\artifacts\\build_artifact_protoc.bat'],
Jan Tattermusch6d159822016-02-19 16:03:22 -0800327 environ={'generator': generator,
328 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800329
330 def __str__(self):
331 return self.name
332
333
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800334def targets():
335 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800336 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800337 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800338 for platform in ('linux', 'macos', 'windows')
339 for arch in ('x86', 'x64')] +
Ken Payson5998cd72016-08-10 15:39:43 -0700340 [PythonArtifact('linux', 'x86', 'cp27-cp27m'),
341 PythonArtifact('linux', 'x86', 'cp27-cp27mu'),
342 PythonArtifact('linux', 'x86', 'cp34-cp34m'),
343 PythonArtifact('linux', 'x86', 'cp35-cp35m'),
Ken Payson626fb452017-02-17 22:52:27 -0800344 PythonArtifact('linux', 'x86', 'cp36-cp36m'),
Ken Payson5998cd72016-08-10 15:39:43 -0700345 PythonArtifact('linux', 'x64', 'cp27-cp27m'),
346 PythonArtifact('linux', 'x64', 'cp27-cp27mu'),
347 PythonArtifact('linux', 'x64', 'cp34-cp34m'),
348 PythonArtifact('linux', 'x64', 'cp35-cp35m'),
Ken Payson626fb452017-02-17 22:52:27 -0800349 PythonArtifact('linux', 'x64', 'cp36-cp36m'),
Ken Payson5998cd72016-08-10 15:39:43 -0700350 PythonArtifact('macos', 'x64', 'python2.7'),
351 PythonArtifact('macos', 'x64', 'python3.4'),
352 PythonArtifact('macos', 'x64', 'python3.5'),
Ken Payson626fb452017-02-17 22:52:27 -0800353 PythonArtifact('macos', 'x64', 'python3.6'),
Ken Payson5998cd72016-08-10 15:39:43 -0700354 PythonArtifact('windows', 'x86', 'Python27_32bits'),
355 PythonArtifact('windows', 'x86', 'Python34_32bits'),
356 PythonArtifact('windows', 'x86', 'Python35_32bits'),
Ken Payson626fb452017-02-17 22:52:27 -0800357 PythonArtifact('windows', 'x86', 'Python36_32bits'),
Ken Payson5998cd72016-08-10 15:39:43 -0700358 PythonArtifact('windows', 'x64', 'Python27'),
359 PythonArtifact('windows', 'x64', 'Python34'),
360 PythonArtifact('windows', 'x64', 'Python35'),
Ken Payson626fb452017-02-17 22:52:27 -0800361 PythonArtifact('windows', 'x64', 'Python36'),
murgatroid9941a9e832016-02-03 09:47:35 -0800362 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800363 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800364 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800365 PHPArtifact('linux', 'x64'),
366 PHPArtifact('macos', 'x64')])