OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python2.7 |
| 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), |
| 65 timeout_seconds=30*60, |
| 66 flake_retries=flake_retries, |
| 67 timeout_retries=timeout_retries, |
| 68 shell=shell) |
| 69 return jobspec |
| 70 |
| 71 |
| 72 _MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7' |
| 73 |
| 74 _ARCH_FLAG_MAP = { |
| 75 'x86': '-m32', |
| 76 'x64': '-m64' |
| 77 } |
| 78 |
| 79 python_version_arch_map = { |
| 80 'x86': 'Python27_32bits', |
| 81 'x64': 'Python27' |
| 82 } |
| 83 |
| 84 class PythonArtifact: |
| 85 """Builds Python artifacts.""" |
| 86 |
| 87 def __init__(self, platform, arch): |
| 88 self.name = 'python_%s_%s' % (platform, arch) |
| 89 self.platform = platform |
| 90 self.arch = arch |
| 91 self.labels = ['artifact', 'python', platform, arch] |
| 92 self.python_version = python_version_arch_map[arch] |
| 93 |
| 94 def pre_build_jobspecs(self): |
| 95 return [] |
| 96 |
| 97 def build_jobspec(self): |
| 98 environ = {} |
| 99 if self.platform == 'linux': |
| 100 if self.arch == 'x86': |
| 101 environ['SETARCH_CMD'] = 'linux32' |
| 102 return create_docker_jobspec(self.name, |
| 103 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 104 'tools/run_tests/build_artifact_python.sh', |
| 105 environ=environ) |
| 106 elif self.platform == 'windows': |
| 107 return create_jobspec(self.name, |
| 108 ['tools\\run_tests\\build_artifact_python.bat', |
| 109 self.python_version |
| 110 ], |
| 111 shell=True) |
| 112 else: |
| 113 environ['SKIP_PIP_INSTALL'] = 'TRUE' |
| 114 return create_jobspec(self.name, |
| 115 ['tools/run_tests/build_artifact_python.sh'], |
| 116 environ=environ) |
| 117 |
| 118 def __str__(self): |
| 119 return self.name |
| 120 |
| 121 |
| 122 class RubyArtifact: |
| 123 """Builds ruby native gem.""" |
| 124 |
| 125 def __init__(self, platform, arch): |
| 126 self.name = 'ruby_native_gem_%s_%s' % (platform, arch) |
| 127 self.platform = platform |
| 128 self.arch = arch |
| 129 self.labels = ['artifact', 'ruby', platform, arch] |
| 130 |
| 131 def pre_build_jobspecs(self): |
| 132 return [] |
| 133 |
| 134 def build_jobspec(self): |
| 135 if self.platform == 'windows': |
| 136 raise Exception("Not supported yet") |
| 137 else: |
| 138 if self.platform == 'linux': |
| 139 environ = {} |
| 140 if self.arch == 'x86': |
| 141 environ['SETARCH_CMD'] = 'linux32' |
| 142 return create_docker_jobspec(self.name, |
| 143 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 144 'tools/run_tests/build_artifact_ruby.sh', |
| 145 environ=environ) |
| 146 else: |
| 147 return create_jobspec(self.name, |
| 148 ['tools/run_tests/build_artifact_ruby.sh']) |
| 149 |
| 150 |
| 151 class CSharpExtArtifact: |
| 152 """Builds C# native extension library""" |
| 153 |
| 154 def __init__(self, platform, arch): |
| 155 self.name = 'csharp_ext_%s_%s' % (platform, arch) |
| 156 self.platform = platform |
| 157 self.arch = arch |
| 158 self.labels = ['artifact', 'csharp', platform, arch] |
| 159 |
| 160 def pre_build_jobspecs(self): |
| 161 if self.platform == 'windows': |
| 162 return [create_jobspec('prebuild_%s' % self.name, |
| 163 ['tools\\run_tests\\pre_build_c.bat'], |
| 164 shell=True, |
| 165 flake_retries=5, |
| 166 timeout_retries=2)] |
| 167 else: |
| 168 return [] |
| 169 |
| 170 def build_jobspec(self): |
| 171 if self.platform == 'windows': |
| 172 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch |
| 173 return create_jobspec(self.name, |
| 174 ['tools\\run_tests\\build_artifact_csharp.bat', |
| 175 'vsprojects\\grpc_csharp_ext.sln', |
| 176 '/p:Configuration=Release', |
| 177 '/p:PlatformToolset=v120', |
| 178 '/p:Platform=%s' % msbuild_platform], |
| 179 shell=True) |
| 180 else: |
| 181 environ = {'CONFIG': 'opt', |
| 182 'EMBED_OPENSSL': 'true', |
| 183 'EMBED_ZLIB': 'true', |
| 184 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE', |
| 185 'LDFLAGS': ''} |
| 186 if self.platform == 'linux': |
| 187 return create_docker_jobspec(self.name, |
| 188 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 189 'tools/run_tests/build_artifact_csharp.sh', |
| 190 environ=environ) |
| 191 else: |
| 192 archflag = _ARCH_FLAG_MAP[self.arch] |
| 193 environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG) |
| 194 environ['LDFLAGS'] += ' %s' % archflag |
| 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 |
| 202 |
| 203 node_gyp_arch_map = { |
| 204 'x86': 'ia32', |
| 205 'x64': 'x64' |
| 206 } |
| 207 |
| 208 class NodeExtArtifact: |
| 209 """Builds Node native extension""" |
| 210 |
| 211 def __init__(self, platform, arch): |
| 212 self.name = 'node_ext_{0}_{1}'.format(platform, arch) |
| 213 self.platform = platform |
| 214 self.arch = arch |
| 215 self.gyp_arch = node_gyp_arch_map[arch] |
| 216 self.labels = ['artifact', 'node', platform, arch] |
| 217 |
| 218 def pre_build_jobspecs(self): |
| 219 return [] |
| 220 |
| 221 def build_jobspec(self): |
| 222 if self.platform == 'windows': |
| 223 return create_jobspec(self.name, |
| 224 ['tools\\run_tests\\build_artifact_node.bat', |
| 225 self.gyp_arch], |
| 226 shell=True) |
| 227 else: |
| 228 if self.platform == 'linux': |
| 229 return create_docker_jobspec( |
| 230 self.name, |
| 231 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 232 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch)) |
| 233 else: |
| 234 return create_jobspec(self.name, |
| 235 ['tools/run_tests/build_artifact_node.sh', |
| 236 self.gyp_arch]) |
| 237 |
| 238 class PHPArtifact: |
| 239 """Builds PHP PECL package""" |
| 240 |
| 241 def __init__(self, platform, arch): |
| 242 self.name = 'php_pecl_package_{0}_{1}'.format(platform, arch) |
| 243 self.platform = platform |
| 244 self.arch = arch |
| 245 self.labels = ['artifact', 'php', platform, arch] |
| 246 |
| 247 def pre_build_jobspecs(self): |
| 248 return [] |
| 249 |
| 250 def build_jobspec(self): |
| 251 if self.platform == 'linux': |
| 252 return create_docker_jobspec( |
| 253 self.name, |
| 254 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 255 'tools/run_tests/build_artifact_php.sh') |
| 256 else: |
| 257 return create_jobspec(self.name, |
| 258 ['tools/run_tests/build_artifact_php.sh']) |
| 259 |
| 260 class ProtocArtifact: |
| 261 """Builds protoc and protoc-plugin artifacts""" |
| 262 |
| 263 def __init__(self, platform, arch): |
| 264 self.name = 'protoc_%s_%s' % (platform, arch) |
| 265 self.platform = platform |
| 266 self.arch = arch |
| 267 self.labels = ['artifact', 'protoc', platform, arch] |
| 268 |
| 269 def pre_build_jobspecs(self): |
| 270 return [] |
| 271 |
| 272 def build_jobspec(self): |
| 273 if self.platform != 'windows': |
| 274 cxxflags = '-DNDEBUG %s' % _ARCH_FLAG_MAP[self.arch] |
| 275 ldflags = '%s' % _ARCH_FLAG_MAP[self.arch] |
| 276 if self.platform != 'macos': |
| 277 ldflags += ' -static-libgcc -static-libstdc++ -s' |
| 278 environ={'CONFIG': 'opt', |
| 279 'CXXFLAGS': cxxflags, |
| 280 'LDFLAGS': ldflags, |
| 281 'PROTOBUF_LDFLAGS_EXTRA': ldflags} |
| 282 if self.platform == 'linux': |
| 283 return create_docker_jobspec(self.name, |
| 284 'tools/dockerfile/grpc_artifact_protoc', |
| 285 'tools/run_tests/build_artifact_protoc.sh', |
| 286 environ=environ) |
| 287 else: |
| 288 environ['CXXFLAGS'] += ' -std=c++11 -stdlib=libc++ %s' % _MACOS_COMPAT_F
LAG |
| 289 return create_jobspec(self.name, |
| 290 ['tools/run_tests/build_artifact_protoc.sh'], |
| 291 environ=environ) |
| 292 else: |
| 293 generator = 'Visual Studio 12 Win64' if self.arch == 'x64' else 'Visual St
udio 12' |
| 294 vcplatform = 'x64' if self.arch == 'x64' else 'Win32' |
| 295 return create_jobspec(self.name, |
| 296 ['tools\\run_tests\\build_artifact_protoc.bat'], |
| 297 environ={'generator': generator, |
| 298 'Platform': vcplatform}) |
| 299 |
| 300 def __str__(self): |
| 301 return self.name |
| 302 |
| 303 |
| 304 def targets(): |
| 305 """Gets list of supported targets""" |
| 306 return ([Cls(platform, arch) |
| 307 for Cls in (CSharpExtArtifact, NodeExtArtifact, ProtocArtifact) |
| 308 for platform in ('linux', 'macos', 'windows') |
| 309 for arch in ('x86', 'x64')] + |
| 310 [PythonArtifact('linux', 'x86'), |
| 311 PythonArtifact('linux', 'x64'), |
| 312 PythonArtifact('macos', 'x64'), |
| 313 PythonArtifact('windows', 'x86'), |
| 314 PythonArtifact('windows', 'x64'), |
| 315 RubyArtifact('linux', 'x86'), |
| 316 RubyArtifact('linux', 'x64'), |
| 317 RubyArtifact('macos', 'x64'), |
| 318 PHPArtifact('linux', 'x64'), |
| 319 PHPArtifact('macos', 'x64')]) |
OLD | NEW |