forked from meta-flutter/workspace-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_files.py
More file actions
executable file
·135 lines (101 loc) · 3.65 KB
/
version_files.py
File metadata and controls
executable file
·135 lines (101 loc) · 3.65 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: (C) 2020-2023 Joel Winarske
#
# SPDX-License-Identifier: Apache-2.0
#
#
# Script to build custom Flutter AOT artifacts for Release and Profile runtime
import json
import os
import signal
import sys
from fw_common import check_python_version
from fw_common import download_https_file
from fw_common import handle_ctrl_c
from fw_common import make_sure_path_exists
from fw_common import print_banner
from fw_common import test_internet_connection
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--path', default='', type=str,
help='Create JSON files correlating Flutter SDK to Engine and Dart commits')
args = parser.parse_args()
if args.path == '':
sys.exit("Must specify value for --path")
#
# Control+C handler
#
signal.signal(signal.SIGINT, handle_ctrl_c)
#
# Version Files
#
if args.path:
print_banner("Creating Version files")
get_version_files(args.path)
return
def get_version_files(cwd):
"""Get Dart and Engine Version files"""
import concurrent.futures
if cwd is None:
return
else:
make_sure_path_exists(cwd)
release_linux = get_linux_release_file(cwd)
res = {}
with open(release_linux, 'r') as f:
for release in json.load(f).get('releases', []):
if 'dart_sdk_version' in release:
res[release['version']] = release['dart_sdk_version']
dest_file = os.path.join(cwd, 'dart-revision.json')
print_banner("Writing %s" % dest_file)
with open(dest_file, 'w+') as o:
json.dump(res, o, sort_keys=True, indent=2)
print_banner('Fetching Engine revisions')
engine_revs = {}
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
with open(release_linux, 'r') as f:
for release in json.load(f).get('releases', []):
version_ = release['version']
hash_ = release['hash']
futures.append(executor.submit(get_engine_commit, version_, hash_))
for future in concurrent.futures.as_completed(futures):
res = future.result()
engine_revs[res[0]] = res[1]
dest_file = os.path.join(cwd, 'engine-revision.json')
print_banner("Writing %s" % dest_file)
with open(dest_file, 'w+') as o:
json.dump(engine_revs, o, sort_keys=True, indent=2)
os.remove(os.path.join(cwd, 'releases_linux.json.sha256'))
print_banner("Done")
def get_linux_release_file(cwd):
"""Returns dictionary of releases_linux.json"""
filename = 'releases_linux.json'
url = f'https://storage.googleapis.com/flutter_infra_release/releases/{filename}'
sha256_file = os.path.join(cwd, f'{filename}.sha256')
if os.path.exists(sha256_file):
os.remove(sha256_file)
download_https_file(cwd, url, filename, None, None, None, None, None)
return os.path.join(cwd, filename)
def get_engine_commit(version, hash_):
"""Get matching engine commit hash."""
import pycurl
import certifi
from io import BytesIO
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(
pycurl.URL, f'https://raw.githubusercontent.com/flutter/flutter/{hash_}/bin/internal/engine.version')
c.setopt(pycurl.WRITEDATA, buffer)
c.setopt(pycurl.CAINFO, certifi.where())
c.perform()
c.close()
get_body = buffer.getvalue()
return version, get_body.decode('utf8').strip()
if __name__ == "__main__":
check_python_version()
if not test_internet_connection():
sys.exit("version_files.py requires an internet connection")
main()