Unverified Commit 639c9935 authored by Dan Field's avatar Dan Field Committed by GitHub

wire in fuchsiaApp (#33781)

parent 9474a9f3
...@@ -387,10 +387,11 @@ class PrebuiltIOSApp extends IOSApp { ...@@ -387,10 +387,11 @@ class PrebuiltIOSApp extends IOSApp {
} }
class ApplicationPackageStore { class ApplicationPackageStore {
ApplicationPackageStore({ this.android, this.iOS }); ApplicationPackageStore({ this.android, this.iOS, this.fuchsia });
AndroidApk android; AndroidApk android;
IOSApp iOS; IOSApp iOS;
FuchsiaApp fuchsia;
Future<ApplicationPackage> getPackageForPlatform(TargetPlatform platform) async { Future<ApplicationPackage> getPackageForPlatform(TargetPlatform platform) async {
switch (platform) { switch (platform) {
...@@ -403,10 +404,12 @@ class ApplicationPackageStore { ...@@ -403,10 +404,12 @@ class ApplicationPackageStore {
case TargetPlatform.ios: case TargetPlatform.ios:
iOS ??= IOSApp.fromIosProject(FlutterProject.current().ios); iOS ??= IOSApp.fromIosProject(FlutterProject.current().ios);
return iOS; return iOS;
case TargetPlatform.fuchsia:
fuchsia ??= FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia);
return fuchsia;
case TargetPlatform.darwin_x64: case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64: case TargetPlatform.windows_x64:
case TargetPlatform.fuchsia:
case TargetPlatform.tester: case TargetPlatform.tester:
case TargetPlatform.web: case TargetPlatform.web:
return null; return null;
......
...@@ -7,6 +7,7 @@ import 'package:meta/meta.dart'; ...@@ -7,6 +7,7 @@ import 'package:meta/meta.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../globals.dart';
import '../project.dart'; import '../project.dart';
abstract class FuchsiaApp extends ApplicationPackage { abstract class FuchsiaApp extends ApplicationPackage {
...@@ -14,6 +15,11 @@ abstract class FuchsiaApp extends ApplicationPackage { ...@@ -14,6 +15,11 @@ abstract class FuchsiaApp extends ApplicationPackage {
/// Creates a new [FuchsiaApp] from a fuchsia sub project. /// Creates a new [FuchsiaApp] from a fuchsia sub project.
factory FuchsiaApp.fromFuchsiaProject(FuchsiaProject project) { factory FuchsiaApp.fromFuchsiaProject(FuchsiaProject project) {
if (!project.existsSync()) {
// If the project doesn't exist at all the current hint to run flutter
// create is accurate.
return null;
}
return BuildableFuchsiaApp( return BuildableFuchsiaApp(
project: project, project: project,
); );
...@@ -23,6 +29,11 @@ abstract class FuchsiaApp extends ApplicationPackage { ...@@ -23,6 +29,11 @@ abstract class FuchsiaApp extends ApplicationPackage {
/// ///
/// [applicationBinary] is the path to the .far archive. /// [applicationBinary] is the path to the .far archive.
factory FuchsiaApp.fromPrebuiltApp(FileSystemEntity applicationBinary) { factory FuchsiaApp.fromPrebuiltApp(FileSystemEntity applicationBinary) {
final FileSystemEntityType entityType = fs.typeSync(applicationBinary.path);
if (entityType != FileSystemEntityType.file) {
printError('File "${applicationBinary.path}" does not exist or is not a .far file. Use far archive.');
return null;
}
return PrebuiltFuchsiaApp( return PrebuiltFuchsiaApp(
farArchive: applicationBinary.path, farArchive: applicationBinary.path,
); );
......
...@@ -10,6 +10,7 @@ import 'package:file/memory.dart'; ...@@ -10,6 +10,7 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/fuchsia/application_package.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -305,6 +306,52 @@ void main() { ...@@ -305,6 +306,52 @@ void main() {
expect(iosApp, null); expect(iosApp, null);
}, overrides: overrides); }, overrides: overrides);
}); });
group('FuchsiaApp', () {
final Map<Type, Generator> overrides = <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
Platform: _kNoColorTerminalPlatform,
OperatingSystemUtils: () => MockOperatingSystemUtils(),
};
testUsingContext('Error on non-existing file', () {
final PrebuiltFuchsiaApp fuchsiaApp =
FuchsiaApp.fromPrebuiltApp(fs.file('not_existing.far'));
expect(fuchsiaApp, isNull);
final BufferLogger logger = context.get<Logger>();
expect(
logger.errorText,
'File "not_existing.far" does not exist or is not a .far file. Use far archive.\n',
);
}, overrides: overrides);
testUsingContext('Error on non-far file', () {
fs.directory('regular_folder').createSync();
final PrebuiltFuchsiaApp fuchsiaApp =
FuchsiaApp.fromPrebuiltApp(fs.file('regular_folder'));
expect(fuchsiaApp, isNull);
final BufferLogger logger = context.get<Logger>();
expect(
logger.errorText,
'File "regular_folder" does not exist or is not a .far file. Use far archive.\n',
);
}, overrides: overrides);
testUsingContext('Success with far file', () {
fs.file('bundle.far').createSync();
final PrebuiltFuchsiaApp fuchsiaApp = FuchsiaApp.fromPrebuiltApp(fs.file('bundle.far'));
final BufferLogger logger = context.get<Logger>();
expect(logger.errorText, isEmpty);
expect(fuchsiaApp.id, 'bundle.far');
}, overrides: overrides);
testUsingContext('returns null when there is no fuchsia', () async {
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final BuildableFuchsiaApp fuchsiaApp = FuchsiaApp.fromFuchsiaProject(FlutterProject.fromDirectory(fs.currentDirectory).fuchsia);
expect(fuchsiaApp, null);
}, overrides: overrides);
});
} }
const String _aaptDataWithExplicitEnabledAndMainLauncherActivity = const String _aaptDataWithExplicitEnabledAndMainLauncherActivity =
......
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