Commit 9cfa9660 authored by Devon Carew's avatar Devon Carew

dissallow -release mode on emulators (#4204)

* dissallow -release mode on emulators

* have the help text print the default mode
parent e4e3906c
...@@ -77,6 +77,7 @@ Future<Process> runDetached(List<String> cmd) { ...@@ -77,6 +77,7 @@ Future<Process> runDetached(List<String> cmd) {
} }
/// Run cmd and return stdout. /// Run cmd and return stdout.
///
/// Throws an error if cmd exits with a non-zero value. /// Throws an error if cmd exits with a non-zero value.
String runCheckedSync(List<String> cmd, { String runCheckedSync(List<String> cmd, {
String workingDirectory, bool truncateCommand: false String workingDirectory, bool truncateCommand: false
......
...@@ -39,6 +39,12 @@ String camelCase(String str) { ...@@ -39,6 +39,12 @@ String camelCase(String str) {
return str; return str;
} }
String toTitleCase(String str) {
if (str.isEmpty)
return str;
return str.substring(0, 1).toUpperCase() + str.substring(1);
}
/// Return the plural of the given word (`cat(s)`). /// Return the plural of the given word (`cat(s)`).
String pluralize(String word, int count) => count == 1 ? word : word + 's'; String pluralize(String word, int count) => count == 1 ? word : word + 's';
......
...@@ -27,6 +27,9 @@ bool isAotBuildMode(BuildMode mode) { ...@@ -27,6 +27,9 @@ bool isAotBuildMode(BuildMode mode) {
return mode == BuildMode.profile || mode == BuildMode.release; return mode == BuildMode.profile || mode == BuildMode.release;
} }
// Returns true if the given build mode can be used on emulators / simulators.
bool isEmulatorBuildMode(BuildMode mode) => mode == BuildMode.debug;
enum HostPlatform { enum HostPlatform {
darwin_x64, darwin_x64,
linux_x64, linux_x64,
......
...@@ -8,6 +8,7 @@ import 'dart:io'; ...@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../base/process.dart'; import '../base/process.dart';
import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../dart/sdk.dart'; import '../dart/sdk.dart';
import '../globals.dart'; import '../globals.dart';
...@@ -69,15 +70,39 @@ String _getSdkExtensionPath(String packagesPath, String package) { ...@@ -69,15 +70,39 @@ String _getSdkExtensionPath(String packagesPath, String package) {
return path.join(path.dirname(packageDir.resolveSymbolicLinksSync()), 'sdk_ext'); return path.join(path.dirname(packageDir.resolveSymbolicLinksSync()), 'sdk_ext');
} }
/// Build an AOT snapshot. Return `null` (and log to `printError`) if the method
/// fails.
String buildAotSnapshot( String buildAotSnapshot(
String mainPath, String mainPath,
TargetPlatform platform, TargetPlatform platform,
BuildMode buildMode, { BuildMode buildMode, {
String outputPath: _kDefaultAotOutputDir, String outputPath: _kDefaultAotOutputDir,
bool interpreter: false bool interpreter: false
}) {
try {
return _buildAotSnapshot(
mainPath,
platform,
buildMode,
outputPath: outputPath,
interpreter: interpreter
);
} on String catch (error) {
// Catch the String exceptions thrown from the `runCheckedSync` methods below.
printError(error);
return null;
}
}
String _buildAotSnapshot(
String mainPath,
TargetPlatform platform,
BuildMode buildMode, {
String outputPath: _kDefaultAotOutputDir,
bool interpreter: false
}) { }) {
if (!isAotBuildMode(buildMode)) { if (!isAotBuildMode(buildMode)) {
printError('${getModeName(buildMode)} mode does not support AOT compilation.'); printError('${toTitleCase(getModeName(buildMode))} mode does not support AOT compilation.');
return null; return null;
} }
...@@ -120,8 +145,7 @@ String buildAotSnapshot( ...@@ -120,8 +145,7 @@ String buildAotSnapshot(
String packagesPath = path.absolute(Directory.current.path, 'packages'); String packagesPath = path.absolute(Directory.current.path, 'packages');
if (!FileSystemEntity.isDirectorySync(packagesPath)) { if (!FileSystemEntity.isDirectorySync(packagesPath)) {
printStatus('Missing packages directory. Running `pub get` to work around\n' + printStatus('Missing packages directory; running `pub get` (to work around https://github.com/dart-lang/sdk/issues/26362).');
'https://github.com/dart-lang/sdk/issues/26362');
// We don't use [pubGet] because we explicitly want to avoid --no-package-symlinks. // We don't use [pubGet] because we explicitly want to avoid --no-package-symlinks.
runCheckedSync(<String>[sdkBinaryName('pub'), 'get', '--no-precompile']); runCheckedSync(<String>[sdkBinaryName('pub'), 'get', '--no-precompile']);
} }
...@@ -229,8 +253,10 @@ String buildAotSnapshot( ...@@ -229,8 +253,10 @@ String buildAotSnapshot(
genSnapshotCmd.add(mainPath); genSnapshotCmd.add(mainPath);
printStatus('Building snapshot...'); String typeName = path.basename(tools.getEngineArtifactsDirectory(platform, buildMode).path);
runCheckedSync(genSnapshotCmd); printStatus('Building snapshot in ${getModeName(buildMode)} mode ($typeName)...');
runCheckedSync(genSnapshotCmd, truncateCommand: true);
// On iOS, we use Xcode to compile the snapshot into a static library that the // On iOS, we use Xcode to compile the snapshot into a static library that the
// end-developer can link into their app. // end-developer can link into their app.
......
...@@ -22,7 +22,7 @@ import 'trace.dart'; ...@@ -22,7 +22,7 @@ import 'trace.dart';
abstract class RunCommandBase extends FlutterCommand { abstract class RunCommandBase extends FlutterCommand {
RunCommandBase() { RunCommandBase() {
addBuildModeFlags(); addBuildModeFlags(defaultToRelease: false);
argParser.addFlag('trace-startup', argParser.addFlag('trace-startup',
negatable: true, negatable: true,
...@@ -99,6 +99,11 @@ class RunCommand extends RunCommandBase { ...@@ -99,6 +99,11 @@ class RunCommand extends RunCommandBase {
} }
} }
if (deviceForCommand.isLocalEmulator && !isEmulatorBuildMode(getBuildMode())) {
printError('${toTitleCase(getModeName(getBuildMode()))} mode is not supported for emulators.');
return 1;
}
DebuggingOptions options; DebuggingOptions options;
if (getBuildMode() == BuildMode.release) { if (getBuildMode() == BuildMode.release) {
......
...@@ -43,6 +43,8 @@ abstract class FlutterCommand extends Command { ...@@ -43,6 +43,8 @@ abstract class FlutterCommand extends Command {
bool get shouldRunPub => _usesPubOption && argResults['pub']; bool get shouldRunPub => _usesPubOption && argResults['pub'];
BuildMode _defaultBuildMode;
void usesTargetOption() { void usesTargetOption() {
argParser.addOption('target', argParser.addOption('target',
abbr: 't', abbr: 't',
...@@ -58,29 +60,31 @@ abstract class FlutterCommand extends Command { ...@@ -58,29 +60,31 @@ abstract class FlutterCommand extends Command {
_usesPubOption = true; _usesPubOption = true;
} }
void addBuildModeFlags() { void addBuildModeFlags({ bool defaultToRelease: true }) {
_defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
argParser.addFlag('debug', argParser.addFlag('debug',
negatable: false, negatable: false,
help: 'Build a debug version of your app (the default).'); help: 'Build a debug version of your app${defaultToRelease ? '' : ' (default mode)'}.');
argParser.addFlag('profile', argParser.addFlag('profile',
negatable: false, negatable: false,
help: 'Build a profile (ahead of time compilation) version of your app.'); help: 'Build a version of your app specialized for performance profiling.');
argParser.addFlag('release', argParser.addFlag('release',
negatable: false, negatable: false,
help: 'Build a release version of your app.'); help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
} }
BuildMode getBuildMode() { BuildMode getBuildMode() {
List<bool> modeFlags = <bool>[argResults['debug'], argResults['profile'], argResults['release']]; List<bool> modeFlags = <bool>[argResults['debug'], argResults['profile'], argResults['release']];
if (modeFlags.where((bool flag) => flag).length > 1) if (modeFlags.where((bool flag) => flag).length > 1)
throw new UsageException('Only one of --debug, --profile, or --release should be specified.', null); throw new UsageException('Only one of --debug, --profile, or --release can be specified.', null);
if (argResults['debug'])
BuildMode mode = BuildMode.debug; return BuildMode.debug;
if (argResults['profile']) if (argResults['profile'])
mode = BuildMode.profile; return BuildMode.profile;
if (argResults['release']) if (argResults['release'])
mode = BuildMode.release; return BuildMode.release;
return mode; return _defaultBuildMode;
} }
void _setupApplicationPackages() { void _setupApplicationPackages() {
......
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