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

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

Issue 2480193002: Stop to use contextmanager for goma.build_with_goma (Closed)
Patch Set: use env_update Created 4 years, 1 month 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 import re 5 import re
6 from contextlib import contextmanager 6 from contextlib import contextmanager
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 class GomaApi(recipe_api.RecipeApi): 10 class GomaApi(recipe_api.RecipeApi):
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 return self._goma_jobs 79 return self._goma_jobs
80 80
81 def remove_j_flag(self, command): 81 def remove_j_flag(self, command):
82 """Remove -j flag from command. 82 """Remove -j flag from command.
83 This function elimitnates -j flag from command for 83 This function elimitnates -j flag from command for
84 '-j', '80' style and '-j80' style. 84 '-j', '80' style and '-j80' style.
85 85
86 Args: 86 Args:
87 command: List of command line arg. 87 command: List of command line arg.
88
89 Returns:
90 list(string): Command line args parallel option removed.
88 """ 91 """
92 command = command[:]
89 parallel_flag_regexp = re.compile('-j\d*') 93 parallel_flag_regexp = re.compile('-j\d*')
90 for i in range(len(command)): 94 for i in range(len(command)):
91 if (isinstance(command[i], str) and 95 if (isinstance(command[i], str) and
92 parallel_flag_regexp.match(command[i])): 96 parallel_flag_regexp.match(command[i])):
93 if command[i] == '-j': 97 if command[i] == '-j':
94 command.pop(i + 1) 98 command.pop(i + 1)
95 command.pop(i) 99 command.pop(i)
96 return 100 break
101 return command
97 102
98 def ensure_goma(self, canary=False): 103 def ensure_goma(self, canary=False):
99 with self.m.step.nest('ensure_goma'): 104 with self.m.step.nest('ensure_goma'):
100 with self.m.step.context({'infra_step': True}): 105 with self.m.step.context({'infra_step': True}):
101 try: 106 try:
102 self.m.cipd.set_service_account_credentials( 107 self.m.cipd.set_service_account_credentials(
103 self.service_account_json_path) 108 self.service_account_json_path)
104 109
105 self.m.cipd.install_client() 110 self.m.cipd.install_client()
106 goma_package = ('infra_internal/goma/client/%s' % 111 goma_package = ('infra_internal/goma/client/%s' %
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ninja_log_command=None, env=None, 322 ninja_log_command=None, env=None,
318 allow_build_without_goma=False): 323 allow_build_without_goma=False):
319 """Make context wrapping goma start/stop. 324 """Make context wrapping goma start/stop.
320 325
321 Args ninja_log_* are NOT used to run actual build in this context. 326 Args ninja_log_* are NOT used to run actual build in this context.
322 These args are only used to collect log and upload them. 327 These args are only used to collect log and upload them.
323 328
324 Args: 329 Args:
325 ninja_log_outdir: Directory of ninja log. (e.g. "out/Release") 330 ninja_log_outdir: Directory of ninja log. (e.g. "out/Release")
326 ninja_log_compiler: Compiler used in ninja. (e.g. "clang") 331 ninja_log_compiler: Compiler used in ninja. (e.g. "clang")
327 ninja_log_command: Command used for build. 332 ninja_log_command: Command used for build.
ukai 2016/11/08 04:11:57 could be ninja_command ?
tikuta 2016/11/09 05:31:12 Done.
328 This is used only to be sent as part of log, 333 This is used only to be sent as part of log,
329 NOT used to run actual build. 334 NOT used to run actual build.
ukai 2016/11/08 04:11:57 fix comment?
tikuta 2016/11/09 05:31:12 Done.
330 (e.g. ['ninja', '-C', 'out/Release', '-j', '100']) 335 (e.g. ['ninja', '-C', 'out/Release', '-j', '100'])
331 env: Environment controlling goma behavior. 336 env: Environment controlling goma behavior.
332 This should be used for ninja if allow_build_without_goma is True. 337 This should be used for ninja if allow_build_without_goma is True.
333 Otherwise, only used for goma behavior control. 338 Otherwise, only used for goma behavior control.
334 allow_build_without_goma (bool): 339 allow_build_without_goma (bool):
335 If this is not True, goma starting failure is ignored. 340 If this is not True, goma starting failure is ignored.
336 This argument should be used with env. 341 This argument should be used with env.
337 If starting goma fails, env and ninja_log_command are modified. 342 If starting goma fails, env and ninja_log_command are modified.
ukai 2016/11/08 04:11:57 update comment?
tikuta 2016/11/09 05:31:12 Done.
338 343
344 Returns:
345 (env_update, command):
346 Please use env_update and command for ninja in build_with_goma context
347 (e.g. ninja_env.update(env_update)).
348 Appropriate values are set when starting goma fails.
349
339 Raises: 350 Raises:
340 StepFailure or InfraFailure if it fails to build. 351 StepFailure or InfraFailure if it fails to build.
341 """ 352 """
342 ninja_log_exit_status = 0 353 ninja_log_exit_status = 0
343
344 if allow_build_without_goma: 354 if allow_build_without_goma:
345 assert(env is not None) 355 assert(env is not None)
356 assert(ninja_log_command is not None)
357 env = env.copy()
358 ninja_log_command = ninja_log_command[:]
359
346 try: 360 try:
347 self.start(env) 361 self.start(env)
348 except: 362 except:
349 env['GOMA_DISABLED'] = 'true' 363 ninja_log_command = self.remove_j_flag(ninja_log_command)
350 self.remove_j_flag(ninja_log_command)
351 try: 364 try:
352 yield 365 yield ({'GOMA_DISABLED':'true'}, ninja_log_command)
353 except self.m.step.StepFailure as e: # pragma: no cover 366 except self.m.step.StepFailure as e: # pragma: no cover
354 ninja_log_exit_status = e.retcode 367 ninja_log_exit_status = e.retcode
355 raise e 368 raise e
356 except self.m.step.InfraFailure as e: # pragma: no cover 369 except self.m.step.InfraFailure as e: # pragma: no cover
357 ninja_log_exit_status = -1 370 ninja_log_exit_status = -1
358 raise e 371 raise e
359 finally: 372 finally:
360 self._upload_logs(ninja_log_outdir=ninja_log_outdir, 373 self._upload_logs(ninja_log_outdir=ninja_log_outdir,
361 ninja_log_compiler=ninja_log_compiler, 374 ninja_log_compiler=ninja_log_compiler,
362 ninja_log_command=ninja_log_command, 375 ninja_log_command=ninja_log_command,
363 ninja_log_exit_status=ninja_log_exit_status, 376 ninja_log_exit_status=ninja_log_exit_status,
364 name='upload log goma start failed') 377 name='upload log goma start failed')
365 return 378 return
366 else: 379 else:
367 self.start(env) 380 self.start(env)
368 381
369 try: 382 try:
370 yield 383 yield ({}, ninja_log_command)
371 except self.m.step.StepFailure as e: # pragma: no cover 384 except self.m.step.StepFailure as e: # pragma: no cover
372 ninja_log_exit_status = e.retcode 385 ninja_log_exit_status = e.retcode
373 raise e 386 raise e
374 except self.m.step.InfraFailure as e: # pragma: no cover 387 except self.m.step.InfraFailure as e: # pragma: no cover
375 ninja_log_exit_status = -1 388 ninja_log_exit_status = -1
376 raise e 389 raise e
377 finally: 390 finally:
378 self.stop(ninja_log_outdir=ninja_log_outdir, 391 self.stop(ninja_log_outdir=ninja_log_outdir,
379 ninja_log_compiler=ninja_log_compiler, 392 ninja_log_compiler=ninja_log_compiler,
380 ninja_log_command=ninja_log_command, 393 ninja_log_command=ninja_log_command,
381 ninja_log_exit_status=ninja_log_exit_status) 394 ninja_log_exit_status=ninja_log_exit_status)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698