Unverified Commit 5228a785 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Fuchsia step 1: add SDK version file and artifact download (#31073)

parent 96e1fc9c
Ow5Xdviq7OwKr7XNuf-Bw0nBMeAr849mFn7gc_RUpzUC
......@@ -16,27 +16,53 @@ import 'base/platform.dart';
import 'globals.dart';
/// A tag for a set of development artifacts that need to be cached.
enum DevelopmentArtifact {
class DevelopmentArtifact {
const DevelopmentArtifact._(this.name, {this.unstable = false});
/// The name of the artifact.
///
/// This should match the flag name in precache.dart
final String name;
/// Whether this artifact should not be usable on stable branches.
final bool unstable;
/// Artifacts required for Android development.
android,
static const DevelopmentArtifact android = DevelopmentArtifact._('android');
/// Artifacts required for iOS development.
iOS,
static const DevelopmentArtifact iOS = DevelopmentArtifact._('ios');
/// Artifacts required for web development,
web,
static const DevelopmentArtifact web = DevelopmentArtifact._('web', unstable: true);
/// Artifacts required for desktop macOS.
macOS,
static const DevelopmentArtifact macOS = DevelopmentArtifact._('macos', unstable: true);
/// Artifacts required for desktop Windows.
windows,
static const DevelopmentArtifact windows = DevelopmentArtifact._('windows', unstable: true);
/// Artifacts required for desktop linux.
linux,
static const DevelopmentArtifact linux = DevelopmentArtifact._('linux', unstable: true);
/// Artifacts required for Fuchsia.
static const DevelopmentArtifact fuchsia = DevelopmentArtifact._('fuchsia', unstable: true);
/// Artifacts required by all developments.
universal,
static const DevelopmentArtifact universal = DevelopmentArtifact._('universal');
/// The vaulues of DevelopmentArtifacts.
static final List<DevelopmentArtifact> values = <DevelopmentArtifact>[
android,
iOS,
web,
macOS,
windows,
linux,
fuchsia,
universal,
];
}
/// A wrapper around the `bin/cache/` directory.
......@@ -54,6 +80,7 @@ class Cache {
_artifacts.add(WindowsEngineArtifacts(this));
_artifacts.add(MacOSEngineArtifacts(this));
_artifacts.add(LinuxEngineArtifacts(this));
_artifacts.add(FuchsiaCacheArtifacts(this));
} else {
_artifacts.addAll(artifacts);
}
......@@ -155,12 +182,19 @@ class Cache {
return _dartSdkVersion;
}
String _engineRevision;
/// The current version of the Flutter engine the flutter tool will download.
String get engineRevision {
_engineRevision ??= getVersionFor('engine');
return _engineRevision;
}
String _engineRevision;
/// The current version of the Fuchsia SDK the flutter tool will download.
String get fuchsiaRevision {
_fuchsiaRevision ??= getVersionFor('fuchsia');
return _fuchsiaRevision;
}
String _fuchsiaRevision;
static Cache get instance => context[Cache];
......@@ -817,6 +851,33 @@ class GradleWrapper extends CachedArtifact {
}
}
/// The Fuchsia core SDK.
class FuchsiaCacheArtifacts extends CachedArtifact {
FuchsiaCacheArtifacts(Cache cache) : super('fuchsia', cache, const <DevelopmentArtifact> {
DevelopmentArtifact.fuchsia,
});
static const String _cipdBaseUrl = 'https://chrome-infra-packages.appspot.com/dl';
static const String _macOSSdk = 'fuchsia/sdk/core/mac-amd64';
static const String _linuxSdk = 'fuchsia/sdk/core/linux-amd64';
@override
Future<void> updateInner() async {
// Step 1: Determine variant of Fuchsia SDK to download.
String packageName;
if (platform.isLinux) {
packageName = _linuxSdk;
} else if (platform.isMacOS) {
packageName = _macOSSdk;
} else {
// Unsupported.
return;
}
final String url = '$_cipdBaseUrl/$packageName/+/$version';
await _downloadZipArchive('Downloading package fuchsia SDK...', Uri.parse(url), location);
}
}
// Many characters are problematic in filenames, especially on Windows.
final Map<int, List<int>> _flattenNameSubstitutions = <int, List<int>>{
r'@'.codeUnitAt(0): '@@'.codeUnits,
......
......@@ -25,6 +25,10 @@ class PrecacheCommand extends FlutterCommand {
help: 'Precache artifacts for windows desktop development');
argParser.addFlag('macos', negatable: true, defaultsTo: false,
help: 'Precache artifacts for macOS desktop development');
argParser.addFlag('fuchsia', negatable: true, defaultsTo: false,
help: 'Precache artifacts for Fuchsia development');
argParser.addFlag('universal', negatable: true, defaultsTo: true,
help: 'Precache artifacts required for all developments');
}
@override
......@@ -41,28 +45,16 @@ class PrecacheCommand extends FlutterCommand {
if (argResults['all-platforms']) {
cache.includeAllPlatforms = true;
}
final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{ DevelopmentArtifact.universal };
if (argResults['android']) {
requiredArtifacts.add(DevelopmentArtifact.android);
}
if (argResults['ios']) {
requiredArtifacts.add(DevelopmentArtifact.iOS);
}
if (!FlutterVersion.instance.isStable) {
if (argResults['web']) {
requiredArtifacts.add(DevelopmentArtifact.web);
}
if (argResults['linux']) {
requiredArtifacts.add(DevelopmentArtifact.linux);
final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{};
for (DevelopmentArtifact artifact in DevelopmentArtifact.values) {
// Don't include unstable artifacts on stable branches.
if (FlutterVersion.instance.isStable && artifact.unstable) {
continue;
}
if (argResults['windows']) {
requiredArtifacts.add(DevelopmentArtifact.windows);
}
if (argResults['macos']) {
requiredArtifacts.add(DevelopmentArtifact.macOS);
if (argResults[artifact.name]) {
requiredArtifacts.add(artifact);
}
}
if (cache.isUpToDate()) {
printStatus('Already up-to-date.');
} else {
......
......@@ -27,7 +27,7 @@ void main() {
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows']
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia']
);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
......@@ -37,6 +37,7 @@ void main() {
DevelopmentArtifact.macOS,
DevelopmentArtifact.linux,
DevelopmentArtifact.windows,
DevelopmentArtifact.fuchsia,
}));
}, overrides: <Type, Generator>{
Cache: () => cache,
......@@ -51,7 +52,7 @@ void main() {
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows']
const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia']
);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
......
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