• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2016 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15"""Definition of targets to build distribution packages."""
16
17import os.path
18import sys
19
20sys.path.insert(0, os.path.abspath('..'))
21import python_utils.jobset as jobset
22
23
24def create_docker_jobspec(name,
25                          dockerfile_dir,
26                          shell_command,
27                          environ={},
28                          flake_retries=0,
29                          timeout_retries=0):
30    """Creates jobspec for a task running under docker."""
31    environ = environ.copy()
32    environ['RUN_COMMAND'] = shell_command
33
34    docker_args = []
35    for k, v in environ.items():
36        docker_args += ['-e', '%s=%s' % (k, v)]
37    docker_env = {
38        'DOCKERFILE_DIR': dockerfile_dir,
39        'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
40        'OUTPUT_DIR': 'artifacts'
41    }
42    jobspec = jobset.JobSpec(
43        cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] +
44        docker_args,
45        environ=docker_env,
46        shortname='build_package.%s' % (name),
47        timeout_seconds=30 * 60,
48        flake_retries=flake_retries,
49        timeout_retries=timeout_retries)
50    return jobspec
51
52
53def create_jobspec(name,
54                   cmdline,
55                   environ=None,
56                   cwd=None,
57                   shell=False,
58                   flake_retries=0,
59                   timeout_retries=0,
60                   cpu_cost=1.0):
61    """Creates jobspec."""
62    jobspec = jobset.JobSpec(cmdline=cmdline,
63                             environ=environ,
64                             cwd=cwd,
65                             shortname='build_package.%s' % (name),
66                             timeout_seconds=10 * 60,
67                             flake_retries=flake_retries,
68                             timeout_retries=timeout_retries,
69                             cpu_cost=cpu_cost,
70                             shell=shell)
71    return jobspec
72
73
74class CSharpPackage:
75    """Builds C# packages."""
76
77    def __init__(self, unity=False):
78        self.unity = unity
79        self.labels = ['package', 'csharp', 'windows']
80        if unity:
81            self.name = 'csharp_package_unity_windows'
82            self.labels += ['unity']
83        else:
84            self.name = 'csharp_package_nuget_windows'
85            self.labels += ['nuget']
86
87    def pre_build_jobspecs(self):
88        return []
89
90    def build_jobspec(self):
91        if self.unity:
92            # use very high CPU cost to avoid running nuget package build
93            # and unity build concurrently
94            return create_jobspec(self.name, ['build_unitypackage.bat'],
95                                  cwd='src\\csharp',
96                                  cpu_cost=1e6,
97                                  shell=True)
98        else:
99            return create_jobspec(self.name, ['build_packages_dotnetcli.bat'],
100                                  cwd='src\\csharp',
101                                  shell=True)
102
103    def __str__(self):
104        return self.name
105
106
107class RubyPackage:
108    """Collects ruby gems created in the artifact phase"""
109
110    def __init__(self):
111        self.name = 'ruby_package'
112        self.labels = ['package', 'ruby', 'linux']
113
114    def pre_build_jobspecs(self):
115        return []
116
117    def build_jobspec(self):
118        return create_docker_jobspec(
119            self.name, 'tools/dockerfile/grpc_artifact_linux_x64',
120            'tools/run_tests/artifacts/build_package_ruby.sh')
121
122
123class PythonPackage:
124    """Collects python eggs and wheels created in the artifact phase"""
125
126    def __init__(self):
127        self.name = 'python_package'
128        self.labels = ['package', 'python', 'linux']
129
130    def pre_build_jobspecs(self):
131        return []
132
133    def build_jobspec(self):
134        return create_docker_jobspec(
135            self.name, 'tools/dockerfile/grpc_artifact_linux_x64',
136            'tools/run_tests/artifacts/build_package_python.sh')
137
138
139class PHPPackage:
140    """Copy PHP PECL package artifact"""
141
142    def __init__(self):
143        self.name = 'php_package'
144        self.labels = ['package', 'php', 'linux']
145
146    def pre_build_jobspecs(self):
147        return []
148
149    def build_jobspec(self):
150        return create_docker_jobspec(
151            self.name, 'tools/dockerfile/grpc_artifact_linux_x64',
152            'tools/run_tests/artifacts/build_package_php.sh')
153
154
155def targets():
156    """Gets list of supported targets"""
157    return [
158        CSharpPackage(),
159        CSharpPackage(unity=True),
160        RubyPackage(),
161        PythonPackage(),
162        PHPPackage()
163    ]
164