blob: 6b8411e2eb0d9d9919d8d55afbe59ac4599bed02 (
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
81
|
#!/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.
"""Gets the latest google3 LLVM version"""
from __future__ import print_function
from pipes import quote
import argparse
from assert_not_in_chroot import VerifyOutsideChroot
from cros_utils import command_executer
class LLVMVersion(object):
"""Provides a method to retrieve the latest google3 LLVM version."""
def __init__(self, log_level="none"):
self._ce = command_executer.GetCommandExecuter(log_level=log_level)
def GetGoogle3LLVMVersion(self):
"""Gets the latest google3 LLVM version.
Returns:
The latest LLVM version as an integer.
Raises:
ValueError: An invalid path has been provided to the cat command.
"""
path_to_google3_llvm_version = ('/google/src/head/depot/google3/third_party'
'/crosstool/v18/stable/installs/llvm/'
'revision')
# Cmd to get latest google3 LLVM version.
cat_cmd = 'cat %s' % quote(path_to_google3_llvm_version)
# Get latest version.
ret, g3_version, err = self._ce.RunCommandWOutput(
cat_cmd, print_to_console=False)
if ret: # Failed to get the latest google3 LLVM version.
raise ValueError('Failed to get google3 LLVM version: %s' % err)
# Change type to an integer
return int(g3_version.rstrip())
def main():
"""Prints the google3 LLVM version.
Parses the command line for the optional command line
argument.
Raises:
AssertionError: The script was run inside the chroot.
"""
VerifyOutsideChroot()
# create parser and add optional command-line argument
parser = argparse.ArgumentParser(description='Get the google3 LLVM version.')
parser.add_argument(
'--log_level',
default='none',
choices=['none', 'quiet', 'average', 'verbose'],
help='the level for the logs (default: %(default)s)')
# parse command-line arguments
args_output = parser.parse_args()
cur_log_level = args_output.log_level # get log level
print(LLVMVersion(log_level=cur_log_level).GetGoogle3LLVMVersion())
if __name__ == '__main__':
main()
|