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

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

Issue 1884523002: Extract update_scripts out of annotated_run (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: presubmit Created 4 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « scripts/slave/unittests/annotated_run_test.py ('k') | 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
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import logging
7 import os
8 import subprocess
9 import sys
10 import tempfile
11
12
13 # Install Infra build environment.
14 BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
15 os.path.abspath(__file__))))
16 sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts'))
17
18 from common import annotator
19 from common import env
20
21
22 LOGGER = logging.getLogger('update_scripts')
23
24
25 def _run_command(cmd, **kwargs):
26 LOGGER.debug('Executing command: %s', cmd)
27 kwargs.setdefault('stderr', subprocess.STDOUT)
28 proc = subprocess.Popen(cmd, **kwargs)
29 stdout, _ = proc.communicate()
30
31 LOGGER.debug('Process [%s] returned [%d] with output:\n%s',
32 cmd, proc.returncode, stdout)
33 return proc.returncode, stdout
34
35
36 def update_scripts():
37 if os.environ.get('RUN_SLAVE_UPDATED_SCRIPTS'):
38 os.environ.pop('RUN_SLAVE_UPDATED_SCRIPTS')
39 return False
40
41 stream = annotator.StructuredAnnotationStream()
42
43 with stream.step('update_scripts') as s:
44 gclient_name = 'gclient'
45 if sys.platform.startswith('win'):
46 gclient_name += '.bat'
47 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools',
48 gclient_name)
49 gclient_cmd = [gclient_path, 'sync', '--force', '--verbose', '--jobs=2',
50 '--break_repo_locks']
51 try:
52 fd, output_json = tempfile.mkstemp()
53 os.close(fd)
54 gclient_cmd += ['--output-json', output_json]
55 except Exception:
56 # Super paranoia try block.
57 output_json = None
58 cmd_dict = {
59 'name': 'update_scripts',
60 'cmd': gclient_cmd,
61 'cwd': env.Build,
62 }
63 annotator.print_step(cmd_dict, os.environ, stream)
64 rv, _ = _run_command(gclient_cmd, cwd=env.Build)
65 if rv != 0:
66 s.step_text('gclient sync failed!')
67 s.step_exception()
68 elif output_json:
69 try:
70 with open(output_json, 'r') as f:
71 gclient_json = json.load(f)
72 for line in json.dumps(
73 gclient_json, sort_keys=True,
74 indent=4, separators=(',', ': ')).splitlines():
75 s.step_log_line('gclient_json', line)
76 s.step_log_end('gclient_json')
77
78 build_checkout = gclient_json['solutions'].get('build/')
79 if build_checkout:
80 s.step_text('%(scm)s - %(revision)s' % build_checkout)
81 s.set_build_property('build_scm', json.dumps(build_checkout['scm']))
82 s.set_build_property('build_revision',
83 json.dumps(build_checkout['revision']))
84 except Exception as e:
85 s.step_text('Unable to process gclient JSON %s' % repr(e))
86 s.step_exception()
87 finally:
88 try:
89 os.remove(output_json)
90 except Exception as e:
91 LOGGER.warning("LEAKED: %s", output_json, exc_info=True)
92 else:
93 s.step_text('Unable to get SCM data')
94 s.step_exception()
95
96 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1'
97
98 # After running update scripts, set PYTHONIOENCODING=UTF-8 for the real
99 # annotated_run.
100 os.environ['PYTHONIOENCODING'] = 'UTF-8'
101
102 return True
OLDNEW
« no previous file with comments | « scripts/slave/unittests/annotated_run_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698