Nathaniel Manista | cbf21da | 2016-02-02 22:17:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 2 | # 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 | |
| 33 | import jobset |
| 34 | |
| 35 | |
| 36 | def 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 | |
| 58 | def 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 Tattermusch | 5b762b6 | 2016-02-09 08:18:02 -0800 | [diff] [blame] | 65 | timeout_seconds=30*60, |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 66 | flake_retries=flake_retries, |
| 67 | timeout_retries=timeout_retries, |
| 68 | shell=shell) |
| 69 | return jobspec |
| 70 | |
| 71 | |
| 72 | def 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 Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 82 | _MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7' |
| 83 | |
| 84 | _ARCH_FLAG_MAP = { |
| 85 | 'x86': '-m32', |
| 86 | 'x64': '-m64' |
| 87 | } |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 88 | |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 89 | python_version_arch_map = { |
| 90 | 'x86': 'Python27_32bits', |
| 91 | 'x64': 'Python27' |
| 92 | } |
| 93 | |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 94 | class 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" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 102 | self.python_version = python_version_arch_map[arch] |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 103 | |
| 104 | def pre_build_jobspecs(self): |
| 105 | return [] |
| 106 | |
| 107 | def build_jobspec(self): |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 108 | 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" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 118 | ['tools\\run_tests\\build_artifact_python.bat', |
| 119 | self.python_version |
| 120 | ], |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 121 | shell=True) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 122 | else: |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 123 | environ['SKIP_PIP_INSTALL'] = 'TRUE' |
| 124 | return create_jobspec(self.name, |
| 125 | ['tools/run_tests/build_artifact_python.sh'], |
| 126 | environ=environ) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 127 | |
| 128 | def __str__(self): |
| 129 | return self.name |
| 130 | |
| 131 | |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 132 | class 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 Tattermusch | 7cf8bf4 | 2016-02-03 13:41:07 -0800 | [diff] [blame] | 151 | environ['SETARCH_CMD'] = 'linux32' |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 152 | 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 Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 161 | class 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 Tiller | 71ea4a1 | 2016-02-04 15:06:41 -0800 | [diff] [blame] | 193 | 'EMBED_ZLIB': 'true', |
| 194 | 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE'} |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 195 | 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 Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 208 | |
murgatroid99 | 673f65b | 2016-02-01 11:19:07 -0800 | [diff] [blame] | 209 | node_gyp_arch_map = { |
| 210 | 'x86': 'ia32', |
| 211 | 'x64': 'x64' |
| 212 | } |
| 213 | |
| 214 | class 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 Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 244 | class PHPArtifact: |
| 245 | """Builds PHP PECL package""" |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 246 | |
| 247 | def __init__(self, platform, arch): |
Stanley Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 248 | self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch) |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 249 | 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): |
Stanley Cheung | 80db5be | 2016-02-24 21:35:56 -0800 | [diff] [blame^] | 257 | if self.platform == 'linux': |
| 258 | return create_docker_jobspec( |
| 259 | self.name, |
| 260 | 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 261 | 'tools/run_tests/build_artifact_php.sh') |
| 262 | else: |
| 263 | return create_jobspec(self.name, |
| 264 | ['tools/run_tests/build_artifact_php.sh']) |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 265 | |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 266 | class ProtocArtifact: |
| 267 | """Builds protoc and protoc-plugin artifacts""" |
| 268 | |
| 269 | def __init__(self, platform, arch): |
| 270 | self.name = 'protoc_%s_%s' % (platform, arch) |
| 271 | self.platform = platform |
| 272 | self.arch = arch |
| 273 | self.labels = ['artifact', 'protoc', platform, arch] |
| 274 | |
| 275 | def pre_build_jobspecs(self): |
| 276 | return [] |
| 277 | |
| 278 | def build_jobspec(self): |
| 279 | if self.platform != 'windows': |
| 280 | cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch] |
Jan Tattermusch | e7b7d86 | 2016-02-19 09:49:35 -0800 | [diff] [blame] | 281 | ldflags = '%s' % _ARCH_FLAG_MAP[self.arch] |
| 282 | if self.platform != 'macos': |
Jan Tattermusch | 07591a5 | 2016-02-19 10:28:24 -0800 | [diff] [blame] | 283 | ldflags += ' -static-libgcc -static-libstdc++ -s' |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 284 | environ={'CONFIG': 'opt', |
| 285 | 'CXXFLAGS': cxxflags, |
| 286 | 'LDFLAGS': ldflags, |
| 287 | 'PROTOBUF_LDFLAGS_EXTRA': ldflags} |
| 288 | if self.platform == 'linux': |
| 289 | return create_docker_jobspec(self.name, |
| 290 | 'tools/dockerfile/grpc_artifact_protoc', |
| 291 | 'tools/run_tests/build_artifact_protoc.sh', |
| 292 | environ=environ) |
| 293 | else: |
Jan Tattermusch | e7b7d86 | 2016-02-19 09:49:35 -0800 | [diff] [blame] | 294 | environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 295 | return create_jobspec(self.name, |
| 296 | ['tools/run_tests/build_artifact_protoc.sh'], |
| 297 | environ=environ) |
| 298 | else: |
Jan Tattermusch | 6d15982 | 2016-02-19 16:03:22 -0800 | [diff] [blame] | 299 | generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12' |
| 300 | vcplatform = 'x64' if self.arch == 'x64' else 'Win32' |
| 301 | return create_jobspec(self.name, |
| 302 | ['tools\\run_tests\\build_artifact_protoc.bat'], |
| 303 | environ={'generator': generator, |
| 304 | 'Platform': vcplatform}) |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 305 | |
| 306 | def __str__(self): |
| 307 | return self.name |
| 308 | |
| 309 | |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 310 | def targets(): |
| 311 | """Gets list of supported targets""" |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 312 | return ([Cls(platform, arch) |
Jan Tattermusch | 6d15982 | 2016-02-19 16:03:22 -0800 | [diff] [blame] | 313 | for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact) |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 314 | for platform in ('linux', 'macos', 'windows') |
| 315 | for arch in ('x86', 'x64')] + |
| 316 | [PythonArtifact('linux', 'x86'), |
| 317 | PythonArtifact('linux', 'x64'), |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame] | 318 | PythonArtifact('macos', 'x64'), |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 319 | PythonArtifact('windows', 'x86'), |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 320 | PythonArtifact('windows', 'x64'), |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 321 | RubyArtifact('linux', 'x86'), |
murgatroid99 | 33c808b | 2016-02-03 15:27:41 -0800 | [diff] [blame] | 322 | RubyArtifact('linux', 'x64'), |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 323 | RubyArtifact('macos', 'x64'), |
Stanley Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 324 | PHPArtifact('linux', 'x64'), |
| 325 | PHPArtifact('macos', 'x64')]) |