blob: 803d3d106b21532521712c393b76854c49466c45 [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,
46 'DOCKER_RUN_SCRIPT': 'tools/jenkins/docker_run.sh',
47 'OUTPUT_DIR': 'artifacts'}
48 jobspec = jobset.JobSpec(
49 cmdline=['tools/jenkins/build_and_run_docker.sh'] + docker_args,
50 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
72def macos_arch_env(arch):
73 """Returns environ specifying -arch arguments for make."""
74 if arch == 'x86':
75 arch_arg = '-arch i386'
76 elif arch == 'x64':
77 arch_arg = '-arch x86_64'
78 else:
79 raise Exception('Unsupported arch')
80 return {'CFLAGS': arch_arg, 'LDFLAGS': arch_arg}
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 +010089python_version_arch_map = {
90 'x86': 'Python27_32bits',
91 'x64': 'Python27'
92}
93
Jan Tattermusch8640f922016-02-01 18:58:46 -080094class PythonArtifact:
95 """Builds Python artifacts."""
96
97 def __init__(self, platform, arch):
98 self.name = 'python_%s_%s' % (platform, arch)
99 self.platform = platform
100 self.arch = arch
101 self.labels = ['artifact', 'python', platform, arch]
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100102 self.python_version = python_version_arch_map[arch]
Jan Tattermusch8640f922016-02-01 18:58:46 -0800103
104 def pre_build_jobspecs(self):
105 return []
106
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'
112 return create_docker_jobspec(self.name,
113 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
114 'tools/run_tests/build_artifact_python.sh',
115 environ=environ)
116 elif self.platform == 'windows':
117 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100118 ['tools\\run_tests\\build_artifact_python.bat',
119 self.python_version
120 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100121 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800122 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100123 environ['SKIP_PIP_INSTALL'] = 'TRUE'
124 return create_jobspec(self.name,
125 ['tools/run_tests/build_artifact_python.sh'],
126 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800127
128 def __str__(self):
129 return self.name
130
131
Jan Tattermusch44372132016-02-01 16:20:03 -0800132class RubyArtifact:
133 """Builds ruby native gem."""
134
135 def __init__(self, platform, arch):
136 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
137 self.platform = platform
138 self.arch = arch
139 self.labels = ['artifact', 'ruby', platform, arch]
140
141 def pre_build_jobspecs(self):
142 return []
143
144 def build_jobspec(self):
145 if self.platform == 'windows':
146 raise Exception("Not supported yet")
147 else:
148 if self.platform == 'linux':
149 environ = {}
150 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800151 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800152 return create_docker_jobspec(self.name,
153 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
154 'tools/run_tests/build_artifact_ruby.sh',
155 environ=environ)
156 else:
157 return create_jobspec(self.name,
158 ['tools/run_tests/build_artifact_ruby.sh'])
159
160
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800161class CSharpExtArtifact:
162 """Builds C# native extension library"""
163
164 def __init__(self, platform, arch):
165 self.name = 'csharp_ext_%s_%s' % (platform, arch)
166 self.platform = platform
167 self.arch = arch
168 self.labels = ['artifact', 'csharp', platform, arch]
169
170 def pre_build_jobspecs(self):
171 if self.platform == 'windows':
172 return [create_jobspec('prebuild_%s' % self.name,
173 ['tools\\run_tests\\pre_build_c.bat'],
174 shell=True,
175 flake_retries=5,
176 timeout_retries=2)]
177 else:
178 return []
179
180 def build_jobspec(self):
181 if self.platform == 'windows':
182 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
183 return create_jobspec(self.name,
184 ['tools\\run_tests\\build_artifact_csharp.bat',
185 'vsprojects\\grpc_csharp_ext.sln',
186 '/p:Configuration=Release',
187 '/p:PlatformToolset=v120',
188 '/p:Platform=%s' % msbuild_platform],
189 shell=True)
190 else:
191 environ = {'CONFIG': 'opt',
192 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800193 'EMBED_ZLIB': 'true',
194 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE'}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800195 if self.platform == 'linux':
196 return create_docker_jobspec(self.name,
197 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
198 'tools/run_tests/build_artifact_csharp.sh')
199 else:
200 environ.update(macos_arch_env(self.arch))
201 return create_jobspec(self.name,
202 ['tools/run_tests/build_artifact_csharp.sh'],
203 environ=environ)
204
205 def __str__(self):
206 return self.name
207
Jan Tattermusche046f712016-02-18 16:06:10 -0800208
murgatroid99673f65b2016-02-01 11:19:07 -0800209node_gyp_arch_map = {
210 'x86': 'ia32',
211 'x64': 'x64'
212}
213
214class NodeExtArtifact:
215 """Builds Node native extension"""
216
217 def __init__(self, platform, arch):
218 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
219 self.platform = platform
220 self.arch = arch
221 self.gyp_arch = node_gyp_arch_map[arch]
222 self.labels = ['artifact', 'node', platform, arch]
223
224 def pre_build_jobspecs(self):
225 return []
226
227 def build_jobspec(self):
228 if self.platform == 'windows':
229 return create_jobspec(self.name,
230 ['tools\\run_tests\\build_artifact_node.bat',
231 self.gyp_arch],
232 shell=True)
233 else:
234 if self.platform == 'linux':
235 return create_docker_jobspec(
236 self.name,
237 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
238 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
239 else:
240 return create_jobspec(self.name,
241 ['tools/run_tests/build_artifact_node.sh',
242 self.gyp_arch])
243
Stanley Cheungbf74d692016-02-23 22:39:25 -0800244class PHPArtifact:
245 """Builds PHP PECL package"""
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800246
247 def __init__(self, platform, arch):
Stanley Cheungbf74d692016-02-23 22:39:25 -0800248 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch)
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800249 self.platform = platform
250 self.arch = arch
251 self.labels = ['artifact', 'php', platform, arch]
252
253 def pre_build_jobspecs(self):
254 return []
255
256 def build_jobspec(self):
257 return create_docker_jobspec(
258 self.name,
259 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
260 'tools/run_tests/build_artifact_php.sh')
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800261
Jan Tattermusche046f712016-02-18 16:06:10 -0800262class ProtocArtifact:
263 """Builds protoc and protoc-plugin artifacts"""
264
265 def __init__(self, platform, arch):
266 self.name = 'protoc_%s_%s' % (platform, arch)
267 self.platform = platform
268 self.arch = arch
269 self.labels = ['artifact', 'protoc', platform, arch]
270
271 def pre_build_jobspecs(self):
272 return []
273
274 def build_jobspec(self):
275 if self.platform != 'windows':
276 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch]
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800277 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch]
278 if self.platform != 'macos':
Jan Tattermusch07591a52016-02-19 10:28:24 -0800279 ldflags += ' -static-libgcc -static-libstdc++ -s'
Jan Tattermusche046f712016-02-18 16:06:10 -0800280 environ={'CONFIG': 'opt',
281 'CXXFLAGS': cxxflags,
282 'LDFLAGS': ldflags,
283 'PROTOBUF_LDFLAGS_EXTRA': ldflags}
284 if self.platform == 'linux':
285 return create_docker_jobspec(self.name,
286 'tools/dockerfile/grpc_artifact_protoc',
287 'tools/run_tests/build_artifact_protoc.sh',
288 environ=environ)
289 else:
Jan Tattermusche7b7d862016-02-19 09:49:35 -0800290 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG
Jan Tattermusche046f712016-02-18 16:06:10 -0800291 return create_jobspec(self.name,
292 ['tools/run_tests/build_artifact_protoc.sh'],
293 environ=environ)
294 else:
Jan Tattermusch6d159822016-02-19 16:03:22 -0800295 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12'
296 vcplatform = 'x64' if self.arch == 'x64' else 'Win32'
297 return create_jobspec(self.name,
298 ['tools\\run_tests\\build_artifact_protoc.bat'],
299 environ={'generator': generator,
300 'Platform': vcplatform})
Jan Tattermusche046f712016-02-18 16:06:10 -0800301
302 def __str__(self):
303 return self.name
304
305
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800306def targets():
307 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800308 return ([Cls(platform, arch)
Jan Tattermusch6d159822016-02-19 16:03:22 -0800309 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact)
murgatroid9941a9e832016-02-03 09:47:35 -0800310 for platform in ('linux', 'macos', 'windows')
311 for arch in ('x86', 'x64')] +
312 [PythonArtifact('linux', 'x86'),
313 PythonArtifact('linux', 'x64'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800314 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100315 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100316 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800317 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800318 RubyArtifact('linux', 'x64'),
Stanley Cheung5adb71f2016-02-13 00:03:02 -0800319 RubyArtifact('macos', 'x64'),
Stanley Cheungbf74d692016-02-23 22:39:25 -0800320 PHPArtifact('linux', 'x64'),
321 PHPArtifact('macos', 'x64')])