3
3
import hashlib
4
4
import json
5
5
import os
6
- import urllib3
6
+ import sys
7
+ from pathlib import Path
7
8
9
+ import urllib3
8
10
from packaging .version import parse
9
- from pathlib import Path
10
11
11
12
# Find the current stable versions of each browser we
12
13
# support and the sha256 of these. That's useful for
13
14
# updating `//common:repositories.bzl`
14
15
15
16
http = urllib3 .PoolManager ()
16
17
18
+
17
19
def calculate_hash (url ):
20
+ print ("Calculate hash for %s" % url , file = sys .stderr )
18
21
h = hashlib .sha256 ()
19
- r = http .request (' GET' , url , preload_content = False )
22
+ r = http .request (" GET" , url , preload_content = False )
20
23
for b in iter (lambda : r .read (4096 ), b"" ):
21
24
h .update (b )
22
25
return h .hexdigest ()
23
26
27
+
24
28
def get_chrome_milestone ():
25
29
channel = os .getenv ("CHROME_CHANNEL" , "Stable" )
26
- r = http .request ('GET' , f'https://chromiumdash.appspot.com/fetch_releases?channel={ channel } &num=1&platform=Mac,Linux' )
30
+ r = http .request (
31
+ "GET" , f"https://chromiumdash.appspot.com/fetch_releases?channel={ channel } &num=1&platform=Mac,Linux"
32
+ )
27
33
all_versions = json .loads (r .data )
28
34
# use the same milestone for all chrome releases, so pick the lowest
29
35
milestone = min ([version ["milestone" ] for version in all_versions if version ["milestone" ]])
30
- r = http .request ('GET' , 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json' )
36
+ r = http .request (
37
+ "GET" , "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
38
+ )
31
39
versions = json .loads (r .data )["versions" ]
32
40
33
41
return sorted (
34
- filter (lambda v : v ['version' ].split ('.' )[0 ] == str (milestone ), versions ),
35
- key = lambda v : parse (v ['version' ])
42
+ filter (lambda v : v ["version" ].split ("." )[0 ] == str (milestone ), versions ), key = lambda v : parse (v ["version" ])
36
43
)[- 1 ]
37
44
45
+
38
46
def chromedriver (selected_version ):
39
47
content = ""
40
48
41
- selected_version = get_chrome_milestone ()
42
-
43
49
drivers = selected_version ["downloads" ]["chromedriver" ]
44
50
45
51
linux = [d ["url" ] for d in drivers if d ["platform" ] == "linux64" ][0 ]
46
52
sha = calculate_hash (linux )
47
53
48
- content = content + """
49
- http_archive(
54
+ content = (
55
+ content
56
+ + """ http_archive(
50
57
name = "linux_chromedriver",
51
58
url = "%s",
52
59
sha256 = "%s",
53
60
strip_prefix = "chromedriver-linux64",
54
61
build_file_content = "exports_files([\\ "chromedriver\\ "])",
55
62
)
56
- """ % (linux , sha )
63
+ """
64
+ % (linux , sha )
65
+ )
57
66
58
67
mac = [d ["url" ] for d in drivers if d ["platform" ] == "mac-x64" ][0 ]
59
68
sha = calculate_hash (mac )
60
- content = content + """
69
+ content = (
70
+ content
71
+ + """
61
72
http_archive(
62
73
name = "mac_chromedriver",
63
74
url = "%s",
64
75
sha256 = "%s",
65
76
strip_prefix = "chromedriver-mac-x64",
66
77
build_file_content = "exports_files([\\ "chromedriver\\ "])",
67
78
)
68
- """ % (mac , sha )
79
+ """
80
+ % (mac , sha )
81
+ )
69
82
70
83
return content
71
84
85
+
72
86
def chrome (selected_version ):
73
87
chrome_downloads = selected_version ["downloads" ]["chrome" ]
74
88
@@ -93,13 +107,15 @@ def chrome(selected_version):
93
107
\" \" \" ,
94
108
)
95
109
96
- """ % (linux , sha )
110
+ """ % (
111
+ linux ,
112
+ sha ,
113
+ )
97
114
98
115
mac = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "mac-x64" ][0 ]
99
116
sha = calculate_hash (mac )
100
117
101
- content += """
102
- http_archive(
118
+ content += """ http_archive(
103
119
name = "mac_chrome",
104
120
url = "%s",
105
121
sha256 = "%s",
@@ -111,12 +127,16 @@ def chrome(selected_version):
111
127
build_file_content = "exports_files([\\ "Chrome.app\\ "])",
112
128
)
113
129
114
- """ % (mac , sha )
130
+ """ % (
131
+ mac ,
132
+ sha ,
133
+ )
115
134
116
135
return content
117
136
137
+
118
138
def edge ():
119
- r = http .request (' GET' , ' https://edgeupdates.microsoft.com/api/products' )
139
+ r = http .request (" GET" , " https://edgeupdates.microsoft.com/api/products" )
120
140
all_data = json .loads (r .data )
121
141
122
142
edge = None
@@ -145,71 +165,91 @@ def edge():
145
165
},
146
166
build_file_content = "exports_files([\\ "Edge.app\\ "])",
147
167
)
148
- """ % (edge , hash .lower (), version )
168
+ """ % (
169
+ edge ,
170
+ hash .lower (),
171
+ version ,
172
+ )
149
173
150
174
return ""
151
175
176
+
152
177
def edgedriver ():
153
- r = http .request (' GET' , ' https://msedgedriver.azureedge.net/LATEST_STABLE' )
154
- v = r .data .decode (' utf-16' ).strip ()
178
+ r = http .request (" GET" , " https://msedgedriver.azureedge.net/LATEST_STABLE" )
179
+ v = r .data .decode (" utf-16" ).strip ()
155
180
156
181
content = ""
157
182
158
183
linux = "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % v
159
184
sha = calculate_hash (linux )
160
- content = content + """
185
+ content = (
186
+ content
187
+ + """
161
188
http_archive(
162
189
name = "linux_edgedriver",
163
190
url = "%s",
164
191
sha256 = "%s",
165
192
build_file_content = "exports_files([\\ "msedgedriver\\ "])",
166
193
)
167
- """ % (linux , sha )
194
+ """
195
+ % (linux , sha )
196
+ )
168
197
169
198
mac = "https://msedgedriver.azureedge.net/%s/edgedriver_mac64.zip" % v
170
199
sha = calculate_hash (mac )
171
- content = content + """
200
+ content = (
201
+ content
202
+ + """
172
203
http_archive(
173
204
name = "mac_edgedriver",
174
205
url = "%s",
175
206
sha256 = "%s",
176
207
build_file_content = "exports_files([\\ "msedgedriver\\ "])",
177
208
)
178
- """ % (mac , sha )
209
+ """
210
+ % (mac , sha )
211
+ )
179
212
return content
180
213
214
+
181
215
def geckodriver ():
182
216
content = ""
183
217
184
- r = http .request (' GET' , ' https://api.github.com/repos/mozilla/geckodriver/releases/latest' )
185
- for a in json .loads (r .data )[' assets' ]:
186
- if a [' name' ].endswith (' -linux64.tar.gz' ):
187
- url = a [' browser_download_url' ]
218
+ r = http .request (" GET" , " https://api.github.com/repos/mozilla/geckodriver/releases/latest" )
219
+ for a in json .loads (r .data )[" assets" ]:
220
+ if a [" name" ].endswith (" -linux64.tar.gz" ):
221
+ url = a [" browser_download_url" ]
188
222
sha = calculate_hash (url )
189
- content = content + \
190
- """
191
- http_archive(
223
+ content = (
224
+ content
225
+ + """ http_archive(
192
226
name = "linux_geckodriver",
193
227
url = "%s",
194
228
sha256 = "%s",
195
229
build_file_content = "exports_files([\\ "geckodriver\\ "])",
196
230
)
197
- """ % (url , sha )
231
+ """
232
+ % (url , sha )
233
+ )
198
234
199
- if a [' name' ].endswith (' -macos.tar.gz' ):
200
- url = a [' browser_download_url' ]
235
+ if a [" name" ].endswith (" -macos.tar.gz" ):
236
+ url = a [" browser_download_url" ]
201
237
sha = calculate_hash (url )
202
- content = content + \
203
- """
238
+ content = (
239
+ content
240
+ + """
204
241
http_archive(
205
242
name = "mac_geckodriver",
206
243
url = "%s",
207
244
sha256 = "%s",
208
245
build_file_content = "exports_files([\\ "geckodriver\\ "])",
209
246
)
210
- """ % (url , sha )
247
+ """
248
+ % (url , sha )
249
+ )
211
250
return content
212
251
252
+
213
253
def firefox ():
214
254
firefox_versions = json .loads (firefox_version_data ())
215
255
@@ -247,8 +287,9 @@ def firefox_mac(version):
247
287
def print_firefox (version , workspace_name , sha_linux , sha_mac ):
248
288
content = ""
249
289
250
- content = content + f"""
251
- http_archive(
290
+ content = (
291
+ content
292
+ + f""" http_archive(
252
293
name = "linux_{ workspace_name } firefox",
253
294
url = "{ firefox_linux (version )} ",
254
295
sha256 = "{ sha_linux } ",
@@ -266,22 +307,25 @@ def print_firefox(version, workspace_name, sha_linux, sha_mac):
266
307
)
267
308
268
309
"""
310
+ )
269
311
270
- content = content + f"""
271
- dmg_archive(
312
+ content = (
313
+ content
314
+ + f""" dmg_archive(
272
315
name = "mac_{ workspace_name } firefox",
273
316
url = "{ firefox_mac (version )} ",
274
317
sha256 = "{ sha_mac } ",
275
318
build_file_content = "exports_files([\\ "Firefox.app\\ "])",
276
319
)
277
320
278
321
"""
322
+ )
279
323
280
324
return content
281
325
282
- if __name__ == '__main__' :
283
- content = """
284
- # This file has been generated using `bazel run scripts:pinned_browsers`
326
+
327
+ if __name__ == "__main__" :
328
+ content = """ # This file has been generated using `bazel run scripts:pinned_browsers`
285
329
286
330
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
287
331
load("//common/private:dmg_archive.bzl", "dmg_archive")
@@ -290,6 +334,7 @@ def print_firefox(version, workspace_name, sha_linux, sha_mac):
290
334
291
335
def pin_browsers():
292
336
local_drivers()
337
+
293
338
"""
294
339
content = content + firefox ()
295
340
content = content + geckodriver ()
@@ -300,7 +345,7 @@ def pin_browsers():
300
345
content = content + chromedriver (chrome_milestone )
301
346
302
347
current_script_dir = Path (os .path .realpath (__file__ )).parent
303
- target_file_path = current_script_dir .parent / ' common/repositories.bzl'
348
+ target_file_path = current_script_dir .parent / " common/repositories.bzl"
304
349
305
- with open (target_file_path , 'w' ) as file :
350
+ with open (target_file_path , "w" ) as file :
306
351
file .write (content )
0 commit comments