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, |
Jan Tattermusch | 9835d4b | 2016-04-29 15:05:05 -0700 | [diff] [blame] | 46 | 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh', |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 47 | 'OUTPUT_DIR': 'artifacts'} |
| 48 | jobspec = jobset.JobSpec( |
Jan Tattermusch | 9835d4b | 2016-04-29 15:05:05 -0700 | [diff] [blame] | 49 | cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + docker_args, |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 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 | |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 72 | _MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7' |
| 73 | |
| 74 | _ARCH_FLAG_MAP = { |
| 75 | 'x86': '-m32', |
| 76 | 'x64': '-m64' |
| 77 | } |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 78 | |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 79 | python_version_arch_map = { |
| 80 | 'x86': 'Python27_32bits', |
| 81 | 'x64': 'Python27' |
| 82 | } |
| 83 | |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 84 | class PythonArtifact: |
| 85 | """Builds Python artifacts.""" |
| 86 | |
Masood Malekghassemi | 010eb48 | 2016-05-03 15:59:40 -0700 | [diff] [blame] | 87 | def __init__(self, platform, arch, manylinux_build=None): |
| 88 | if manylinux_build: |
| 89 | self.name = 'python_%s_%s_%s' % (platform, arch, manylinux_build) |
| 90 | else: |
| 91 | self.name = 'python_%s_%s' % (platform, arch) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 92 | self.platform = platform |
| 93 | self.arch = arch |
| 94 | self.labels = ['artifact', 'python', platform, arch] |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 95 | self.python_version = python_version_arch_map[arch] |
Masood Malekghassemi | 010eb48 | 2016-05-03 15:59:40 -0700 | [diff] [blame] | 96 | self.manylinux_build = manylinux_build |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 97 | |
| 98 | def pre_build_jobspecs(self): |
| 99 | return [] |
| 100 | |
| 101 | def build_jobspec(self): |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 102 | environ = {} |
| 103 | if self.platform == 'linux': |
| 104 | if self.arch == 'x86': |
| 105 | environ['SETARCH_CMD'] = 'linux32' |
Masood Malekghassemi | 010eb48 | 2016-05-03 15:59:40 -0700 | [diff] [blame] | 106 | # Inside the manylinux container, the python installations are located in |
| 107 | # special places... |
| 108 | environ['PYTHON'] = '/opt/python/{}/bin/python'.format(self.manylinux_build) |
| 109 | environ['PIP'] = '/opt/python/{}/bin/pip'.format(self.manylinux_build) |
| 110 | # Our docker image has all the prerequisites pip-installed already. |
| 111 | environ['SKIP_PIP_INSTALL'] = '1' |
| 112 | # Platform autodetection for the manylinux1 image breaks so we set the |
| 113 | # defines ourselves. |
| 114 | # TODO(atash) get better platform-detection support in core so we don't |
| 115 | # need to do this manually... |
Masood Malekghassemi | f4c70ca | 2016-05-05 19:14:05 -0700 | [diff] [blame] | 116 | environ['CFLAGS'] = '-DGPR_MANYLINUX1=1' |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 117 | return create_docker_jobspec(self.name, |
Masood Malekghassemi | 010eb48 | 2016-05-03 15:59:40 -0700 | [diff] [blame] | 118 | 'tools/dockerfile/grpc_artifact_python_manylinux_%s' % self.arch, |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 119 | 'tools/run_tests/build_artifact_python.sh', |
| 120 | environ=environ) |
| 121 | elif self.platform == 'windows': |
| 122 | return create_jobspec(self.name, |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 123 | ['tools\\run_tests\\build_artifact_python.bat', |
Masood Malekghassemi | 751fbb0 | 2016-05-04 16:12:56 -0700 | [diff] [blame] | 124 | self.python_version, |
| 125 | '32' if self.arch == 'x86' else '64' |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 126 | ], |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 127 | shell=True) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 128 | else: |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 129 | environ['SKIP_PIP_INSTALL'] = 'TRUE' |
| 130 | return create_jobspec(self.name, |
| 131 | ['tools/run_tests/build_artifact_python.sh'], |
| 132 | environ=environ) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 133 | |
| 134 | def __str__(self): |
| 135 | return self.name |
| 136 | |
| 137 | |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 138 | class RubyArtifact: |
| 139 | """Builds ruby native gem.""" |
| 140 | |
| 141 | def __init__(self, platform, arch): |
| 142 | self.name = 'ruby_native_gem_%s_%s' % (platform, arch) |
| 143 | self.platform = platform |
| 144 | self.arch = arch |
| 145 | self.labels = ['artifact', 'ruby', platform, arch] |
| 146 | |
| 147 | def pre_build_jobspecs(self): |
| 148 | return [] |
| 149 | |
| 150 | def build_jobspec(self): |
| 151 | if self.platform == 'windows': |
| 152 | raise Exception("Not supported yet") |
| 153 | else: |
| 154 | if self.platform == 'linux': |
| 155 | environ = {} |
| 156 | if self.arch == 'x86': |
Jan Tattermusch | 7cf8bf4 | 2016-02-03 13:41:07 -0800 | [diff] [blame] | 157 | environ['SETARCH_CMD'] = 'linux32' |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 158 | return create_docker_jobspec(self.name, |
| 159 | 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 160 | 'tools/run_tests/build_artifact_ruby.sh', |
| 161 | environ=environ) |
| 162 | else: |
| 163 | return create_jobspec(self.name, |
| 164 | ['tools/run_tests/build_artifact_ruby.sh']) |
| 165 | |
| 166 | |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 167 | class CSharpExtArtifact: |
| 168 | """Builds C# native extension library""" |
| 169 | |
| 170 | def __init__(self, platform, arch): |
| 171 | self.name = 'csharp_ext_%s_%s' % (platform, arch) |
| 172 | self.platform = platform |
| 173 | self.arch = arch |
| 174 | self.labels = ['artifact', 'csharp', platform, arch] |
| 175 | |
| 176 | def pre_build_jobspecs(self): |
| 177 | if self.platform == 'windows': |
| 178 | return [create_jobspec('prebuild_%s' % self.name, |
| 179 | ['tools\\run_tests\\pre_build_c.bat'], |
| 180 | shell=True, |
| 181 | flake_retries=5, |
| 182 | timeout_retries=2)] |
| 183 | else: |
| 184 | return [] |
| 185 | |
| 186 | def build_jobspec(self): |
| 187 | if self.platform == 'windows': |
| 188 | msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch |
| 189 | return create_jobspec(self.name, |
| 190 | ['tools\\run_tests\\build_artifact_csharp.bat', |
| 191 | 'vsprojects\\grpc_csharp_ext.sln', |
| 192 | '/p:Configuration=Release', |
| 193 | '/p:PlatformToolset=v120', |
| 194 | '/p:Platform=%s' % msbuild_platform], |
| 195 | shell=True) |
| 196 | else: |
| 197 | environ = {'CONFIG': 'opt', |
| 198 | 'EMBED_OPENSSL': 'true', |
Craig Tiller | 71ea4a1 | 2016-02-04 15:06:41 -0800 | [diff] [blame] | 199 | 'EMBED_ZLIB': 'true', |
Jan Tattermusch | 60cbec7 | 2016-02-26 13:47:16 -0800 | [diff] [blame] | 200 | 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE', |
| 201 | 'LDFLAGS': ''} |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 202 | if self.platform == 'linux': |
| 203 | return create_docker_jobspec(self.name, |
| 204 | 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
Jan Tattermusch | 60cbec7 | 2016-02-26 13:47:16 -0800 | [diff] [blame] | 205 | 'tools/run_tests/build_artifact_csharp.sh', |
| 206 | environ=environ) |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 207 | else: |
Jan Tattermusch | 60cbec7 | 2016-02-26 13:47:16 -0800 | [diff] [blame] | 208 | archflag = _ARCH_FLAG_MAP[self.arch] |
| 209 | environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG) |
| 210 | environ['LDFLAGS'] += ' %s' % archflag |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 211 | return create_jobspec(self.name, |
| 212 | ['tools/run_tests/build_artifact_csharp.sh'], |
| 213 | environ=environ) |
| 214 | |
| 215 | def __str__(self): |
| 216 | return self.name |
| 217 | |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 218 | |
murgatroid99 | 673f65b | 2016-02-01 11:19:07 -0800 | [diff] [blame] | 219 | node_gyp_arch_map = { |
| 220 | 'x86': 'ia32', |
| 221 | 'x64': 'x64' |
| 222 | } |
| 223 | |
| 224 | class NodeExtArtifact: |
| 225 | """Builds Node native extension""" |
| 226 | |
| 227 | def __init__(self, platform, arch): |
| 228 | self.name = 'node_ext_{0}_{1}'.format(platform, arch) |
| 229 | self.platform = platform |
| 230 | self.arch = arch |
| 231 | self.gyp_arch = node_gyp_arch_map[arch] |
| 232 | self.labels = ['artifact', 'node', platform, arch] |
| 233 | |
| 234 | def pre_build_jobspecs(self): |
| 235 | return [] |
| 236 | |
| 237 | def build_jobspec(self): |
| 238 | if self.platform == 'windows': |
| 239 | return create_jobspec(self.name, |
| 240 | ['tools\\run_tests\\build_artifact_node.bat', |
| 241 | self.gyp_arch], |
| 242 | shell=True) |
| 243 | else: |
| 244 | if self.platform == 'linux': |
| 245 | return create_docker_jobspec( |
| 246 | self.name, |
| 247 | 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 248 | 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch)) |
| 249 | else: |
| 250 | return create_jobspec(self.name, |
| 251 | ['tools/run_tests/build_artifact_node.sh', |
| 252 | self.gyp_arch]) |
| 253 | |
Stanley Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 254 | class PHPArtifact: |
| 255 | """Builds PHP PECL package""" |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 256 | |
| 257 | def __init__(self, platform, arch): |
Stanley Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 258 | self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch) |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 259 | self.platform = platform |
| 260 | self.arch = arch |
| 261 | self.labels = ['artifact', 'php', platform, arch] |
| 262 | |
| 263 | def pre_build_jobspecs(self): |
| 264 | return [] |
| 265 | |
| 266 | def build_jobspec(self): |
Stanley Cheung | 80db5be | 2016-02-24 21:35:56 -0800 | [diff] [blame] | 267 | if self.platform == 'linux': |
| 268 | return create_docker_jobspec( |
| 269 | self.name, |
| 270 | 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 271 | 'tools/run_tests/build_artifact_php.sh') |
| 272 | else: |
| 273 | return create_jobspec(self.name, |
| 274 | ['tools/run_tests/build_artifact_php.sh']) |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 275 | |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 276 | class ProtocArtifact: |
| 277 | """Builds protoc and protoc-plugin artifacts""" |
| 278 | |
| 279 | def __init__(self, platform, arch): |
| 280 | self.name = 'protoc_%s_%s' % (platform, arch) |
| 281 | self.platform = platform |
| 282 | self.arch = arch |
| 283 | self.labels = ['artifact', 'protoc', platform, arch] |
| 284 | |
| 285 | def pre_build_jobspecs(self): |
| 286 | return [] |
| 287 | |
| 288 | def build_jobspec(self): |
| 289 | if self.platform != 'windows': |
| 290 | cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch] |
Jan Tattermusch | e7b7d86 | 2016-02-19 09:49:35 -0800 | [diff] [blame] | 291 | ldflags = '%s' % _ARCH_FLAG_MAP[self.arch] |
| 292 | if self.platform != 'macos': |
Jan Tattermusch | 07591a5 | 2016-02-19 10:28:24 -0800 | [diff] [blame] | 293 | ldflags += ' -static-libgcc -static-libstdc++ -s' |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 294 | environ={'CONFIG': 'opt', |
| 295 | 'CXXFLAGS': cxxflags, |
| 296 | 'LDFLAGS': ldflags, |
| 297 | 'PROTOBUF_LDFLAGS_EXTRA': ldflags} |
| 298 | if self.platform == 'linux': |
| 299 | return create_docker_jobspec(self.name, |
| 300 | 'tools/dockerfile/grpc_artifact_protoc', |
| 301 | 'tools/run_tests/build_artifact_protoc.sh', |
| 302 | environ=environ) |
| 303 | else: |
Jan Tattermusch | e7b7d86 | 2016-02-19 09:49:35 -0800 | [diff] [blame] | 304 | environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_FLAG |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 305 | return create_jobspec(self.name, |
| 306 | ['tools/run_tests/build_artifact_protoc.sh'], |
| 307 | environ=environ) |
| 308 | else: |
Jan Tattermusch | 6d15982 | 2016-02-19 16:03:22 -0800 | [diff] [blame] | 309 | generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual Studio 12' |
| 310 | vcplatform = 'x64' if self.arch == 'x64' else 'Win32' |
| 311 | return create_jobspec(self.name, |
| 312 | ['tools\\run_tests\\build_artifact_protoc.bat'], |
| 313 | environ={'generator': generator, |
| 314 | 'Platform': vcplatform}) |
Jan Tattermusch | e046f71 | 2016-02-18 16:06:10 -0800 | [diff] [blame] | 315 | |
| 316 | def __str__(self): |
| 317 | return self.name |
| 318 | |
| 319 | |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 320 | def targets(): |
| 321 | """Gets list of supported targets""" |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 322 | return ([Cls(platform, arch) |
Jan Tattermusch | 6d15982 | 2016-02-19 16:03:22 -0800 | [diff] [blame] | 323 | for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact) |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 324 | for platform in ('linux', 'macos', 'windows') |
| 325 | for arch in ('x86', 'x64')] + |
Masood Malekghassemi | 010eb48 | 2016-05-03 15:59:40 -0700 | [diff] [blame] | 326 | [PythonArtifact('linux', 'x86', 'cp27-cp27m'), |
| 327 | PythonArtifact('linux', 'x86', 'cp27-cp27mu'), |
| 328 | PythonArtifact('linux', 'x64', 'cp27-cp27m'), |
| 329 | PythonArtifact('linux', 'x64', 'cp27-cp27mu'), |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame] | 330 | PythonArtifact('macos', 'x64'), |
Nicolas "Pixel" Noble | 6a4e473 | 2016-02-20 01:30:57 +0100 | [diff] [blame] | 331 | PythonArtifact('windows', 'x86'), |
Nicolas "Pixel" Noble | de808bb | 2016-02-18 01:13:14 +0100 | [diff] [blame] | 332 | PythonArtifact('windows', 'x64'), |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 333 | RubyArtifact('linux', 'x86'), |
murgatroid99 | 33c808b | 2016-02-03 15:27:41 -0800 | [diff] [blame] | 334 | RubyArtifact('linux', 'x64'), |
Stanley Cheung | 5adb71f | 2016-02-13 00:03:02 -0800 | [diff] [blame] | 335 | RubyArtifact('macos', 'x64'), |
Stanley Cheung | bf74d69 | 2016-02-23 22:39:25 -0800 | [diff] [blame] | 336 | PHPArtifact('linux', 'x64'), |
| 337 | PHPArtifact('macos', 'x64')]) |