Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1472)

Side by Side Diff: tools/migration/bin/migrate_batch.dart

Issue 2987633002: Added functionality to dump relevant status file entries to a single file to make it easier to see … (Closed)
Patch Set: Addressed additional comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/migration/.packages ('k') | tools/migration/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Given the beginning and ending file names in a batch, does as much automated 5 /// Given the beginning and ending file names in a batch, does as much automated
6 /// migration and possible and prints out the remaining manual steps required. 6 /// migration and possible and prints out the remaining manual steps required.
7 /// 7 ///
8 /// This should be safe to run, and safe to re-run on an in-progress chunk. 8 /// This should be safe to run, and safe to re-run on an in-progress chunk.
9 /// However, it has not been thoroughly tested, so run at your own risk. 9 /// However, it has not been thoroughly tested, so run at your own risk.
10 10
11 import 'dart:io'; 11 import 'dart:io';
12 12
13 import 'package:path/path.dart' as p; 13 import 'package:path/path.dart' as p;
14 14
15 import 'package:migration/src/log.dart'; 15 import 'package:migration/src/log.dart';
16 import 'package:status_file/status_file.dart';
16 17
17 const simpleDirs = const ["corelib", "language", "lib"]; 18 const simpleDirs = const ["corelib", "language", "lib"];
18 19
19 final String sdkRoot = 20 final String sdkRoot =
20 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), '../../../')); 21 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), '../../../'));
21 22
22 final String testRoot = p.join(sdkRoot, "tests"); 23 final String testRoot = p.join(sdkRoot, "tests");
23 24
24 bool dryRun = false; 25 bool dryRun = false;
25 26
(...skipping 29 matching lines...) Expand all
55 if (startIndex == -1 && tests[i].twoPath.compareTo(first) >= 0) { 56 if (startIndex == -1 && tests[i].twoPath.compareTo(first) >= 0) {
56 startIndex = i; 57 startIndex = i;
57 } 58 }
58 59
59 if (tests[i].twoPath.compareTo(last) > 0) { 60 if (tests[i].twoPath.compareTo(last) > 0) {
60 endIndex = i; 61 endIndex = i;
61 break; 62 break;
62 } 63 }
63 } 64 }
64 65
66 if ((endIndex - startIndex) == 0) {
67 print(bold("No tests to migrate."));
68 return;
69 }
70
65 print("Migrating ${bold(endIndex - startIndex)} tests from ${bold(first)} " 71 print("Migrating ${bold(endIndex - startIndex)} tests from ${bold(first)} "
66 "to ${bold(last)}..."); 72 "to ${bold(last)}...");
67 print(""); 73 print("");
68 74
75 tests = tests.getRange(startIndex, endIndex);
69 var todos = <String>[]; 76 var todos = <String>[];
70 var migratedTests = 0; 77 var migratedTests = 0;
71 var unmigratedTests = 0; 78 var unmigratedTests = 0;
72 for (var i = startIndex; i < endIndex; i++) { 79 for (var test in tests) {
73 if (tests[i].migrate(todos)) { 80 if (test.migrate(todos)) {
74 migratedTests++; 81 migratedTests++;
75 } else { 82 } else {
76 unmigratedTests++; 83 unmigratedTests++;
77 } 84 }
78 } 85 }
79 86
80 print(""); 87 print("");
81 88
82 var summary = ""; 89 var summary = "";
83 90
84 if (migratedTests > 0) { 91 if (migratedTests > 0) {
85 var s = migratedTests == 1 ? "" : "s"; 92 var s = migratedTests == 1 ? "" : "s";
86 summary += "Successfully migrated ${green(migratedTests)} test$s. "; 93 summary += "Successfully migrated ${green(migratedTests)} test$s. ";
87 } 94 }
88 95
89 if (unmigratedTests > 0) { 96 if (unmigratedTests > 0) {
90 var s = migratedTests == 1 ? "" : "s"; 97 var s = migratedTests == 1 ? "" : "s";
91 summary += "Need manual work on ${red(unmigratedTests)} test$s:"; 98 summary += "Need manual work on ${red(unmigratedTests)} test$s:";
92 } 99 }
93 100
94 print(summary); 101 print(summary);
95 todos.forEach(todo); 102 todos.forEach(todo);
103
104 // Print status file entries.
105 var statusFileEntries = new StringBuffer();
106 var statusFiles = loadStatusFiles();
107 for (var statusFile in statusFiles) {
108 printStatusFileEntries(statusFileEntries, tests, statusFile);
109 }
110
111 new File("statuses.migration")
112 .writeAsStringSync(statusFileEntries.toString());
113 print(
114 bold("Wrote relevant test status file entries to 'statuses.migration'"));
115 }
116
117 /// Returns a [String] of the relevant status file entries associated with the
118 /// tests in [tests] found in [statusFile].
119 void printStatusFileEntries(
120 StringBuffer statusFileEntries, List<Fork> tests, StatusFile statusFile) {
121 var filteredStatusFile = new StatusFile(statusFile.path);
122 var testNames = <String>[];
123 for (var test in tests) {
124 testNames.add(test.twoPath.split("/").last.split(".")[0]);
125 }
126 for (var section in statusFile.sections) {
127 StatusSection currentSection;
128 for (var entry in section.entries) {
129 for (var testName in testNames) {
130 if (entry.path.contains(testName)) {
131 if (currentSection == null) {
132 currentSection = new StatusSection(section.condition);
133 }
134 currentSection.entries.add(entry);
135 }
136 }
137 }
138 if (currentSection != null) {
139 filteredStatusFile.sections.add(currentSection);
140 }
141 }
142 if (!filteredStatusFile.isEmpty) {
143 statusFileEntries.writeln("Entries for status file ${statusFile.path}:");
144 statusFileEntries.writeln(filteredStatusFile);
145 }
96 } 146 }
97 147
98 String toTwoPath(String path) { 148 String toTwoPath(String path) {
99 // Allow eliding "_test" and/or ".dart" to make things more command-line 149 // Allow eliding "_test" and/or ".dart" to make things more command-line
100 // friendly. 150 // friendly.
101 if (!path.endsWith("_test.dart")) path += "_test.dart"; 151 if (!path.endsWith("_test.dart")) path += "_test.dart";
102 if (!path.endsWith(".dart")) path += ".dart"; 152 if (!path.endsWith(".dart")) path += ".dart";
103 153
104 for (var dir in simpleDirs) { 154 for (var dir in simpleDirs) {
105 if (p.isWithin(dir, path)) { 155 if (p.isWithin(dir, path)) {
(...skipping 24 matching lines...) Expand all
130 List<Fork> scanTests() { 180 List<Fork> scanTests() {
131 var tests = <String, Fork>{}; 181 var tests = <String, Fork>{};
132 182
133 addTestDirectory(String fromDir, String twoDir) { 183 addTestDirectory(String fromDir, String twoDir) {
134 for (var entry 184 for (var entry
135 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) { 185 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) {
136 if (!entry.path.endsWith("_test.dart")) continue; 186 if (!entry.path.endsWith("_test.dart")) continue;
137 187
138 var fromPath = p.relative(entry.path, from: testRoot); 188 var fromPath = p.relative(entry.path, from: testRoot);
139 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir)); 189 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir));
140
141 var fork = tests.putIfAbsent(twoPath, () => new Fork(twoPath)); 190 var fork = tests.putIfAbsent(twoPath, () => new Fork(twoPath));
142 if (fromDir.contains("_strong")) { 191 if (fromDir.contains("_strong")) {
143 fork.strongPath = fromPath; 192 fork.strongPath = fromPath;
144 } else { 193 } else {
145 fork.onePath = fromPath; 194 fork.onePath = fromPath;
146 } 195 }
147 } 196 }
148 } 197 }
149 198
150 addTestDirectory("corelib", "corelib_2"); 199 addTestDirectory("corelib", "corelib_2");
151 addTestDirectory("corelib_strong", "corelib_2"); 200 addTestDirectory("corelib_strong", "corelib_2");
152 addTestDirectory("html", "lib_2/html"); 201 addTestDirectory("html", "lib_2/html");
153 addTestDirectory("isolate", "lib_2/isolate"); 202 addTestDirectory("isolate", "lib_2/isolate");
154 addTestDirectory("language", "language_2"); 203 addTestDirectory("language", "language_2");
155 addTestDirectory("language_strong", "language_2"); 204 addTestDirectory("language_strong", "language_2");
156 addTestDirectory("lib", "lib_2"); 205 addTestDirectory("lib", "lib_2");
157 addTestDirectory("lib_strong", "lib_2"); 206 addTestDirectory("lib_strong", "lib_2");
158 207
159 var sorted = tests.values.toList(); 208 var sorted = tests.values.toList();
160 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath)); 209 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath));
161 return sorted; 210 return sorted;
162 } 211 }
163 212
213 List<StatusFile> loadStatusFiles() {
214 var statusFiles = <StatusFile>[];
215
216 addStatusFile(String fromDir) {
217 for (var entry
218 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) {
219 if (!entry.path.endsWith(".status")) continue;
220
221 statusFiles.add(new StatusFile.read(entry.path));
222 }
223 }
224
225 addStatusFile("corelib");
226 addStatusFile("corelib_strong");
227 addStatusFile("html");
228 addStatusFile("isolate");
229 addStatusFile("language");
230 addStatusFile("language_strong");
231 addStatusFile("lib");
232 addStatusFile("lib_strong");
233 return statusFiles;
234 }
235
164 /// Moves the file from [from] to [to], which are both assumed to be relative 236 /// Moves the file from [from] to [to], which are both assumed to be relative
165 /// paths inside "tests". 237 /// paths inside "tests".
166 void moveFile(String from, String to) { 238 void moveFile(String from, String to) {
167 if (dryRun) { 239 if (dryRun) {
168 print(" Dry run: move $from to $to"); 240 print(" Dry run: move $from to $to");
169 return; 241 return;
170 } 242 }
171 243
172 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to)); 244 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to));
173 } 245 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 353 }
282 } 354 }
283 355
284 if (checkForUnitTest(twoPath, twoSource)) { 356 if (checkForUnitTest(twoPath, twoSource)) {
285 todos.add("Migrate ${bold(twoPath)} off unittest."); 357 todos.add("Migrate ${bold(twoPath)} off unittest.");
286 } 358 }
287 359
288 return todos.length == todosBefore; 360 return todos.length == todosBefore;
289 } 361 }
290 } 362 }
OLDNEW
« no previous file with comments | « tools/migration/.packages ('k') | tools/migration/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698