Chromium Code Reviews| Index: tools/migration/bin/migrate_batch.dart |
| diff --git a/tools/migration/bin/migrate_batch.dart b/tools/migration/bin/migrate_batch.dart |
| index 43fe1c0d4a42cf2aa703f6583130858a96bbfe0f..4e99917e2b2229af764fc305eafdaa8159d8f301 100644 |
| --- a/tools/migration/bin/migrate_batch.dart |
| +++ b/tools/migration/bin/migrate_batch.dart |
| @@ -13,6 +13,7 @@ import 'dart:io'; |
| import 'package:path/path.dart' as p; |
| import 'package:migration/src/log.dart'; |
| +import 'package:migration/src/validate.dart'; |
| import 'package:status_file/status_file.dart'; |
| const simpleDirs = const ["corelib", "language", "lib"]; |
| @@ -72,20 +73,33 @@ void main(List<String> arguments) { |
| "to ${bold(last)}..."); |
| print(""); |
| - tests = tests.getRange(startIndex, endIndex); |
| - var todos = <String>[]; |
| + var allTodos = <String, List<String>>{}; |
| + tests = tests.sublist(startIndex, endIndex); |
| var migratedTests = 0; |
| var unmigratedTests = 0; |
| for (var test in tests) { |
| - if (test.migrate(todos)) { |
| + var todos = test.migrate(); |
| + if (todos.isEmpty) { |
| migratedTests++; |
| } else { |
| unmigratedTests++; |
| + allTodos[test.twoPath] = todos; |
| } |
| } |
| - print(""); |
| + // Print status file entries. |
| + var statusFileEntries = new StringBuffer(); |
| + var statusFiles = loadStatusFiles(); |
| + for (var statusFile in statusFiles) { |
| + printStatusFileEntries(statusFileEntries, tests, statusFile); |
| + } |
| + new File("statuses.migration") |
| + .writeAsStringSync(statusFileEntries.toString()); |
| + print("Wrote relevant test status file entries to 'statuses.migration'."); |
| + |
| + // Tell the user what's left TODO. |
| + print(""); |
| var summary = ""; |
| if (migratedTests > 0) { |
| @@ -94,24 +108,17 @@ void main(List<String> arguments) { |
| } |
| if (unmigratedTests > 0) { |
| - var s = migratedTests == 1 ? "" : "s"; |
| + var s = unmigratedTests == 1 ? "" : "s"; |
| summary += "Need manual work on ${red(unmigratedTests)} test$s:"; |
| } |
| print(summary); |
| - todos.forEach(todo); |
| - |
| - // Print status file entries. |
| - var statusFileEntries = new StringBuffer(); |
| - var statusFiles = loadStatusFiles(); |
| - for (var statusFile in statusFiles) { |
| - printStatusFileEntries(statusFileEntries, tests, statusFile); |
| + var todoTests = allTodos.keys.toList(); |
| + todoTests.sort(); |
| + for (var todoTest in todoTests) { |
| + print("- ${bold(todoTest)}:"); |
| + allTodos[todoTest].forEach(todo); |
| } |
| - |
| - new File("statuses.migration") |
| - .writeAsStringSync(statusFileEntries.toString()); |
| - print( |
| - bold("Wrote relevant test status file entries to 'statuses.migration'")); |
| } |
| /// Returns a [String] of the relevant status file entries associated with the |
| @@ -241,6 +248,9 @@ void moveFile(String from, String to) { |
| return; |
| } |
| + // Create the directory if needed. |
| + new Directory(p.dirname(p.join(testRoot, to))).createSync(recursive: true); |
|
bkonyi
2017/07/26 17:59:26
Nice! I just ran into this case.
|
| + |
| new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to)); |
| } |
| @@ -260,13 +270,6 @@ void deleteFile(String path) { |
| new File(p.join(testRoot, path)).deleteSync(); |
| } |
| -bool checkForUnitTest(String path, String source) { |
| - if (!source.contains("package:unittest")) return false; |
| - |
| - note("${bold(path)} uses unittest package."); |
| - return true; |
| -} |
| - |
| class Fork { |
| final String twoPath; |
| String onePath; |
| @@ -298,10 +301,10 @@ class Fork { |
| Fork(this.twoPath); |
| - bool migrate(List<String> todos) { |
| + List<String> migrate() { |
| print("- ${bold(twoPath)}:"); |
| - var todosBefore = todos.length; |
| + var todos = <String>[]; |
| var isMigrated = new File(p.join(testRoot, twoPath)).existsSync(); |
| // If there is a migrated version and it's the same as an unmigrated one, |
| @@ -314,8 +317,8 @@ class Fork { |
| } else { |
| note("${bold(onePath)} does not match already-migrated " |
| "${bold(twoPath)}."); |
| - todos.add("Merge ${bold(onePath)} into ${bold(twoPath)}."); |
| - checkForUnitTest(onePath, oneSource); |
| + todos.add("Merge from ${bold(onePath)} into this file."); |
| + validateFile(onePath, oneSource); |
| } |
| } |
| @@ -326,8 +329,8 @@ class Fork { |
| } else { |
| note("${bold(strongPath)} does not match already-migrated " |
| "${bold(twoPath)}."); |
| - todos.add("Merge ${bold(strongPath)} into ${bold(twoPath)}."); |
| - checkForUnitTest(strongPath, strongSource); |
| + todos.add("Merge from ${bold(strongPath)} into this file."); |
| + validateFile(strongPath, strongSource); |
| } |
| } |
| } else { |
| @@ -343,20 +346,19 @@ class Fork { |
| moveFile(onePath, twoPath); |
| deleteFile(strongPath); |
| done("Merged identical forks."); |
| - checkForUnitTest(twoPath, oneSource); |
| + validateFile(twoPath, oneSource); |
| } else { |
| // Otherwise, a manual merge is required. Start with the strong one. |
| + print(new File(strongPath).existsSync()); |
| moveFile(strongPath, twoPath); |
| done("Moved strong fork, kept 1.0 fork, manual merge required."); |
| - todos.add("Merge ${bold(onePath)} into ${bold(twoPath)}."); |
| - checkForUnitTest(onePath, oneSource); |
| + todos.add("Merge from ${bold(onePath)} into this file."); |
| + validateFile(onePath, oneSource); |
| } |
| } |
| - if (checkForUnitTest(twoPath, twoSource)) { |
| - todos.add("Migrate ${bold(twoPath)} off unittest."); |
| - } |
| + validateFile(twoPath, twoSource, todos); |
| - return todos.length == todosBefore; |
| + return todos; |
| } |
| } |