Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: scripts/slave/recipe_modules/goma/api.py

Issue 2375843005: Stop redirect stdout/stderr and remove close_fds=True (Closed)
Patch Set: add comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from contextlib import contextmanager 5 from contextlib import contextmanager
6 6
7 from recipe_engine import recipe_api 7 from recipe_engine import recipe_api
8 8
9 class GomaApi(recipe_api.RecipeApi): 9 class GomaApi(recipe_api.RecipeApi):
10 """GomaApi contains helper functions for using goma.""" 10 """GomaApi contains helper functions for using goma."""
11 11
12 def __init__(self, **kwargs): 12 def __init__(self, **kwargs):
13 super(GomaApi, self).__init__(**kwargs) 13 super(GomaApi, self).__init__(**kwargs)
14 self._goma_dir = None 14 self._goma_dir = None
15 self._goma_started = False 15 self._goma_started = False
16 16
17 self._goma_ctl_env = {} 17 self._goma_ctl_env = {}
18 self._cloudtail_pid = None
19 self._goma_jobs = None 18 self._goma_jobs = None
20 19
21 @property 20 @property
22 def service_account_json_path(self): 21 def service_account_json_path(self):
23 if self.m.platform.is_win: 22 if self.m.platform.is_win:
24 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' 23 return 'C:\\creds\\service_accounts\\service-account-goma-client.json'
25 return '/creds/service_accounts/service-account-goma-client.json' 24 return '/creds/service_accounts/service-account-goma-client.json'
26 25
27 @property 26 @property
28 def cloudtail_path(self): 27 def cloudtail_path(self):
29 assert self._goma_dir 28 assert self._goma_dir
30 return self.m.path.join(self._goma_dir, 'cloudtail') 29 return self.m.path.join(self._goma_dir, 'cloudtail')
31 30
32 @property 31 @property
32 def cloudtail_pid_file(self):
33 return self.m.path['tmp_base'].join('cloudtail.pid')
34
35 @property
33 def json_path(self): 36 def json_path(self):
34 assert self._goma_dir 37 assert self._goma_dir
35 return self.m.path.join(self._goma_dir, 'jsonstatus') 38 return self.m.path.join(self._goma_dir, 'jsonstatus')
36 39
37 @property 40 @property
38 def recommended_goma_jobs(self): 41 def recommended_goma_jobs(self):
39 """ 42 """
40 Return the recommended number of jobs for parallel build using Goma. 43 Return the recommended number of jobs for parallel build using Goma.
41 44
42 This function caches the _goma_jobs. 45 This function caches the _goma_jobs.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 def build_data_dir(self): 129 def build_data_dir(self):
127 return self.m.properties.get('build_data_dir') 130 return self.m.properties.get('build_data_dir')
128 131
129 def _start_cloudtail(self): 132 def _start_cloudtail(self):
130 """Start cloudtail to upload compiler_proxy.INFO 133 """Start cloudtail to upload compiler_proxy.INFO
131 134
132 Raises: 135 Raises:
133 InfraFailure if it fails to start cloudtail 136 InfraFailure if it fails to start cloudtail
134 """ 137 """
135 138
136 assert self._cloudtail_pid is None 139 self.m.python(
137
138 step_result = self.m.python(
139 name='start cloudtail', 140 name='start cloudtail',
140 script=self.resource('cloudtail_utils.py'), 141 script=self.resource('cloudtail_utils.py'),
141 args=['start', 142 args=['start',
142 '--cloudtail-path', self.cloudtail_path], 143 '--cloudtail-path', self.cloudtail_path,
144 '--pid-file', self.m.raw_io.output(
145 leak_to=self.cloudtail_pid_file)],
143 env=self._goma_ctl_env, 146 env=self._goma_ctl_env,
144 stdout=self.m.raw_io.output(),
145 step_test_data=( 147 step_test_data=(
146 lambda: self.m.raw_io.test_api.stream_output('12345')), 148 lambda: self.m.raw_io.test_api.output('12345')),
147 infra_step=True) 149 infra_step=True)
148 150
149 self._cloudtail_pid = step_result.stdout
150
151 def _stop_cloudtail(self): 151 def _stop_cloudtail(self):
152 """Stop cloudtail started by _start_cloudtail 152 """Stop cloudtail started by _start_cloudtail
153 153
154 Raises: 154 Raises:
155 InfraFailure if it fails to stop cloudtail 155 InfraFailure if it fails to stop cloudtail
156 """ 156 """
157 157
158 assert self._cloudtail_pid is not None
159
160 self.m.python( 158 self.m.python(
161 name='stop cloudtail', 159 name='stop cloudtail',
162 script=self.resource('cloudtail_utils.py'), 160 script=self.resource('cloudtail_utils.py'),
163 args=['stop', 161 args=['stop',
164 '--killed-pid', self._cloudtail_pid], 162 '--killed-pid-file', self.cloudtail_pid_file],
165 infra_step=True) 163 infra_step=True)
166 164
167 self._cloudtail_pid = None
168
169 def start(self, env=None, **kwargs): 165 def start(self, env=None, **kwargs):
170 """Start goma compiler_proxy. 166 """Start goma compiler_proxy.
171 167
172 A user MUST execute ensure_goma beforehand. 168 A user MUST execute ensure_goma beforehand.
173 It is user's responsibility to handle failure of starting compiler_proxy. 169 It is user's responsibility to handle failure of starting compiler_proxy.
174 """ 170 """
175 assert self._goma_dir 171 assert self._goma_dir
176 assert not self._goma_started 172 assert not self._goma_started
177 173
178 if self.build_data_dir: 174 if self.build_data_dir:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ninja_log_exit_status = e.retcode 321 ninja_log_exit_status = e.retcode
326 raise e 322 raise e
327 except self.m.step.InfraFailure as e: # pragma: no cover 323 except self.m.step.InfraFailure as e: # pragma: no cover
328 ninja_log_exit_status = -1 324 ninja_log_exit_status = -1
329 raise e 325 raise e
330 finally: 326 finally:
331 self.stop(ninja_log_outdir=ninja_log_outdir, 327 self.stop(ninja_log_outdir=ninja_log_outdir,
332 ninja_log_compiler=ninja_log_compiler, 328 ninja_log_compiler=ninja_log_compiler,
333 ninja_log_command=ninja_log_command, 329 ninja_log_command=ninja_log_command,
334 ninja_log_exit_status=ninja_log_exit_status) 330 ninja_log_exit_status=ninja_log_exit_status)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698