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

Side by Side Diff: tools/migration/lib/src/fork.dart

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

Powered by Google App Engine
This is Rietveld 408576698