blob: a34fa8e4faad9a30ff46ce3f4bf58945fbca794b [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
83class CSharpExtArtifact:
84 """Builds C# native extension library"""
85
86 def __init__(self, platform, arch):
87 self.name = 'csharp_ext_%s_%s' % (platform, arch)
88 self.platform = platform
89 self.arch = arch
90 self.labels = ['artifact', 'csharp', platform, arch]
91
92 def pre_build_jobspecs(self):
93 if self.platform == 'windows':
94 return [create_jobspec('prebuild_%s' % self.name,
95 ['tools\\run_tests\\pre_build_c.bat'],
96 shell=True,
97 flake_retries=5,
98 timeout_retries=2)]
99 else:
100 return []
101
102 def build_jobspec(self):
103 if self.platform == 'windows':
104 msbuild_platform = 'Win32' if self.arch == 'x86' else self.arch
105 return create_jobspec(self.name,
106 ['tools\\run_tests\\build_artifact_csharp.bat',
107 'vsprojects\\grpc_csharp_ext.sln',
108 '/p:Configuration=Release',
109 '/p:PlatformToolset=v120',
110 '/p:Platform=%s' % msbuild_platform],
111 shell=True)
112 else:
113 environ = {'CONFIG': 'opt',
114 'EMBED_OPENSSL': 'true',
115 'EMBED_ZLIB': 'true'}
116 if self.platform == 'linux':
117 return create_docker_jobspec(self.name,
118 'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
119 'tools/run_tests/build_artifact_csharp.sh')
120 else:
121 environ.update(macos_arch_env(self.arch))
122 return create_jobspec(self.name,
123 ['tools/run_tests/build_artifact_csharp.sh'],
124 environ=environ)
125
126 def __str__(self):
127 return self.name
128
129
130def targets():
131 """Gets list of supported targets"""
132 return [CSharpExtArtifact('linux', 'x86'),
133 CSharpExtArtifact('linux', 'x64'),
134 CSharpExtArtifact('macos', 'x86'),
135 CSharpExtArtifact('macos', 'x64'),
136 CSharpExtArtifact('windows', 'x86'),
137 CSharpExtArtifact('windows', 'x64')]