Unverified Commit dfecafa4 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool,fuchsia] Update the install flow for packaging migration. (#34447)

parent 81bbd3e1
......@@ -27,6 +27,12 @@ import 'fuchsia_pm.dart';
// -x: do not disable other active sources (if the provided source is
// enabled)
//
// add_repo_cfg - add a repository config to the set of known repositories,
// using a source config
// -n: name of the update source (optional, with URL)
// -f: file path or url to a source config file
// -h: SHA256 hash of source config file (optional, with URL)
//
// rm_src - remove a source, if it exists
// -n: name of the update source
//
......@@ -73,4 +79,31 @@ class FuchsiaAmberCtl {
await device.shell('amber_ctl get_up -n $packageName');
return result.exitCode == 0;
}
/// Converts the amber source config created when [server] was set up to a
/// pkg_resolver repo config, and teaches the pkg_resolver instance running
/// on [device] about the [FuchsiaPackageServer].
Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
final String configUrl = '${server.url}/config.json';
final RunResult result =
await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl');
return result.exitCode == 0;
}
/// Instructs the pkg_resolver instance running on [device] to prefetch the
/// package [packageName].
Future<bool> pkgCtlResolve(FuchsiaDevice device, FuchsiaPackageServer server,
String packageName) async {
final String packageUrl = 'fuchsia-pkg://${server.name}/$packageName';
final RunResult result = await device.shell('pkgctl resolve $packageUrl');
return result.exitCode == 0;
}
/// Instructs the pkg_resolver instance running on [device] to forget about
/// the Fuchsia package server that it was accessing via [serverUrl].
Future<bool> pkgCtlRepoRemove(FuchsiaDevice device, FuchsiaPackageServer server) async {
final String repoUrl = 'fuchsia-pkg://${server.name}';
final RunResult result = await device.shell('pkgctl repo remove --repo-url $repoUrl');
return result.exitCode == 0;
}
}
......@@ -265,7 +265,9 @@ class FuchsiaDevice extends Device {
}
// Start up a package server.
fuchsiaPackageServer = FuchsiaPackageServer(packageRepo.path, host, port);
const String packageServerName = 'flutter_tool';
fuchsiaPackageServer = FuchsiaPackageServer(
packageRepo.path, packageServerName, host, port);
if (!await fuchsiaPackageServer.start()) {
printError('Failed to start the Fuchsia package server');
return LaunchResult.failed();
......@@ -277,16 +279,17 @@ class FuchsiaDevice extends Device {
return LaunchResult.failed();
}
// Teach amber about the package server.
if (!await fuchsiaDeviceTools.amberCtl.addSrc(this, fuchsiaPackageServer)) {
// Teach the package controller about the package server.
if (!await fuchsiaDeviceTools.amberCtl.addRepoCfg(this, fuchsiaPackageServer)) {
printError('Failed to teach amber about the package server');
return LaunchResult.failed();
}
serverRegistered = true;
// Tell amber to prefetch the app.
if (!await fuchsiaDeviceTools.amberCtl.getUp(this, appName)) {
printError('Failed to get amber to prefetch the package');
// Tell the package controller to prefetch the app.
if (!await fuchsiaDeviceTools.amberCtl.pkgCtlResolve(
this, fuchsiaPackageServer, appName)) {
printError('Failed to get pkgctl to prefetch the package');
return LaunchResult.failed();
}
......@@ -298,15 +301,16 @@ class FuchsiaDevice extends Device {
// Instruct tiles_ctl to start the app.
final String fuchsiaUrl =
'fuchsia-pkg://fuchsia.com/$appName#meta/$appName.cmx';
'fuchsia-pkg://$packageServerName/$appName#meta/$appName.cmx';
if (!await fuchsiaDeviceTools.tilesCtl.add(this, fuchsiaUrl, <String>[])) {
printError('Failed to add the app to tiles');
return LaunchResult.failed();
}
} finally {
// Try to un-teach amber about the package server if needed.
// Try to un-teach the package controller about the package server if
// needed.
if (serverRegistered) {
await fuchsiaDeviceTools.amberCtl.rmSrc(this, fuchsiaPackageServer);
await fuchsiaDeviceTools.amberCtl.pkgCtlRepoRemove(this, fuchsiaPackageServer);
}
// Shutdown the package server and delete the package repo;
fuchsiaPackageServer?.stop();
......
......@@ -166,6 +166,7 @@ class FuchsiaPM {
/// Example usage:
/// var server = FuchsiaPackageServer(
/// '/path/to/repo',
/// 'server_name',
/// await FuchsiaDevFinder.resolve(deviceName),
/// await freshPort());
/// try {
......@@ -176,7 +177,7 @@ class FuchsiaPM {
/// server.stop();
/// }
class FuchsiaPackageServer {
FuchsiaPackageServer(this._repo, this._host, this._port);
FuchsiaPackageServer(this._repo, this.name, this._host, this._port);
final String _repo;
final String _host;
......@@ -187,6 +188,9 @@ class FuchsiaPackageServer {
/// The url that can be used by the device to access this package server.
String get url => 'http://$_host:$_port';
// The name used to reference the server by fuchsia-pkg:// urls.
final String name;
/// Usees [FuchiaPM.newrepo] and [FuchsiaPM.serve] to spin up a new Fuchsia
/// package server.
///
......
......@@ -695,6 +695,22 @@ class FakeFuchsiaAmberCtl implements FuchsiaAmberCtl {
Future<bool> getUp(FuchsiaDevice device, String packageName) async {
return true;
}
@override
Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
return true;
}
@override
Future<bool> pkgCtlResolve(FuchsiaDevice device, FuchsiaPackageServer server,
String packageName) async {
return true;
}
@override
Future<bool> pkgCtlRepoRemove(FuchsiaDevice device, FuchsiaPackageServer server) async {
return true;
}
}
class FailingAmberCtl implements FuchsiaAmberCtl {
......@@ -712,6 +728,22 @@ class FailingAmberCtl implements FuchsiaAmberCtl {
Future<bool> getUp(FuchsiaDevice device, String packageName) async {
return false;
}
@override
Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
return false;
}
@override
Future<bool> pkgCtlResolve(FuchsiaDevice device, FuchsiaPackageServer server,
String packageName) async {
return false;
}
@override
Future<bool> pkgCtlRepoRemove(FuchsiaDevice device, FuchsiaPackageServer server) async {
return false;
}
}
class FakeFuchsiaTilesCtl implements FuchsiaTilesCtl {
......
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