blob: 32a98c90b8aad060aff6481de5a5614e24295818 [file] [log] [blame]
Jan Tattermuschbe538a12016-01-28 14:58:15 -08001#!/usr/bin/env python
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
33import jobset
34
35
36def 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
58def 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=5*60,
66 flake_retries=flake_retries,
67 timeout_retries=timeout_retries,
68 shell=shell)
69 return jobspec
70
71
72def 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 Tattermusch8640f922016-02-01 18:58:46 -080083class 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 Tattermuschbe538a12016-01-28 14:58:15 -0800111class CSharpExtArtifact:
112 """Builds C# native extension library"""
113
114 def __init__(self, platform, arch):
115 self.name = 'csharp_ext_%s_%s' % (platform, arch)
116 self.platform = platform
117 self.arch = arch
118 self.labels = ['artifact', 'csharp', platform, arch]
119
120 def pre_build_jobspecs(self):
121 if self.platform == 'windows':
122 return [create_jobspec('prebuild_%s' % self.name,
123 ['tools\\run_tests\\pre_build_c.bat'],
124 shell=True,
125 flake_retries=5,
126 timeout_retries=2)]
127 else:
128 return []
129
130 def build_jobspec(self):
131 if self.platform == 'windows':
132 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
133 return create_jobspec(self.name,
134 ['tools\\run_tests\\build_artifact_csharp.bat',
135 'vsprojects\\grpc_csharp_ext.sln',
136 '/p:Configuration=Release',
137 '/p:PlatformToolset=v120',
138 '/p:Platform=%s' % msbuild_platform],
139 shell=True)
140 else:
141 environ = {'CONFIG': 'opt',
142 'EMBED_OPENSSL': 'true',
143 'EMBED_ZLIB': 'true'}
144 if self.platform == 'linux':
145 return create_docker_jobspec(self.name,
146 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
147 'tools/run_tests/build_artifact_csharp.sh')
148 else:
149 environ.update(macos_arch_env(self.arch))
150 return create_jobspec(self.name,
151 ['tools/run_tests/build_artifact_csharp.sh'],
152 environ=environ)
153
154 def __str__(self):
155 return self.name
156
157
158def targets():
159 """Gets list of supported targets"""
160 return [CSharpExtArtifact('linux', 'x86'),
161 CSharpExtArtifact('linux', 'x64'),
162 CSharpExtArtifact('macos', 'x86'),
163 CSharpExtArtifact('macos', 'x64'),
164 CSharpExtArtifact('windows', 'x86'),
Jan Tattermusch8640f922016-02-01 18:58:46 -0800165 CSharpExtArtifact('windows', 'x64'),
166 PythonArtifact('linux', 'x86'),
167 PythonArtifact('linux', 'x64')]