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."""
17 "url" : "https://chromium.googlesource.com/chromium/src.git",
18 "deps_file" : ".DEPS.git",
21 "src/data/page_cycler": "https://chrome-internal.googlesource.com/" +
22 "chrome/data/page_cycler/.git",
23 "src/tools/perf/data": "https://chrome-internal.googlesource.com/" +
24 "chrome/tools/perf/data/.git",
25 "src/v8_bleeding_edge": "git://github.com/v8/v8.git",
31 GCLIENT_SPEC
= ''.join([l
for l
in GCLIENT_SPEC
.splitlines()])
34 def OutputAnnotationStepStart(name
):
35 """Outputs appropriate annotation to signal the start of a step to
39 name: The name of the step.
42 print '@@@SEED_STEP %s@@@' % name
43 print '@@@STEP_CURSOR %s@@@' % name
44 print '@@@STEP_STARTED@@@'
48 def OutputAnnotationStepClosed():
49 """Outputs appropriate annotation to signal the closing of a step to
52 print '@@@STEP_CLOSED@@@'
56 def CreateAndChangeToSourceDirectory(working_directory
):
57 """Creates a directory 'bisect' as a subdirectory of 'working_directory'. If
58 the function is successful, the current working directory will change to that
59 of the new 'bisect' directory.
62 True if the directory was successfully created (or already existed).
65 os
.chdir(working_directory
)
69 if e
.errno
!= errno
.EEXIST
:
75 def RunGClient(params
):
76 """Runs gclient with the specified parameters.
79 params: A list of parameters to pass to gclient.
82 The return code of the call.
85 # "HOME" isn't normally defined on windows, but is needed
86 # for git to find the user's .netrc file.
87 if not os
.getenv('HOME'):
88 os
.environ
['HOME'] = os
.environ
['USERPROFILE']
90 shell
= os
.name
== 'nt'
91 cmd
= ['gclient'] + params
92 return subprocess
.call(cmd
, shell
=shell
)
95 def RunGClientAndCreateConfig():
96 """Runs gclient and creates a config containing both src and src-internal.
99 The return code of the call.
101 return_code
= RunGClient(
102 ['config', '--spec=%s' % GCLIENT_SPEC
, '--git-deps'])
106 def RunGClientAndSync(reset
):
107 """Runs gclient and does a normal sync.
110 reset: Whether to reset any changes to the depot.
113 The return code of the call.
115 params
= ['sync', '--verbose']
117 params
.extend(['--reset', '--force', '--delete_unversioned_trees'])
118 return RunGClient(params
)
121 def SetupGitDepot(output_buildbot_annotations
, reset
):
122 """Sets up the depot for the bisection. The depot will be located in a
123 subdirectory called 'bisect'.
126 reset: Whether to reset any changes to the depot.
129 True if gclient successfully created the config file and did a sync, False
132 name
= 'Setting up Bisection Depot'
134 if output_buildbot_annotations
:
135 OutputAnnotationStepStart(name
)
139 if not RunGClientAndCreateConfig():
140 if not RunGClientAndSync(reset
):
143 if output_buildbot_annotations
:
145 OutputAnnotationStepClosed()
150 def CreateBisectDirectoryAndSetupDepot(opts
, reset
=False):
151 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
155 opts: The options parsed from the command line through parse_args().
156 reset: Whether to reset any changes to the depot.
159 Returns 0 on success, otherwise 1.
161 if not CreateAndChangeToSourceDirectory(opts
.working_directory
):
162 print 'Error: Could not create bisect directory.'
166 if not SetupGitDepot(opts
.output_buildbot_annotations
, reset
):
167 print 'Error: Failed to grab source.'