OLD | NEW |
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 import 'package:path/path.dart' as p; | 5 import 'package:path/path.dart' as p; |
6 | 6 |
7 import 'editable_status_file.dart'; | 7 import 'editable_status_file.dart'; |
8 import 'fork.dart'; | 8 import 'fork.dart'; |
9 import 'io.dart'; | 9 import 'io.dart'; |
10 import 'log.dart'; | 10 import 'log.dart'; |
11 import 'test_directories.dart'; | 11 import 'test_directories.dart'; |
12 | 12 |
13 /// Migrates the status file entries that match [files]. | 13 /// Migrates the status file entries that match [files]. |
14 void migrateStatusEntries(List<Fork> files, Map<String, List<String>> todos) { | 14 void migrateStatusEntries(List<Fork> files, Map<String, List<String>> todos) { |
15 var entriesToMove = new EntrySet(); | 15 var entriesToMove = new EntrySet(); |
16 | 16 |
17 _collectEntries(files, entriesToMove, isOne: true); | 17 _collectEntries(files, entriesToMove, isOne: true); |
18 _collectEntries(files, entriesToMove, isOne: false); | 18 _collectEntries(files, entriesToMove, isOne: false); |
19 | 19 |
20 for (var statusFile in entriesToMove.statusFiles) { | 20 for (var statusFile in entriesToMove.statusFiles) { |
21 var sections = entriesToMove.sections(statusFile); | 21 var sections = entriesToMove.sections(statusFile); |
22 _addEntries(statusFile, sections); | 22 _addEntries(statusFile, sections); |
23 } | 23 } |
24 | 24 |
25 // If any entries need manual splitting, let the user know. | 25 // If any entries need manual splitting, let the user know. |
26 for (var dir in entriesToMove._todoHeaders.keys) { | 26 for (var statusFile in entriesToMove._todoHeaders.keys) { |
27 var destination = "$dir.status"; | 27 var headers = entriesToMove._todoHeaders[statusFile]; |
28 var headers = entriesToMove._todoHeaders[dir]; | |
29 var splits = headers.map((header) { | 28 var splits = headers.map((header) { |
30 var files = | 29 var files = filesForHeader(header).map((file) => bold(file)).join(", "); |
31 filesForHeader(header).map((file) => bold("${dir}_$file")).join(", "); | 30 return "Manually split status file section across $files status files:\n" |
32 return "Need to manually split status file section in ${bold(destination)}
" | 31 " $header"; |
33 " across files $files:\n $header"; | |
34 }).toList(); | 32 }).toList(); |
35 | 33 |
36 if (splits.isNotEmpty) todos[destination] = splits; | 34 if (splits.isNotEmpty) todos[statusFile] = splits; |
37 } | 35 } |
38 } | 36 } |
39 | 37 |
40 /// Given the header for a status file section, looks at the condition | 38 /// Given the header for a status file section, looks at the condition |
41 /// expression to determine which status files it should go in. | 39 /// expression to determine which status files it should go in. |
42 Set<String> filesForHeader(String header) { | 40 Set<String> filesForHeader(String header) { |
43 // Figure out which status file it goes into. | 41 // Figure out which status file it goes into. |
44 var result = new Set<String>(); | 42 var result = new Set<String>(); |
45 | 43 |
46 // The various compilers are roughly separate products. | 44 // The various compilers are roughly separate products. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 83 |
86 final _todoHeaders = <String, Set<String>>{}; | 84 final _todoHeaders = <String, Set<String>>{}; |
87 | 85 |
88 Iterable<String> get statusFiles => _files.keys; | 86 Iterable<String> get statusFiles => _files.keys; |
89 | 87 |
90 /// Attempts to add the [entry] under [header] in a status file in [fromDir] | 88 /// Attempts to add the [entry] under [header] in a status file in [fromDir] |
91 /// to this EntrySet. | 89 /// to this EntrySet. |
92 /// | 90 /// |
93 /// Returns true if successful or false if the header's condition doesn't fit | 91 /// Returns true if successful or false if the header's condition doesn't fit |
94 /// into a single status file and needs to be manually split by the user. | 92 /// into a single status file and needs to be manually split by the user. |
95 bool add(String fromDir, String header, String entry) { | 93 bool add(String fromFile, String fromDir, String header, String entry) { |
96 var toDir = toTwoDirectory(fromDir); | 94 var toDir = toTwoDirectory(fromDir); |
97 | 95 |
98 // Figure out which status file it goes into. | 96 // Figure out which status file it goes into. |
99 var possibleFiles = filesForHeader(header); | 97 var possibleFiles = filesForHeader(header); |
100 var destination = "$toDir.status"; | 98 var destination = "$toDir.status"; |
101 | 99 |
102 if (possibleFiles.length > 1) { | 100 if (possibleFiles.length > 1) { |
103 // The condition matches multiple files, so the user is going to have to | 101 // The condition matches multiple files, so the user is going to have to |
104 // manually split it up into multiple sections first. | 102 // manually split it up into multiple sections first. |
105 // TODO(rnystrom): Would be good to automate this, though it requires | 103 // TODO(rnystrom): Would be good to automate this, though it requires |
106 // being able to work with condition expressions directly. | 104 // being able to work with condition expressions directly. |
107 _todoHeaders.putIfAbsent(toDir, () => new Set()).add(header); | 105 var statusRelative = p.relative(fromFile, from: testRoot); |
| 106 _todoHeaders.putIfAbsent(statusRelative, () => new Set()).add(header); |
108 return false; | 107 return false; |
109 } | 108 } |
110 | 109 |
111 // If the condition places it directly into one file, put it there. | 110 // If the condition places it directly into one file, put it there. |
112 if (possibleFiles.length == 1) { | 111 if (possibleFiles.length == 1) { |
113 destination = "${toDir}_${possibleFiles.single}.status"; | 112 destination = "${toDir}_${possibleFiles.single}.status"; |
114 } | 113 } |
115 | 114 |
116 var sections = _files.putIfAbsent(p.join(toDir, destination), () => {}); | 115 var sections = _files.putIfAbsent(p.join(toDir, destination), () => {}); |
117 | 116 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // migrated, or a multitest within that. In both cases, the entry | 150 // migrated, or a multitest within that. In both cases, the entry |
152 // path will begin with the full path of the file. We don't migrate | 151 // path will begin with the full path of the file. We don't migrate |
153 // directory or glob patterns because those may also match other | 152 // directory or glob patterns because those may also match other |
154 // files that have not been migrated yet. | 153 // files that have not been migrated yet. |
155 // TODO(rnystrom): It would be good to detect when a glob matches | 154 // TODO(rnystrom): It would be good to detect when a glob matches |
156 // a migrated file and let the user know that they may need to | 155 // a migrated file and let the user know that they may need to |
157 // manually handle it. | 156 // manually handle it. |
158 if (!entryPath.startsWith(filePath)) continue; | 157 if (!entryPath.startsWith(filePath)) continue; |
159 | 158 |
160 // Add it to the 2.0 one. | 159 // Add it to the 2.0 one. |
161 if (entriesToMove.add(fromDir, editable.lineAt(section.lineNumber), | 160 if (entriesToMove.add( |
| 161 path, |
| 162 fromDir, |
| 163 editable.lineAt(section.lineNumber), |
162 editable.lineAt(entry.lineNumber))) { | 164 editable.lineAt(entry.lineNumber))) { |
163 // Remove it from the original status file. | 165 // Remove it from the original status file. |
164 deleteLines.add(entry.lineNumber - 1); | 166 deleteLines.add(entry.lineNumber - 1); |
165 } | 167 } |
166 } | 168 } |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 // TODO(rnystrom): If all of the entries are deleted from a section, it | 172 // TODO(rnystrom): If all of the entries are deleted from a section, it |
171 // would be nice to delete the section header too. | 173 // would be nice to delete the section header too. |
(...skipping 27 matching lines...) Expand all Loading... |
199 break; | 201 break; |
200 } | 202 } |
201 } | 203 } |
202 | 204 |
203 if (!found) { | 205 if (!found) { |
204 // This section doesn't exist in the status file, so add it. | 206 // This section doesn't exist in the status file, so add it. |
205 editable.append(header, entries[header]); | 207 editable.append(header, entries[header]); |
206 } | 208 } |
207 } | 209 } |
208 } | 210 } |
OLD | NEW |