@@ -118,6 +118,10 @@ class _BrowserRoller {
118
118
for (final _Platform platform in _platforms) {
119
119
await _rollChromium (platform);
120
120
await _rollChromeDriver (platform);
121
+ // For now, we only test Firefox on Linux.
122
+ if (platform.os == 'linux' ) {
123
+ await _rollFirefox (platform);
124
+ }
121
125
}
122
126
if (dryRun) {
123
127
print ('\n Dry Run Done!\n Non-published roll artifacts kept here: ${_rollDir .path }\n ' );
@@ -163,6 +167,22 @@ data:
163
167
''' ;
164
168
}
165
169
170
+ // Returns the contents for the CIPD config required to publish a new Firefox package.
171
+ String _getCipdFirefoxConfig ({
172
+ required String package,
173
+ required String majorVersion,
174
+ required String root,
175
+ }) {
176
+ return '''
177
+ package: $package
178
+ description: Firefox $majorVersion used for testing
179
+ preserve_writable: true
180
+ root: $root
181
+ data:
182
+ - dir: .
183
+ ''' ;
184
+ }
185
+
166
186
// Download a file from the internet, and put it in a temporary location.
167
187
Future <io.File > _downloadTemporaryFile (String url) async {
168
188
// Use the hash of the Url to temporarily store a file under tmp
@@ -193,6 +213,26 @@ data:
193
213
await zipFile.delete ();
194
214
}
195
215
216
+ // Uncompresses a `file` into a `destination` Directory (must exist).
217
+ Future <void > _uncompressAndDeleteFile (io.File tarFile, io.Directory destination) async {
218
+ vprint (' Uncompressing [${tarFile .path }] into [$destination ]' );
219
+ final io.ProcessResult unzipResult = await io.Process .run ('tar' , < String > [
220
+ '-x' ,
221
+ '-f' ,
222
+ tarFile.path,
223
+ '-C' ,
224
+ destination.path,
225
+ ]);
226
+
227
+ if (unzipResult.exitCode != 0 ) {
228
+ throw StateError (
229
+ 'Failed to unzip the downloaded archive ${tarFile .path }.\n '
230
+ 'The unzip process exited with code ${unzipResult .exitCode }.' );
231
+ }
232
+ vprint (' Deleting [${tarFile .path }]' );
233
+ await tarFile.delete ();
234
+ }
235
+
196
236
// Write String `contents` to a file in `path`.
197
237
//
198
238
// This is used to write CIPD config files to disk.
@@ -366,4 +406,43 @@ data:
366
406
// Run CIPD
367
407
await _uploadToCipd (config: cipdConfigFile, version: majorVersion, buildId: chromeBuild);
368
408
}
409
+
410
+
411
+ // Downloads Firefox from the internet, packs it in the directory structure
412
+ // that the LUCI script wants. The result of this will be then uploaded to CIPD.
413
+ Future <void > _rollFirefox (_Platform platform) async {
414
+ final String version = _lock.firefoxLock.version;
415
+ final String url = platform.binding.getFirefoxDownloadUrl (version);
416
+ final String cipdPackageName = 'flutter_internal/browsers/firefox/${platform .name }' ;
417
+ final io.Directory platformDir = io.Directory (path.join (_rollDir.path, platform.name));
418
+ print ('\n Rolling Firefox for ${platform .name } (version:$version )' );
419
+ // Bail out if CIPD already has version:$majorVersion for this package!
420
+ if (! dryRun && await _cipdKnowsPackageVersion (package: cipdPackageName, versionTag: version)) {
421
+ print (' Skipping $cipdPackageName version:$version . Already uploaded to CIPD!' );
422
+ vprint (' Update browser_lock.yaml and use a different version value.' );
423
+ return ;
424
+ }
425
+
426
+ await platformDir.create (recursive: true );
427
+ vprint (' Created target directory [${platformDir .path }]' );
428
+
429
+ final io.File firefoxDownload = await _downloadTemporaryFile (url);
430
+
431
+ await _uncompressAndDeleteFile (firefoxDownload, platformDir);
432
+
433
+ final io.Directory ? actualContentRoot = await _locateContentRoot (platformDir);
434
+ assert (actualContentRoot != null );
435
+ final String relativePlatformDirPath = path.relative (actualContentRoot! .path, from: _rollDir.path);
436
+
437
+ // Create the config manifest to upload to CIPD
438
+ final io.File cipdConfigFile = await _writeFile (
439
+ path.join (_rollDir.path, 'cipd.firefox.${platform .name }.yaml' ),
440
+ _getCipdFirefoxConfig (
441
+ package: cipdPackageName,
442
+ majorVersion: version,
443
+ root: relativePlatformDirPath,
444
+ ));
445
+ // Run CIPD
446
+ await _uploadToCipd (config: cipdConfigFile, version: version, buildId: version);
447
+ }
369
448
}
0 commit comments