Unverified Commit 259641c4 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Allow downloading of desktop embedding artifacts (#30648)

parent 1a3201bc
......@@ -51,6 +51,9 @@ class Cache {
_artifacts.add(GradleWrapper(this));
_artifacts.add(FlutterWebSdk(this));
_artifacts.add(FlutterSdk(this));
_artifacts.add(WindowsEngineArtifacts(this));
_artifacts.add(MacOSEngineArtifacts(this));
_artifacts.add(LinuxEngineArtifacts(this));
} else {
_artifacts.addAll(artifacts);
}
......@@ -535,11 +538,14 @@ abstract class EngineCachedArtifact extends CachedArtifact {
_makeFilesExecutable(dir);
final File frameworkZip = fs.file(fs.path.join(dir.path, 'Flutter.framework.zip'));
if (frameworkZip.existsSync()) {
final Directory framework = fs.directory(fs.path.join(dir.path, 'Flutter.framework'));
framework.createSync();
os.unzip(frameworkZip, framework);
const List<String> frameworkNames = <String>['Flutter', 'FlutterMacOS'];
for (String frameworkName in frameworkNames) {
final File frameworkZip = fs.file(fs.path.join(dir.path, '$frameworkName.framework.zip'));
if (frameworkZip.existsSync()) {
final Directory framework = fs.directory(fs.path.join(dir.path, '$frameworkName.framework'));
framework.createSync();
os.unzip(frameworkZip, framework);
}
}
}
......@@ -630,6 +636,72 @@ class FlutterSdk extends EngineCachedArtifact {
List<String> getLicenseDirs() => const <String>[];
}
class MacOSEngineArtifacts extends EngineCachedArtifact {
MacOSEngineArtifacts(Cache cache) : super(
'macos-sdk',
cache,
const <DevelopmentArtifact> { DevelopmentArtifact.macOS },
);
@override
List<String> getPackageDirs() => const <String>[];
@override
List<List<String>> getBinaryDirs() {
if (platform.isMacOS) {
return _macOSDesktopBinaryDirs;
}
return const <List<String>>[];
}
@override
List<String> getLicenseDirs() => const <String>[];
}
class WindowsEngineArtifacts extends EngineCachedArtifact {
WindowsEngineArtifacts(Cache cache) : super(
'windows-sdk',
cache,
const <DevelopmentArtifact> { DevelopmentArtifact.windows },
);
@override
List<String> getPackageDirs() => const <String>[];
@override
List<List<String>> getBinaryDirs() {
if (platform.isWindows) {
return _windowsDesktopBinaryDirs;
}
return const <List<String>>[];
}
@override
List<String> getLicenseDirs() => const <String>[];
}
class LinuxEngineArtifacts extends EngineCachedArtifact {
LinuxEngineArtifacts(Cache cache) : super(
'linux-sdk',
cache,
const <DevelopmentArtifact> { DevelopmentArtifact.linux },
);
@override
List<String> getPackageDirs() => const <String>[];
@override
List<List<String>> getBinaryDirs() {
if (platform.isLinux) {
return _linuxDesktopBinaryDirs;
}
return const <List<String>>[];
}
@override
List<String> getLicenseDirs() => const <String>[];
}
class AndroidEngineArtifacts extends EngineCachedArtifact {
AndroidEngineArtifacts(Cache cache) : super(
'android-sdk',
......@@ -797,6 +869,20 @@ void _ensureExists(Directory directory) {
}
}
const List<List<String>> _windowsDesktopBinaryDirs = <List<String>>[
<String>['windows-x64', 'windows-x64/windows-x64-flutter.zip'],
<String>['windows-x64', 'windows-x64/flutter-cpp-client-wrapper.zip'],
];
const List<List<String>> _linuxDesktopBinaryDirs = <List<String>>[
<String>['linux-x64', 'linux-x64/linux-x64-flutter.zip'],
<String>['linux-x64', 'linux-x64/flutter-cpp-client-wrapper.zip'],
];
const List<List<String>> _macOSDesktopBinaryDirs = <List<String>>[
<String>['darwin-x64', 'darwin-x64/FlutterMacOS.framework.zip'],
];
const List<List<String>> _osxBinaryDirs = <List<String>>[
<String>['android-arm-profile/darwin-x64', 'android-arm-profile/darwin-x64.zip'],
<String>['android-arm-release/darwin-x64', 'android-arm-release/darwin-x64.zip'],
......
......@@ -7,6 +7,7 @@ import 'dart:async';
import '../cache.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
import '../version.dart';
class PrecacheCommand extends FlutterCommand {
PrecacheCommand() {
......@@ -18,6 +19,12 @@ class PrecacheCommand extends FlutterCommand {
help: 'Precache artifacts for iOS developemnt');
argParser.addFlag('web', negatable: true, defaultsTo: false,
help: 'Precache artifacts for web development');
argParser.addFlag('linux', negatable: true, defaultsTo: false,
help: 'Precache artifacts for linux desktop development');
argParser.addFlag('windows', negatable: true, defaultsTo: false,
help: 'Precache artifacts for windows desktop development');
argParser.addFlag('macos', negatable: true, defaultsTo: false,
help: 'Precache artifacts for macOS desktop development');
}
@override
......@@ -41,8 +48,19 @@ class PrecacheCommand extends FlutterCommand {
if (argResults['ios']) {
requiredArtifacts.add(DevelopmentArtifact.iOS);
}
if (argResults['web']) {
requiredArtifacts.add(DevelopmentArtifact.web);
if (!FlutterVersion.instance.isStable) {
if (argResults['web']) {
requiredArtifacts.add(DevelopmentArtifact.web);
}
if (argResults['linux']) {
requiredArtifacts.add(DevelopmentArtifact.linux);
}
if (argResults['windows']) {
requiredArtifacts.add(DevelopmentArtifact.windows);
}
if (argResults['macos']) {
requiredArtifacts.add(DevelopmentArtifact.macOS);
}
}
if (cache.isUpToDate()) {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/precache.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart';
void main() {
group('precache', () {
final MockCache cache = MockCache();
Set<DevelopmentArtifact> artifacts;
when(cache.isUpToDate()).thenReturn(false);
when(cache.updateAll(any)).thenAnswer((Invocation invocation) {
artifacts = invocation.positionalArguments.first;
return Future<void>.value(null);
});
testUsingContext('Adds artifact flags to requested artifacts', () async {
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows']
);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
DevelopmentArtifact.iOS,
DevelopmentArtifact.android,
DevelopmentArtifact.web,
DevelopmentArtifact.macOS,
DevelopmentArtifact.linux,
DevelopmentArtifact.windows,
}));
}, overrides: <Type, Generator>{
Cache: () => cache,
});
final MockFlutterVersion flutterVersion = MockFlutterVersion();
when(flutterVersion.isStable).thenReturn(true);
testUsingContext('Adds artifact flags to requested artifacts on stable', () async {
// Release lock between test cases.
Cache.releaseLockEarly();
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows']
);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
DevelopmentArtifact.iOS,
DevelopmentArtifact.android,
}));
}, overrides: <Type, Generator>{
Cache: () => cache,
FlutterVersion: () => flutterVersion,
});
});
}
class MockFlutterVersion extends Mock implements FlutterVersion {}
class MockCache extends Mock implements Cache {}
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