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