-
Notifications
You must be signed in to change notification settings - Fork 3
/
chrome_bisect.py
executable file
·112 lines (98 loc) · 3.32 KB
/
chrome_bisect.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
''' wrapper for bisect-builds.py which simplifies option setting '''
from platform import system, machine
import os
import sys
import requests
import bisect_builds
def get_relative_chrome_versions(minus=0):
''' returns current Chrome stable milestone number minus value of minus'''
url = 'https://versionhistory.googleapis.com' \
'/v1/chrome/platforms/all/channels/stable/versions/all/releases' \
'?fields=releases%2Fversion%2CnextPageToken'
resp = requests.get(url)
versions = resp.json().get('releases')
milestones = []
for version in versions:
ver = version.get('version')
if ver:
milestone = int(ver.split('.')[0])
if milestone not in milestones:
milestones.append(milestone)
milestones.sort(reverse=True)
return milestones[minus]
def detect_archive():
'''returns an appropriate value for archive based on current OS and architecture.'''
myos = system()
sixty_four = sys.maxsize > 2**32
mymachine = machine()
archive = None
if myos == 'Windows':
if sixty_four:
archive = 'win64'
else:
archive = 'win'
elif myos == 'Linux':
if sixty_four:
archive = 'linux64'
else:
archive = 'linux'
elif myos == 'Darwin':
if mymachine == 'arm64':
archive = 'mac-arm'
elif mymachine == 'x86_64':
archive = 'mac64'
if not archive:
print('Could not auto-detect value for --archive. ' \
f'OS: {myos}, 64-bit: {sixty_four}, machine: {mymachine}')
sys.exit(1)
return archive
def add_default_args(args):
'''sets appropriate default arguments for bisect-builds.py'''
# return --help quick
if '--help' in args or '-h' in args:
return args
# always add --verify-range and --use-local-cache
for def_arg in ['--verify-range', '--use-local-cache']:
if def_arg not in args:
args.append(def_arg)
# if --archive is not set detect an appropriate value to set
archive_set = False
for arg in list(args):
arg = arg.split('=')[0]
if arg in ['-a', '--archive']:
archive_set = True
if not archive_set:
archive = detect_archive()
args.extend(['--archive', archive])
# if --good is not set set to Chrome stable milestone - 6
good_set = False
for arg in list(args):
arg = arg.split('=')[0]
if arg in ['-g', '--good']:
good_set = True
if not good_set:
good = get_relative_chrome_versions(6)
good_milestone = f'M{good}'
args.extend(['--good', good_milestone])
return args
def main():
'''main screen turn on'''
if '--' in sys.argv:
split_at = sys.argv.index('--')
bisect_args = sys.argv[:split_at]
chrome_args = sys.argv[split_at:]
else:
bisect_args = sys.argv
chrome_args = []
os.environ['REQUESTS_CA_BUNDLE'] = 'roots.pem'
os.environ['SSL_CERT_FILE'] = 'roots.pem'
bisect_args = add_default_args(bisect_args)
sys.argv = bisect_args + chrome_args
print(f'running bisect-builds.py with options: {" ".join(sys.argv[1:])}')
bisect_builds.main()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(1)