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