aboutsummaryrefslogtreecommitdiff
path: root/llvm_tools/update_all_tryjobs_with_auto.py
blob: 11e67ed4b50916ce4f8380ad997d63bf01055669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- 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

import chroot
import update_tryjob_status


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."""

  chroot.VerifyOutsideChroot()

  args_output = GetCommandLineArgs()

  with open(args_output.last_tested) as tryjobs:
    bisect_contents = json.load(tryjobs)

  for tryjob in bisect_contents['jobs']:
    if tryjob['status'] == update_tryjob_status.TryjobStatus.PENDING.value:
      tryjob['status'] = update_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()