Unverified Commit c584a5ea authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate fuchsia_device to null safety (#95438)

parent 38cffc9c
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../artifacts.dart'; import '../artifacts.dart';
import '../asset.dart'; import '../asset.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -45,12 +41,13 @@ Future<void> _validateCmxFile(FuchsiaProject fuchsiaProject) async { ...@@ -45,12 +41,13 @@ Future<void> _validateCmxFile(FuchsiaProject fuchsiaProject) async {
// 3. Using these manifests, use the Fuchsia SDK 'pm' tool to create the // 3. Using these manifests, use the Fuchsia SDK 'pm' tool to create the
// Fuchsia package. // Fuchsia package.
Future<void> buildFuchsia({ Future<void> buildFuchsia({
@required FuchsiaProject fuchsiaProject, required FuchsiaProject fuchsiaProject,
@required TargetPlatform targetPlatform, required TargetPlatform targetPlatform,
@required String target, // E.g., lib/main.dart String? target, // E.g., lib/main.dart
BuildInfo buildInfo = BuildInfo.debug, BuildInfo buildInfo = BuildInfo.debug,
String runnerPackageSource = FuchsiaPackageServer.toolHost, String runnerPackageSource = FuchsiaPackageServer.toolHost,
}) async { }) async {
final String targetPath = target ??= 'lib/main.dart';
await _validateCmxFile(fuchsiaProject); await _validateCmxFile(fuchsiaProject);
final Directory outDir = globals.fs.directory(getFuchsiaBuildDirectory()); final Directory outDir = globals.fs.directory(getFuchsiaBuildDirectory());
if (!outDir.existsSync()) { if (!outDir.existsSync()) {
...@@ -58,18 +55,18 @@ Future<void> buildFuchsia({ ...@@ -58,18 +55,18 @@ Future<void> buildFuchsia({
} }
await _timedBuildStep('fuchsia-kernel-compile', await _timedBuildStep('fuchsia-kernel-compile',
() => fuchsiaSdk.fuchsiaKernelCompiler.build( () => fuchsiaSdk!.fuchsiaKernelCompiler.build(
fuchsiaProject: fuchsiaProject, target: target, buildInfo: buildInfo)); fuchsiaProject: fuchsiaProject, target: targetPath, buildInfo: buildInfo));
if (buildInfo.usesAot) { if (buildInfo.usesAot) {
await _timedBuildStep('fuchsia-gen-snapshot', await _timedBuildStep('fuchsia-gen-snapshot',
() => _genSnapshot(fuchsiaProject, target, buildInfo, targetPlatform)); () => _genSnapshot(fuchsiaProject, targetPath, buildInfo, targetPlatform));
} }
await _timedBuildStep('fuchsia-build-assets', await _timedBuildStep('fuchsia-build-assets',
() => _buildAssets(fuchsiaProject, target, buildInfo)); () => _buildAssets(fuchsiaProject, targetPath, buildInfo));
await _timedBuildStep('fuchsia-build-package', await _timedBuildStep('fuchsia-build-package',
() => _buildPackage(fuchsiaProject, target, buildInfo, runnerPackageSource)); () => _buildPackage(fuchsiaProject, targetPath, buildInfo, runnerPackageSource));
} }
Future<void> _genSnapshot( Future<void> _genSnapshot(
...@@ -84,7 +81,7 @@ Future<void> _genSnapshot( ...@@ -84,7 +81,7 @@ Future<void> _genSnapshot(
final String elf = globals.fs.path.join(outDir, 'elf.aotsnapshot'); final String elf = globals.fs.path.join(outDir, 'elf.aotsnapshot');
final String genSnapshot = globals.artifacts.getArtifactPath( final String genSnapshot = globals.artifacts!.getArtifactPath(
Artifact.genSnapshot, Artifact.genSnapshot,
platform: targetPlatform, platform: targetPlatform,
mode: buildInfo.mode, mode: buildInfo.mode,
...@@ -118,7 +115,7 @@ Future<void> _buildAssets( ...@@ -118,7 +115,7 @@ Future<void> _buildAssets(
BuildInfo buildInfo, BuildInfo buildInfo,
) async { ) async {
final String assetDir = getAssetBuildDirectory(); final String assetDir = getAssetBuildDirectory();
final AssetBundle assets = await buildAssets( final AssetBundle? assets = await buildAssets(
manifestPath: fuchsiaProject.project.pubspecFile.path, manifestPath: fuchsiaProject.project.pubspecFile.path,
packagesPath: fuchsiaProject.project.packagesFile.path, packagesPath: fuchsiaProject.project.packagesFile.path,
assetDirPath: assetDir, assetDirPath: assetDir,
...@@ -148,7 +145,7 @@ Future<void> _buildAssets( ...@@ -148,7 +145,7 @@ Future<void> _buildAssets(
} }
void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst) { void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst) {
final Map<String, dynamic> cmx = castStringKeyedMap(json.decode(src.readAsStringSync())); final Map<String, Object?> cmx = castStringKeyedMap(json.decode(src.readAsStringSync())) ?? <String, Object?>{};
// If the app author has already specified the runner in the cmx file, then // If the app author has already specified the runner in the cmx file, then
// do not override it with something else. // do not override it with something else.
if (cmx.containsKey('runner')) { if (cmx.containsKey('runner')) {
...@@ -171,7 +168,6 @@ void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst) ...@@ -171,7 +168,6 @@ void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst)
break; break;
default: default:
throwToolExit('Fuchsia does not support build mode "$mode"'); throwToolExit('Fuchsia does not support build mode "$mode"');
break;
} }
cmx['runner'] = 'fuchsia-pkg://$runnerPackageSource/$runner#meta/$runner.cmx'; cmx['runner'] = 'fuchsia-pkg://$runnerPackageSource/$runner#meta/$runner.cmx';
dst.writeAsStringSync(json.encode(cmx)); dst.writeAsStringSync(json.encode(cmx));
...@@ -218,7 +214,10 @@ Future<void> _buildPackage( ...@@ -218,7 +214,10 @@ Future<void> _buildPackage(
manifestFile.writeAsStringSync('meta/package=$pkgDir/meta/package\n', manifestFile.writeAsStringSync('meta/package=$pkgDir/meta/package\n',
mode: FileMode.append); mode: FileMode.append);
final FuchsiaPM fuchsiaPM = fuchsiaSdk.fuchsiaPM; final FuchsiaPM? fuchsiaPM = fuchsiaSdk?.fuchsiaPM;
if (fuchsiaPM == null) {
return;
}
if (!await fuchsiaPM.init(pkgDir, appName)) { if (!await fuchsiaPM.init(pkgDir, appName)) {
return; return;
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../base/process.dart'; import '../base/process.dart';
import 'fuchsia_device.dart'; import 'fuchsia_device.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../base/process.dart'; import '../base/process.dart';
import 'fuchsia_device.dart'; import 'fuchsia_device.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../base/process.dart'; import '../base/process.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
...@@ -23,7 +21,7 @@ class FuchsiaTilesCtl { ...@@ -23,7 +21,7 @@ class FuchsiaTilesCtl {
/// found. /// found.
static Future<int> findAppKey(FuchsiaDevice device, String appName) async { static Future<int> findAppKey(FuchsiaDevice device, String appName) async {
final FuchsiaTilesCtl tilesCtl = fuchsiaDeviceTools.tilesCtl; final FuchsiaTilesCtl tilesCtl = fuchsiaDeviceTools.tilesCtl;
final Map<int, String> runningApps = await tilesCtl.list(device); final Map<int, String>? runningApps = await tilesCtl.list(device);
if (runningApps == null) { if (runningApps == null) {
globals.printTrace('tiles_ctl is not running'); globals.printTrace('tiles_ctl is not running');
return -1; return -1;
...@@ -39,7 +37,7 @@ class FuchsiaTilesCtl { ...@@ -39,7 +37,7 @@ class FuchsiaTilesCtl {
/// Ensures that tiles is running on the device. /// Ensures that tiles is running on the device.
static Future<bool> ensureStarted(FuchsiaDevice device) async { static Future<bool> ensureStarted(FuchsiaDevice device) async {
final FuchsiaTilesCtl tilesCtl = fuchsiaDeviceTools.tilesCtl; final FuchsiaTilesCtl tilesCtl = fuchsiaDeviceTools.tilesCtl;
final Map<int, String> runningApps = await tilesCtl.list(device); final Map<int, String>? runningApps = await tilesCtl.list(device);
if (runningApps == null) { if (runningApps == null) {
return tilesCtl.start(device); return tilesCtl.start(device);
} }
...@@ -58,7 +56,7 @@ class FuchsiaTilesCtl { ...@@ -58,7 +56,7 @@ class FuchsiaTilesCtl {
/// ///
/// Returns an empty mapping if tiles_ctl is running but no apps are running. /// Returns an empty mapping if tiles_ctl is running but no apps are running.
/// Returns null if tiles_ctl is not running. /// Returns null if tiles_ctl is not running.
Future<Map<int, String>> list(FuchsiaDevice device) async { Future<Map<int, String>?> list(FuchsiaDevice device) async {
// Output of tiles_ctl list has the format: // Output of tiles_ctl list has the format:
// Found 1 tiles: // Found 1 tiles:
// Tile key 1 url fuchsia-pkg://fuchsia.com/stocks#meta/stocks.cmx ... // Tile key 1 url fuchsia-pkg://fuchsia.com/stocks#meta/stocks.cmx ...
...@@ -75,11 +73,13 @@ class FuchsiaTilesCtl { ...@@ -75,11 +73,13 @@ class FuchsiaTilesCtl {
for (final String line in result.stdout.split('\n')) { for (final String line in result.stdout.split('\n')) {
final List<String> words = line.split(' '); final List<String> words = line.split(' ');
if (words.isNotEmpty && words[0] == 'Tile') { if (words.isNotEmpty && words[0] == 'Tile') {
final int key = int.tryParse(words[2]); final int? key = int.tryParse(words[2]);
if (key != null) {
final String url = words[4]; final String url = words[4];
tiles[key] = url; tiles[key] = url;
} }
} }
}
return tiles; return tiles;
} }
......
...@@ -91,7 +91,7 @@ void main() { ...@@ -91,7 +91,7 @@ void main() {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(canListDevices: false); final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(canListDevices: false);
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices( final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(), platform: FakePlatform(),
fuchsiaSdk: null, fuchsiaSdk: FakeFuchsiaSdk(devices: 'ignored'),
fuchsiaWorkflow: fuchsiaWorkflow, fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(), logger: BufferLogger.test(),
); );
...@@ -154,7 +154,7 @@ void main() { ...@@ -154,7 +154,7 @@ void main() {
testUsingContext('disposing device disposes the portForwarder', () async { testUsingContext('disposing device disposes the portForwarder', () async {
final FakePortForwarder portForwarder = FakePortForwarder(); final FakePortForwarder portForwarder = FakePortForwarder();
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
device.portForwarder = portForwarder; device.portForwarder = portForwarder;
await device.dispose(); await device.dispose();
...@@ -162,7 +162,7 @@ void main() { ...@@ -162,7 +162,7 @@ void main() {
}); });
testWithoutContext('default capabilities', () async { testWithoutContext('default capabilities', () async {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.directory('fuchsia').createSync(recursive: true); memoryFileSystem.directory('fuchsia').createSync(recursive: true);
memoryFileSystem.file('pubspec.yaml').createSync(); memoryFileSystem.file('pubspec.yaml').createSync();
...@@ -174,13 +174,13 @@ void main() { ...@@ -174,13 +174,13 @@ void main() {
}); });
test('is ephemeral', () { test('is ephemeral', () {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(device.ephemeral, true); expect(device.ephemeral, true);
}); });
testWithoutContext('supported for project', () async { testWithoutContext('supported for project', () async {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.directory('fuchsia').createSync(recursive: true); memoryFileSystem.directory('fuchsia').createSync(recursive: true);
memoryFileSystem.file('pubspec.yaml').createSync(); memoryFileSystem.file('pubspec.yaml').createSync();
...@@ -189,7 +189,7 @@ void main() { ...@@ -189,7 +189,7 @@ void main() {
}); });
testWithoutContext('not supported for project', () async { testWithoutContext('not supported for project', () async {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.file('pubspec.yaml').createSync(); memoryFileSystem.file('pubspec.yaml').createSync();
...@@ -197,7 +197,7 @@ void main() { ...@@ -197,7 +197,7 @@ void main() {
}); });
testUsingContext('targetPlatform does not throw when sshConfig is missing', () async { testUsingContext('targetPlatform does not throw when sshConfig is missing', () async {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64); expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -212,7 +212,7 @@ void main() { ...@@ -212,7 +212,7 @@ void main() {
stdout: 'aarch64', stdout: 'aarch64',
)); ));
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64); expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
...@@ -226,7 +226,7 @@ void main() { ...@@ -226,7 +226,7 @@ void main() {
stdout: 'x86_64', stdout: 'x86_64',
)); ));
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.targetPlatform, TargetPlatform.fuchsia_x64); expect(await device.targetPlatform, TargetPlatform.fuchsia_x64);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
...@@ -240,7 +240,7 @@ void main() { ...@@ -240,7 +240,7 @@ void main() {
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22', stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
)); ));
final FuchsiaDevice device = FuchsiaDevice('id'); final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
expect(await device.hostAddress, 'fe80::8c6c:2fff:fe3d:c5e1%25ethp0003'); expect(await device.hostAddress, 'fe80::8c6c:2fff:fe3d:c5e1%25ethp0003');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
...@@ -254,7 +254,7 @@ void main() { ...@@ -254,7 +254,7 @@ void main() {
exitCode: 1, exitCode: 1,
)); ));
final FuchsiaDevice device = FuchsiaDevice('id'); final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
await expectLater(() => device.hostAddress, throwsToolExit()); await expectLater(() => device.hostAddress, throwsToolExit());
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
...@@ -267,7 +267,7 @@ void main() { ...@@ -267,7 +267,7 @@ void main() {
command: <String>['ssh', '-F', '/ssh_config', 'id', r'echo $SSH_CONNECTION'], command: <String>['ssh', '-F', '/ssh_config', 'id', r'echo $SSH_CONNECTION'],
)); ));
final FuchsiaDevice device = FuchsiaDevice('id'); final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
expect(() async => device.hostAddress, throwsToolExit()); expect(() async => device.hostAddress, throwsToolExit());
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
...@@ -289,7 +289,7 @@ void main() { ...@@ -289,7 +289,7 @@ void main() {
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/artifact', 'id', 'find /hub -name vmservice-port'], command: <String>['ssh', '-F', '/artifact', 'id', 'find /hub -name vmservice-port'],
)); ));
final FuchsiaDevice device = FuchsiaDevice('id'); final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
await expectLater(device.servicePorts, throwsToolExit(message: 'No Dart Observatories found. Are you running a debug build?')); await expectLater(device.servicePorts, throwsToolExit(message: 'No Dart Observatories found. Are you running a debug build?'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -766,7 +766,7 @@ void main() { ...@@ -766,7 +766,7 @@ void main() {
}); });
testUsingContext('does not throw on non-existent ssh config', () async { testUsingContext('does not throw on non-existent ssh config', () async {
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.sdkNameAndVersion, equals('Fuchsia')); expect(await device.sdkNameAndVersion, equals('Fuchsia'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -780,7 +780,7 @@ void main() { ...@@ -780,7 +780,7 @@ void main() {
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'], command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
stdout: 'version' stdout: 'version'
)); ));
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.sdkNameAndVersion, equals('Fuchsia version')); expect(await device.sdkNameAndVersion, equals('Fuchsia version'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -794,7 +794,7 @@ void main() { ...@@ -794,7 +794,7 @@ void main() {
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'], command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
exitCode: 1, exitCode: 1,
)); ));
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.sdkNameAndVersion, equals('Fuchsia')); expect(await device.sdkNameAndVersion, equals('Fuchsia'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -807,7 +807,7 @@ void main() { ...@@ -807,7 +807,7 @@ void main() {
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'], command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
)); ));
final FuchsiaDevice device = FuchsiaDevice('123'); final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.sdkNameAndVersion, equals('Fuchsia')); expect(await device.sdkNameAndVersion, equals('Fuchsia'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
......
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