Skip to content

Commit 1f9fea6

Browse files
a-sivaCommit Queue
authored andcommitted
Fix dds launcher to use the dartaotruntime directly if it is available.
TEST=ci Change-Id: I32fc7ce15108e0ea67626731c676e0b6533db47a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434260 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 55d93b2 commit 1f9fea6

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

pkg/dds/lib/dds_launcher.dart

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
88

9+
import 'package:path/path.dart' as path;
10+
911
import 'dds.dart' hide DartDevelopmentService;
1012
import 'src/arg_parser.dart';
1113
import 'src/dds_impl.dart';
@@ -55,29 +57,58 @@ class DartDevelopmentServiceLauncher {
5557
String? dartExecutable,
5658
String? google3WorkspaceRoot,
5759
}) async {
58-
final process = await Process.start(
59-
dartExecutable ?? Platform.executable,
60-
<String>[
61-
'development-service',
62-
'--${DartDevelopmentServiceOptions.vmServiceUriOption}=$remoteVmServiceUri',
63-
if (serviceUri != null) ...<String>[
64-
'--${DartDevelopmentServiceOptions.bindAddressOption}=${serviceUri.host}',
65-
'--${DartDevelopmentServiceOptions.bindPortOption}=${serviceUri.port}',
66-
],
67-
if (!enableAuthCodes)
68-
'--${DartDevelopmentServiceOptions.disableServiceAuthCodesFlag}',
69-
if (serveDevTools)
70-
'--${DartDevelopmentServiceOptions.serveDevToolsFlag}',
71-
if (devToolsServerAddress != null)
72-
'--${DartDevelopmentServiceOptions.devToolsServerAddressOption}=$devToolsServerAddress',
73-
if (enableServicePortFallback)
74-
'--${DartDevelopmentServiceOptions.enableServicePortFallbackFlag}',
75-
for (final String tag in cachedUserTags)
76-
'--${DartDevelopmentServiceOptions.cachedUserTagsOption}=$tag',
77-
if (google3WorkspaceRoot != null)
78-
'--${DartDevelopmentServiceOptions.google3WorkspaceRootOption}=$google3WorkspaceRoot',
60+
var args = <String>[
61+
'--${DartDevelopmentServiceOptions.vmServiceUriOption}=$remoteVmServiceUri',
62+
if (serviceUri != null) ...<String>[
63+
'--${DartDevelopmentServiceOptions.bindAddressOption}=${serviceUri.host}', '--${DartDevelopmentServiceOptions.bindPortOption}=${serviceUri.port}',
7964
],
80-
);
65+
if (!enableAuthCodes)
66+
'--${DartDevelopmentServiceOptions.disableServiceAuthCodesFlag}',
67+
if (serveDevTools)
68+
'--${DartDevelopmentServiceOptions.serveDevToolsFlag}',
69+
if (devToolsServerAddress != null)
70+
'--${DartDevelopmentServiceOptions.devToolsServerAddressOption}=$devToolsServerAddress',
71+
if (enableServicePortFallback)
72+
'--${DartDevelopmentServiceOptions.enableServicePortFallbackFlag}',
73+
for (final String tag in cachedUserTags)
74+
'--${DartDevelopmentServiceOptions.cachedUserTagsOption}=$tag',
75+
if (google3WorkspaceRoot != null)
76+
'--${DartDevelopmentServiceOptions.google3WorkspaceRootOption}=$google3WorkspaceRoot',
77+
];
78+
late String executable;
79+
if (dartExecutable == null) {
80+
// If a dart executable is not specified and we are able to locate
81+
// the 'dartaotruntime' executable and the AOT snapshot for dds
82+
// then invoke it directly as it would avoid the additional hop
83+
// of going through the dart CLI process to invoke dds.
84+
executable = Platform.executable;
85+
var sdkPath = path.absolute(path.dirname(path.dirname(executable)), 'bin');
86+
var snapshotsDir = path.join(sdkPath, 'snapshots');
87+
final type = FileSystemEntity.typeSync(snapshotsDir);
88+
if (type != FileSystemEntityType.directory &&
89+
type != FileSystemEntityType.link) {
90+
// This is the less common case where the user is in
91+
// the checked out Dart SDK, and is executing `dart` via:
92+
// ./out/ReleaseX64/dart ... or in google3.
93+
sdkPath = path.absolute(path.dirname(executable));
94+
snapshotsDir = sdkPath;
95+
}
96+
final dartAotRuntime = path.absolute(
97+
sdkPath, Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime');
98+
final ddsAotSnapshot =
99+
path.absolute(snapshotsDir, 'dds_aot.dart.snapshot');
100+
if (File(dartAotRuntime).existsSync()
101+
&& File(ddsAotSnapshot).existsSync()) {
102+
executable = dartAotRuntime;
103+
args = [ddsAotSnapshot, ...args];
104+
} else {
105+
args = ['development-service', ...args];
106+
}
107+
} else {
108+
executable = dartExecutable;
109+
args = ['development-service', ...args];
110+
}
111+
final process = await Process.start(executable, args);
81112
final completer = Completer<DartDevelopmentServiceLauncher>();
82113
late StreamSubscription<Object?> stderrSub;
83114
stderrSub = process.stderr

0 commit comments

Comments
 (0)