simplify toolchain setup

This commit is contained in:
Devon Carew 2016-04-04 13:10:56 -07:00
parent 73bee3ae29
commit 653566dd23
17 changed files with 20 additions and 79 deletions

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
@ -118,7 +117,7 @@ class ApplicationPackageStore {
}
}
static Future<ApplicationPackageStore> forConfigs(List<BuildConfiguration> configs) async {
static ApplicationPackageStore forConfigs(List<BuildConfiguration> configs) {
AndroidApk android;
IOSApp iOS;

View File

@ -185,8 +185,6 @@ class BuildApkCommand extends FlutterCommand {
return 1;
}
await downloadToolchain();
// TODO(devoncarew): This command should take an arg for the output type (arm / x64).
return await buildAndroid(

View File

@ -40,10 +40,7 @@ class BuildFlxCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
String compilerPath = argResults['compiler'];
if (compilerPath == null)
await downloadToolchain();
else
if (compilerPath != null)
toolchain = new Toolchain(compiler: new SnapshotCompiler(compilerPath));
String outputPath = argResults['output-file'];

View File

@ -31,13 +31,6 @@ class BuildIOSCommand extends FlutterCommand {
return 1;
}
printTrace('Ensuring toolchains are up to date.');
await Future.wait([
downloadToolchain(),
downloadApplicationPackages(),
], eagerError: true);
IOSApp app = applicationPackages.iOS;
if (app == null) {

View File

@ -262,11 +262,6 @@ class AppDomain extends Domain {
Directory.current = new Directory(projectDirectory);
try {
await Future.wait([
command.downloadToolchain(),
command.downloadApplicationPackages(),
], eagerError: true);
int result = await startApp(
device,
command.applicationPackages,
@ -304,11 +299,6 @@ class AppDomain extends Domain {
Directory.current = new Directory(projectDirectory);
try {
await Future.wait([
command.downloadToolchain(),
command.downloadApplicationPackages(),
], eagerError: true);
ApplicationPackage app = command.applicationPackages.getPackageForPlatform(device.platform);
return device.stopApp(app);
} finally {

View File

@ -80,8 +80,6 @@ class DriveCommand extends RunCommandBase {
@override
Future<int> runInProject() async {
await toolchainDownloader(this);
String testFile = _getTestFile();
if (testFile == null) {
return 1;
@ -311,18 +309,3 @@ Future<int> stopApp(DriveCommand command) async {
bool stopped = await command.device.stopApp(package);
return stopped ? 0 : 1;
}
/// Downloads Flutter toolchain.
typedef Future<Null> ToolchainDownloader(DriveCommand command);
ToolchainDownloader toolchainDownloader = downloadToolchain;
void restoreToolchainDownloader() {
toolchainDownloader = downloadToolchain;
}
Future<Null> downloadToolchain(DriveCommand command) async {
printTrace('Downloading toolchain.');
await Future.wait([
command.downloadToolchain(),
command.downloadApplicationPackages(),
], eagerError: true);
}

View File

@ -21,8 +21,6 @@ class InstallCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
await downloadApplicationPackages();
Device device = deviceForCommand;
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);

View File

@ -32,9 +32,6 @@ class ListenCommand extends RunCommandBase {
@override
Future<int> runInProject() async {
await downloadApplicationPackages();
await downloadToolchain();
Iterable<String> directories = () sync* {
yield* argResults.rest;
yield '.';

View File

@ -34,13 +34,6 @@ class RefreshCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
printTrace('Downloading toolchain.');
await Future.wait([
downloadToolchain(),
downloadApplicationPackages(),
], eagerError: true);
Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools');
try {
String snapshotPath = path.join(tempDir.path, 'snapshot_blob.bin');

View File

@ -94,13 +94,6 @@ class RunCommand extends RunCommandBase {
@override
Future<int> runInProject() async {
printTrace('Downloading toolchain.');
await Future.wait([
downloadToolchain(),
downloadApplicationPackages(),
], eagerError: true);
bool clearLogs = argResults['clear-logs'];
int debugPort;

View File

@ -162,8 +162,6 @@ class RunMojoCommand extends FlutterCommand {
return 1;
}
await downloadToolchain();
String targetApp = argResults['app'];
if (targetApp == null) {
targetApp = _kDefaultBundlePath;

View File

@ -21,7 +21,6 @@ class StopCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
await downloadApplicationPackages();
Device device = deviceForCommand;
ApplicationPackage app = applicationPackages.getPackageForPlatform(device.platform);
printStatus('Stopping apps on ${device.name}.');

View File

@ -38,8 +38,6 @@ class TraceCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
await downloadApplicationPackages();
ApplicationPackage androidApp = applicationPackages.android;
AndroidDevice device = deviceForCommand;

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:path/path.dart' as path;
import '../base/process.dart';
@ -9,21 +11,22 @@ import '../base/process.dart';
const String kCFBundleIdentifierKey = "CFBundleIdentifier";
String getValueFromFile(String plistFilePath, String key) {
// TODO(chinmaygarde): For now, we only need to read from plist files on a
// mac host. If this changes, we will need our own Dart plist reader.
// TODO(chinmaygarde): For now, we only need to read from plist files on a mac
// host. If this changes, we will need our own Dart plist reader.
// Don't use PlistBuddy since that is not guaranteed to be installed.
// 'defaults' requires the path to be absolute and without the 'plist'
// extension.
if (!FileSystemEntity.isFileSync(plistFilePath))
return null;
String normalizedPlistPath = path.withoutExtension(path.absolute(plistFilePath));
try {
String value = runCheckedSync(<String>[
'/usr/bin/defaults',
'read',
normalizedPlistPath,
key
]).trim();
'/usr/bin/defaults', 'read', normalizedPlistPath, key
]);
return value.isEmpty ? null : value;
} catch (error) {
return null;

View File

@ -58,12 +58,12 @@ abstract class FlutterCommand extends Command {
_usesPubOption = true;
}
Future<Null> downloadToolchain() async {
toolchain ??= await Toolchain.forConfigs(buildConfigurations);
void _setupToolchain() {
toolchain ??= Toolchain.forConfigs(buildConfigurations);
}
Future<Null> downloadApplicationPackages() async {
applicationPackages ??= await ApplicationPackageStore.forConfigs(buildConfigurations);
void _setupApplicationPackages() {
applicationPackages ??= ApplicationPackageStore.forConfigs(buildConfigurations);
}
@override
@ -126,6 +126,9 @@ abstract class FlutterCommand extends Command {
return exitCode;
}
_setupToolchain();
_setupApplicationPackages();
return await runInProject();
}

View File

@ -57,7 +57,7 @@ class Toolchain {
final SnapshotCompiler compiler;
static Future<Toolchain> forConfigs(List<BuildConfiguration> configs) async {
static Toolchain forConfigs(List<BuildConfiguration> configs) {
for (BuildConfiguration config in configs) {
String compilerPath = _getCompilerPath(config);
if (compilerPath != null)

View File

@ -35,7 +35,6 @@ void main() {
command = new DriveCommand();
applyMocksToCommand(command);
useInMemoryFileSystem(cwd: '/some/app');
toolchainDownloader = (_) async { };
targetDeviceFinder = () {
throw 'Unexpected call to targetDeviceFinder';
};