Skip to content

Commit 7869bc3

Browse files
jcollins-gcommit-bot@chromium.org
authored andcommitted
Steel thread through fantasyland.
This includes a mostly feature-identical version of tool/migrate_ecosystem.sh, written in Dart. Bug: #40280 Change-Id: Ib3fe2f353208038ac6c3f035fcdb17f638c68e49 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134786 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Janice Collins <[email protected]>
1 parent c6b0ee3 commit 7869bc3

9 files changed

+306
-96
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (c) 2020, 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+
/// This binary can generate and update an integrated workspace for upgrading
8+
/// individual packages and their dependencies simultaneously.
9+
10+
import 'package:nnbd_migration/src/fantasyland/fantasy_workspace.dart';
11+
import 'package:path/path.dart' as path;
12+
import 'package:args/args.dart';
13+
14+
final parser = ArgParser()
15+
..addMultiOption('extra-packages', abbr: 'e', splitCommas: true)
16+
..addOption('package-name', abbr: 'p')
17+
..addFlag('analysis-options-hack', defaultsTo: true, negatable: true)
18+
..addFlag('strip-sdk-constraint-hack', defaultsTo: true, negatable: true)
19+
..addFlag('force-migrate-deps', defaultsTo: true, negatable: true)
20+
..addFlag('force-migrate-package', defaultsTo: false, negatable: true)
21+
..addFlag('force-migrate-extras', defaultsTo: true, negatable: true)
22+
..addFlag('help', abbr: 'h');
23+
24+
Future<void> main(List<String> args) async {
25+
ArgResults results = parser.parse(args);
26+
27+
if (results['help'] as bool) {
28+
_showHelp(null, useStdError: false);
29+
exit(0);
30+
}
31+
32+
if (results.rest.length != 1) {
33+
_showHelp('error: only one argument allowed for workspace directory');
34+
exit(1);
35+
}
36+
37+
List<String> extraPackages = results['extra-packages'] as List<String>;
38+
String packageName = results['package-name'] as String;
39+
40+
if (packageName == null) {
41+
_showHelp('error: --package_name required');
42+
exit(1);
43+
}
44+
assert(packageName != null);
45+
assert(extraPackages != null);
46+
47+
FantasyWorkspace workspace = await buildFantasyLand(
48+
packageName, extraPackages, path.canonicalize(results.rest.first));
49+
workspace.makeAllSymlinks();
50+
51+
if (results['analysis-options-hack'] as bool) {
52+
stderr.writeln('warning: analysis options hack not implemented');
53+
}
54+
55+
if (results['strip-sdk-constraint-hack'] as bool) {
56+
stderr.writeln('warning: sdk constraint hack not implemented');
57+
}
58+
59+
if (results['force-migrate-deps'] as bool ||
60+
results['force-migrate-package'] as bool ||
61+
results['force-migrate-extras'] as bool) {
62+
stderr.writeln('warning: auto-migration not implemented');
63+
}
64+
}
65+
66+
// TODO(jcollins-g): add symbolic link support to analyzer filesystem.
67+
extension _Symlinks on FantasyWorkspace {
68+
void makeAllSymlinks() {
69+
for (var package in subPackages.values) {
70+
Link l = Link(path.join(workspaceRootPath, package.name));
71+
if (!l.existsSync()) {
72+
l.createSync(
73+
path.relative(package.packageRoot.path, from: workspaceRootPath));
74+
}
75+
}
76+
}
77+
}
78+
79+
void _showHelp(String message, {bool useStdError = true}) {
80+
var writer = useStdError ? stderr : stdout;
81+
82+
writer.writeln(message ?? '');
83+
writer.writeln(
84+
'Usage: dart ${Platform.script.toFilePath()} [options] workspace_dir');
85+
writer.writeln();
86+
writer.writeln(parser.usage);
87+
}

