Disable ContentSettingBubbleModelTest.RPHAllow which is flaky.
[chromium-blink-merge.git] / tools / bisect_utils.py
blob590c4c9308d833967e2466ab49d5f7c290eed81a
1 # Copyright (c) 2013 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.
5 """Set of operations/utilities related to checking out the depot, and
6 outputting annotations on the buildbot waterfall. These are intended to be
7 used by the bisection scripts."""
9 import errno
10 import os
11 import shutil
12 import subprocess
15 GCLIENT_SPEC = """
16 solutions = [
17 { "name" : "src",
18 "url" : "https://chromium.googlesource.com/chromium/src.git",
19 "deps_file" : ".DEPS.git",
20 "managed" : True,
21 "custom_deps" : {
22 "src/data/page_cycler": "https://chrome-internal.googlesource.com/" +
23 "chrome/data/page_cycler/.git",
24 "src/tools/perf/data": "https://chrome-internal.googlesource.com/" +
25 "chrome/tools/perf/data/.git",
26 "src/v8_bleeding_edge": "git://github.com/v8/v8.git",
28 "safesync_url": "",
31 """
32 GCLIENT_SPEC = ''.join([l for l in GCLIENT_SPEC.splitlines()])
33 FILE_DEPS_GIT = '.DEPS.git'
36 def OutputAnnotationStepStart(name):
37 """Outputs appropriate annotation to signal the start of a step to
38 a trybot.
40 Args:
41 name: The name of the step.
42 """
43 print
44 print '@@@SEED_STEP %s@@@' % name
45 print '@@@STEP_CURSOR %s@@@' % name
46 print '@@@STEP_STARTED@@@'
47 print
50 def OutputAnnotationStepClosed():
51 """Outputs appropriate annotation to signal the closing of a step to
52 a trybot."""
53 print
54 print '@@@STEP_CLOSED@@@'
55 print
58 def CreateAndChangeToSourceDirectory(working_directory):
59 """Creates a directory 'bisect' as a subdirectory of 'working_directory'. If
60 the function is successful, the current working directory will change to that
61 of the new 'bisect' directory.
63 Returns:
64 True if the directory was successfully created (or already existed).
65 """
66 cwd = os.getcwd()
67 os.chdir(working_directory)
68 try:
69 os.mkdir('bisect')
70 except OSError, e:
71 if e.errno != errno.EEXIST:
72 return False
73 os.chdir('bisect')
74 return True
77 def RunGClient(params):
78 """Runs gclient with the specified parameters.
80 Args:
81 params: A list of parameters to pass to gclient.
83 Returns:
84 The return code of the call.
85 """
86 if os.name == 'nt':
87 # "HOME" isn't normally defined on windows, but is needed
88 # for git to find the user's .netrc file.
89 if not os.getenv('HOME'):
90 os.environ['HOME'] = os.environ['USERPROFILE']
92 shell = os.name == 'nt'
93 cmd = ['gclient'] + params
94 return subprocess.call(cmd, shell=shell)
97 def RunGClientAndCreateConfig():
98 """Runs gclient and creates a config containing both src and src-internal.
100 Returns:
101 The return code of the call.
103 return_code = RunGClient(
104 ['config', '--spec=%s' % GCLIENT_SPEC, '--git-deps'])
105 return return_code
108 def IsDepsFileBlink():
109 """Reads .DEPS.git and returns whether or not we're using blink.
111 Returns:
112 True if blink, false if webkit.
114 locals = {'Var': lambda _: locals["vars"][_],
115 'From': lambda *args: None}
116 execfile(FILE_DEPS_GIT, {}, locals)
117 return 'blink.git' in locals['vars']['webkit_url']
120 def RemoveThirdPartyWebkitDirectory():
121 """Removes third_party/WebKit.
123 Returns:
124 True on success.
126 try:
127 path_to_dir = os.path.join(os.getcwd(), 'third_party', 'WebKit')
128 if os.path.exists(path_to_dir):
129 shutil.rmtree(path_to_dir)
130 except OSError, e:
131 if e.errno != errno.ENOENT:
132 return False
133 return True
136 def RunGClientAndSync(reset):
137 """Runs gclient and does a normal sync.
139 Args:
140 reset: Whether to reset any changes to the depot.
142 Returns:
143 The return code of the call.
145 params = ['sync', '--verbose']
146 if reset:
147 params.extend(['--reset', '--force', '--delete_unversioned_trees'])
148 return RunGClient(params)
151 def SetupGitDepot(output_buildbot_annotations, reset):
152 """Sets up the depot for the bisection. The depot will be located in a
153 subdirectory called 'bisect'.
155 Args:
156 reset: Whether to reset any changes to the depot.
158 Returns:
159 True if gclient successfully created the config file and did a sync, False
160 otherwise.
162 name = 'Setting up Bisection Depot'
164 if output_buildbot_annotations:
165 OutputAnnotationStepStart(name)
167 passed = False
169 if not RunGClientAndCreateConfig():
170 passed_deps_check = True
171 if os.path.isfile(os.path.join('src', FILE_DEPS_GIT)):
172 cwd = os.getcwd()
173 os.chdir('src')
174 if not IsDepsFileBlink():
175 passed_deps_check = RemoveThirdPartyWebkitDirectory()
176 else:
177 passed_deps_check = True
178 os.chdir(cwd)
180 if passed_deps_check and not RunGClientAndSync(reset):
181 passed = True
183 if output_buildbot_annotations:
184 print
185 OutputAnnotationStepClosed()
187 return passed
190 def CreateBisectDirectoryAndSetupDepot(opts, reset=False):
191 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
192 there using gclient.
194 Args:
195 opts: The options parsed from the command line through parse_args().
196 reset: Whether to reset any changes to the depot.
198 Returns:
199 Returns 0 on success, otherwise 1.
201 if not CreateAndChangeToSourceDirectory(opts.working_directory):
202 print 'Error: Could not create bisect directory.'
203 print
204 return 1
206 if not SetupGitDepot(opts.output_buildbot_annotations, reset):
207 print 'Error: Failed to grab source.'
208 print
209 return 1
211 return 0