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

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: Updated to use pkg:status_file, and updated to improve performance Created 3 years, 4 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 statusFileEntries.write(printStatusFileEntries(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 String printStatusFileEntries(List<Fork> tests, StatusFile statusFile) {
120 var statusFileEntries = new StringBuffer();
Bob Nystrom 2017/07/25 23:48:21 Instead of creating a new StringBuffer in each cal
bkonyi 2017/07/26 00:27:12 Done.
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 = null;
Bob Nystrom 2017/07/25 23:48:21 "= null" isn't needed. https://www.dartlang.org/g
bkonyi 2017/07/26 00:27:12 Done.
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.toString());
Bob Nystrom 2017/07/25 23:48:21 ".toString()" isn't needed. StringBuffer.writeln()
bkonyi 2017/07/26 00:27:12 Done.
145 }
146 return statusFileEntries.toString();
96 } 147 }
97 148
98 String toTwoPath(String path) { 149 String toTwoPath(String path) {
99 // Allow eliding "_test" and/or ".dart" to make things more command-line 150 // Allow eliding "_test" and/or ".dart" to make things more command-line
100 // friendly. 151 // friendly.
101 if (!path.endsWith("_test.dart")) path += "_test.dart"; 152 if (!path.endsWith("_test.dart")) path += "_test.dart";
102 if (!path.endsWith(".dart")) path += ".dart"; 153 if (!path.endsWith(".dart")) path += ".dart";
103 154
104 for (var dir in simpleDirs) { 155 for (var dir in simpleDirs) {
105 if (p.isWithin(dir, path)) { 156 if (p.isWithin(dir, path)) {
(...skipping 24 matching lines...) Expand all
130 List<Fork> scanTests() { 181 List<Fork> scanTests() {
131 var tests = <String, Fork>{}; 182 var tests = <String, Fork>{};
132 183
133 addTestDirectory(String fromDir, String twoDir) { 184 addTestDirectory(String fromDir, String twoDir) {
134 for (var entry 185 for (var entry
135 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) { 186 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) {
136 if (!entry.path.endsWith("_test.dart")) continue; 187 if (!entry.path.endsWith("_test.dart")) continue;
137 188
138 var fromPath = p.relative(entry.path, from: testRoot); 189 var fromPath = p.relative(entry.path, from: testRoot);
139 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir)); 190 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir));
140
141 var fork = tests.putIfAbsent(twoPath, () => new Fork(twoPath)); 191 var fork = tests.putIfAbsent(twoPath, () => new Fork(twoPath));
142 if (fromDir.contains("_strong")) { 192 if (fromDir.contains("_strong")) {
143 fork.strongPath = fromPath; 193 fork.strongPath = fromPath;
144 } else { 194 } else {
145 fork.onePath = fromPath; 195 fork.onePath = fromPath;
146 } 196 }
147 } 197 }
148 } 198 }
149 199
150 addTestDirectory("corelib", "corelib_2"); 200 addTestDirectory("corelib", "corelib_2");
151 addTestDirectory("corelib_strong", "corelib_2"); 201 addTestDirectory("corelib_strong", "corelib_2");
152 addTestDirectory("html", "lib_2/html"); 202 addTestDirectory("html", "lib_2/html");
153 addTestDirectory("isolate", "lib_2/isolate"); 203 addTestDirectory("isolate", "lib_2/isolate");
154 addTestDirectory("language", "language_2"); 204 addTestDirectory("language", "language_2");
155 addTestDirectory("language_strong", "language_2"); 205 addTestDirectory("language_strong", "language_2");
156 addTestDirectory("lib", "lib_2"); 206 addTestDirectory("lib", "lib_2");
157 addTestDirectory("lib_strong", "lib_2"); 207 addTestDirectory("lib_strong", "lib_2");
158 208
159 var sorted = tests.values.toList(); 209 var sorted = tests.values.toList();
160 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath)); 210 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath));
161 return sorted; 211 return sorted;
162 } 212 }
163 213
214 List<StatusFile> loadStatusFiles() {
215 var statusFiles = <String, List<StatusFile>>{};
Bob Nystrom 2017/07/25 23:48:21 Looks like my suggestion was wrong and you don't a
bkonyi 2017/07/26 00:27:12 Done.
216
217 addStatusFile(String fromDir) {
218 var statusFileList = statusFiles.putIfAbsent(fromDir, () => <StatusFile>[]);
219 for (var entry
220 in new Directory(p.join(testRoot, fromDir)).listSync(recursive: true)) {
221 if (!entry.path.endsWith(".status")) continue;
222
223 statusFileList.add(new StatusFile.read(entry.path));
224 }
225 }
226
227 addStatusFile("corelib");
228 addStatusFile("corelib_strong");
229 addStatusFile("html");
230 addStatusFile("isolate");
231 addStatusFile("language");
232 addStatusFile("language_strong");
233 addStatusFile("lib");
234 addStatusFile("lib_strong");
235 var statusFilesList = <StatusFile>[];
236 for (var list in statusFiles.values) {
237 statusFilesList.addAll(list);
238 }
239 return statusFilesList;
240 }
241
164 /// Moves the file from [from] to [to], which are both assumed to be relative 242 /// Moves the file from [from] to [to], which are both assumed to be relative
165 /// paths inside "tests". 243 /// paths inside "tests".
166 void moveFile(String from, String to) { 244 void moveFile(String from, String to) {
167 if (dryRun) { 245 if (dryRun) {
168 print(" Dry run: move $from to $to"); 246 print(" Dry run: move $from to $to");
169 return; 247 return;
170 } 248 }
171 249
172 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to)); 250 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to));
173 } 251 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 359 }
282 } 360 }
283 361
284 if (checkForUnitTest(twoPath, twoSource)) { 362 if (checkForUnitTest(twoPath, twoSource)) {
285 todos.add("Migrate ${bold(twoPath)} off unittest."); 363 todos.add("Migrate ${bold(twoPath)} off unittest.");
286 } 364 }
287 365
288 return todos.length == todosBefore; 366 return todos.length == todosBefore;
289 } 367 }
290 } 368 }
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