pkg/nnbd_migration/lib/src/fantasyland/fantasy_repo.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ final Map<String, FantasyRepoSettings> _repoTable = {
1616
'build_version', '$githubHost:kevmoo/build_version.git'),
1717
'csv': FantasyRepoSettings('csv', '$githubHost:close2/csv.git'),
1818
'git': FantasyRepoSettings('git', '$githubHost:kevmoo/git.git'),
19-
'node_interop': FantasyRepoSettings(
20-
'node_interop', '$githubHost:pulyaevskiy/node-interop.git'),
19+
'node-interop': FantasyRepoSettings(
20+
'node-interop', '$githubHost:pulyaevskiy/node-interop.git'),
2121
'node_preamble': FantasyRepoSettings(
2222
'package_config', '$githubHost:mbullington/node_preamble.dart.git'),
2323
'package_config': FantasyRepoSettings('package_config',

pkg/nnbd_migration/lib/src/fantasyland/fantasy_repo_impl.dart

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ class FantasyRepoGitImpl extends FantasyRepo {
7373
/// initializing.
7474
Future<void> _clone(SubprocessLauncher launcher) async {
7575
assert(_isInitialized == false);
76-
if (!repoRoot.parent.exists) {
77-
await repoRoot.parent.create();
78-
}
76+
repoRoot.parent.create();
7977
await launcher.runStreamed('git', ['init', repoRoot.path]);
8078
await launcher.runStreamed(
8179
'git',
@@ -111,34 +109,17 @@ class FantasyRepoGitImpl extends FantasyRepo {
111109
'!**/pubspec.lock\n',
112110
'!**/.dart_tool/package_config.json\n'
113111
].join());
114-
try {
115-
await _update(launcher);
116-
} catch (e) {
117-
if (e is FantasyRepoUpdateException) {
118-
throw FantasyRepoCloneException(
119-
'Unable to initialize clone for: $repoSettings');
120-
}
121-
// Other kinds of exceptions are not expected, so rethrow.
122-
rethrow;
123-
}
112+
await launcher.runStreamed(
113+
'git', ['pull', '--depth=1', '--rebase', 'originHTTP'],
114+
workingDirectory: repoRoot.path, retries: 5);
124115
}
125116

126117
Future<void> _update(SubprocessLauncher launcher) async {
127118
assert(_isInitialized == false);
128119
try {
129-
List<String> args;
130-
if (repoSettings.branch == 'master') {
131-
args = [
132-
'pull',
133-
'--depth=1',
134-
'--rebase',
135-
'originHTTP',
136-
repoSettings.revision
137-
];
138-
} else {
139-
args = ['pull', '--rebase', 'originHTTP', repoSettings.revision];
140-
}
141-
await launcher.runStreamed('git', args, workingDirectory: repoRoot.path);
120+
await launcher.runStreamed(
121+
'git', ['pull', '--rebase', 'originHTTP', repoSettings.revision],
122+
workingDirectory: repoRoot.path, retries: 5);
142123
} catch (e) {
143124
if (e is ProcessException) {
144125
throw FantasyRepoUpdateException(

pkg/nnbd_migration/lib/src/fantasyland/fantasy_sub_package.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ final Map<String, FantasySubPackageSettings> _subPackageTable = {
123123
subDir: path.join('pkg', 'vm_service')),
124124
'quiver': FantasySubPackageSettings(
125125
'quiver', FantasyRepoSettings.fromName('quiver-dart')),
126+
'webkit_inspection_protocol': FantasySubPackageSettings(
127+
'webkit_inspection_protocol',
128+
FantasyRepoSettings.fromName('webkit_inspection_protocol.dart')),
126129
};
127130

128131
/// Data class containing settings for a package within a [FantasyWorkspaceImpl].

pkg/nnbd_migration/lib/src/fantasyland/fantasy_workspace.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// TODO(jcollins-g): finish port away from io
6-
import 'dart:io' show Directory;
7-
85
import 'package:nnbd_migration/src/fantasyland/fantasy_sub_package.dart';
96
import 'package:nnbd_migration/src/fantasyland/fantasy_workspace_impl.dart';
107

118
export 'package:nnbd_migration/src/fantasyland/fantasy_sub_package.dart';
129

1310
/// Represent a single [FantasyWorkspace].
1411
abstract class FantasyWorkspace {
15-
Directory get workspaceRoot;
12+
String get workspaceRootPath;
1613

1714
/// Fully initialized subpackages.
18-
Map<String, FantasySubPackage> subPackages;
15+
Map<FantasySubPackageSettings, FantasySubPackage> subPackages;
16+
17+
/// Add a package to the workspace, given [packageSettings].
18+
///
19+
/// Completes when the repository and subPackage is added.
20+
Future<FantasySubPackage> addPackageToWorkspace(
21+
FantasySubPackageSettings packageSettings);
1922
}
2023

2124
/// Build a "fantasyland"-style repository structure suitable for applying

0 commit comments

Comments
 (0)