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

Side by Side Diff: tools/auto_bisect/bisect_utils.py

Issue 429763003: Extract Builder and subclasses to separate module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/auto_bisect/builder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Utility functions used by the bisect tool. 5 """Utility functions used by the bisect tool.
6 6
7 This includes functions related to checking out the depot and outputting 7 This includes functions related to checking out the depot and outputting
8 annotations for the Buildbot waterfall. 8 annotations for the Buildbot waterfall.
9 """ 9 """
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 'managed': True, 58 'managed': True,
59 'custom_deps': {}, 59 'custom_deps': {},
60 'safesync_url': '', 60 'safesync_url': '',
61 }, 61 },
62 ] 62 ]
63 GCLIENT_SPEC_ANDROID = "\ntarget_os = ['android']" 63 GCLIENT_SPEC_ANDROID = "\ntarget_os = ['android']"
64 GCLIENT_CUSTOM_DEPS_V8 = {'src/v8_bleeding_edge': 'git://github.com/v8/v8.git'} 64 GCLIENT_CUSTOM_DEPS_V8 = {'src/v8_bleeding_edge': 'git://github.com/v8/v8.git'}
65 FILE_DEPS_GIT = '.DEPS.git' 65 FILE_DEPS_GIT = '.DEPS.git'
66 FILE_DEPS = 'DEPS' 66 FILE_DEPS = 'DEPS'
67 67
68 REPO_SYNC_COMMAND = ('git checkout -f $(git rev-list --max-count=1 '
69 '--before=%d remotes/m/master)')
70
71 # Paths to CrOS-related files, relative to ...
qyearsley 2014/07/30 01:49:45 What are these paths relative to? Where is cros/ch
prasadv 2014/08/15 17:49:36 I'm not sure about either, I believe we've functio
72 CROS_SDK_PATH = os.path.join('..', 'cros', 'chromite', 'bin', 'cros_sdk')
73 CROS_TEST_KEY_PATH = os.path.join(
74 '..', 'cros', 'chromite', 'ssh_keys', 'testing_rsa')
75 CROS_SCRIPT_KEY_PATH = os.path.join(
76 '..', 'cros', 'src', 'scripts', 'mod_for_test_scripts', 'ssh_keys',
77 'testing_rsa')
78
68 REPO_PARAMS = [ 79 REPO_PARAMS = [
69 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/', 80 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/',
70 '--repo-url', 81 '--repo-url',
71 'https://git.chromium.org/external/repo.git' 82 'https://git.chromium.org/external/repo.git'
72 ] 83 ]
73 84
74 REPO_SYNC_COMMAND = ('git checkout -f $(git rev-list --max-count=1 '
75 '--before=%d remotes/m/master)')
76
77 ORIGINAL_ENV = {}
78
79 85
80 def OutputAnnotationStepStart(name): 86 def OutputAnnotationStepStart(name):
81 """Outputs annotation to signal the start of a step to a trybot. 87 """Outputs annotation to signal the start of a step to a trybot.
82 88
83 Args: 89 Args:
84 name: The name of the step. 90 name: The name of the step.
85 """ 91 """
86 print 92 print
87 print '@@@SEED_STEP %s@@@' % name 93 print '@@@SEED_STEP %s@@@' % name
88 print '@@@STEP_CURSOR %s@@@' % name 94 print '@@@STEP_CURSOR %s@@@' % name
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 params: A list of parameters to pass to gclient. 196 params: A list of parameters to pass to gclient.
191 cwd: Working directory to run from. 197 cwd: Working directory to run from.
192 198
193 Returns: 199 Returns:
194 The return code of the call. 200 The return code of the call.
195 """ 201 """
196 cmd = ['gclient'] + params 202 cmd = ['gclient'] + params
197 return _SubprocessCall(cmd, cwd=cwd) 203 return _SubprocessCall(cmd, cwd=cwd)
198 204
199 205
206 def SetupCrosRepo():
207 """Sets up CrOS repo for bisecting ChromeOS.
208
209 Returns:
210 True if successful, False otherwise.
211 """
212 cwd = os.getcwd()
213 try:
214 os.mkdir('cros')
215 except OSError as e:
216 if e.errno != errno.EEXIST: # EEXIST means the directory already exists.
217 return False
218 os.chdir('cros')
219
220 cmd = ['init', '-u'] + REPO_PARAMS
221
222 passed = False
223
224 if not _RunRepo(cmd):
225 if not _RunRepo(['sync']):
226 passed = True
227 os.chdir(cwd)
228
229 return passed
230
231
200 def _RunRepo(params): 232 def _RunRepo(params):
201 """Runs CrOS repo command with specified parameters. 233 """Runs CrOS repo command with specified parameters.
202 234
203 Args: 235 Args:
204 params: A list of parameters to pass to gclient. 236 params: A list of parameters to pass to gclient.
205 237
206 Returns: 238 Returns:
207 The return code of the call (zero indicates success). 239 The return code of the call (zero indicates success).
208 """ 240 """
209 cmd = ['repo'] + params 241 cmd = ['repo'] + params
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if not RunGClientAndSync(): 408 if not RunGClientAndSync():
377 passed = True 409 passed = True
378 410
379 if opts.output_buildbot_annotations: 411 if opts.output_buildbot_annotations:
380 print 412 print
381 OutputAnnotationStepClosed() 413 OutputAnnotationStepClosed()
382 414
383 return passed 415 return passed
384 416
385 417
386 def SetupCrosRepo():
387 """Sets up CrOS repo for bisecting ChromeOS.
388
389 Returns:
390 True if successful, False otherwise.
391 """
392 cwd = os.getcwd()
393 try:
394 os.mkdir('cros')
395 except OSError as e:
396 if e.errno != errno.EEXIST: # EEXIST means the directory already exists.
397 return False
398 os.chdir('cros')
399
400 cmd = ['init', '-u'] + REPO_PARAMS
401
402 passed = False
403
404 if not _RunRepo(cmd):
405 if not _RunRepo(['sync']):
406 passed = True
407 os.chdir(cwd)
408
409 return passed
410
411
412 def CopyAndSaveOriginalEnvironmentVars():
413 """Makes a copy of the current environment variables.
414
415 Before making a copy of the environment variables and setting a global
416 variable, this function unsets a certain set of environment variables.
417 """
418 # TODO: Waiting on crbug.com/255689, will remove this after.
419 vars_to_remove = [
420 'CHROME_SRC',
421 'CHROMIUM_GYP_FILE',
422 'GYP_CROSSCOMPILE',
423 'GYP_DEFINES',
424 'GYP_GENERATORS',
425 'GYP_GENERATOR_FLAGS',
426 'OBJCOPY',
427 ]
428 for key in os.environ:
429 if 'ANDROID' in key:
430 vars_to_remove.append(key)
431 for key in vars_to_remove:
432 if os.environ.has_key(key):
433 del os.environ[key]
434
435 global ORIGINAL_ENV
436 ORIGINAL_ENV = os.environ.copy()
437
438
439 def SetupAndroidBuildEnvironment(opts, path_to_src=None):
440 """Sets up the android build environment.
441
442 Args:
443 opts: The options parsed from the command line through parse_args().
444 path_to_src: Path to the src checkout.
445
446 Returns:
447 True if successful.
448 """
449 # Revert the environment variables back to default before setting them up
450 # with envsetup.sh.
451 env_vars = os.environ.copy()
452 for k, _ in env_vars.iteritems():
453 del os.environ[k]
454 for k, v in ORIGINAL_ENV.iteritems():
455 os.environ[k] = v
456
457 envsetup_path = os.path.join('build', 'android', 'envsetup.sh')
458 proc = subprocess.Popen(['bash', '-c', 'source %s && env' % envsetup_path],
459 stdout=subprocess.PIPE,
460 stderr=subprocess.PIPE,
461 cwd=path_to_src)
462 out, _ = proc.communicate()
463
464 for line in out.splitlines():
465 k, _, v = line.partition('=')
466 os.environ[k] = v
467
468 # envsetup.sh no longer sets OS=android in GYP_DEFINES environment variable.
469 # (See http://crrev.com/170273005). So, we set this variable explicitly here
470 # in order to build Chrome on Android.
471 if 'GYP_DEFINES' not in os.environ:
472 os.environ['GYP_DEFINES'] = 'OS=android'
473 else:
474 os.environ['GYP_DEFINES'] += ' OS=android'
475
476 if opts.use_goma:
477 os.environ['GYP_DEFINES'] += ' use_goma=1'
478 return not proc.returncode
479
480
481 def SetupPlatformBuildEnvironment(opts):
482 """Performs any platform-specific setup.
483
484 Args:
485 opts: The options parsed from the command line through parse_args().
486
487 Returns:
488 True if successful.
489 """
490 if 'android' in opts.target_platform:
491 CopyAndSaveOriginalEnvironmentVars()
492 return SetupAndroidBuildEnvironment(opts)
493 elif opts.target_platform == 'cros':
494 return SetupCrosRepo()
495
496 return True
497
498
499 def CheckIfBisectDepotExists(opts): 418 def CheckIfBisectDepotExists(opts):
500 """Checks if the bisect directory already exists. 419 """Checks if the bisect directory already exists.
501 420
502 Args: 421 Args:
503 opts: The options parsed from the command line through parse_args(). 422 opts: The options parsed from the command line through parse_args().
504 423
505 Returns: 424 Returns:
506 Returns True if it exists. 425 Returns True if it exists.
507 """ 426 """
508 path_to_dir = os.path.join(opts.working_directory, 'bisect', 'src') 427 path_to_dir = os.path.join(opts.working_directory, 'bisect', 'src')
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return sys.platform.startswith('linux') 589 return sys.platform.startswith('linux')
671 590
672 591
673 def IsMacHost(): 592 def IsMacHost():
674 """Checks whether or not the script is running on Mac. 593 """Checks whether or not the script is running on Mac.
675 594
676 Returns: 595 Returns:
677 True if running on Mac. 596 True if running on Mac.
678 """ 597 """
679 return sys.platform.startswith('darwin') 598 return sys.platform.startswith('darwin')
OLDNEW
« no previous file with comments | « no previous file | tools/auto_bisect/builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698