Commit 525855d5 authored by Dan Field's avatar Dan Field Committed by Flutter GitHub Bot

download font-subset (#49234)

parent f0a175f4
......@@ -62,17 +62,19 @@ enum Artifact {
// Fuchsia artifacts from the engine prebuilts.
fuchsiaKernelCompiler,
fuchsiaFlutterRunner,
/// Tools related to subsetting or icon font files.
fontSubset,
constFinder,
}
String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
final String exe = platform == TargetPlatform.windows_x64 ? '.exe' : '';
switch (artifact) {
case Artifact.genSnapshot:
return 'gen_snapshot';
case Artifact.flutterTester:
if (platform == TargetPlatform.windows_x64) {
return 'flutter_tester.exe';
}
return 'flutter_tester';
return 'flutter_tester$exe';
case Artifact.snapshotDart:
return 'snapshot.dart';
case Artifact.flutterFramework:
......@@ -98,10 +100,7 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
case Artifact.frontendServerSnapshotForEngineDartSdk:
return 'frontend_server.dart.snapshot';
case Artifact.engineDartBinary:
if (platform == TargetPlatform.windows_x64) {
return 'dart.exe';
}
return 'dart';
return 'dart$exe';
case Artifact.dart2jsSnapshot:
return 'dart2js.dart.snapshot';
case Artifact.dartdevcSnapshot:
......@@ -140,6 +139,10 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
final String jitOrAot = mode.isJit ? '_jit' : '_aot';
final String productOrNo = mode.isRelease ? '_product' : '';
return 'flutter$jitOrAot${productOrNo}_runner-0.far';
case Artifact.fontSubset:
return 'font-subset$exe';
case Artifact.constFinder:
return 'const_finder.dart.snapshot';
}
assert(false, 'Invalid artifact $artifact.');
return null;
......@@ -366,6 +369,9 @@ class CachedArtifacts extends Artifacts {
case Artifact.skyEnginePath:
final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
return _fileSystem.path.join(dartPackageDirectory.path, _artifactToFileName(artifact));
case Artifact.fontSubset:
case Artifact.constFinder:
return _cache.getArtifactDirectory('font-subset').childFile(_artifactToFileName(artifact, platform, mode)).path;
default:
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
......@@ -538,6 +544,10 @@ class LocalEngineArtifacts extends Artifacts {
final String jitOrAot = mode.isJit ? '_jit' : '_aot';
final String productOrNo = mode.isRelease ? '_product' : '';
return _fileSystem.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far');
case Artifact.fontSubset:
return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
case Artifact.constFinder:
return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
}
assert(false, 'Invalid artifact $artifact.');
return null;
......
......@@ -124,6 +124,7 @@ class Cache {
for (final String artifactName in IosUsbArtifacts.artifactNames) {
_artifacts.add(IosUsbArtifacts(artifactName, this));
}
_artifacts.add(FontSubsetArtifacts(this));
} else {
_artifacts.addAll(artifacts);
}
......@@ -709,7 +710,10 @@ abstract class EngineCachedArtifact extends CachedArtifact {
final String cacheDir = toolsDir[0];
final String urlPath = toolsDir[1];
final Directory dir = globals.fs.directory(globals.fs.path.join(location.path, cacheDir));
await _downloadZipArchive('Downloading $cacheDir tools...', Uri.parse(url + urlPath), dir);
// Avoid printing things like 'Downloading linux-x64 tools...' multiple times.
final String friendlyName = urlPath.replaceAll('/artifacts.zip', '').replaceAll('.zip', '');
await _downloadZipArchive('Downloading $friendlyName tools...', Uri.parse(url + urlPath), dir);
_makeFilesExecutable(dir);
......@@ -1176,6 +1180,33 @@ class MacOSFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts {
}
}
/// Cached artifacts for font subsetting.
class FontSubsetArtifacts extends EngineCachedArtifact {
FontSubsetArtifacts(Cache cache) : super(artifactName, cache, DevelopmentArtifact.universal);
static const String artifactName = 'font-subset';
@override
List<List<String>> getBinaryDirs() {
const Map<String, List<String>> artifacts = <String, List<String>> {
'macos': <String>['darwin-x64', 'darwin-x64/$artifactName.zip'],
'linux': <String>['linux-x64', 'linux-x64/$artifactName.zip'],
'windows': <String>['windows-x64', 'windows-x64/$artifactName.zip'],
};
final List<String> binaryDirs = artifacts[globals.platform.operatingSystem];
if (binaryDirs == null) {
throwToolExit('Unsupported operating system: ${globals.platform.operatingSystem}');
}
return <List<String>>[binaryDirs];
}
@override
List<String> getLicenseDirs() => const <String>[];
@override
List<String> getPackageDirs() => const <String>[];
}
/// Cached iOS/USB binary artifacts.
class IosUsbArtifacts extends CachedArtifact {
IosUsbArtifacts(String name, Cache cache) : super(
......
......@@ -278,17 +278,19 @@ void main() {
MemoryFileSystem memoryFileSystem;
MockCache mockCache;
MockOperatingSystemUtils mockOperatingSystemUtils;
MockHttpClient mockHttpClient;
setUp(() {
fakeHttpClient = FakeHttpClient();
mockHttpClient = MockHttpClient();
fakePlatform = FakePlatform()..environment = const <String, String>{};
memoryFileSystem = MemoryFileSystem();
mockCache = MockCache();
mockOperatingSystemUtils = MockOperatingSystemUtils();
when(mockOperatingSystemUtils.verifyZip(any)).thenReturn(true);
});
testUsingContext('makes binary dirs readable and executable by all', () async {
when(mockOperatingSystemUtils.verifyZip(any)).thenReturn(true);
final Directory artifactDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_artifact.');
final Directory downloadDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_download.');
when(mockCache.getArtifactDirectory(any)).thenReturn(artifactDir);
......@@ -316,6 +318,47 @@ void main() {
OperatingSystemUtils: () => mockOperatingSystemUtils,
Platform: () => fakePlatform,
});
testUsingContext('prints a friendly name when downloading', () async {
when(mockOperatingSystemUtils.verifyZip(any)).thenReturn(false);
final MockHttpClientRequest httpClientRequest = MockHttpClientRequest();
final MockHttpClientResponse httpClientResponse = MockHttpClientResponse();
when(httpClientResponse.statusCode).thenReturn(200);
when(httpClientRequest.close()).thenAnswer((_) async => httpClientResponse);
when(mockHttpClient.getUrl(any)).thenAnswer((_) async => httpClientRequest);
final Directory artifactDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_artifact.');
final Directory downloadDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_download.');
when(mockCache.getArtifactDirectory(any)).thenReturn(artifactDir);
when(mockCache.getDownloadDir()).thenReturn(downloadDir);
final FakeCachedArtifact artifact = FakeCachedArtifact(
cache: mockCache,
binaryDirs: <List<String>>[
<String>['bin_dir', 'darwin-x64/artifacts.zip'],
<String>['font-subset', 'darwin-x64/font-subset.zip'],
],
requiredArtifacts: DevelopmentArtifact.universal,
);
await artifact.updateInner();
expect(testLogger.statusText, isNotNull);
expect(testLogger.statusText, isNotEmpty);
expect(
testLogger.statusText.split('\n'),
<String>[
'Downloading darwin-x64 tools...',
'Downloading darwin-x64/font-subset tools...',
'',
],
);
}, overrides: <Type, Generator>{
Cache: () => mockCache,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
HttpClientFactory: () => () => mockHttpClient,
OperatingSystemUtils: () => mockOperatingSystemUtils,
Platform: () => fakePlatform,
});
});
group('AndroidMavenArtifacts', () {
......@@ -446,6 +489,45 @@ void main() {
]);
});
}, skip: !globals.platform.isLinux);
testUsingContext('FontSubset in univeral artifacts', () {
final MockCache mockCache = MockCache();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
expect(artifacts.developmentArtifact, DevelopmentArtifact.universal);
});
testUsingContext('FontSubset artifacts on linux', () {
final MockCache mockCache = MockCache();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['linux-x64', 'linux-x64/font-subset.zip']]);
}, overrides: <Type, Generator> {
Platform: () => FakePlatform()..operatingSystem = 'linux',
});
testUsingContext('FontSubset artifacts on windows', () {
final MockCache mockCache = MockCache();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['windows-x64', 'windows-x64/font-subset.zip']]);
}, overrides: <Type, Generator> {
Platform: () => FakePlatform()..operatingSystem = 'windows',
});
testUsingContext('FontSubset artifacts on macos', () {
final MockCache mockCache = MockCache();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['darwin-x64', 'darwin-x64/font-subset.zip']]);
}, overrides: <Type, Generator> {
Platform: () => FakePlatform()..operatingSystem = 'macos',
});
testUsingContext('FontSubset artifacts on fuchsia', () {
final MockCache mockCache = MockCache();
final FontSubsetArtifacts artifacts = FontSubsetArtifacts(mockCache);
expect(() => artifacts.getBinaryDirs(), throwsToolExit(message: 'Unsupported operating system: ${globals.platform.operatingSystem}'));
}, overrides: <Type, Generator> {
Platform: () => FakePlatform()..operatingSystem = 'fuchsia',
});
}
class FakeCachedArtifact extends EngineCachedArtifact {
......@@ -513,3 +595,6 @@ class MockCache extends Mock implements Cache {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
class MockPlatform extends Mock implements Platform {}
class MockVersionedPackageResolver extends Mock implements VersionedPackageResolver {}
class MockHttpClientRequest extends Mock implements HttpClientRequest {}
class MockHttpClientResponse extends Mock implements HttpClientResponse {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment