blob: dd6930e14f8ded06eec9028d20bd51adab9279f7 [file] [log] [blame]
// Copyright 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../build.dart';
import '../cipd.dart';
import '../fetch.dart';
import '../useful_directory.dart';
import 'package:file/file.dart';
const _cipdToChromeArchivePlatforms = {
'linux-amd64': 'linux64',
'mac-amd64': 'mac-x64',
'mac-arm64': 'mac-arm64',
'windows-amd64': 'win64',
};
// See https://googlechromelabs.github.io/chrome-for-testing/
const chromeDownloadHost = 'edgedl.me.gvt1.com';
const chromeDownloadPath = 'edgedl/chrome/chrome-for-testing';
Uri _chromeUrl(String product, String platform, String version) {
final os = _cipdToChromeArchivePlatforms[platform]!;
final archiveName = '$product-$os.zip';
return Uri.https(
chromeDownloadHost, '$chromeDownloadPath/$version/$os/$archiveName');
}
class ChromeDriverPackage extends CipdPackage with HttpDownloader, UnzipBuild {
final String directory;
ChromeDriverPackage(String cipdPlatform, String version)
: directory =
'chromedriver-${_cipdToChromeArchivePlatforms[cipdPlatform]}',
super('dart/third_party/chromedriver/$cipdPlatform',
_chromeUrl('chromedriver', cipdPlatform, version), version);
@override
Future<Directory> build(
List<FileSystemEntity> inputs, Directory workingDirectory) async =>
(await super.build(inputs, workingDirectory)).childDirectory(directory);
@override
Future<bool> check(Directory artifacts) async =>
await artifacts.childFile('chromedriver').exists() ||
await artifacts.childFile('chromedriver.exe').exists();
}
class ChromePackage extends CipdPackage with HttpDownloader, UnzipBuild {
final String cipdPlatform;
ChromePackage(this.cipdPlatform, String version)
: super('dart/browsers/chrome/$cipdPlatform',
_chromeUrl('chrome', cipdPlatform, version), version);
Future<Directory> _renameMac(Directory unzipDirectory, String arch) async {
final binaryDirectory = unzipDirectory.resolve(
'chrome-mac-$arch/Google Chrome for Testing.app/Contents/MacOS');
final binary = binaryDirectory.childFile('Google Chrome for Testing');
await binary.rename(binaryDirectory.childFile('Google Chrome').path);
return (await unzipDirectory.move(
'chrome-mac-$arch/Google Chrome for Testing.app',
'chrome/Google Chrome.app'))
.parent;
}
@override
Future<Directory> build(
List<FileSystemEntity> inputs, Directory workingDirectory) async {
var unzipDirectory = await super.build(inputs, workingDirectory);
// TODO(athom): The recipes expect chrome to be in different folders than it
// is in the zips on cloud storage. If we change the recipes we could avoid
// this if-else.
if (cipdPlatform == 'linux-amd64') {
final chromeDir = await unzipDirectory.move('chrome-linux64', 'chrome');
final chrome = chromeDir.resolveFile('chrome');
await chrome.rename(chromeDir.resolveFile('google-chrome').path);
} else if (cipdPlatform == 'mac-amd64') {
unzipDirectory = await _renameMac(unzipDirectory, 'x64');
} else if (cipdPlatform == 'mac-arm64') {
unzipDirectory = await _renameMac(unzipDirectory, 'arm64');
} else if (cipdPlatform == 'windows-amd64') {
await unzipDirectory.move('chrome-win64', 'Chrome/Application');
}
return unzipDirectory;
}
@override
Future<bool> check(Directory artifacts) async =>
await artifacts.resolveFile('chrome/google-chrome').exists() ||
await artifacts
.resolveFile('Google Chrome.app/Contents/MacOS/Google Chrome')
.exists() ||
await artifacts.resolveFile('Chrome/Application/chrome.exe').exists();
}