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), |
murgatroid99 | 673f65b | 2016-02-01 11:19:07 -0800 | [diff] [blame] | 65 | timeout_seconds=10*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 | |
| 82 | |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 83 | class 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: |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame^] | 99 | environ = {} |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 100 | if self.platform == 'linux': |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame^] | 101 | environ['BDIST_WHEEL_MAYBE'] = 'bdist_wheel' |
Jan Tattermusch | 7cf8bf4 | 2016-02-03 13:41:07 -0800 | [diff] [blame] | 102 | if self.arch == 'x86': |
| 103 | environ['SETARCH_CMD'] = 'linux32' |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 104 | return create_docker_jobspec(self.name, |
| 105 | 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
Jan Tattermusch | 7cf8bf4 | 2016-02-03 13:41:07 -0800 | [diff] [blame] | 106 | 'tools/run_tests/build_artifact_python.sh', |
| 107 | environ=environ) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 108 | else: |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame^] | 109 | environ['SKIP_PIP_INSTALL'] = 'TRUE' |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 110 | return create_jobspec(self.name, |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame^] | 111 | ['tools/run_tests/build_artifact_python.sh'], |
| 112 | environ=environ) |
Jan Tattermusch | 8640f92 | 2016-02-01 18:58:46 -0800 | [diff] [blame] | 113 | |
| 114 | def __str__(self): |
| 115 | return self.name |
| 116 | |
| 117 | |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 118 | class RubyArtifact: |
| 119 | """Builds ruby native gem.""" |
| 120 | |
| 121 | def __init__(self, platform, arch): |
| 122 | self.name = 'ruby_native_gem_%s_%s' % (platform, arch) |
| 123 | self.platform = platform |
| 124 | self.arch = arch |
| 125 | self.labels = ['artifact', 'ruby', platform, arch] |
| 126 | |
| 127 | def pre_build_jobspecs(self): |
| 128 | return [] |
| 129 | |
| 130 | def build_jobspec(self): |
| 131 | if self.platform == 'windows': |
| 132 | raise Exception("Not supported yet") |
| 133 | else: |
| 134 | if self.platform == 'linux': |
| 135 | environ = {} |
| 136 | if self.arch == 'x86': |
Jan Tattermusch | 7cf8bf4 | 2016-02-03 13:41:07 -0800 | [diff] [blame] | 137 | environ['SETARCH_CMD'] = 'linux32' |
Jan Tattermusch | 4437213 | 2016-02-01 16:20:03 -0800 | [diff] [blame] | 138 | return create_docker_jobspec(self.name, |
| 139 | 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 140 | 'tools/run_tests/build_artifact_ruby.sh', |
| 141 | environ=environ) |
| 142 | else: |
| 143 | return create_jobspec(self.name, |
| 144 | ['tools/run_tests/build_artifact_ruby.sh']) |
| 145 | |
| 146 | |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 147 | class CSharpExtArtifact: |
| 148 | """Builds C# native extension library""" |
| 149 | |
| 150 | def __init__(self, platform, arch): |
| 151 | self.name = 'csharp_ext_%s_%s' % (platform, arch) |
| 152 | self.platform = platform |
| 153 | self.arch = arch |
| 154 | self.labels = ['artifact', 'csharp', platform, arch] |
| 155 | |
| 156 | def pre_build_jobspecs(self): |
| 157 | if self.platform == 'windows': |
| 158 | return [create_jobspec('prebuild_%s' % self.name, |
| 159 | ['tools\\run_tests\\pre_build_c.bat'], |
| 160 | shell=True, |
| 161 | flake_retries=5, |
| 162 | timeout_retries=2)] |
| 163 | else: |
| 164 | return [] |
| 165 | |
| 166 | def build_jobspec(self): |
| 167 | if self.platform == 'windows': |
| 168 | msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch |
| 169 | return create_jobspec(self.name, |
| 170 | ['tools\\run_tests\\build_artifact_csharp.bat', |
| 171 | 'vsprojects\\grpc_csharp_ext.sln', |
| 172 | '/p:Configuration=Release', |
| 173 | '/p:PlatformToolset=v120', |
| 174 | '/p:Platform=%s' % msbuild_platform], |
| 175 | shell=True) |
| 176 | else: |
| 177 | environ = {'CONFIG': 'opt', |
| 178 | 'EMBED_OPENSSL': 'true', |
| 179 | 'EMBED_ZLIB': 'true'} |
| 180 | if self.platform == 'linux': |
| 181 | return create_docker_jobspec(self.name, |
| 182 | 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch, |
| 183 | 'tools/run_tests/build_artifact_csharp.sh') |
| 184 | else: |
| 185 | environ.update(macos_arch_env(self.arch)) |
| 186 | return create_jobspec(self.name, |
| 187 | ['tools/run_tests/build_artifact_csharp.sh'], |
| 188 | environ=environ) |
| 189 | |
| 190 | def __str__(self): |
| 191 | return self.name |
| 192 | |
murgatroid99 | 673f65b | 2016-02-01 11:19:07 -0800 | [diff] [blame] | 193 | node_gyp_arch_map = { |
| 194 | 'x86': 'ia32', |
| 195 | 'x64': 'x64' |
| 196 | } |
| 197 | |
| 198 | class NodeExtArtifact: |
| 199 | """Builds Node native extension""" |
| 200 | |
| 201 | def __init__(self, platform, arch): |
| 202 | self.name = 'node_ext_{0}_{1}'.format(platform, arch) |
| 203 | self.platform = platform |
| 204 | self.arch = arch |
| 205 | self.gyp_arch = node_gyp_arch_map[arch] |
| 206 | self.labels = ['artifact', 'node', platform, arch] |
| 207 | |
| 208 | def pre_build_jobspecs(self): |
| 209 | return [] |
| 210 | |
| 211 | def build_jobspec(self): |
| 212 | if self.platform == 'windows': |
| 213 | return create_jobspec(self.name, |
| 214 | ['tools\\run_tests\\build_artifact_node.bat', |
| 215 | self.gyp_arch], |
| 216 | shell=True) |
| 217 | else: |
| 218 | if self.platform == 'linux': |
| 219 | return create_docker_jobspec( |
| 220 | self.name, |
| 221 | 'tools/dockerfile/grpc_artifact_linux_{}'.format(self.arch), |
| 222 | 'tools/run_tests/build_artifact_node.sh {}'.format(self.gyp_arch)) |
| 223 | else: |
| 224 | return create_jobspec(self.name, |
| 225 | ['tools/run_tests/build_artifact_node.sh', |
| 226 | self.gyp_arch]) |
| 227 | |
Jan Tattermusch | be538a1 | 2016-01-28 14:58:15 -0800 | [diff] [blame] | 228 | |
| 229 | def targets(): |
| 230 | """Gets list of supported targets""" |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 231 | return ([Cls(platform, arch) |
| 232 | for Cls in (CSharpExtArtifact, NodeExtArtifact) |
| 233 | for platform in ('linux', 'macos', 'windows') |
| 234 | for arch in ('x86', 'x64')] + |
| 235 | [PythonArtifact('linux', 'x86'), |
| 236 | PythonArtifact('linux', 'x64'), |
Jan Tattermusch | e066717 | 2016-02-03 15:57:57 -0800 | [diff] [blame^] | 237 | PythonArtifact('macos', 'x64'), |
murgatroid99 | 41a9e83 | 2016-02-03 09:47:35 -0800 | [diff] [blame] | 238 | RubyArtifact('linux', 'x86'), |
murgatroid99 | 33c808b | 2016-02-03 15:27:41 -0800 | [diff] [blame] | 239 | RubyArtifact('linux', 'x64'), |
| 240 | RubyArtifact('macos', 'x64')]) |