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

Side by Side Diff: tools/bisect_utils.py

Issue 18991015: Unset some environment vars so they can be set up via the bisect script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from review. Created 7 years, 5 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 | « tools/bisect-perf-regression.py ('k') | 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 (c) 2013 The Chromium Authors. All rights reserved. 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 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 """Set of operations/utilities related to checking out the depot, and 5 """Set of operations/utilities related to checking out the depot, and
6 outputting annotations on the buildbot waterfall. These are intended to be 6 outputting annotations on the buildbot waterfall. These are intended to be
7 used by the bisection scripts.""" 7 used by the bisection scripts."""
8 8
9 import errno 9 import errno
10 import os 10 import os
(...skipping 23 matching lines...) Expand all
34 34
35 REPO_PARAMS = [ 35 REPO_PARAMS = [
36 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/', 36 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/',
37 '--repo-url', 37 '--repo-url',
38 'https://git.chromium.org/external/repo.git' 38 'https://git.chromium.org/external/repo.git'
39 ] 39 ]
40 40
41 REPO_SYNC_COMMAND = 'git checkout -f $(git rev-list --max-count=1 '\ 41 REPO_SYNC_COMMAND = 'git checkout -f $(git rev-list --max-count=1 '\
42 '--before=%d remotes/m/master)' 42 '--before=%d remotes/m/master)'
43 43
44 ORIGINAL_ENV = {}
45
44 def OutputAnnotationStepStart(name): 46 def OutputAnnotationStepStart(name):
45 """Outputs appropriate annotation to signal the start of a step to 47 """Outputs appropriate annotation to signal the start of a step to
46 a trybot. 48 a trybot.
47 49
48 Args: 50 Args:
49 name: The name of the step. 51 name: The name of the step.
50 """ 52 """
51 print 53 print
52 print '@@@SEED_STEP %s@@@' % name 54 print '@@@SEED_STEP %s@@@' % name
53 print '@@@STEP_CURSOR %s@@@' % name 55 print '@@@STEP_CURSOR %s@@@' % name
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 passed = False 278 passed = False
277 279
278 if not RunRepo(cmd): 280 if not RunRepo(cmd):
279 if not RunRepo(['sync']): 281 if not RunRepo(['sync']):
280 passed = True 282 passed = True
281 os.chdir(cwd) 283 os.chdir(cwd)
282 284
283 return passed 285 return passed
284 286
285 287
288 def CopyAndSaveOriginalEnvironmentVars():
289 """Makes a copy of the current environment variables."""
290 # TODO: Waiting on crbug.com/255689, will remove this after.
291 vars_to_remove = []
292 for k, v in os.environ.iteritems():
293 if 'ANDROID' in k:
294 vars_to_remove.append(k)
295 vars_to_remove.append('CHROME_SRC')
296 vars_to_remove.append('CHROMIUM_GYP_FILE')
297 vars_to_remove.append('GOMA_DIR')
298 vars_to_remove.append('GYP_CROSSCOMPILE')
299 vars_to_remove.append('GYP_DEFINES')
300 vars_to_remove.append('GYP_GENERATORS')
301 vars_to_remove.append('GYP_GENERATOR_FLAGS')
302 vars_to_remove.append('OBJCOPY')
303 for k in vars_to_remove:
304 if os.environ.has_key(k):
305 del os.environ[k]
306
307 global ORIGINAL_ENV
308 ORIGINAL_ENV = os.environ.copy()
309
310
286 def SetupAndroidBuildEnvironment(opts): 311 def SetupAndroidBuildEnvironment(opts):
287 """Sets up the android build environment. 312 """Sets up the android build environment.
288 313
289 Args: 314 Args:
290 opts: The options parsed from the command line through parse_args(). 315 opts: The options parsed from the command line through parse_args().
291 path_to_file: Path to the bisect script's directory. 316 path_to_file: Path to the bisect script's directory.
292 317
293 Returns: 318 Returns:
294 True if successful. 319 True if successful.
295 """ 320 """
321
322 # Revert the environment variables back to default before setting them up
323 # with envsetup.sh.
324 env_vars = os.environ.copy()
325 for k, _ in env_vars.iteritems():
326 del os.environ[k]
327 for k, v in ORIGINAL_ENV.iteritems():
328 os.environ[k] = v
329
296 path_to_file = os.path.join('build', 'android', 'envsetup.sh') 330 path_to_file = os.path.join('build', 'android', 'envsetup.sh')
297 proc = subprocess.Popen(['bash', '-c', 'source %s && env' % path_to_file], 331 proc = subprocess.Popen(['bash', '-c', 'source %s && env' % path_to_file],
298 stdout=subprocess.PIPE, 332 stdout=subprocess.PIPE,
299 stderr=subprocess.PIPE, 333 stderr=subprocess.PIPE,
300 cwd='src') 334 cwd='src')
301 (out, _) = proc.communicate() 335 (out, _) = proc.communicate()
302 336
303 for line in out.splitlines(): 337 for line in out.splitlines():
304 (k, _, v) = line.partition('=') 338 (k, _, v) = line.partition('=')
305 os.environ[k] = v 339 os.environ[k] = v
306 return not proc.returncode 340 return not proc.returncode
307 341
308 342
309 def SetupPlatformBuildEnvironment(opts): 343 def SetupPlatformBuildEnvironment(opts):
310 """Performs any platform specific setup. 344 """Performs any platform specific setup.
311 345
312 Args: 346 Args:
313 opts: The options parsed from the command line through parse_args(). 347 opts: The options parsed from the command line through parse_args().
314 path_to_file: Path to the bisect script's directory. 348 path_to_file: Path to the bisect script's directory.
315 349
316 Returns: 350 Returns:
317 True if successful. 351 True if successful.
318 """ 352 """
319 if opts.target_platform == 'android': 353 if opts.target_platform == 'android':
354 CopyAndSaveOriginalEnvironmentVars()
320 return SetupAndroidBuildEnvironment(opts) 355 return SetupAndroidBuildEnvironment(opts)
321 elif opts.target_platform == 'cros': 356 elif opts.target_platform == 'cros':
322 return SetupCrosRepo() 357 return SetupCrosRepo()
323 358
324 return True 359 return True
325 360
326 361
327 def CreateBisectDirectoryAndSetupDepot(opts, reset=False): 362 def CreateBisectDirectoryAndSetupDepot(opts, reset=False):
328 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot 363 """Sets up a subdirectory 'bisect' and then retrieves a copy of the depot
329 there using gclient. 364 there using gclient.
330 365
331 Args: 366 Args:
332 opts: The options parsed from the command line through parse_args(). 367 opts: The options parsed from the command line through parse_args().
333 reset: Whether to reset any changes to the depot. 368 reset: Whether to reset any changes to the depot.
334 369
335 Returns: 370 Returns:
336 Returns 0 on success, otherwise 1. 371 Returns 0 on success, otherwise 1.
337 """ 372 """
338 if not CreateAndChangeToSourceDirectory(opts.working_directory): 373 if not CreateAndChangeToSourceDirectory(opts.working_directory):
339 print 'Error: Could not create bisect directory.' 374 print 'Error: Could not create bisect directory.'
340 print 375 print
341 return 1 376 return 1
342 377
343 if not SetupGitDepot(opts, reset): 378 if not SetupGitDepot(opts, reset):
344 print 'Error: Failed to grab source.' 379 print 'Error: Failed to grab source.'
345 print 380 print
346 return 1 381 return 1
347 382
348 return 0 383 return 0
OLDNEW
« no previous file with comments | « tools/bisect-perf-regression.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698