| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 import argparse | 6 import argparse |
| 7 import collections | 7 import collections |
| 8 import contextlib | 8 import contextlib |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| 11 import os | 11 import os |
| 12 import shutil | 12 import shutil |
| 13 import socket | 13 import socket |
| 14 import subprocess | 14 import subprocess |
| 15 import sys | 15 import sys |
| 16 import tempfile | 16 import tempfile |
| 17 | 17 |
| 18 | 18 |
| 19 # Install Infra build environment. | 19 # Install Infra build environment. |
| 20 BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname( | 20 BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname( |
| 21 os.path.abspath(__file__)))) | 21 os.path.abspath(__file__)))) |
| 22 sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts')) | 22 sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts')) |
| 23 | 23 |
| 24 from common import annotator | 24 from common import annotator |
| 25 from common import chromium_utils | 25 from common import chromium_utils |
| 26 from common import env | 26 from common import env |
| 27 from common import master_cfg_utils | 27 from common import master_cfg_utils |
| 28 from slave import gce | 28 from slave import gce |
| 29 from slave import infra_platform | 29 from slave import infra_platform |
| 30 from slave import update_scripts |
| 30 | 31 |
| 31 # Logging instance. | 32 # Logging instance. |
| 32 LOGGER = logging.getLogger('annotated_run') | 33 LOGGER = logging.getLogger('annotated_run') |
| 33 | 34 |
| 34 # Return codes used by Butler/Annotee to indicate their failure (as opposed to | 35 # Return codes used by Butler/Annotee to indicate their failure (as opposed to |
| 35 # a forwarded return code from the underlying process). | 36 # a forwarded return code from the underlying process). |
| 36 LOGDOG_ERROR_RETURNCODES = ( | 37 LOGDOG_ERROR_RETURNCODES = ( |
| 37 # Butler runtime error. | 38 # Butler runtime error. |
| 38 250, | 39 250, |
| 39 # Annotee runtime error. | 40 # Annotee runtime error. |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 help='Path to the service account JSON. If one is not provided, the ' | 759 help='Path to the service account JSON. If one is not provided, the ' |
| 759 'local system credentials will be used.') | 760 'local system credentials will be used.') |
| 760 group.add_argument('--logdog-pubsub-topic', | 761 group.add_argument('--logdog-pubsub-topic', |
| 761 help='Override the LogDog Pub/Sub topic to write to.') | 762 help='Override the LogDog Pub/Sub topic to write to.') |
| 762 group.add_argument('--logdog-host', | 763 group.add_argument('--logdog-host', |
| 763 help='Override the LogDog Coordinator host.') | 764 help='Override the LogDog Coordinator host.') |
| 764 | 765 |
| 765 return parser.parse_args(argv) | 766 return parser.parse_args(argv) |
| 766 | 767 |
| 767 | 768 |
| 768 def update_scripts(): | |
| 769 if os.environ.get('RUN_SLAVE_UPDATED_SCRIPTS'): | |
| 770 os.environ.pop('RUN_SLAVE_UPDATED_SCRIPTS') | |
| 771 return False | |
| 772 | |
| 773 stream = annotator.StructuredAnnotationStream() | |
| 774 | |
| 775 with stream.step('update_scripts') as s: | |
| 776 gclient_name = 'gclient' | |
| 777 if sys.platform.startswith('win'): | |
| 778 gclient_name += '.bat' | |
| 779 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools', | |
| 780 gclient_name) | |
| 781 gclient_cmd = [gclient_path, 'sync', '--force', '--verbose', '--jobs=2', | |
| 782 '--break_repo_locks'] | |
| 783 try: | |
| 784 fd, output_json = tempfile.mkstemp() | |
| 785 os.close(fd) | |
| 786 gclient_cmd += ['--output-json', output_json] | |
| 787 except Exception: | |
| 788 # Super paranoia try block. | |
| 789 output_json = None | |
| 790 cmd_dict = { | |
| 791 'name': 'update_scripts', | |
| 792 'cmd': gclient_cmd, | |
| 793 'cwd': env.Build, | |
| 794 } | |
| 795 annotator.print_step(cmd_dict, os.environ, stream) | |
| 796 rv, _ = _run_command(gclient_cmd, cwd=env.Build) | |
| 797 if rv != 0: | |
| 798 s.step_text('gclient sync failed!') | |
| 799 s.step_exception() | |
| 800 elif output_json: | |
| 801 try: | |
| 802 with open(output_json, 'r') as f: | |
| 803 gclient_json = json.load(f) | |
| 804 for line in json.dumps( | |
| 805 gclient_json, sort_keys=True, | |
| 806 indent=4, separators=(',', ': ')).splitlines(): | |
| 807 s.step_log_line('gclient_json', line) | |
| 808 s.step_log_end('gclient_json') | |
| 809 | |
| 810 build_checkout = gclient_json['solutions'].get('build/') | |
| 811 if build_checkout: | |
| 812 s.step_text('%(scm)s - %(revision)s' % build_checkout) | |
| 813 s.set_build_property('build_scm', json.dumps(build_checkout['scm'])) | |
| 814 s.set_build_property('build_revision', | |
| 815 json.dumps(build_checkout['revision'])) | |
| 816 except Exception as e: | |
| 817 s.step_text('Unable to process gclient JSON %s' % repr(e)) | |
| 818 s.step_exception() | |
| 819 finally: | |
| 820 try: | |
| 821 os.remove(output_json) | |
| 822 except Exception as e: | |
| 823 LOGGER.warning("LEAKED: %s", output_json, exc_info=True) | |
| 824 else: | |
| 825 s.step_text('Unable to get SCM data') | |
| 826 s.step_exception() | |
| 827 | |
| 828 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' | |
| 829 | |
| 830 # After running update scripts, set PYTHONIOENCODING=UTF-8 for the real | |
| 831 # annotated_run. | |
| 832 os.environ['PYTHONIOENCODING'] = 'UTF-8' | |
| 833 | |
| 834 return True | |
| 835 | |
| 836 | |
| 837 def clean_old_recipe_engine(): | 769 def clean_old_recipe_engine(): |
| 838 """Clean stale pycs from the old location of recipe_engine. | 770 """Clean stale pycs from the old location of recipe_engine. |
| 839 | 771 |
| 840 This function should only be needed for a little while after the recipe | 772 This function should only be needed for a little while after the recipe |
| 841 packages rollout (2015-09-16). | 773 packages rollout (2015-09-16). |
| 842 """ | 774 """ |
| 843 for (dirpath, _, filenames) in os.walk( | 775 for (dirpath, _, filenames) in os.walk( |
| 844 os.path.join(env.Build, 'third_party', 'recipe_engine')): | 776 os.path.join(env.Build, 'third_party', 'recipe_engine')): |
| 845 for filename in filenames: | 777 for filename in filenames: |
| 846 if filename.endswith('.pyc'): | 778 if filename.endswith('.pyc'): |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 properties['build_data_dir'] = build_data_dir | 902 properties['build_data_dir'] = build_data_dir |
| 971 | 903 |
| 972 # Write our annotated_run.py monitoring event. | 904 # Write our annotated_run.py monitoring event. |
| 973 write_monitoring_event(config, build_data_dir, properties) | 905 write_monitoring_event(config, build_data_dir, properties) |
| 974 | 906 |
| 975 # Execute our recipe. | 907 # Execute our recipe. |
| 976 return _exec_recipe(rt, opts, basedir, tdir, config, properties) | 908 return _exec_recipe(rt, opts, basedir, tdir, config, properties) |
| 977 | 909 |
| 978 | 910 |
| 979 def shell_main(argv): | 911 def shell_main(argv): |
| 980 if update_scripts(): | 912 if update_scripts.update_scripts(): |
| 981 # Re-execute with the updated annotated_run.py. | 913 # Re-execute with the updated annotated_run.py. |
| 982 rv, _ = _run_command([sys.executable] + argv) | 914 rv, _ = _run_command([sys.executable] + argv) |
| 983 return rv | 915 return rv |
| 984 else: | 916 else: |
| 985 return main(argv[1:]) | 917 return main(argv[1:]) |
| 986 | 918 |
| 987 | 919 |
| 988 if __name__ == '__main__': | 920 if __name__ == '__main__': |
| 989 logging.basicConfig(level=logging.INFO) | 921 logging.basicConfig(level=logging.INFO) |
| 990 sys.exit(shell_main(sys.argv)) | 922 sys.exit(shell_main(sys.argv)) |
| OLD | NEW |