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."""
18 "url" : "https://chromium.googlesource.com/chromium/src.git",
19 "deps_file" : ".DEPS.git",
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",
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
41 name: The name of the step.
44 print '@@@SEED_STEP %s@@@' % name
45 print '@@@STEP_CURSOR %s@@@' % name
46 print '@@@STEP_STARTED@@@'
50 def OutputAnnotationStepClosed():
51 """Outputs appropriate annotation to signal the closing of a step to
54 print '@@@STEP_CLOSED@@@'
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.
64 True if the directory was successfully created (or already existed).
67 os
.chdir(working_directory
)
71 if e
.errno
!= errno
.EEXIST
:
77 def RunGClient(params
):
78 """Runs gclient with the specified parameters.
81 params: A list of parameters to pass to gclient.
84 The return code of the call.
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.
101 The return code of the call.
103 return_code
= RunGClient(
104 ['config', '--spec=%s' % GCLIENT_SPEC
, '--git-deps'])
108 def IsDepsFileBlink():
109 """Reads .DEPS.git and returns whether or not we're using blink.
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.
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
)
131 if e
.errno
!= errno
.ENOENT
:
136 def RunGClientAndSync(reset
):
137 """Runs gclient and does a normal sync.
140 reset: Whether to reset any changes to the depot.
143 The return code of the call.
145 params
= ['sync', '--verbose']
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'.
156 reset: Whether to reset any changes to the depot.
159 True if gclient successfully created the config file and did a sync, False
162 name
= 'Setting up Bisection Depot'
164 if output_buildbot_annotations
:
165 OutputAnnotationStepStart(name
)
169 if not RunGClientAndCreateConfig():
170 passed_deps_check
= True
171 if os
.path
.isfile(os
.path
.join('src', FILE_DEPS_GIT
)):
174 if not IsDepsFileBlink():
175 passed_deps_check
= RemoveThirdPartyWebkitDirectory()
177 passed_deps_check
= True
180 if passed_deps_check
and not RunGClientAndSync(reset
):
183 if output_buildbot_annotations
:
185 OutputAnnotationStepClosed()
190 def CreateBisectDirectoryAndSetupDepot(opts
, reset
=False):
191 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
195 opts: The options parsed from the command line through parse_args().
196 reset: Whether to reset any changes to the depot.
199 Returns 0 on success, otherwise 1.
201 if not CreateAndChangeToSourceDirectory(opts
.working_directory
):
202 print 'Error: Could not create bisect directory.'
206 if not SetupGitDepot(opts
.output_buildbot_annotations
, reset
):
207 print 'Error: Failed to grab source.'