blob: 3e08c1d62b3d74996eacd1c436c87c39677c7579 [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
87 def __init__(self, platform, arch):
88 self.name = 'python_%s_%s' % (platform, arch)
89 self.platform = platform
90 self.arch = arch
91 self.labels = ['artifact', 'python', platform, arch]
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010092 self.python_version = python_version_arch_map[arch]
Jan Tattermusch8640f922016-02-01 18:58:46 -080093
94 def pre_build_jobspecs(self):
95 return []
96
97 def build_jobspec(self):
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +010098 environ = {}
99 if self.platform == 'linux':
100 if self.arch == 'x86':
101 environ['SETARCH_CMD'] = 'linux32'
102 return create_docker_jobspec(self.name,
103 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
104 'tools/run_tests/build_artifact_python.sh',
105 environ=environ)
106 elif self.platform == 'windows':
107 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100108 ['tools\\run_tests\\build_artifact_python.bat',
109 self.python_version
110 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100111 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800112 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100113 environ['SKIP_PIP_INSTALL'] = 'TRUE'
114 return create_jobspec(self.name,
115 ['tools/run_tests/build_artifact_python.sh'],
116 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800117
118 def __str__(self):
119 return self.name
120
121
Jan Tattermusch44372132016-02-01 16:20:03 -0800122class RubyArtifact:
123 """Builds ruby native gem."""
124
125 def __init__(self, platform, arch):
126 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
127 self.platform = platform
128 self.arch = arch
129 self.labels = ['artifact', 'ruby', platform, arch]
130
131 def pre_build_jobspecs(self):
132 return []
133
134 def build_jobspec(self):
135 if self.platform == 'windows':
136 raise Exception("Not supported yet")
137 else:
138 if self.platform == 'linux':
139 environ = {}
140 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800141 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800142 return create_docker_jobspec(self.name,
143 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
144 'tools/run_tests/build_artifact_ruby.sh',
145 environ=environ)
146 else:
147 return create_jobspec(self.name,
148 ['tools/run_tests/build_artifact_ruby.sh'])
149
150
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800151class CSharpExtArtifact:
152 """Builds C# native extension library"""
153
154 def __init__(self, platform, arch):
155 self.name = 'csharp_ext_%s_%s' % (platform, arch)
156 self.platform = platform
157 self.arch = arch
158 self.labels = ['artifact', 'csharp', platform, arch]
159
160 def pre_build_jobspecs(self):
161 if self.platform == 'windows':
162 return [create_jobspec('prebuild_%s' % self.name,
163 ['tools\\run_tests\\pre_build_c.bat'],
164 shell=True,
165 flake_retries=5,
166 timeout_retries=2)]
167 else:
168 return []
169
170 def build_jobspec(self):
171 if self.platform == 'windows':
172 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
173 return create_jobspec(self.name,
174 ['tools\\run_tests\\build_artifact_csharp.bat',
175 'vsprojects\\grpc_csharp_ext.sln',
176 '/p:Configuration=Release',
177 '/p:PlatformToolset=v120',
178 '/p:Platform=%s' % msbuild_platform],
179 shell=True)
180 else:
181 environ = {'CONFIG': 'opt',
182 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800183 'EMBED_ZLIB': 'true',
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800184 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
185 'LDFLAGS': ''}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800186 if self.platform == 'linux':
187 return create_docker_jobspec(self.name,
188 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800189 'tools/run_tests/build_artifact_csharp.sh',
190 environ=environ)
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800191 else:
Jan Tattermusch60cbec72016-02-26 13:47:16 -0800192 archflag = _ARCH_FLAG_MAP[self.arch]
193 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
194 environ['LDFLAGS'] += ' %s' % archflag
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800195 return create_jobspec(self.name,
196 ['tools/run_tests/build_artifact_csharp.sh'],
197 environ=environ)
198
199 def __str__(self):
200 return self.name
201
Jan Tattermusche046f712016-02-18 16:06:10 -0800202
murgatroid99673f65b2016-02-01 11:19:07 -0800203node_gyp_arch_map = {
204 'x86': 'ia32',
205 'x64': 'x64'
206}
207
208class NodeExtArtifact:
209 """Builds Node native extension"""
210
211 def __init__(self, platform, arch):
212 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
213 self.platform = platform
214 self.arch = arch
215 self.gyp_arch = node_gyp_arch_map[arch]
216 self.labels = ['artifact', 'node', platform, arch]
217
218 def pre_build_jobspecs(self):
219 return []
220
221 def build_jobspec(self):
222 if self.platform == 'windows':
223 return create_jobspec(self.name,
224 ['tools\\run_tests\\build_artifact_node.bat',
225 self.gyp_arch],
226 shell=True)
227 else:
228 if self.platform == 'linux':
229 return create_docker_jobspec(
230 self.name,
231 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
232 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
233 else:
234 return create_jobspec(self.name,
235 ['tools/run_tests/build_artifact_node.sh',
236 self.gyp_arch])
237
Stanley Cheungbf74d692016-02-23 22:39:25 -0800238class PHPArtifact:
239 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800240
241 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800242 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800243 self.platform = platform
244 self.arch = arch
245 self.labels = ['artifact', 'php', platform, arch]
246
247 def pre_build_jobspecs(self):
248 return []
249
250 def build_jobspec(self):
Stanley Cheung80db5be2016-02-24 21:35:56 -0800251 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_php.sh')
256 else:
257 return create_jobspec(self.name,
258 ['tools/run_tests/build_artifact_php.sh'])
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800259
Jan Tattermusche046f712016-02-18 16:06:10 -0800260class ProtocArtifact:
261 """Builds protoc and protoc-plugin artifacts"""
262
263 def __init__(self, platform, arch):
264 self.name = 'protoc_%s_%s' % (platform, arch)
265 self.platform = platform
266 self.arch = arch
267 self.labels = ['artifact', 'protoc', platform, arch]
268
269 def pre_build_jobspecs(self):
270 return []
271
272 def build_jobspec(self):
273 if self.platform != 'windows':
274 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800275 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
276 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800277 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800278 environ={'CONFIG': 'opt',
279 'CXXFLAGS': cxxflags,
280 'LDFLAGS': ldflags,
281 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
282 if self.platform == 'linux':
283 return create_docker_jobspec(self.name,
284 'tools/dockerfile/grpc_artifact_protoc',
285 'tools/run_tests/build_artifact_protoc.sh',
286 environ=environ)
287 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800288 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800289 return create_jobspec(self.name,
290 ['tools/run_tests/build_artifact_protoc.sh'],
291 environ=environ)
292 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800293 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
294 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
295 return create_jobspec(self.name,
296 ['tools\\run_tests\\build_artifact_protoc.bat'],
297 environ={'generator': generator,
298 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800299
300 def __str__(self):
301 return self.name
302
303
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800304def targets():
305 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800306 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800307 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800308 for platform in ('linux', 'macos', 'windows')
309 for arch in ('x86', 'x64')] +
310 [PythonArtifact('linux', 'x86'),
311 PythonArtifact('linux', 'x64'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800312 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100313 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100314 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800315 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800316 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800317 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800318 PHPArtifact('linux', 'x64'),
319 PHPArtifact('macos', 'x64')])