blob: b565fbb3f0357145b870c838251e7add3cd1f605 [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
82
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010083python_version_arch_map = {
84 'x86': 'Python27_32bits',
85 'x64': 'Python27'
86}
87
Jan Tattermusch8640f922016-02-01 18:58:46 -080088class PythonArtifact:
89 """Builds Python artifacts."""
90
91 def __init__(self, platform, arch):
92 self.name = 'python_%s_%s' % (platform, arch)
93 self.platform = platform
94 self.arch = arch
95 self.labels = ['artifact', 'python', platform, arch]
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +010096 self.python_version = python_version_arch_map[arch]
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'
106 return create_docker_jobspec(self.name,
107 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
108 'tools/run_tests/build_artifact_python.sh',
109 environ=environ)
110 elif self.platform == 'windows':
111 return create_jobspec(self.name,
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100112 ['tools\\run_tests\\build_artifact_python.bat',
113 self.python_version
114 ],
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100115 shell=True)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800116 else:
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100117 environ['SKIP_PIP_INSTALL'] = 'TRUE'
118 return create_jobspec(self.name,
119 ['tools/run_tests/build_artifact_python.sh'],
120 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800121
122 def __str__(self):
123 return self.name
124
125
Jan Tattermusch44372132016-02-01 16:20:03 -0800126class RubyArtifact:
127 """Builds ruby native gem."""
128
129 def __init__(self, platform, arch):
130 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
131 self.platform = platform
132 self.arch = arch
133 self.labels = ['artifact', 'ruby', platform, arch]
134
135 def pre_build_jobspecs(self):
136 return []
137
138 def build_jobspec(self):
139 if self.platform == 'windows':
140 raise Exception("Not supported yet")
141 else:
142 if self.platform == 'linux':
143 environ = {}
144 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800145 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800146 return create_docker_jobspec(self.name,
147 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
148 'tools/run_tests/build_artifact_ruby.sh',
149 environ=environ)
150 else:
151 return create_jobspec(self.name,
152 ['tools/run_tests/build_artifact_ruby.sh'])
153
154
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800155class CSharpExtArtifact:
156 """Builds C# native extension library"""
157
158 def __init__(self, platform, arch):
159 self.name = 'csharp_ext_%s_%s' % (platform, arch)
160 self.platform = platform
161 self.arch = arch
162 self.labels = ['artifact', 'csharp', platform, arch]
163
164 def pre_build_jobspecs(self):
165 if self.platform == 'windows':
166 return [create_jobspec('prebuild_%s' % self.name,
167 ['tools\\run_tests\\pre_build_c.bat'],
168 shell=True,
169 flake_retries=5,
170 timeout_retries=2)]
171 else:
172 return []
173
174 def build_jobspec(self):
175 if self.platform == 'windows':
176 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
177 return create_jobspec(self.name,
178 ['tools\\run_tests\\build_artifact_csharp.bat',
179 'vsprojects\\grpc_csharp_ext.sln',
180 '/p:Configuration=Release',
181 '/p:PlatformToolset=v120',
182 '/p:Platform=%s' % msbuild_platform],
183 shell=True)
184 else:
185 environ = {'CONFIG': 'opt',
186 'EMBED_OPENSSL': 'true',
Craig Tiller71ea4a12016-02-04 15:06:41 -0800187 'EMBED_ZLIB': 'true',
188 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE'}
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800189 if self.platform == 'linux':
190 return create_docker_jobspec(self.name,
191 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
192 'tools/run_tests/build_artifact_csharp.sh')
193 else:
194 environ.update(macos_arch_env(self.arch))
195 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
murgatroid99673f65b2016-02-01 11:19:07 -0800202node_gyp_arch_map = {
203 'x86': 'ia32',
204 'x64': 'x64'
205}
206
207class NodeExtArtifact:
208 """Builds Node native extension"""
209
210 def __init__(self, platform, arch):
211 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
212 self.platform = platform
213 self.arch = arch
214 self.gyp_arch = node_gyp_arch_map[arch]
215 self.labels = ['artifact', 'node', platform, arch]
216
217 def pre_build_jobspecs(self):
218 return []
219
220 def build_jobspec(self):
221 if self.platform == 'windows':
222 return create_jobspec(self.name,
223 ['tools\\run_tests\\build_artifact_node.bat',
224 self.gyp_arch],
225 shell=True)
226 else:
227 if self.platform == 'linux':
228 return create_docker_jobspec(
229 self.name,
230 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
231 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
232 else:
233 return create_jobspec(self.name,
234 ['tools/run_tests/build_artifact_node.sh',
235 self.gyp_arch])
236
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800237
238def targets():
239 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800240 return ([Cls(platform, arch)
241 for Cls in (CSharpExtArtifact, NodeExtArtifact)
242 for platform in ('linux', 'macos', 'windows')
243 for arch in ('x86', 'x64')] +
244 [PythonArtifact('linux', 'x86'),
245 PythonArtifact('linux', 'x64'),
Jan Tattermusche0667172016-02-03 15:57:57 -0800246 PythonArtifact('macos', 'x64'),
Nicolas "Pixel" Noble6a4e4732016-02-20 01:30:57 +0100247 PythonArtifact('windows', 'x86'),
Nicolas "Pixel" Noblede808bb2016-02-18 01:13:14 +0100248 PythonArtifact('windows', 'x64'),
murgatroid9941a9e832016-02-03 09:47:35 -0800249 RubyArtifact('linux', 'x86'),
murgatroid9933c808b2016-02-03 15:27:41 -0800250 RubyArtifact('linux', 'x64'),
251 RubyArtifact('macos', 'x64')])