Unverified Commit f707f6f6 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] add flutterRoot field to JSON machine output (#62053)

parent d053a4d0
...@@ -317,7 +317,11 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -317,7 +317,11 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.flutterVersion.fetchTagsAndUpdate(); globals.flutterVersion.fetchTagsAndUpdate();
String status; String status;
if (machineFlag) { if (machineFlag) {
status = const JsonEncoder.withIndent(' ').convert(globals.flutterVersion.toJson()); final Map<String, Object> jsonOut = globals.flutterVersion.toJson();
if (jsonOut != null) {
jsonOut['flutterRoot'] = Cache.flutterRoot;
}
status = const JsonEncoder.withIndent(' ').convert(jsonOut);
} else { } else {
status = globals.flutterVersion.toString(); status = globals.flutterVersion.toString();
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:convert';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/features.dart';
...@@ -128,4 +130,21 @@ void main() { ...@@ -128,4 +130,21 @@ void main() {
// Only printed by verbose tool. // Only printed by verbose tool.
expect(result.stdout, isNot(contains('exiting with code 0'))); expect(result.stdout, isNot(contains('exiting with code 0')));
}); });
test('flutter --version --machine outputs JSON with flutterRoot', () async {
final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await const LocalProcessManager().run(<String>[
flutterBin,
'--version',
'--machine',
]);
final Map<String, Object> versionInfo = json.decode(result.stdout
.toString()
.replaceAll('Building flutter tool...', '')
.replaceAll('Waiting for another flutter command to release the startup lock...', '')
.trim()) as Map<String, Object>;
expect(versionInfo, containsPair('flutterRoot', isNotNull));
});
} }
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