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

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

Issue 2256183003: Ensure gclient solutions are always managed. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 4 years, 4 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 # Copyright 2016 The Chromium Authors. All rights reserved. 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 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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import re
8 import subprocess 9 import subprocess
9 import sys 10 import sys
10 import tempfile 11 import tempfile
11 12
12 13
13 # Install Infra build environment. 14 # Install Infra build environment.
14 BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname( 15 BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
15 os.path.abspath(__file__)))) 16 os.path.abspath(__file__))))
16 sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts')) 17 sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts'))
17 18
18 from common import annotator 19 from common import annotator
19 from common import env 20 from common import env
20 21
21 22
22 LOGGER = logging.getLogger('update_scripts') 23 LOGGER = logging.getLogger('update_scripts')
23 24
24 25
25 def _run_command(cmd, **kwargs): 26 def _run_command(cmd, **kwargs):
26 LOGGER.debug('Executing command: %s', cmd) 27 LOGGER.debug('Executing command: %s', cmd)
27 kwargs.setdefault('stderr', subprocess.STDOUT) 28 kwargs.setdefault('stderr', subprocess.STDOUT)
28 proc = subprocess.Popen(cmd, **kwargs) 29 proc = subprocess.Popen(cmd, **kwargs)
29 stdout, _ = proc.communicate() 30 stdout, _ = proc.communicate()
30 31
31 LOGGER.debug('Process [%s] returned [%d] with output:\n%s', 32 LOGGER.debug('Process [%s] returned [%d] with output:\n%s',
32 cmd, proc.returncode, stdout) 33 cmd, proc.returncode, stdout)
33 return proc.returncode, stdout 34 return proc.returncode, stdout
34 35
35 36
37 def ensure_managed(dot_gclient_filename):
38 """Rewrites a .gclient file to set "managed": True.
39
40 Returns:
41 True if the .gclient file was modified.
42 """
43
44 with open(dot_gclient_filename) as fh:
45 contents = fh.read()
46
47 new_contents = re.sub(r'("managed"\s*:\s*)False', r'\1True', contents)
48
49 if contents != new_contents:
50 with open(dot_gclient_filename, 'w') as fh:
51 fh.write(new_contents)
52 return True
53 return False
54
55
36 def update_scripts(): 56 def update_scripts():
37 if os.environ.get('RUN_SLAVE_UPDATED_SCRIPTS'): 57 if os.environ.get('RUN_SLAVE_UPDATED_SCRIPTS'):
38 os.environ.pop('RUN_SLAVE_UPDATED_SCRIPTS') 58 os.environ.pop('RUN_SLAVE_UPDATED_SCRIPTS')
39 return False 59 return False
40 60
41 stream = annotator.StructuredAnnotationStream() 61 stream = annotator.StructuredAnnotationStream()
42 62
43 with stream.step('update_scripts') as s: 63 with stream.step('update_scripts') as s:
64 if ensure_managed(os.path.join(env.Build, os.pardir, '.gclient')):
65 s.step_text('Top-level gclient solution was unmanaged, '
66 'changed to managed')
67
44 gclient_name = 'gclient' 68 gclient_name = 'gclient'
45 if sys.platform.startswith('win'): 69 if sys.platform.startswith('win'):
46 gclient_name += '.bat' 70 gclient_name += '.bat'
47 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools', 71 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools',
48 gclient_name) 72 gclient_name)
49 gclient_cmd = [gclient_path, 'sync', '--force', '--verbose', '--jobs=2', 73 gclient_cmd = [gclient_path, 'sync', '--force', '--verbose', '--jobs=2',
50 '--break_repo_locks'] 74 '--break_repo_locks']
51 try: 75 try:
52 fd, output_json = tempfile.mkstemp() 76 fd, output_json = tempfile.mkstemp()
53 os.close(fd) 77 os.close(fd)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 s.step_text('Unable to get SCM data') 117 s.step_text('Unable to get SCM data')
94 s.step_exception() 118 s.step_exception()
95 119
96 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' 120 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1'
97 121
98 # After running update scripts, set PYTHONIOENCODING=UTF-8 for the real 122 # After running update scripts, set PYTHONIOENCODING=UTF-8 for the real
99 # annotated_run. 123 # annotated_run.
100 os.environ['PYTHONIOENCODING'] = 'UTF-8' 124 os.environ['PYTHONIOENCODING'] = 'UTF-8'
101 125
102 return True 126 return True
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