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

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: Rebased and added "warning" comments. 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.
72 # WARNING(qyearsley, 2014-08-15): These haven't been tested recently.
73 CROS_SDK_PATH = os.path.join('..', 'cros', 'chromite', 'bin', 'cros_sdk')
74 CROS_TEST_KEY_PATH = os.path.join(
75 '..', 'cros', 'chromite', 'ssh_keys', 'testing_rsa')
76 CROS_SCRIPT_KEY_PATH = os.path.join(
77 '..', 'cros', 'src', 'scripts', 'mod_for_test_scripts', 'ssh_keys',
78 'testing_rsa')
79
68 REPO_PARAMS = [ 80 REPO_PARAMS = [
69 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/', 81 'https://chrome-internal.googlesource.com/chromeos/manifest-internal/',
70 '--repo-url', 82 '--repo-url',
71 'https://git.chromium.org/external/repo.git' 83 'https://git.chromium.org/external/repo.git'
72 ] 84 ]
73 85
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 86
80 def OutputAnnotationStepStart(name): 87 def OutputAnnotationStepStart(name):
81 """Outputs annotation to signal the start of a step to a trybot. 88 """Outputs annotation to signal the start of a step to a trybot.
82 89
83 Args: 90 Args:
84 name: The name of the step. 91 name: The name of the step.
85 """ 92 """
86 print 93 print
87 print '@@@SEED_STEP %s@@@' % name 94 print '@@@SEED_STEP %s@@@' % name
88 print '@@@STEP_CURSOR %s@@@' % name 95 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. 197 params: A list of parameters to pass to gclient.
191 cwd: Working directory to run from. 198 cwd: Working directory to run from.
192 199
193 Returns: 200 Returns:
194 The return code of the call. 201 The return code of the call.
195 """ 202 """
196 cmd = ['gclient'] + params 203 cmd = ['gclient'] + params
197 return _SubprocessCall(cmd, cwd=cwd) 204 return _SubprocessCall(cmd, cwd=cwd)
198 205
199 206
207 def SetupCrosRepo():
208 """Sets up CrOS repo for bisecting ChromeOS.
209
210 Returns:
211 True if successful, False otherwise.
212 """
213 cwd = os.getcwd()
214 try:
215 os.mkdir('cros')
216 except OSError as e:
217 if e.errno != errno.EEXIST: # EEXIST means the directory already exists.
218 return False
219 os.chdir('cros')
220
221 cmd = ['init', '-u'] + REPO_PARAMS
222
223 passed = False
224
225 if not _RunRepo(cmd):
226 if not _RunRepo(['sync']):
227 passed = True
228 os.chdir(cwd)
229
230 return passed
231
232
200 def _RunRepo(params): 233 def _RunRepo(params):
201 """Runs CrOS repo command with specified parameters. 234 """Runs CrOS repo command with specified parameters.
202 235
203 Args: 236 Args:
204 params: A list of parameters to pass to gclient. 237 params: A list of parameters to pass to gclient.
205 238
206 Returns: 239 Returns:
207 The return code of the call (zero indicates success). 240 The return code of the call (zero indicates success).
208 """ 241 """
209 cmd = ['repo'] + params 242 cmd = ['repo'] + params
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if not RunGClientAndSync(): 409 if not RunGClientAndSync():
377 passed = True 410 passed = True
378 411
379 if opts.output_buildbot_annotations: 412 if opts.output_buildbot_annotations:
380 print 413 print
381 OutputAnnotationStepClosed() 414 OutputAnnotationStepClosed()
382 415
383 return passed 416 return passed
384 417
385 418
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): 419 def CheckIfBisectDepotExists(opts):
500 """Checks if the bisect directory already exists. 420 """Checks if the bisect directory already exists.
501 421
502 Args: 422 Args:
503 opts: The options parsed from the command line through parse_args(). 423 opts: The options parsed from the command line through parse_args().
504 424
505 Returns: 425 Returns:
506 Returns True if it exists. 426 Returns True if it exists.
507 """ 427 """
508 path_to_dir = os.path.join(opts.working_directory, 'bisect', 'src') 428 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') 590 return sys.platform.startswith('linux')
671 591
672 592
673 def IsMacHost(): 593 def IsMacHost():
674 """Checks whether or not the script is running on Mac. 594 """Checks whether or not the script is running on Mac.
675 595
676 Returns: 596 Returns:
677 True if running on Mac. 597 True if running on Mac.
678 """ 598 """
679 return sys.platform.startswith('darwin') 599 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