Unverified Commit 22f37641 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Track number of package dependencies in Flutter (#20831)

* Track number of package dependencies in Flutter

Relands #20774.

* Use evalFlutter instead of startProcess.

That way we don't need `flutter` on the PATH.
parent b7261586
...@@ -47,10 +47,7 @@ Future<double> findCostsForFile(File file) async { ...@@ -47,10 +47,7 @@ Future<double> findCostsForFile(File file) async {
return total; return total;
} }
const String _kBenchmarkKey = 'technical_debt_in_dollars'; Future<double> findCostsForRepo() async {
Future<Null> main() async {
await task(() async {
final Process git = await startProcess( final Process git = await startProcess(
'git', 'git',
<String>['ls-files', '--full-name', flutterDirectory.path], <String>['ls-files', '--full-name', flutterDirectory.path],
...@@ -62,9 +59,34 @@ Future<Null> main() async { ...@@ -62,9 +59,34 @@ Future<Null> main() async {
final int gitExitCode = await git.exitCode; final int gitExitCode = await git.exitCode;
if (gitExitCode != 0) if (gitExitCode != 0)
throw new Exception('git exit with unexpected error code $gitExitCode'); throw new Exception('git exit with unexpected error code $gitExitCode');
return total;
}
Future<int> countDependencies() async {
final List<String> lines = (await evalFlutter(
'update-packages',
options: <String>['--transitive-closure'],
)).split('\n');
final int count = lines.where((String line) => line.contains('->')).length;
if (count < 2) // we'll always have flutter and flutter_test, at least...
throw new Exception('"flutter update-packages --transitive-closure" returned bogus output:\n${lines.join("\n")}');
return count;
}
const String _kCostBenchmarkKey = 'technical_debt_in_dollars';
const String _kNumberOfDependenciesKey = 'dependencies_count';
Future<Null> main() async {
await task(() async {
return new TaskResult.success( return new TaskResult.success(
<String, dynamic>{_kBenchmarkKey: total}, <String, dynamic>{
benchmarkScoreKeys: <String>[_kBenchmarkKey], _kCostBenchmarkKey: await findCostsForRepo(),
_kNumberOfDependenciesKey: await countDependencies(),
},
benchmarkScoreKeys: <String>[
_kCostBenchmarkKey,
_kNumberOfDependenciesKey,
],
); );
}); });
} }
...@@ -265,7 +265,7 @@ Future<int> exec( ...@@ -265,7 +265,7 @@ Future<int> exec(
String executable, String executable,
List<String> arguments, { List<String> arguments, {
Map<String, String> environment, Map<String, String> environment,
bool canFail = false, bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
}) async { }) async {
final Process process = await startProcess(executable, arguments, environment: environment); final Process process = await startProcess(executable, arguments, environment: environment);
...@@ -300,7 +300,7 @@ Future<String> eval( ...@@ -300,7 +300,7 @@ Future<String> eval(
String executable, String executable,
List<String> arguments, { List<String> arguments, {
Map<String, String> environment, Map<String, String> environment,
bool canFail = false, bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
}) async { }) async {
final Process process = await startProcess(executable, arguments, environment: environment); final Process process = await startProcess(executable, arguments, environment: environment);
...@@ -332,7 +332,7 @@ Future<String> eval( ...@@ -332,7 +332,7 @@ Future<String> eval(
Future<int> flutter(String command, { Future<int> flutter(String command, {
List<String> options = const <String>[], List<String> options = const <String>[],
bool canFail = false, bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
Map<String, String> environment, Map<String, String> environment,
}) { }) {
final List<String> args = <String>[command]..addAll(options); final List<String> args = <String>[command]..addAll(options);
...@@ -343,7 +343,7 @@ Future<int> flutter(String command, { ...@@ -343,7 +343,7 @@ Future<int> flutter(String command, {
/// Runs a `flutter` command and returns the standard output as a string. /// Runs a `flutter` command and returns the standard output as a string.
Future<String> evalFlutter(String command, { Future<String> evalFlutter(String command, {
List<String> options = const <String>[], List<String> options = const <String>[],
bool canFail = false, bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
Map<String, String> environment, Map<String, String> environment,
}) { }) {
final List<String> args = <String>[command]..addAll(options); final List<String> args = <String>[command]..addAll(options);
......
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