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 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 | 8 |
9 import 'io.dart'; | 9 import 'io.dart'; |
10 import 'log.dart'; | 10 import 'log.dart'; |
| 11 import 'test_directories.dart'; |
11 import 'validate.dart'; | 12 import 'validate.dart'; |
12 | 13 |
13 /// Tracks one test and the various forked locations where it may appear. | 14 /// Tracks one test and the various forked locations where it may appear. |
14 /// | 15 /// |
15 /// * "One" refers to the original Dart 1.0 location of the test: language/, | 16 /// * "One" refers to the original Dart 1.0 location of the test: language/, |
16 /// corelib/, etc. | 17 /// corelib/, etc. |
17 /// | 18 /// |
18 /// * "Strong" is the DDC fork of the file: language_strong, etc. | 19 /// * "Strong" is the DDC fork of the file: language_strong, etc. |
19 /// | 20 /// |
20 /// * "Two" is the migrated 2.0 destination location: language_2, etc. | 21 /// * "Two" is the migrated 2.0 destination location: language_2, etc. |
21 class Fork { | 22 class Fork { |
22 final String twoPath; | 23 final String twoPath; |
23 String onePath; | 24 String get onePath => toOnePath(twoPath); |
24 String strongPath; | 25 String get strongPath => toStrongPath(twoPath); |
25 | 26 |
26 String get twoSource { | 27 String get twoSource { |
27 if (twoPath == null) return null; | 28 if (twoPath == null) return null; |
28 if (_twoSource == null) _twoSource = readFile(twoPath); | 29 if (_twoSource == null) _twoSource = readFile(twoPath); |
29 return _twoSource; | 30 return _twoSource; |
30 } | 31 } |
31 | 32 |
32 String _twoSource; | 33 String _twoSource; |
33 | 34 |
34 String get oneSource { | 35 String get oneSource { |
35 if (onePath == null) return null; | 36 if (onePath == null) return null; |
36 if (_oneSource == null) _oneSource = readFile(onePath); | 37 if (_oneSource == null) _oneSource = readFile(onePath); |
37 return _oneSource; | 38 return _oneSource; |
38 } | 39 } |
39 | 40 |
40 String _oneSource; | 41 String _oneSource; |
41 | 42 |
42 String get strongSource { | 43 String get strongSource { |
43 if (strongPath == null) return null; | 44 if (strongPath == null) return null; |
44 if (_strongSource == null) _strongSource = readFile(strongPath); | 45 if (_strongSource == null) _strongSource = readFile(strongPath); |
45 return _strongSource; | 46 return _strongSource; |
46 } | 47 } |
47 | 48 |
48 bool get isMigrated => new File(p.join(testRoot, twoPath)).existsSync(); | 49 bool get oneExists => new File(p.join(testRoot, onePath)).existsSync(); |
| 50 bool get strongExists => new File(p.join(testRoot, strongPath)).existsSync(); |
| 51 bool get twoExists => new File(p.join(testRoot, twoPath)).existsSync(); |
49 | 52 |
50 String _strongSource; | 53 String _strongSource; |
51 | 54 |
52 Fork(this.twoPath); | 55 Fork(this.twoPath); |
53 | 56 |
54 List<String> migrate() { | 57 List<String> migrate() { |
55 print("- ${bold(twoPath)}:"); | 58 print("- ${bold(twoPath)}:"); |
56 | 59 |
57 var todos = <String>[]; | 60 var todos = <String>[]; |
58 | 61 |
59 if (onePath == null && strongPath == null) { | 62 if (!oneExists && !twoExists) { |
60 // It's already been migrated, so there's nothing to move. | 63 // It's already been migrated, so there's nothing to move. |
61 note("Is already migrated."); | 64 note("Is already migrated."); |
62 } else if (isMigrated) { | 65 } else if (twoExists) { |
63 // If there is a migrated version and it's the same as an unmigrated one, | 66 // If there is a migrated version and it's the same as an unmigrated one, |
64 // delete the unmigrated one. | 67 // delete the unmigrated one. |
65 if (onePath != null) { | 68 if (oneExists) { |
66 if (oneSource == twoSource) { | 69 if (oneSource == twoSource) { |
67 deleteFile(onePath); | 70 deleteFile(onePath); |
68 done("Deleted already-migrated $onePath."); | 71 done("Deleted already-migrated $onePath."); |
69 } else { | 72 } else { |
70 note("${bold(onePath)} does not match already-migrated file."); | 73 note("${bold(onePath)} does not match already-migrated file."); |
71 todos.add("Merge from ${bold(onePath)} into this file."); | 74 todos.add("Merge from ${bold(onePath)} into this file."); |
72 validateFile(onePath, oneSource); | 75 validateFile(onePath, oneSource); |
73 } | 76 } |
74 } | 77 } |
75 | 78 |
76 if (strongPath != null) { | 79 if (strongExists) { |
77 if (strongSource == twoSource) { | 80 if (strongSource == twoSource) { |
78 deleteFile(strongPath); | 81 deleteFile(strongPath); |
79 done("Deleted already-migrated ${bold(strongPath)}."); | 82 done("Deleted already-migrated ${bold(strongPath)}."); |
80 } else { | 83 } else { |
81 note("${bold(strongPath)} does not match already-migrated file."); | 84 note("${bold(strongPath)} does not match already-migrated file."); |
82 todos.add("Merge from ${bold(strongPath)} into this file."); | 85 todos.add("Merge from ${bold(strongPath)} into this file."); |
83 validateFile(strongPath, strongSource); | 86 validateFile(strongPath, strongSource); |
84 } | 87 } |
85 } | 88 } |
86 } else { | 89 } else { |
87 if (strongPath == null) { | 90 if (!strongExists) { |
88 // If it only exists in one place, just move it. | 91 // If it only exists in one place, just move it. |
89 moveFile(onePath, twoPath); | 92 moveFile(onePath, twoPath); |
90 done("Moved from ${bold(onePath)} (no strong mode fork)."); | 93 done("Moved from ${bold(onePath)} (no strong mode fork)."); |
91 } else if (onePath == null) { | 94 } else if (!oneExists) { |
92 // If it only exists in one place, just move it. | 95 // If it only exists in one place, just move it. |
93 moveFile(strongPath, twoPath); | 96 moveFile(strongPath, twoPath); |
94 done("Moved from ${bold(strongPath)} (no 1.0 mode fork)."); | 97 done("Moved from ${bold(strongPath)} (no 1.0 mode fork)."); |
95 } else if (oneSource == strongSource) { | 98 } else if (oneSource == strongSource) { |
96 // The forks are identical, pick one. | 99 // The forks are identical, pick one. |
97 moveFile(onePath, twoPath); | 100 moveFile(onePath, twoPath); |
98 deleteFile(strongPath); | 101 deleteFile(strongPath); |
99 done("Merged identical forks."); | 102 done("Merged identical forks."); |
100 validateFile(twoPath, oneSource); | 103 validateFile(twoPath, oneSource); |
101 } else { | 104 } else { |
102 // Otherwise, a manual merge is required. Start with the strong one. | 105 // Otherwise, a manual merge is required. Start with the strong one. |
103 moveFile(strongPath, twoPath); | 106 moveFile(strongPath, twoPath); |
104 done("Moved strong fork, kept 1.0 fork, manual merge required."); | 107 done("Moved strong fork, kept 1.0 fork, manual merge required."); |
105 todos.add("Merge from ${bold(onePath)} into this file."); | 108 todos.add("Merge from ${bold(onePath)} into this file."); |
106 validateFile(onePath, oneSource); | 109 validateFile(onePath, oneSource); |
107 } | 110 } |
108 } | 111 } |
109 | 112 |
110 // See what work is left to be done in the migrated file. | 113 // See what work is left to be done in the migrated file. |
111 if (isMigrated) { | 114 if (twoExists) { |
112 validateFile(twoPath, twoSource, todos); | 115 validateFile(twoPath, twoSource, todos); |
113 } | 116 } |
114 | 117 |
115 return todos; | 118 return todos; |
116 } | 119 } |
117 } | 120 } |
OLD | NEW |