Commit 0d21e69b authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix flutter upgrade and flutter build ios (#4564)

* Fix `flutter upgrade`

* Fix builds on iOS
parent 0f1132f9
...@@ -10,16 +10,26 @@ import '../globals.dart'; ...@@ -10,16 +10,26 @@ import '../globals.dart';
typedef String StringConverter(String string); typedef String StringConverter(String string);
// TODO(ianh): We have way too many ways to run subprocesses in this project.
Map<String, String> _environment(bool allowReentrantFlutter) {
return allowReentrantFlutter ? <String, String>{ 'FLUTTER_ALREADY_LOCKED': 'true' } : null;
}
/// This runs the command in the background from the specified working /// This runs the command in the background from the specified working
/// directory. Completes when the process has been started. /// directory. Completes when the process has been started.
Future<Process> runCommand(List<String> cmd, { String workingDirectory }) async { Future<Process> runCommand(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false
}) async {
printTrace(cmd.join(' ')); printTrace(cmd.join(' '));
String executable = cmd[0]; String executable = cmd[0];
List<String> arguments = cmd.length > 1 ? cmd.sublist(1) : <String>[]; List<String> arguments = cmd.length > 1 ? cmd.sublist(1) : <String>[];
Process process = await Process.start( Process process = await Process.start(
executable, executable,
arguments, arguments,
workingDirectory: workingDirectory workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter)
); );
return process; return process;
} }
...@@ -28,12 +38,17 @@ Future<Process> runCommand(List<String> cmd, { String workingDirectory }) async ...@@ -28,12 +38,17 @@ Future<Process> runCommand(List<String> cmd, { String workingDirectory }) async
/// this process' stdout/stderr. Completes with the process's exit code. /// this process' stdout/stderr. Completes with the process's exit code.
Future<int> runCommandAndStreamOutput(List<String> cmd, { Future<int> runCommandAndStreamOutput(List<String> cmd, {
String workingDirectory, String workingDirectory,
bool allowReentrantFlutter: false,
String prefix: '', String prefix: '',
bool trace: false, bool trace: false,
RegExp filter, RegExp filter,
StringConverter mapFunction StringConverter mapFunction
}) async { }) async {
Process process = await runCommand(cmd, workingDirectory: workingDirectory); Process process = await runCommand(
cmd,
workingDirectory: workingDirectory,
allowReentrantFlutter: allowReentrantFlutter
);
process.stdout process.stdout
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
...@@ -73,42 +88,30 @@ Future<Null> runAndKill(List<String> cmd, Duration timeout) { ...@@ -73,42 +88,30 @@ Future<Null> runAndKill(List<String> cmd, Duration timeout) {
Future<Process> runDetached(List<String> cmd) { Future<Process> runDetached(List<String> cmd) {
printTrace(cmd.join(' ')); printTrace(cmd.join(' '));
Future<Process> proc = Process.start( Future<Process> proc = Process.start(
cmd[0], cmd.getRange(1, cmd.length).toList(), cmd[0], cmd.getRange(1, cmd.length).toList(),
mode: ProcessStartMode.DETACHED); mode: ProcessStartMode.DETACHED
return proc;
}
/// Run cmd and return stdout.
///
/// Throws an error if cmd exits with a non-zero value.
String runCheckedSync(List<String> cmd, {
String workingDirectory, bool truncateCommand: false
}) {
return _runWithLoggingSync(
cmd, workingDirectory: workingDirectory, checked: true, noisyErrors: true, truncateCommand: truncateCommand
); );
return proc;
} }
Future<RunResult> runAsync(List<String> cmd, { String workingDirectory }) async { Future<RunResult> runAsync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false
}) async {
printTrace(cmd.join(' ')); printTrace(cmd.join(' '));
ProcessResult results = await Process.run( ProcessResult results = await Process.run(
cmd[0], cmd[0],
cmd.getRange(1, cmd.length).toList(), cmd.getRange(1, cmd.length).toList(),
workingDirectory: workingDirectory workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter)
); );
RunResult runResults = new RunResult(results); RunResult runResults = new RunResult(results);
printTrace(runResults.toString()); printTrace(runResults.toString());
return runResults; return runResults;
} }
/// Run cmd and return stdout.
String runSync(List<String> cmd, { String workingDirectory }) {
return _runWithLoggingSync(cmd, workingDirectory: workingDirectory);
}
bool exitsHappy(List<String> cli) { bool exitsHappy(List<String> cli) {
printTrace(cli.join(' ')); printTrace(cli.join(' '));
try { try {
return Process.runSync(cli.first, cli.sublist(1)).exitCode == 0; return Process.runSync(cli.first, cli.sublist(1)).exitCode == 0;
} catch (error) { } catch (error) {
...@@ -116,18 +119,53 @@ bool exitsHappy(List<String> cli) { ...@@ -116,18 +119,53 @@ bool exitsHappy(List<String> cli) {
} }
} }
/// Run cmd and return stdout.
///
/// Throws an error if cmd exits with a non-zero value.
String runCheckedSync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false,
bool truncateCommand: false
}) {
return _runWithLoggingSync(
cmd,
workingDirectory: workingDirectory,
allowReentrantFlutter: allowReentrantFlutter,
checked: true,
noisyErrors: true,
truncateCommand: truncateCommand
);
}
/// Run cmd and return stdout.
String runSync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false
}) {
return _runWithLoggingSync(
cmd,
workingDirectory: workingDirectory,
allowReentrantFlutter: allowReentrantFlutter
);
}
String _runWithLoggingSync(List<String> cmd, { String _runWithLoggingSync(List<String> cmd, {
bool checked: false, bool checked: false,
bool noisyErrors: false, bool noisyErrors: false,
String workingDirectory, String workingDirectory,
bool allowReentrantFlutter: false,
bool truncateCommand: false bool truncateCommand: false
}) { }) {
String cmdText = cmd.join(' '); String cmdText = cmd.join(' ');
if (truncateCommand && cmdText.length > 160) if (truncateCommand && cmdText.length > 160)
cmdText = cmdText.substring(0, 160) + '…'; cmdText = cmdText.substring(0, 160) + '…';
printTrace(cmdText); printTrace(cmdText);
ProcessResult results = ProcessResult results = Process.runSync(
Process.runSync(cmd[0], cmd.getRange(1, cmd.length).toList(), workingDirectory: workingDirectory); cmd[0],
cmd.getRange(1, cmd.length).toList(),
workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter)
);
printTrace('Exit code ${results.exitCode} from: ${cmd.join(' ')}'); printTrace('Exit code ${results.exitCode} from: ${cmd.join(' ')}');
......
...@@ -50,9 +50,13 @@ class UpgradeCommand extends FlutterCommand { ...@@ -50,9 +50,13 @@ class UpgradeCommand extends FlutterCommand {
// if necessary. // if necessary.
printStatus(''); printStatus('');
printStatus('Upgrading engine...'); printStatus('Upgrading engine...');
code = await runCommandAndStreamOutput(<String>[ code = await runCommandAndStreamOutput(
'bin/flutter', '--no-lock', '--no-color', 'precache' <String>[
], workingDirectory: Cache.flutterRoot); 'bin/flutter', '--no-color', 'precache'
],
workingDirectory: Cache.flutterRoot,
allowReentrantFlutter: true
);
printStatus(''); printStatus('');
printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString()); printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
......
...@@ -150,7 +150,11 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -150,7 +150,11 @@ Future<XcodeBuildResult> buildXcodeProject({
commands.addAll(<String>['-sdk', 'iphonesimulator', '-arch', 'x86_64']); commands.addAll(<String>['-sdk', 'iphonesimulator', '-arch', 'x86_64']);
} }
RunResult result = await runAsync(commands, workingDirectory: app.rootPath); RunResult result = await runAsync(
commands,
workingDirectory: app.rootPath,
allowReentrantFlutter: true
);
if (result.exitCode != 0) { if (result.exitCode != 0) {
if (result.stderr.isNotEmpty) if (result.stderr.isNotEmpty)
......
...@@ -48,11 +48,6 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -48,11 +48,6 @@ class FlutterCommandRunner extends CommandRunner {
negatable: true, negatable: true,
hide: !verboseHelp, hide: !verboseHelp,
help: 'Whether to use terminal colors.'); help: 'Whether to use terminal colors.');
argParser.addFlag('lock',
negatable: true,
hide: !verboseHelp,
help: 'Whether to lock the Flutter binary artifacts directory while running. (This prevents multiple simultaneous Flutter instances from colliding.)',
defaultsTo: true);
argParser.addFlag('suppress-analytics', argParser.addFlag('suppress-analytics',
negatable: false, negatable: false,
hide: !verboseHelp, hide: !verboseHelp,
...@@ -147,7 +142,7 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -147,7 +142,7 @@ class FlutterCommandRunner extends CommandRunner {
// enginePath's initialiser uses it). // enginePath's initialiser uses it).
Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root'])); Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
if (globalResults['lock']); if (Platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true')
await Cache.lock(); await Cache.lock();
if (globalResults['suppress-analytics']) if (globalResults['suppress-analytics'])
......
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