Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 self.m.python( | 312 self.m.python( |
| 308 name=name or 'upload_log', | 313 name=name or 'upload_log', |
| 309 script=self.package_repo_resource( | 314 script=self.package_repo_resource( |
| 310 'scripts', 'slave', 'upload_goma_logs.py'), | 315 'scripts', 'slave', 'upload_goma_logs.py'), |
| 311 args=args, | 316 args=args, |
| 312 env=self._goma_ctl_env | 317 env=self._goma_ctl_env |
| 313 ) | 318 ) |
| 314 | 319 |
| 315 @contextmanager | 320 @contextmanager |
| 316 def build_with_goma(self, ninja_log_outdir=None, ninja_log_compiler=None, | 321 def build_with_goma(self, ninja_log_outdir=None, ninja_log_compiler=None, |
| 317 ninja_log_command=None, env=None, | 322 ninja_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. | |
| 322 These args are only used to collect log and upload them. | |
| 323 | |
| 324 Args: | 326 Args: |
| 325 ninja_log_outdir: Directory of ninja log. (e.g. "out/Release") | 327 ninja_log_outdir: Directory of ninja log. (e.g. "out/Release") |
| 326 ninja_log_compiler: Compiler used in ninja. (e.g. "clang") | 328 ninja_log_compiler: Compiler used in ninja. (e.g. "clang") |
| 327 ninja_log_command: Command used for build. | 329 ninja_command: Command used for build. |
| 328 This is used only to be sent as part of log, | 330 This is used to be sent as part of log. |
| 329 NOT used to run actual build. | 331 This function does NOT run actual build. |
|
ukai
2016/11/10 02:47:02
it returns this, and if goma is available add -j o
tikuta
2016/11/11 08:14:55
Done.
| |
| 330 (e.g. ['ninja', '-C', 'out/Release', '-j', '100']) | 332 (e.g. ['ninja', '-C', 'out/Release']) |
| 331 env: Environment controlling goma behavior. | 333 env: Environment controlling goma behavior. |
| 332 This should be used for ninja if allow_build_without_goma is True. | 334 This should be used for ninja if allow_build_without_goma is True. |
| 333 Otherwise, only used for goma behavior control. | 335 Otherwise, only used for goma behavior control. |
| 334 allow_build_without_goma (bool): | 336 allow_build_without_goma (bool): |
| 335 If this is not True, goma starting failure is ignored. | 337 If this is not True, goma starting failure is ignored. |
| 336 This argument should be used with env. | 338 Use returned env_update and ninja_command for the cases. |
| 337 If starting goma fails, env and ninja_log_command are modified. | 339 |
| 340 Returns: | |
| 341 (env_update, ninja_command): | |
| 342 Please use env_update and ninja_command | |
| 343 for ninja in build_with_goma context | |
| 344 (e.g. ninja_env.update(env_update)). | |
| 345 Appropriate values are set depends on goma status. | |
| 338 | 346 |
| 339 Raises: | 347 Raises: |
| 340 StepFailure or InfraFailure if it fails to build. | 348 StepFailure or InfraFailure if it fails to build. |
| 341 """ | 349 """ |
| 342 ninja_log_exit_status = 0 | 350 ninja_log_exit_status = 0 |
| 351 if ninja_log_command is None: | |
| 352 ninja_log_command = [] | |
| 353 ninja_command = self.remove_j_flag(ninja_log_command) | |
| 343 | 354 |
| 344 if allow_build_without_goma: | 355 if allow_build_without_goma: |
| 345 assert(env is not None) | 356 assert(env is not None) |
| 357 env = env.copy() | |
| 358 | |
| 346 try: | 359 try: |
| 347 self.start(env) | 360 self.start(env) |
| 348 except: | 361 except: |
| 349 env['GOMA_DISABLED'] = 'true' | |
| 350 self.remove_j_flag(ninja_log_command) | |
| 351 try: | 362 try: |
| 352 yield | 363 yield ({'GOMA_DISABLED':'true'}, ninja_command) |
| 353 except self.m.step.StepFailure as e: # pragma: no cover | 364 except self.m.step.StepFailure as e: # pragma: no cover |
| 354 ninja_log_exit_status = e.retcode | 365 ninja_log_exit_status = e.retcode |
| 355 raise e | 366 raise e |
| 356 except self.m.step.InfraFailure as e: # pragma: no cover | 367 except self.m.step.InfraFailure as e: # pragma: no cover |
| 357 ninja_log_exit_status = -1 | 368 ninja_log_exit_status = -1 |
| 358 raise e | 369 raise e |
| 359 finally: | 370 finally: |
| 360 self._upload_logs(ninja_log_outdir=ninja_log_outdir, | 371 self._upload_logs(ninja_log_outdir=ninja_log_outdir, |
| 361 ninja_log_compiler=ninja_log_compiler, | 372 ninja_log_compiler=ninja_log_compiler, |
| 362 ninja_log_command=ninja_log_command, | 373 ninja_log_command=ninja_command, |
| 363 ninja_log_exit_status=ninja_log_exit_status, | 374 ninja_log_exit_status=ninja_log_exit_status, |
| 364 name='upload log goma start failed') | 375 name='upload log goma start failed') |
| 365 return | 376 return |
| 366 else: | 377 else: |
| 367 self.start(env) | 378 self.start(env) |
| 368 | 379 |
| 380 ninja_command.extend(['-j', self.recommended_goma_jobs]) | |
|
ukai
2016/11/10 02:47:02
prefer -j option before targets on command line.
tikuta
2016/11/11 08:14:55
Done.
| |
| 381 | |
| 369 try: | 382 try: |
| 370 yield | 383 yield ({}, ninja_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_command, |
| 381 ninja_log_exit_status=ninja_log_exit_status) | 394 ninja_log_exit_status=ninja_log_exit_status) |
| OLD | NEW |