blob: 005d99790ad90799f0f4e4526f8312cdff11581f [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={},
Masood Malekghassemi027835f2016-07-15 22:31:50 -070043 flake_retries=0, timeout_retries=0, timeout_seconds=30*60):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080044 """Creates jobspec for a task running under docker."""
45 environ = environ.copy()
46 environ['RUN_COMMAND'] = shell_command
47
48 docker_args=[]
siddharthshukla0589e532016-07-07 16:08:01 +020049 for k,v in environ.items():
Jan Tattermuschbe538a12016-01-28 14:58:15 -080050 docker_args += ['-e', '%s=%s' % (k, v)]
51 docker_env = {'DOCKERFILE_DIR': dockerfile_dir,
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070052 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
Jan Tattermuschbe538a12016-01-28 14:58:15 -080053 'OUTPUT_DIR': 'artifacts'}
54 jobspec = jobset.JobSpec(
Jan Tattermusch9835d4b2016-04-29 15:05:05 -070055 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080056 environ=docker_env,
57 shortname='build_artifact.%s' % (name),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070058 timeout_seconds=timeout_seconds,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080059 flake_retries=flake_retries,
60 timeout_retries=timeout_retries)
61 return jobspec
62
63
64def create_jobspec(name, cmdline, environ=None, shell=False,
Masood Malekghassemi027835f2016-07-15 22:31:50 -070065 flake_retries=0, timeout_retries=0, timeout_seconds=30*60):
Jan Tattermuschbe538a12016-01-28 14:58:15 -080066 """Creates jobspec."""
67 jobspec = jobset.JobSpec(
68 cmdline=cmdline,
69 environ=environ,
70 shortname='build_artifact.%s' % (name),
Masood Malekghassemi027835f2016-07-15 22:31:50 -070071 timeout_seconds=timeout_seconds,
Jan Tattermuschbe538a12016-01-28 14:58:15 -080072 flake_retries=flake_retries,
73 timeout_retries=timeout_retries,
74 shell=shell)
75 return jobspec
76
77
Jan Tattermusche046f712016-02-18 16:06:10 -080078_MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7'
79
80_ARCH_FLAG_MAP = {
81 'x86': '-m32',
82 'x64': '-m64'
83}
Jan Tattermuschbe538a12016-01-28 14:58:15 -080084
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010085
Jan Tattermusch8640f922016-02-01 18:58:46 -080086class PythonArtifact:
87 """Builds Python artifacts."""
88
Ken Payson5998cd72016-08-10 15:39:43 -070089 def __init__(self, platform, arch, py_version):
90 self.name = 'python_%s_%s_%s' % (platform, arch, py_version)
Jan Tattermusch8640f922016-02-01 18:58:46 -080091 self.platform = platform
92 self.arch = arch
Ken Payson5998cd72016-08-10 15:39:43 -070093 self.labels = ['artifact', 'python', platform, arch, py_version]
94 self.py_version = py_version
Jan Tattermusch8640f922016-02-01 18:58:46 -080095
96 def pre_build_jobspecs(self):
Masood Malekghassemi0e128752016-07-15 14:36:54 -070097 return []
Jan Tattermusch8640f922016-02-01 18:58:46 -080098
99 def build_jobspec(self):
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100100 environ = {}
101 if self.platform == 'linux':
102 if self.arch == 'x86':
103 environ['SETARCH_CMD'] = 'linux32'
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700104 # Inside the manylinux container, the python installations are located in
105 # special places...
Ken Payson5998cd72016-08-10 15:39:43 -0700106 environ['PYTHON'] = '/opt/python/{}/bin/python'.format(self.py_version)
107 environ['PIP'] = '/opt/python/{}/bin/pip'.format(self.py_version)
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700108 # Platform autodetection for the manylinux1 image breaks so we set the
109 # defines ourselves.
110 # TODO(atash) get better platform-detection support in core so we don't
111 # need to do this manually...
Masood Malekghassemif4c70ca2016-05-05 19:14:05 -0700112 environ['CFLAGS'] = '-DGPR_MANYLINUX1=1'
Masood Malekghassemiaff69362016-09-21 15:10:36 -0700113 environ['GRPC_BUILD_GRPCIO_TOOLS_DEPENDENTS'] = 'TRUE'
114 environ['GRPC_BUILD_MANYLINUX_WHEEL'] = 'TRUE'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100115 return create_docker_jobspec(self.name,
Masood Malekghassemi010eb482016-05-03 15:59:40 -0700116 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100117 'tools/run_tests/artifacts/build_artifact_python.sh',
Masood Malekghassemi027835f2016-07-15 22:31:50 -0700118 environ=environ,
119 timeout_seconds=60*60)
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100120 elif self.platform == 'windows':
Ken Payson5998cd72016-08-10 15:39:43 -0700121 if 'Python27' in self.py_version or 'Python34' in self.py_version:
122 environ['EXT_COMPILER'] = 'mingw32'
123 else:
124 environ['EXT_COMPILER'] = 'msvc'
125 # For some reason, the batch script %random% always runs with the same
126 # seed. We create a random temp-dir here
127 dir = ''.join(random.choice(string.ascii_uppercase) for _ in range(10))
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100128 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100129 ['tools\\run_tests\\artifacts\\build_artifact_python.bat',
Ken Payson5998cd72016-08-10 15:39:43 -0700130 self.py_version,
131 '32' if self.arch == 'x86' else '64',
132 dir
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100133 ],
Ken Payson5998cd72016-08-10 15:39:43 -0700134 environ=environ,
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100135 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800136 else:
Ken Payson5998cd72016-08-10 15:39:43 -0700137 environ['PYTHON'] = self.py_version
138 environ['SKIP_PIP_INSTALL'] = 'TRUE'
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100139 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100140 ['tools/run_tests/artifacts/build_artifact_python.sh'],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100141 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800142
143 def __str__(self):
144 return self.name
145
146
Jan Tattermusch44372132016-02-01 16:20:03 -0800147class RubyArtifact:
148 """Builds ruby native gem."""
149
150 def __init__(self, platform, arch):
151 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
152 self.platform = platform
153 self.arch = arch
154 self.labels = ['artifact', 'ruby', platform, arch]
155
156 def pre_build_jobspecs(self):
157 return []
158
159 def build_jobspec(self):
160 if self.platform == 'windows':
161 raise Exception("Not supported yet")
162 else:
163 if self.platform == 'linux':
164 environ = {}
165 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800166 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800167 return create_docker_jobspec(self.name,
168 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100169 'tools/run_tests/artifacts/build_artifact_ruby.sh',
Jan Tattermusch44372132016-02-01 16:20:03 -0800170 environ=environ)
171 else:
172 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100173 ['tools/run_tests/artifacts/build_artifact_ruby.sh'])
Jan Tattermusch44372132016-02-01 16:20:03 -0800174
175
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800176class CSharpExtArtifact:
177 """Builds C# native extension library"""
178
179 def __init__(self, platform, arch):
180 self.name = 'csharp_ext_%s_%s' % (platform, arch)
181 self.platform = platform
182 self.arch = arch
183 self.labels = ['artifact', 'csharp', platform, arch]
184
185 def pre_build_jobspecs(self):
186 if self.platform == 'windows':
187 return [create_jobspec('prebuild_%s' % self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100188 ['tools\\run_tests\\helper_scripts\\pre_build_c.bat'],
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800189 shell=True,
190 flake_retries=5,
191 timeout_retries=2)]
192 else:
193 return []
194
195 def build_jobspec(self):
196 if self.platform == 'windows':
197 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
198 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100199 ['tools\\run_tests\\artifacts\\build_artifact_csharp.bat',
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800200 'vsprojects\\grpc_csharp_ext.sln',
201 '/p:Configuration=Release',
202 '/p:PlatformToolset=v120',
203 '/p:Platform=%s' % msbuild_platform],
204 shell=True)
205 else:
206 environ = {'CONFIG': 'opt',
207 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800208 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800209 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
210 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800211 if self.platform == 'linux':
212 return create_docker_jobspec(self.name,
213 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100214 'tools/run_tests/artifacts/build_artifact_csharp.sh',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800215 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800216 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800217 archflag = _ARCH_FLAG_MAP[self.arch]
218 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
219 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800220 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100221 ['tools/run_tests/artifacts/build_artifact_csharp.sh'],
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800222 environ=environ)
223
224 def __str__(self):
225 return self.name
226
Jan Tattermusche046f712016-02-18 16:06:10 -0800227
murgatroid99673f65b2016-02-01 11:19:07 -0800228node_gyp_arch_map = {
229 'x86': 'ia32',
230 'x64': 'x64'
231}
232
233class NodeExtArtifact:
234 """Builds Node native extension"""
235
236 def __init__(self, platform, arch):
237 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
238 self.platform = platform
239 self.arch = arch
240 self.gyp_arch = node_gyp_arch_map[arch]
241 self.labels = ['artifact', 'node', platform, arch]
242
243 def pre_build_jobspecs(self):
244 return []
245
246 def build_jobspec(self):
247 if self.platform == 'windows':
248 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100249 ['tools\\run_tests\\artifacts\\build_artifact_node.bat',
murgatroid99673f65b2016-02-01 11:19:07 -0800250 self.gyp_arch],
251 shell=True)
252 else:
253 if self.platform == 'linux':
254 return create_docker_jobspec(
255 self.name,
256 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100257 'tools/run_tests/artifacts/build_artifact_node.sh {}'.format(self.gyp_arch))
murgatroid99673f65b2016-02-01 11:19:07 -0800258 else:
259 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100260 ['tools/run_tests/artifacts/build_artifact_node.sh',
murgatroid99673f65b2016-02-01 11:19:07 -0800261 self.gyp_arch])
262
Stanley Cheungbf74d692016-02-23 22:39:25 -0800263class PHPArtifact:
264 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800265
266 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800267 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800268 self.platform = platform
269 self.arch = arch
270 self.labels = ['artifact', 'php', platform, arch]
271
272 def pre_build_jobspecs(self):
273 return []
274
275 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800276 if self.platform == 'linux':
277 return create_docker_jobspec(
278 self.name,
279 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100280 'tools/run_tests/artifacts/build_artifact_php.sh')
Stanley Cheung80db5be2016-02-24 21:35:56 -0800281 else:
282 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100283 ['tools/run_tests/artifacts/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800284
Jan Tattermusche046f712016-02-18 16:06:10 -0800285class ProtocArtifact:
286 """Builds protoc and protoc-plugin artifacts"""
287
288 def __init__(self, platform, arch):
289 self.name = 'protoc_%s_%s' % (platform, arch)
290 self.platform = platform
291 self.arch = arch
292 self.labels = ['artifact', 'protoc', platform, arch]
293
294 def pre_build_jobspecs(self):
295 return []
296
297 def build_jobspec(self):
298 if self.platform != 'windows':
299 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800300 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
301 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800302 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800303 environ={'CONFIG': 'opt',
304 'CXXFLAGS': cxxflags,
305 'LDFLAGS': ldflags,
306 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
307 if self.platform == 'linux':
308 return create_docker_jobspec(self.name,
309 'tools/dockerfile/grpc_artifact_protoc',
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100310 'tools/run_tests/artifacts/build_artifact_protoc.sh',
Jan Tattermusche046f712016-02-18 16:06:10 -0800311 environ=environ)
312 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800313 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800314 return create_jobspec(self.name,
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 Tattermusch6d159822016-02-19 16:03:22 -0800318 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
319 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
320 return create_jobspec(self.name,
Jan Tattermusch5c79a312016-12-20 11:02:50 +0100321 ['tools\\run_tests\\artifacts\\build_artifact_protoc.bat'],
Jan Tattermusch6d159822016-02-19 16:03:22 -0800322 environ={'generator': generator,
323 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800324
325 def __str__(self):
326 return self.name
327
328
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800329def targets():
330 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800331 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800332 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800333 for platform in ('linux', 'macos', 'windows')
334 for arch in ('x86', 'x64')] +
Ken Payson5998cd72016-08-10 15:39:43 -0700335 [PythonArtifact('linux', 'x86', 'cp27-cp27m'),
336 PythonArtifact('linux', 'x86', 'cp27-cp27mu'),
337 PythonArtifact('linux', 'x86', 'cp34-cp34m'),
338 PythonArtifact('linux', 'x86', 'cp35-cp35m'),
339 PythonArtifact('linux', 'x64', 'cp27-cp27m'),
340 PythonArtifact('linux', 'x64', 'cp27-cp27mu'),
341 PythonArtifact('linux', 'x64', 'cp34-cp34m'),
342 PythonArtifact('linux', 'x64', 'cp35-cp35m'),
343 PythonArtifact('macos', 'x64', 'python2.7'),
344 PythonArtifact('macos', 'x64', 'python3.4'),
345 PythonArtifact('macos', 'x64', 'python3.5'),
346 PythonArtifact('windows', 'x86', 'Python27_32bits'),
347 PythonArtifact('windows', 'x86', 'Python34_32bits'),
348 PythonArtifact('windows', 'x86', 'Python35_32bits'),
349 PythonArtifact('windows', 'x64', 'Python27'),
350 PythonArtifact('windows', 'x64', 'Python34'),
351 PythonArtifact('windows', 'x64', 'Python35'),
murgatroid9941a9e832016-02-03 09:47:35 -0800352 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800353 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800354 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800355 PHPArtifact('linux', 'x64'),
356 PHPArtifact('macos', 'x64')])