diff --git a/bin/internal/fuchsia.version b/bin/internal/fuchsia.version new file mode 100644 index 0000000000..d6f6c55370 --- /dev/null +++ b/bin/internal/fuchsia.version @@ -0,0 +1 @@ +Ow5Xdviq7OwKr7XNuf-Bw0nBMeAr849mFn7gc_RUpzUC diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index dcfe070c45..f8d0bb2d04 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -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 values = [ + 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.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 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> _flattenNameSubstitutions = >{ r'@'.codeUnitAt(0): '@@'.codeUnits, diff --git a/packages/flutter_tools/lib/src/commands/precache.dart b/packages/flutter_tools/lib/src/commands/precache.dart index 9c39c00db3..ab8e4d5789 100644 --- a/packages/flutter_tools/lib/src/commands/precache.dart +++ b/packages/flutter_tools/lib/src/commands/precache.dart @@ -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 requiredArtifacts = { 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); + final Set requiredArtifacts = {}; + for (DevelopmentArtifact artifact in DevelopmentArtifact.values) { + // Don't include unstable artifacts on stable branches. + if (FlutterVersion.instance.isStable && artifact.unstable) { + continue; } - if (argResults['linux']) { - requiredArtifacts.add(DevelopmentArtifact.linux); - } - 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 { diff --git a/packages/flutter_tools/test/commands/precache_test.dart b/packages/flutter_tools/test/commands/precache_test.dart index 090df1b6c6..217f3cd8c5 100644 --- a/packages/flutter_tools/test/commands/precache_test.dart +++ b/packages/flutter_tools/test/commands/precache_test.dart @@ -27,7 +27,7 @@ void main() { final PrecacheCommand command = PrecacheCommand(); applyMocksToCommand(command); await createTestCommandRunner(command).run( - const ['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows'] + const ['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia'] ); expect(artifacts, unorderedEquals({ DevelopmentArtifact.universal, @@ -37,6 +37,7 @@ void main() { DevelopmentArtifact.macOS, DevelopmentArtifact.linux, DevelopmentArtifact.windows, + DevelopmentArtifact.fuchsia, })); }, overrides: { Cache: () => cache, @@ -51,7 +52,7 @@ void main() { final PrecacheCommand command = PrecacheCommand(); applyMocksToCommand(command); await createTestCommandRunner(command).run( - const ['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows'] + const ['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia'] ); expect(artifacts, unorderedEquals({ DevelopmentArtifact.universal,