blob: e30c5bb3bb48ac54d8f571c9c755a383da7dc589 [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),
murgatroid99673f65b2016-02-01 11:19:07 -080065 timeout_seconds=10*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
Jan Tattermusch8640f922016-02-01 18:58:46 -080083class PythonArtifact:
84 """Builds Python artifacts."""
85
86 def __init__(self, platform, arch):
87 self.name = 'python_%s_%s' % (platform, arch)
88 self.platform = platform
89 self.arch = arch
90 self.labels = ['artifact', 'python', platform, arch]
91
92 def pre_build_jobspecs(self):
93 return []
94
95 def build_jobspec(self):
96 if self.platform == 'windows':
97 raise Exception('Not supported yet.')
98 else:
99 if self.platform == 'linux':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800100 environ = {}
101 if self.arch == 'x86':
102 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch8640f922016-02-01 18:58:46 -0800103 return create_docker_jobspec(self.name,
104 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800105 'tools/run_tests/build_artifact_python.sh',
106 environ=environ)
Jan Tattermusch8640f922016-02-01 18:58:46 -0800107 else:
108 return create_jobspec(self.name,
109 ['tools/run_tests/build_artifact_python.sh'])
110
111 def __str__(self):
112 return self.name
113
114
Jan Tattermusch44372132016-02-01 16:20:03 -0800115class RubyArtifact:
116 """Builds ruby native gem."""
117
118 def __init__(self, platform, arch):
119 self.name = 'ruby_native_gem_%s_%s' % (platform, arch)
120 self.platform = platform
121 self.arch = arch
122 self.labels = ['artifact', 'ruby', platform, arch]
123
124 def pre_build_jobspecs(self):
125 return []
126
127 def build_jobspec(self):
128 if self.platform == 'windows':
129 raise Exception("Not supported yet")
130 else:
131 if self.platform == 'linux':
132 environ = {}
133 if self.arch == 'x86':
Jan Tattermusch7cf8bf42016-02-03 13:41:07 -0800134 environ['SETARCH_CMD'] = 'linux32'
Jan Tattermusch44372132016-02-01 16:20:03 -0800135 return create_docker_jobspec(self.name,
136 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
137 'tools/run_tests/build_artifact_ruby.sh',
138 environ=environ)
139 else:
140 return create_jobspec(self.name,
141 ['tools/run_tests/build_artifact_ruby.sh'])
142
143
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800144class CSharpExtArtifact:
145 """Builds C# native extension library"""
146
147 def __init__(self, platform, arch):
148 self.name = 'csharp_ext_%s_%s' % (platform, arch)
149 self.platform = platform
150 self.arch = arch
151 self.labels = ['artifact', 'csharp', platform, arch]
152
153 def pre_build_jobspecs(self):
154 if self.platform == 'windows':
155 return [create_jobspec('prebuild_%s' % self.name,
156 ['tools\\run_tests\\pre_build_c.bat'],
157 shell=True,
158 flake_retries=5,
159 timeout_retries=2)]
160 else:
161 return []
162
163 def build_jobspec(self):
164 if self.platform == 'windows':
165 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
166 return create_jobspec(self.name,
167 ['tools\\run_tests\\build_artifact_csharp.bat',
168 'vsprojects\\grpc_csharp_ext.sln',
169 '/p:Configuration=Release',
170 '/p:PlatformToolset=v120',
171 '/p:Platform=%s' % msbuild_platform],
172 shell=True)
173 else:
174 environ = {'CONFIG': 'opt',
175 'EMBED_OPENSSL': 'true',
176 'EMBED_ZLIB': 'true'}
177 if self.platform == 'linux':
178 return create_docker_jobspec(self.name,
179 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
180 'tools/run_tests/build_artifact_csharp.sh')
181 else:
182 environ.update(macos_arch_env(self.arch))
183 return create_jobspec(self.name,
184 ['tools/run_tests/build_artifact_csharp.sh'],
185 environ=environ)
186
187 def __str__(self):
188 return self.name
189
murgatroid99673f65b2016-02-01 11:19:07 -0800190node_gyp_arch_map = {
191 'x86': 'ia32',
192 'x64': 'x64'
193}
194
195class NodeExtArtifact:
196 """Builds Node native extension"""
197
198 def __init__(self, platform, arch):
199 self.name = 'node_ext_{0}_{1}'.format(platform, arch)
200 self.platform = platform
201 self.arch = arch
202 self.gyp_arch = node_gyp_arch_map[arch]
203 self.labels = ['artifact', 'node', platform, arch]
204
205 def pre_build_jobspecs(self):
206 return []
207
208 def build_jobspec(self):
209 if self.platform == 'windows':
210 return create_jobspec(self.name,
211 ['tools\\run_tests\\build_artifact_node.bat',
212 self.gyp_arch],
213 shell=True)
214 else:
215 if self.platform == 'linux':
216 return create_docker_jobspec(
217 self.name,
218 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch),
219 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch))
220 else:
221 return create_jobspec(self.name,
222 ['tools/run_tests/build_artifact_node.sh',
223 self.gyp_arch])
224
Jan Tattermuschbe538a12016-01-28 14:58:15 -0800225
226def targets():
227 """Gets list of supported targets"""
murgatroid9941a9e832016-02-03 09:47:35 -0800228 return ([Cls(platform, arch)
229 for Cls in (CSharpExtArtifact, NodeExtArtifact)
230 for platform in ('linux', 'macos', 'windows')
231 for arch in ('x86', 'x64')] +
232 [PythonArtifact('linux', 'x86'),
233 PythonArtifact('linux', 'x64'),
234 RubyArtifact('linux', 'x86'),
235 RubyArtifact('linux', 'x64')])