Commit 752e341d authored by Adam Barth's avatar Adam Barth

Merge pull request #449 from abarth/run_build

Make flutter run_mojo imply flutter build
parents 4d0520bb f6bd26a3
......@@ -9,6 +9,7 @@ import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import '../build_configuration.dart';
import '../file_system.dart';
import 'build.dart';
import 'flutter_command.dart';
import 'start.dart';
......@@ -20,13 +21,6 @@ const String _kKeystorePassword = "chromium";
final Logger _logging = new Logger('flutter_tools.apk');
/// Create the ancestor directories of a file path if they do not already exist.
void _ensureDirectoryExists(String filePath) {
Directory dir = new Directory(path.dirname(filePath));
if (!dir.existsSync())
dir.createSync(recursive: true);
}
/// Copies files into a new directory structure.
class _AssetBuilder {
final Directory outDir;
......@@ -40,7 +34,7 @@ class _AssetBuilder {
void add(File asset, String relativePath) {
String destPath = path.join(_assetDir.path, relativePath);
_ensureDirectoryExists(destPath);
ensureDirectoryExists(destPath);
asset.copySync(destPath);
}
......@@ -147,7 +141,7 @@ class ApkCommand extends FlutterCommand {
}
Directory tempDir = Directory.systemTemp.createTempSync('flutter_tools');
try {
try {
_AssetBuilder assetBuilder = new _AssetBuilder(tempDir, 'assets');
assetBuilder.add(icuData, 'icudtl.dat');
assetBuilder.add(new File(flxPath), 'app.flx');
......@@ -163,7 +157,7 @@ class ApkCommand extends FlutterCommand {
builder.sign(keystore, _kKeystorePassword, _kKeystoreKeyName, unalignedApk);
File finalApk = new File(argResults['output-file']);
_ensureDirectoryExists(finalApk.path);
ensureDirectoryExists(finalApk.path);
builder.align(unalignedApk, finalApk);
return 0;
......@@ -203,10 +197,10 @@ class ApkCommand extends FlutterCommand {
builder.inheritFromParent(this);
int result;
await builder.buildInTempDir(
mainPath: mainPath,
onBundleAvailable: (String localBundlePath) {
result = _buildApk(config, localBundlePath);
}
mainPath: mainPath,
onBundleAvailable: (String localBundlePath) {
result = _buildApk(config, localBundlePath);
}
);
return result;
......
......@@ -12,6 +12,7 @@ import 'package:flx/signing.dart';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
import '../file_system.dart';
import '../toolchain.dart';
import 'flutter_command.dart';
......@@ -109,8 +110,8 @@ ArchiveFile _createSnapshotFile(String snapshotPath) {
const String _kDefaultAssetBase = 'packages/material_design_icons/icons';
const String _kDefaultMainPath = 'lib/main.dart';
const String _kDefaultManifestPath = 'flutter.yaml';
const String _kDefaultOutputPath = 'app.flx';
const String _kDefaultSnapshotPath = 'snapshot_blob.bin';
const String _kDefaultOutputPath = 'build/app.flx';
const String _kDefaultSnapshotPath = 'build/snapshot_blob.bin';
const String _kDefaultPrivateKeyPath = 'privatekey.der';
class BuildCommand extends FlutterCommand {
......@@ -186,6 +187,8 @@ class BuildCommand extends FlutterCommand {
Archive archive = new Archive();
if (!precompiledSnapshot) {
ensureDirectoryExists(snapshotPath);
// In a precompiled snapshot, the instruction buffer contains script
// content equivalents
int result = await toolchain.compiler.compile(mainPath: mainPath, snapshotPath: snapshotPath);
......@@ -208,6 +211,7 @@ class BuildCommand extends FlutterCommand {
AsymmetricKeyPair keyPair = keyPairFromPrivateKeyFileSync(privateKeyPath);
Uint8List zipBytes = new Uint8List.fromList(new ZipEncoder().encode(archive));
ensureDirectoryExists(outputPath);
Bundle bundle = new Bundle.fromContent(
path: outputPath,
manifest: manifestDescriptor,
......
......@@ -11,7 +11,11 @@ import 'package:path/path.dart' as path;
import '../artifacts.dart';
import '../build_configuration.dart';
import '../process.dart';
import 'build.dart';
import 'flutter_command.dart';
import 'start.dart';
const String _kDefaultBundlePath = 'build/app.flx';
final Logger _logging = new Logger('flutter_tools.run_mojo');
......@@ -25,7 +29,11 @@ class RunMojoCommand extends FlutterCommand {
argParser.addFlag('mojo-debug', negatable: false, help: 'Use Debug build of mojo');
argParser.addFlag('mojo-release', negatable: false, help: 'Use Release build of mojo (default)');
argParser.addOption('app', defaultsTo: 'app.flx');
argParser.addOption('target',
defaultsTo: '',
abbr: 't',
help: 'Target app path or filename to start.');
argParser.addOption('app', help: 'Run this Flutter app instead of building the target.');
argParser.addOption('mojo-path', help: 'Path to directory containing mojo_shell and services.');
argParser.addOption('devtools-path', help: 'Path to mojo devtools\' mojo_run command.');
}
......@@ -72,7 +80,7 @@ class RunMojoCommand extends FlutterCommand {
return result;
}
Future<List<String>> _getShellConfig() async {
Future<List<String>> _getShellConfig(String bundlePath) async {
List<String> args = <String>[];
final bool useDevtools = _useDevtools();
......@@ -82,7 +90,7 @@ class RunMojoCommand extends FlutterCommand {
if (argResults['android']) {
args.add('--android');
final String cloudStorageBaseUrl = ArtifactStore.getCloudStorageBaseUrl('shell', 'android-arm');
final String appPath = _makePathAbsolute(argResults['app']);
final String appPath = _makePathAbsolute(bundlePath);
final String appName = path.basename(appPath);
final String appDir = path.dirname(appPath);
args.add('http://app/$appName');
......@@ -90,7 +98,7 @@ class RunMojoCommand extends FlutterCommand {
args.add('--map-origin=http://flutter/=$cloudStorageBaseUrl');
args.add('--url-mappings=mojo:flutter=http://flutter/flutter.mojo');
} else {
final String appPath = _makePathAbsolute(argResults['app']);
final String appPath = _makePathAbsolute(bundlePath);
String flutterPath;
BuildConfiguration config = _getCurrentHostConfig();
if (config == null || config.type == BuildType.prebuilt) {
......@@ -136,7 +144,21 @@ class RunMojoCommand extends FlutterCommand {
return 1;
}
return await runCommandAndStreamOutput(await _getShellConfig());
}
await downloadToolchain();
String bundlePath = argResults['app'];
if (bundlePath == null) {
bundlePath = _kDefaultBundlePath;
String mainPath = StartCommand.findMainDartFile(argResults['target']);
BuildCommand builder = new BuildCommand();
builder.inheritFromParent(this);
int result = await builder.build(mainPath: mainPath, outputPath: bundlePath);
if (result != 0)
return result;
}
return await runCommandAndStreamOutput(await _getShellConfig(bundlePath));
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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;
/// Create the ancestor directories of a file path if they do not already exist.
void ensureDirectoryExists(String filePath) {
String dirPath = path.dirname(filePath);
if (FileSystemEntity.isDirectorySync(dirPath))
return;
new Directory(dirPath).createSync(recursive: true);
}
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