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

Side by Side Diff: scripts/slave/compile.py

Issue 2155413003: Refactoring: separate build steps in real_main for compile.py (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A tool to build chrome, executed by buildbot. 6 """A tool to build chrome, executed by buildbot.
7 7
8 When this is run, the current directory (cwd) should be the outer build 8 When this is run, the current directory (cwd) should be the outer build
9 directory (e.g., chrome-release/build/). 9 directory (e.g., chrome-release/build/).
10 10
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if not entry: 338 if not entry:
339 continue 339 continue
340 key, value = entry.split('=', 1) 340 key, value = entry.split('=', 1)
341 env_in_file[key] = value 341 env_in_file[key] = value
342 env_in_file.update(env_to_store) 342 env_in_file.update(env_to_store)
343 with open(path, 'wb') as f: 343 with open(path, 'wb') as f:
344 f.write(nul.join(['%s=%s' % (k, v) for k, v in env_in_file.iteritems()])) 344 f.write(nul.join(['%s=%s' % (k, v) for k, v in env_in_file.iteritems()]))
345 f.write(nul * 2) 345 f.write(nul * 2)
346 346
347 347
348 def main_ninja(options, args): 348 def main_ninja(options, args, env, goma_ready):
ukai 2016/07/20 01:33:55 instead of passing goma_ready, use options.goma_di
tikuta 2016/07/20 04:20:07 Done.
349 """Interprets options, clobbers object files, and calls ninja.""" 349 """calls ninja."""
ukai 2016/07/20 01:33:55 Args and Returns ?
tikuta 2016/07/20 04:20:07 Done.
350 350
351 # Prepare environment.
352 env = EchoDict(os.environ)
353 goma_ready, goma_cloudtail = goma_setup(options, env)
354 exit_status = -1 351 exit_status = -1
355 try: 352 try:
356 if not goma_ready: 353 if not goma_ready:
shinyak 2016/07/20 02:54:43 Since goma_ready is used only for assertion purpos
tikuta 2016/07/20 04:20:07 Done.
357 assert options.compiler not in ('goma', 'goma-clang') 354 assert options.compiler not in ('goma', 'goma-clang')
358 assert options.goma_dir is None 355 assert options.goma_dir is None
359 356
360 # ninja is different from all the other build systems in that it requires 357 # ninja is different from all the other build systems in that it requires
361 # most configuration to be done at gyp time. This is why this function does 358 # most configuration to be done at gyp time. This is why this function does
362 # less than the other comparable functions in this file. 359 # less than the other comparable functions in this file.
363 print 'chdir to %s' % options.src_dir 360 print 'chdir to %s' % options.src_dir
364 os.chdir(options.src_dir) 361 os.chdir(options.src_dir)
365 362
366 command = [options.ninja_path, '-w', 'dupbuild=err', 363 command = [options.ninja_path, '-w', 'dupbuild=err',
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 filter_obj = EnsureUpToDateFilter() 442 filter_obj = EnsureUpToDateFilter()
446 # Append `-d explain` to help diagnose in the failure case. 443 # Append `-d explain` to help diagnose in the failure case.
447 command += ['-d', 'explain'] 444 command += ['-d', 'explain']
448 chromium_utils.RunCommand(command, env=env, filter_obj=filter_obj) 445 chromium_utils.RunCommand(command, env=env, filter_obj=filter_obj)
449 if not filter_obj.was_up_to_date: 446 if not filter_obj.was_up_to_date:
450 print 'Failing build because ninja reported work to do.' 447 print 'Failing build because ninja reported work to do.'
451 print 'This means that after completing a compile, another was run and' 448 print 'This means that after completing a compile, another was run and'
452 print 'it resulted in still having work to do (that is, a no-op build' 449 print 'it resulted in still having work to do (that is, a no-op build'
453 print 'wasn\'t a no-op). Consult the first "ninja explain:" line for a' 450 print 'wasn\'t a no-op). Consult the first "ninja explain:" line for a'
454 print 'likely culprit.' 451 print 'likely culprit.'
455 return 1 452 return 1, command
456 return exit_status 453 return exit_status, command
ukai 2016/07/20 01:33:55 better to emit json in a file for additional text
Yoshisato Yanagisawa 2016/07/20 02:30:32 I understand that saying different opinions betwee
457 finally: 454 finally:
458 goma_teardown(options, env, exit_status, goma_cloudtail) 455 pass
Yoshisato Yanagisawa 2016/07/20 02:30:32 you do not need finally.
tikuta 2016/07/20 04:20:07 Done.
459
460 override_gsutil = None
461 if options.gsutil_py_path:
462 override_gsutil = [sys.executable, options.gsutil_py_path]
463
464 goma_utils.UploadNinjaLog(
465 options.target_output_dir, options.compiler, command, exit_status,
466 override_gsutil=override_gsutil)
467 456
468 457
469 def get_target_build_dir(args, options): 458 def get_target_build_dir(args, options):
470 """Keep this function in sync with src/build/landmines.py""" 459 """Keep this function in sync with src/build/landmines.py"""
471 if chromium_utils.IsLinux() and options.cros_board: 460 if chromium_utils.IsLinux() and options.cros_board:
472 # When building ChromeOS's Simple Chrome workflow, the output directory 461 # When building ChromeOS's Simple Chrome workflow, the output directory
473 # has a CROS board name suffix. 462 # has a CROS board name suffix.
474 outdir = 'out_%s' % (options.cros_board,) 463 outdir = 'out_%s' % (options.cros_board,)
475 elif options.out_dir: 464 elif options.out_dir:
476 outdir = options.out_dir 465 outdir = options.out_dir
477 else: 466 else:
478 outdir = 'out' 467 outdir = 'out'
479 return os.path.abspath(os.path.join(options.src_dir, outdir, options.target)) 468 return os.path.abspath(os.path.join(options.src_dir, outdir, options.target))
480 469
481 470
482 def real_main(): 471 def get_parsed_options():
483 option_parser = optparse.OptionParser() 472 option_parser = optparse.OptionParser()
484 option_parser.add_option('--clobber', action='store_true', default=False, 473 option_parser.add_option('--clobber', action='store_true', default=False,
485 help='delete the output directory before compiling') 474 help='delete the output directory before compiling')
486 option_parser.add_option('--target', default='Release', 475 option_parser.add_option('--target', default='Release',
487 help='build target (Debug or Release)') 476 help='build target (Debug or Release)')
488 option_parser.add_option('--src-dir', default=None, 477 option_parser.add_option('--src-dir', default=None,
489 help='path to the root of the source tree') 478 help='path to the root of the source tree')
490 option_parser.add_option('--mode', default='dev', 479 option_parser.add_option('--mode', default='dev',
491 help='build mode (dev or official) controlling ' 480 help='build mode (dev or official) controlling '
492 'environment variables set during build') 481 'environment variables set during build')
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 528
540 options, args = option_parser.parse_args() 529 options, args = option_parser.parse_args()
541 530
542 if not options.src_dir: 531 if not options.src_dir:
543 options.src_dir = 'src' 532 options.src_dir = 'src'
544 options.src_dir = os.path.abspath(options.src_dir) 533 options.src_dir = os.path.abspath(options.src_dir)
545 534
546 options.target_output_dir = get_target_build_dir(args, options) 535 options.target_output_dir = get_target_build_dir(args, options)
547 536
548 assert options.build_tool in (None, 'ninja') 537 assert options.build_tool in (None, 'ninja')
549 return main_ninja(options, args) 538 return options, args
539
540
541 def real_man():
Yoshisato Yanagisawa 2016/07/20 02:30:32 real_main? pylint did not detect this?
tikuta 2016/07/20 04:20:07 Thanks. It looks that `git cl upload` does not run
542 options, args = get_parsed_options()
543
544 # Prepare environment.
545 env = EchoDict(os.environ)
546
547 # start goma
548 goma_ready, goma_cloudtail = goma_setup(options, env)
ukai 2016/07/20 01:33:55 move goma_setup and goma_teardown in goma_utils? (
tikuta 2016/07/20 04:20:07 Let me do in another CL. I added TODO comment in g
549
550 # build
551 exit_status, command = main_ninja(options, args, env, goma_ready)
ukai 2016/07/20 01:33:55 catch exception in main_ninja?
tikuta 2016/07/20 04:20:07 Done.
552
553 # stop goma
554 goma_teardown(options, env, exit_status, goma_cloudtail)
555
556 override_gsutil = None
557 if options.gsutil_py_path:
558 override_gsutil = [sys.executable, options.gsutil_py_path]
559
560 goma_utils.UploadNinjaLog(
561 options.target_output_dir, options.compiler, command, exit_status,
562 override_gsutil=override_gsutil)
563
564 return exit_status
550 565
551 566
552 if '__main__' == __name__: 567 if '__main__' == __name__:
553 sys.exit(real_main()) 568 sys.exit(real_main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698