From 17c1b910373e88e9bab7742bef45acec3fe3a121 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 19 Dec 2024 13:59:39 -0800 Subject: [PATCH] [monorepo] Fix tech debt cost benchmark (#160609) * delete null safety stuff since everything is migrated * Filter out engine subdirectory on listing of framework fies. --- .../bin/tasks/technical_debt__cost.dart | 38 +------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/dev/devicelab/bin/tasks/technical_debt__cost.dart b/dev/devicelab/bin/tasks/technical_debt__cost.dart index fe2827a63a..2c4bc541d5 100644 --- a/dev/devicelab/bin/tasks/technical_debt__cost.dart +++ b/dev/devicelab/bin/tasks/technical_debt__cost.dart @@ -9,8 +9,6 @@ import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/task_result.dart'; import 'package:flutter_devicelab/framework/utils.dart'; import 'package:path/path.dart' as path; -import 'package:pub_semver/pub_semver.dart'; -import 'package:pubspec_parse/pubspec_parse.dart'; // the numbers below are prime, so that the totals don't seem round. :-) const double todoCost = 1009.0; // about two average SWE days, in dollars @@ -22,8 +20,6 @@ const double ignoreForFileCost = 2477.0; // similar thinking as skipCost const double asDynamicCost = 2011.0; // a few days to refactor the code. const double deprecationCost = 233.0; // a few hours to remove the old code. const double legacyDeprecationCost = 9973.0; // a couple of weeks. -const double packageNullSafetyMigrationCost = 2017.0; // a few days to migrate package. -const double fileNullSafetyMigrationCost = 257.0; // a few hours to migrate file. final RegExp todoPattern = RegExp(r'(?://|#) *TODO'); final RegExp ignorePattern = RegExp(r'// *ignore:'); @@ -32,9 +28,6 @@ final RegExp asDynamicPattern = RegExp(r'\bas dynamic\b'); final RegExp deprecationPattern = RegExp(r'^ *@[dD]eprecated'); const Pattern globalsPattern = 'globals.'; const String legacyDeprecationPattern = '// flutter_ignore: deprecation_syntax, https'; -final RegExp dartVersionPattern = RegExp(r'// *@dart *= *(\d+).(\d+)'); - -final Version firstNullSafeDartVersion = Version(2, 12, 0); Future findCostsForFile(File file) async { if (path.extension(file.path) == '.py') { @@ -46,7 +39,6 @@ Future findCostsForFile(File file) async { return 0.0; } final bool isTest = file.path.endsWith('_test.dart'); - final bool isDart = file.path.endsWith('.dart'); double total = 0.0; for (final String line in await file.readAsLines()) { if (line.contains(todoPattern)) { @@ -70,38 +62,10 @@ Future findCostsForFile(File file) async { if (isTest && line.contains('skip:') && !line.contains('[intended]')) { total += skipCost; } - if (isDart && isOptingOutOfNullSafety(line)) { - total += fileNullSafetyMigrationCost; - } - } - if (path.basename(file.path) == 'pubspec.yaml' && !packageIsNullSafe(file)) { - total += packageNullSafetyMigrationCost; } return total; } -bool isOptingOutOfNullSafety(String line) { - final RegExpMatch? match = dartVersionPattern.firstMatch(line); - if (match == null) { - return false; - } - assert(match.groupCount == 2); - return Version(int.parse(match.group(1)!), int.parse(match.group(2)!), 0) < - firstNullSafeDartVersion; -} - -bool packageIsNullSafe(File file) { - assert(path.basename(file.path) == 'pubspec.yaml'); - final Pubspec pubspec = Pubspec.parse(file.readAsStringSync()); - final VersionConstraint? constraint = - pubspec.environment == null ? null : pubspec.environment!['sdk']; - final bool hasConstraint = constraint != null && !constraint.isAny && !constraint.isEmpty; - return hasConstraint && - constraint is VersionRange && - constraint.min != null && - Version(constraint.min!.major, constraint.min!.minor, 0) >= firstNullSafeDartVersion; -} - Future findGlobalsForFile(File file) async { if (path.extension(file.path) != '.dart') { return 0; @@ -118,6 +82,8 @@ Future findGlobalsForFile(File file) async { Future findCostsForRepo() async { final Process git = await startProcess('git', [ 'ls-files', + '--exclude', + 'engine', '--full-name', flutterDirectory.path, ], workingDirectory: flutterDirectory.path);