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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scripts/slave/unittests/annotated_run_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/slave/update_scripts.py
diff --git a/scripts/slave/update_scripts.py b/scripts/slave/update_scripts.py
new file mode 100644
index 0000000000000000000000000000000000000000..b37de1476052da9cad06c561d449d3f530ef63ef
--- /dev/null
+++ b/scripts/slave/update_scripts.py
@@ -0,0 +1,102 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import logging
+import os
+import subprocess
+import sys
+import tempfile
+
+
+# Install Infra build environment.
+BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
+ os.path.abspath(__file__))))
+sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts'))
+
+from common import annotator
+from common import env
+
+
+LOGGER = logging.getLogger('update_scripts')
+
+
+def _run_command(cmd, **kwargs):
+ LOGGER.debug('Executing command: %s', cmd)
+ kwargs.setdefault('stderr', subprocess.STDOUT)
+ proc = subprocess.Popen(cmd, **kwargs)
+ stdout, _ = proc.communicate()
+
+ LOGGER.debug('Process [%s] returned [%d] with output:\n%s',
+ cmd, proc.returncode, stdout)
+ return proc.returncode, stdout
+
+
+def update_scripts():
+ if os.environ.get('RUN_SLAVE_UPDATED_SCRIPTS'):
+ os.environ.pop('RUN_SLAVE_UPDATED_SCRIPTS')
+ return False
+
+ stream = annotator.StructuredAnnotationStream()
+
+ with stream.step('update_scripts') as s:
+ gclient_name = 'gclient'
+ if sys.platform.startswith('win'):
+ gclient_name += '.bat'
+ gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools',
+ gclient_name)
+ gclient_cmd = [gclient_path, 'sync', '--force', '--verbose', '--jobs=2',
+ '--break_repo_locks']
+ try:
+ fd, output_json = tempfile.mkstemp()
+ os.close(fd)
+ gclient_cmd += ['--output-json', output_json]
+ except Exception:
+ # Super paranoia try block.
+ output_json = None
+ cmd_dict = {
+ 'name': 'update_scripts',
+ 'cmd': gclient_cmd,
+ 'cwd': env.Build,
+ }
+ annotator.print_step(cmd_dict, os.environ, stream)
+ rv, _ = _run_command(gclient_cmd, cwd=env.Build)
+ if rv != 0:
+ s.step_text('gclient sync failed!')
+ s.step_exception()
+ elif output_json:
+ try:
+ with open(output_json, 'r') as f:
+ gclient_json = json.load(f)
+ for line in json.dumps(
+ gclient_json, sort_keys=True,
+ indent=4, separators=(',', ': ')).splitlines():
+ s.step_log_line('gclient_json', line)
+ s.step_log_end('gclient_json')
+
+ build_checkout = gclient_json['solutions'].get('build/')
+ if build_checkout:
+ s.step_text('%(scm)s - %(revision)s' % build_checkout)
+ s.set_build_property('build_scm', json.dumps(build_checkout['scm']))
+ s.set_build_property('build_revision',
+ json.dumps(build_checkout['revision']))
+ except Exception as e:
+ s.step_text('Unable to process gclient JSON %s' % repr(e))
+ s.step_exception()
+ finally:
+ try:
+ os.remove(output_json)
+ except Exception as e:
+ LOGGER.warning("LEAKED: %s", output_json, exc_info=True)
+ else:
+ s.step_text('Unable to get SCM data')
+ s.step_exception()
+
+ os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1'
+
+ # After running update scripts, set PYTHONIOENCODING=UTF-8 for the real
+ # annotated_run.
+ os.environ['PYTHONIOENCODING'] = 'UTF-8'
+
+ return True
« 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