Unverified Commit b61cbc73 authored by Mehmet Fidanboylu's avatar Mehmet Fidanboylu Committed by GitHub

Add capability to print engine dart sdk to flutter doctor (#13085)

* Add capability to print engine dart sdk to flutter doctor

* First round of review comments

* second round of comments

* Final review comments
parent f44007c8
......@@ -8,10 +8,12 @@ import 'package:meta/meta.dart';
import 'base/context.dart';
import 'base/file_system.dart';
import 'base/io.dart';
import 'base/logger.dart';
import 'base/net.dart';
import 'base/os.dart';
import 'base/platform.dart';
import 'base/process_manager.dart';
import 'globals.dart';
/// A wrapper around the `bin/cache/` directory.
......@@ -105,21 +107,43 @@ class Cache {
}
}
static String _dartSdkVersion;
String _dartSdkVersion;
static String get dartSdkVersion => _dartSdkVersion ??= platform.version;
String get dartSdkVersion => _dartSdkVersion ??= platform.version;
static String _engineRevision;
String _engineRevision;
static String get engineRevision {
if (_engineRevision == null) {
final File revisionFile = fs.file(fs.path.join(flutterRoot, 'bin', 'internal', 'engine.version'));
if (revisionFile.existsSync())
_engineRevision = revisionFile.readAsStringSync().trim();
}
String get engineRevision {
_engineRevision ??= getVersionFor('engine');
return _engineRevision;
}
String _engineDartVersion;
String get engineDartVersion {
if (_engineDartVersion == null) {
final Directory engineDirectory = getArtifactDirectory('engine');
List<String> dartSdkBinParts;
if (platform.isLinux) {
dartSdkBinParts = <String>['linux-x64', 'dart-sdk', 'bin', 'dart'];
} else if (platform.isMacOS) {
dartSdkBinParts = <String>['darwin-x64', 'dart-sdk', 'bin', 'dart'];
} else if (platform.isWindows) {
dartSdkBinParts = <String>['windows-x64', 'dart-sdk', 'bin', 'dart.exe'];
} else {
// Unknown platform, we can't derive version.
return null;
}
final File dartSdkBin = engineDirectory.childFile(fs.path.joinAll(dartSdkBinParts));
final ProcessResult result = processManager.runSync(<String>[dartSdkBin.path, '--version']);
// https://github.com/dart-lang/sdk/issues/31481
// We can use the process utils directly when this is fixed instead of parsing stderr.
_engineDartVersion = result.stderr.trim().replaceAll('Dart VM version: ', '');
}
return _engineDartVersion;
}
static Cache get instance => context[Cache];
/// Return the top-level directory in the cache; this is `bin/cache`.
......@@ -144,7 +168,7 @@ class Cache {
/// Get a named directory from with the cache's artifact directory; for example,
/// `material_fonts` would return `bin/cache/artifacts/material_fonts`.
Directory getArtifactDirectory(String name) {
return fs.directory(fs.path.join(getCacheArtifacts().path, name));
return getCacheArtifacts().childDirectory(name);
}
String getVersionFor(String artifactName) {
......
......@@ -208,6 +208,7 @@ class _FlutterValidator extends DoctorValidator {
));
messages.add(new ValidationMessage('Engine revision ${version.engineRevisionShort}'));
messages.add(new ValidationMessage('Tools Dart version ${version.dartSdkVersion}'));
messages.add(new ValidationMessage('Engine Dart version ${version.engineDartVersion}'));
final String genSnapshotPath =
artifacts.getArtifactPath(Artifact.genSnapshot);
......
......@@ -65,9 +65,10 @@ class FlutterVersion {
String get frameworkDate => frameworkCommitDate;
String get dartSdkVersion => Cache.dartSdkVersion.split(' ')[0];
String get dartSdkVersion => Cache.instance.dartSdkVersion.split(' ')[0];
String get engineDartVersion => Cache.instance.engineDartVersion.split(' ')[0];
String get engineRevision => Cache.engineRevision;
String get engineRevision => Cache.instance.engineRevision;
String get engineRevisionShort => _shortGitRevision(engineRevision);
String _runGit(String command) => runSync(command.split(' '), workingDirectory: Cache.flutterRoot);
......
......@@ -61,6 +61,12 @@ void main() {
_expectVersionMessage('');
});
testFlutterVersion('prints non-empty version for engine Dart SDK', () async {
final FlutterVersion version = FlutterVersion.instance;
final String engineDartVersion = version.engineDartVersion;
expect(engineDartVersion.length, greaterThan(0));
});
testFlutterVersion('does not ping server when version stamp is up-to-date', () async {
final FlutterVersion version = FlutterVersion.instance;
......
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