diff options
author | Salud Lemus <saludlemus@google.com> | 2019-08-29 11:46:49 -0700 |
---|---|---|
committer | Salud Lemus <saludlemus@google.com> | 2019-09-03 21:54:36 +0000 |
commit | c856b68b3ca72481a147e73108ea95b030da2606 (patch) | |
tree | e72022ffb5869ba01beaccaa616bea5c5509eca7 /llvm_tools/update_all_tryjobs_with_auto.py | |
parent | 3effa0615c6958953aa6de826ca2f11aa8a70418 (diff) | |
download | toolchain-utils-c856b68b3ca72481a147e73108ea95b030da2606.tar.gz |
LLVM tools: Added auto bisection of LLVM
Similar to 'llvm_bisection.py' script but uses `cros buildresult` to
update each tryjob's 'status' field. The script sleeps for X minutes and
continues where bisection left off (similar behavior if script
terminates). The script is an infinite loop but terminates when there
are no more revisions between the new 'start' and new 'end' or if an
exception happens.
This script is using the scripts such as bisection script and updating a
tryjob's status script in a loop.
BUG=None
TEST=Ran 'auto_llvm_bisection.py' script with a file that was not
created and start revision of 369410 and end revision of 369420.
Successfully created tryjobs between the start and end and the script
went to sleep for X minutes and woke up to resume where bisection
left off.
Change-Id: I711988b164c41f56ecc2c9478527bdcfe8f5bb88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1776330
Reviewed-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Salud Lemus <saludlemus@google.com>
Diffstat (limited to 'llvm_tools/update_all_tryjobs_with_auto.py')
-rwxr-xr-x | llvm_tools/update_all_tryjobs_with_auto.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/llvm_tools/update_all_tryjobs_with_auto.py b/llvm_tools/update_all_tryjobs_with_auto.py new file mode 100755 index 00000000..4a670c34 --- /dev/null +++ b/llvm_tools/update_all_tryjobs_with_auto.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Updates the status of all tryjobs to the result of `cros buildresult`.""" + +from __future__ import print_function + +import argparse +import json +import os + +from assert_not_in_chroot import VerifyOutsideChroot +from patch_manager import _ConvertToASCII +from update_tryjob_status import GetAutoResult +from update_tryjob_status import TryjobStatus + + +def GetPathToUpdateAllTryjobsWithAutoScript(): + """Returns the absolute path to this script.""" + + return os.path.abspath(__file__) + + +def GetCommandLineArgs(): + """Parses the command line for the command line arguments.""" + + # Default absoute path to the chroot if not specified. + cros_root = os.path.expanduser('~') + cros_root = os.path.join(cros_root, 'chromiumos') + + # Create parser and add optional command-line arguments. + parser = argparse.ArgumentParser(description=__doc__) + + # Add argument for the JSON file to use for the update of a tryjob. + parser.add_argument( + '--last_tested', + required=True, + help='The absolute path to the JSON file that contains the tryjobs used ' + 'for bisecting LLVM.') + + # Add argument for a specific chroot path. + parser.add_argument( + '--chroot_path', + default=cros_root, + help='the path to the chroot (default: %(default)s)') + + args_output = parser.parse_args() + + if not os.path.isfile(args_output.last_tested) or \ + not args_output.last_tested.endswith('.json'): + raise ValueError('File does not exist or does not ending in \'.json\' ' + ': %s' % args_output.last_tested) + + return args_output + + +def main(): + """Updates the status of a tryjob.""" + + VerifyOutsideChroot() + + args_output = GetCommandLineArgs() + + with open(args_output.last_tested) as tryjobs: + bisect_contents = _ConvertToASCII(json.load(tryjobs)) + + for tryjob in bisect_contents['jobs']: + if tryjob['status'] == TryjobStatus.PENDING.value: + tryjob['status'] = GetAutoResult(args_output.chroot_path, + tryjob['buildbucket_id']) + + new_file = '%s.new' % args_output.last_tested + with open(new_file, 'w') as update_tryjobs: + json.dump(bisect_contents, update_tryjobs, indent=4, separators=(',', ': ')) + os.rename(new_file, args_output.last_tested) + + +if __name__ == '__main__': + main() |