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) |
|
shinyak
2016/11/14 08:14:08
I didn't notice before, but `ninja -j` could cause
tikuta
2016/11/14 11:22:02
If there is no arg after '-j' option, IndexError i
| |
| 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. |
| 330 (e.g. ['ninja', '-C', 'out/Release', '-j', '100']) | 332 ninja_command with -j option is returned |
| 333 if goma starts successfully. | |
| 334 (e.g. ['ninja', '-C', 'out/Release']) | |
| 331 env: Environment controlling goma behavior. | 335 env: Environment controlling goma behavior. |
| 332 This should be used for ninja if allow_build_without_goma is True. | 336 This should be used for ninja if allow_build_without_goma is True. |
| 333 Otherwise, only used for goma behavior control. | 337 Otherwise, only used for goma behavior control. |
| 334 allow_build_without_goma (bool): | 338 allow_build_without_goma (bool): |
| 335 If this is not True, goma starting failure is ignored. | 339 If this is not True, goma starting failure is ignored. |
| 336 This argument should be used with env. | 340 Use returned env_update and ninja_command for the cases. |
| 337 If starting goma fails, env and ninja_log_command are modified. | 341 |
| 342 Returns: | |
| 343 (env_update, ninja_command): | |
| 344 Please use env_update and ninja_command | |
|
Paweł Hajdan Jr.
2016/11/14 09:33:23
Some changes in this patch don't seem to follow th
tikuta
2016/11/14 11:22:02
When I made build_with_goma, I thought we need to
tikuta
2016/11/15 07:07:10
Hmm, there is a recipe that does not use ninja.
ht
| |
| 345 for ninja in build_with_goma context | |
| 346 (e.g. ninja_env.update(env_update)). | |
| 347 Appropriate values are set depends on goma status. | |
| 338 | 348 |
| 339 Raises: | 349 Raises: |
| 340 StepFailure or InfraFailure if it fails to build. | 350 StepFailure or InfraFailure if it fails to build. |
| 341 """ | 351 """ |
| 342 ninja_log_exit_status = 0 | 352 ninja_log_exit_status = 0 |
| 353 if ninja_command is None: | |
|
shinyak
2016/11/14 08:14:08
Can we generate meaningful value when ninja_comman
tikuta
2016/11/15 07:07:10
There is a recipe not using ninja, so ninja_comman
shinyak
2016/11/15 07:27:19
Then ninja_command in L386 could be ['-j', '50'] o
tikuta
2016/11/16 06:51:51
I'm not sure what is the best way to handle such c
| |
| 354 ninja_command = [] | |
| 355 ninja_command = self.remove_j_flag(ninja_command) | |
| 343 | 356 |
| 344 if allow_build_without_goma: | 357 if allow_build_without_goma: |
| 345 assert(env is not None) | 358 assert(env is not None) |
| 359 env = env.copy() | |
| 360 | |
| 346 try: | 361 try: |
| 347 self.start(env) | 362 self.start(env) |
| 348 except: | 363 except: |
| 349 env['GOMA_DISABLED'] = 'true' | |
| 350 self.remove_j_flag(ninja_log_command) | |
| 351 try: | 364 try: |
| 352 yield | 365 yield ({'GOMA_DISABLED':'true'}, ninja_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_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 |
| 382 ninja, args = ninja_command[:1], ninja_command[1:] | |
| 383 ninja_command = ninja + ['-j', self.recommended_goma_jobs] + args | |
| 384 | |
| 369 try: | 385 try: |
| 370 yield | 386 yield ({}, ninja_command) |
| 371 except self.m.step.StepFailure as e: # pragma: no cover | 387 except self.m.step.StepFailure as e: # pragma: no cover |
| 372 ninja_log_exit_status = e.retcode | 388 ninja_log_exit_status = e.retcode |
| 373 raise e | 389 raise e |
| 374 except self.m.step.InfraFailure as e: # pragma: no cover | 390 except self.m.step.InfraFailure as e: # pragma: no cover |
| 375 ninja_log_exit_status = -1 | 391 ninja_log_exit_status = -1 |
| 376 raise e | 392 raise e |
| 377 finally: | 393 finally: |
| 378 self.stop(ninja_log_outdir=ninja_log_outdir, | 394 self.stop(ninja_log_outdir=ninja_log_outdir, |
| 379 ninja_log_compiler=ninja_log_compiler, | 395 ninja_log_compiler=ninja_log_compiler, |
| 380 ninja_log_command=ninja_log_command, | 396 ninja_log_command=ninja_command, |
| 381 ninja_log_exit_status=ninja_log_exit_status) | 397 ninja_log_exit_status=ninja_log_exit_status) |
| OLD | NEW |