| OLD | NEW |
| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 path: The path name passed to func. | 303 path: The path name passed to func. |
| 304 _: Exception information from sys.exc_info(). Not used. | 304 _: Exception information from sys.exc_info(). Not used. |
| 305 """ | 305 """ |
| 306 if not os.access(path, os.W_OK): | 306 if not os.access(path, os.W_OK): |
| 307 os.chmod(path, stat.S_IWUSR) | 307 os.chmod(path, stat.S_IWUSR) |
| 308 func(path) | 308 func(path) |
| 309 else: | 309 else: |
| 310 raise | 310 raise |
| 311 | 311 |
| 312 | 312 |
| 313 def _CleanupPreviousGitRuns(): | 313 def _CleanupPreviousGitRuns(cwd=os.getcwd()): |
| 314 """Cleans up any leftover index.lock files after running git.""" | 314 """Cleans up any leftover index.lock files after running git.""" |
| 315 # If a previous run of git crashed, or bot was reset, etc., then we might | 315 # If a previous run of git crashed, or bot was reset, etc., then we might |
| 316 # end up with leftover index.lock files. | 316 # end up with leftover index.lock files. |
| 317 for path, _, files in os.walk(os.getcwd()): | 317 for path, _, files in os.walk(cwd): |
| 318 for cur_file in files: | 318 for cur_file in files: |
| 319 if cur_file.endswith('index.lock'): | 319 if cur_file.endswith('index.lock'): |
| 320 path_to_file = os.path.join(path, cur_file) | 320 path_to_file = os.path.join(path, cur_file) |
| 321 os.remove(path_to_file) | 321 os.remove(path_to_file) |
| 322 | 322 |
| 323 | 323 |
| 324 def RunGClientAndSync(cwd=None): | 324 def RunGClientAndSync(cwd=None): |
| 325 """Runs gclient and does a normal sync. | 325 """Runs gclient and does a normal sync. |
| 326 | 326 |
| 327 Args: | 327 Args: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 Args: | 415 Args: |
| 416 opts: The options parsed from the command line through parse_args(). | 416 opts: The options parsed from the command line through parse_args(). |
| 417 custom_deps: A dictionary of additional dependencies to add to .gclient. | 417 custom_deps: A dictionary of additional dependencies to add to .gclient. |
| 418 """ | 418 """ |
| 419 if CheckIfBisectDepotExists(opts): | 419 if CheckIfBisectDepotExists(opts): |
| 420 path_to_dir = os.path.join(os.path.abspath(opts.working_directory), | 420 path_to_dir = os.path.join(os.path.abspath(opts.working_directory), |
| 421 BISECT_DIR, 'src') | 421 BISECT_DIR, 'src') |
| 422 (output, _) = RunGit(['rev-parse', '--is-inside-work-tree'], | 422 (output, _) = RunGit(['rev-parse', '--is-inside-work-tree'], |
| 423 cwd=path_to_dir) | 423 cwd=path_to_dir) |
| 424 if output.strip() == 'true': | 424 if output.strip() == 'true': |
| 425 # Before checking out master, cleanup up any leftover index.lock files. |
| 426 _CleanupPreviousGitRuns(path_to_dir) |
| 425 # Checks out the master branch, throws an exception if git command fails. | 427 # Checks out the master branch, throws an exception if git command fails. |
| 426 CheckRunGit(['checkout', '-f', 'master'], cwd=path_to_dir) | 428 CheckRunGit(['checkout', '-f', 'master'], cwd=path_to_dir) |
| 427 | |
| 428 if not _CreateAndChangeToSourceDirectory(opts.working_directory): | 429 if not _CreateAndChangeToSourceDirectory(opts.working_directory): |
| 429 raise RuntimeError('Could not create bisect directory.') | 430 raise RuntimeError('Could not create bisect directory.') |
| 430 | 431 |
| 431 if not SetupGitDepot(opts, custom_deps): | 432 if not SetupGitDepot(opts, custom_deps): |
| 432 raise RuntimeError('Failed to grab source.') | 433 raise RuntimeError('Failed to grab source.') |
| 433 | 434 |
| 434 | 435 |
| 435 def RunProcess(command): | 436 def RunProcess(command): |
| 436 """Runs an arbitrary command. | 437 """Runs an arbitrary command. |
| 437 | 438 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 platform = os.environ.get('PROCESSOR_ARCHITECTURE') | 510 platform = os.environ.get('PROCESSOR_ARCHITECTURE') |
| 510 return platform and platform in ['AMD64', 'I64'] | 511 return platform and platform in ['AMD64', 'I64'] |
| 511 | 512 |
| 512 | 513 |
| 513 def IsLinuxHost(): | 514 def IsLinuxHost(): |
| 514 return sys.platform.startswith('linux') | 515 return sys.platform.startswith('linux') |
| 515 | 516 |
| 516 | 517 |
| 517 def IsMacHost(): | 518 def IsMacHost(): |
| 518 return sys.platform.startswith('darwin') | 519 return sys.platform.startswith('darwin') |
| OLD | NEW |