Skip to content

Commit b1b4eff

Browse files
author
Anna Gringauze
authored
Prepare for dart 3.0 alpha changes: generate assets (#1887)
* Generate sdk assets for tests * Generate missing SDK assets and enable null safe tests * Generate SDK assets in webdev tests * Only generate SDK assets if needed * Fix test failures * Fix test failures, refactor SDK layout, add tests * Addressed CR comments * Update changelog * Fix test failures on windows * Format * Addressed CR comments * Address CR comments, fix tests * Address CR comments
1 parent 969f41f commit b1b4eff

30 files changed

+1410
-934
lines changed

.github/workflows/dart.yml

Lines changed: 70 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
- Add back `ChromeProxyService.setExceptionPauseMode()` without override.
1818
- Make hot restart atomic to prevent races on simultaneous execution.
1919
- Return error on expression evaluation if expression evaluator stopped.
20+
- Prepare for Dart 3 alpha breaking changes:
21+
- Generate missing SDK assets for tests.
22+
- Enable frontend server null safe tests.
2023

2124
**Breaking changes**
2225
- Include an optional param to `Dwds.start` to indicate whether it is running
2326
internally or externally.
2427
- Include an optional param to `Dwds.start` to indicate whether it a Flutter app
2528
or not.
2629
- Remove deprecated `ChromeProxyService.setExceptionPauseMode()`.
30+
- Replace `SdkConfiguration.unsoundSdkSummaryPath` with
31+
`SdkConfiguration.weakSdkSummaryPath`.
2732

2833
## 16.0.1
2934

dwds/lib/dart_web_debug_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class Dwds {
8484
bool enableDevtoolsLaunch = true,
8585
DevtoolsLauncher? devtoolsLauncher,
8686
bool launchDevToolsInNewWindow = true,
87-
SdkConfigurationProvider? sdkConfigurationProvider,
87+
SdkConfigurationProvider sdkConfigurationProvider =
88+
const DefaultSdkConfigurationProvider(),
8889
bool emitDebugEvents = true,
8990
bool isInternalBuild = false,
9091
bool isFlutterApp = false,
9192
}) async {
9293
globalLoadStrategy = loadStrategy;
93-
sdkConfigurationProvider ??= DefaultSdkConfigurationProvider();
9494

9595
DevTools? devTools;
9696
Future<String>? extensionUri;

dwds/lib/dwds.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ export 'src/services/expression_compiler.dart'
2929
export 'src/services/expression_compiler_service.dart'
3030
show ExpressionCompilerService;
3131
export 'src/utilities/sdk_configuration.dart'
32-
show SdkConfiguration, SdkConfigurationProvider;
32+
show SdkLayout, SdkConfiguration, SdkConfigurationProvider;

dwds/lib/src/services/expression_compiler_service.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _Compiler {
7777
final workerUri = sdkConfiguration.compilerWorkerUri!;
7878
final sdkSummaryUri = soundNullSafety
7979
? sdkConfiguration.soundSdkSummaryUri!
80-
: sdkConfiguration.unsoundSdkSummaryUri!;
80+
: sdkConfiguration.weakSdkSummaryUri!;
8181

8282
final args = [
8383
'--experimental-expression-compiler',
@@ -241,11 +241,11 @@ class ExpressionCompilerService implements ExpressionCompiler {
241241
this._address,
242242
this._port, {
243243
bool verbose = false,
244-
SdkConfigurationProvider? sdkConfigurationProvider,
244+
SdkConfigurationProvider sdkConfigurationProvider =
245+
const DefaultSdkConfigurationProvider(),
245246
this.experiments = const [],
246247
}) : _verbose = verbose,
247-
_sdkConfigurationProvider =
248-
sdkConfigurationProvider ?? DefaultSdkConfigurationProvider();
248+
_sdkConfigurationProvider = sdkConfigurationProvider;
249249

250250
@override
251251
Future<ExpressionCompilationResult> compileExpressionToJs(

dwds/lib/src/utilities/sdk_configuration.dart

Lines changed: 154 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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+
import 'dart:async';
56
import 'dart:io';
67

78
import 'package:file/file.dart';
@@ -24,42 +25,171 @@ class InvalidSdkConfigurationException implements Exception {
2425
/// SDK configuration provider interface.
2526
///
2627
/// Supports lazily populated configurations by allowing to create
27-
/// configuration asyncronously.
28+
/// configuration asynchronously.
2829
abstract class SdkConfigurationProvider {
30+
const SdkConfigurationProvider();
31+
2932
Future<SdkConfiguration> get configuration;
3033
}
3134

35+
/// Sdk layout.
36+
///
37+
/// Contains definition of the default SDK layout.
38+
/// We keep all the path constants in one place for ease of update.
39+
class SdkLayout {
40+
static final sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));
41+
static final defaultSdkLayout = createDefault(sdkDir);
42+
43+
static SdkLayout createDefault(String sdkDirectory) {
44+
final sdkJsWeakFileName = 'dart_sdk.js';
45+
final sdkJsMapWeakFileName = 'dart_sdk.js.map';
46+
final sdkJsSoundFileName = 'dart_sdk_sound.js';
47+
final sdkJsMapSoundFileName = 'dart_sdk_sound.js.map';
48+
final sdkSummarySoundFileName = 'ddc_outline_sound.dill';
49+
final sdkSummaryWeakFileName = 'ddc_sdk.dill';
50+
final sdkFullDillSoundFileName = 'ddc_platform_sound.dill';
51+
final sdkFullDillWeakFileName = 'ddc_platform.dill';
52+
53+
final sdkSummaryDirectory = p.join(sdkDirectory, 'lib', '_internal');
54+
final sdkJsDirectory =
55+
p.join(sdkDirectory, 'lib', 'dev_compiler', 'kernel', 'amd');
56+
57+
final soundSummaryPath =
58+
p.join(sdkSummaryDirectory, sdkSummarySoundFileName);
59+
final soundFullDillPath =
60+
p.join(sdkSummaryDirectory, sdkFullDillSoundFileName);
61+
final soundJsPath = p.join(sdkJsDirectory, sdkJsSoundFileName);
62+
final soundJsMapPath = p.join(sdkJsDirectory, sdkJsMapSoundFileName);
63+
64+
final weakSummaryPath = p.join(sdkSummaryDirectory, sdkSummaryWeakFileName);
65+
final weakFullDillPath =
66+
p.join(sdkSummaryDirectory, sdkFullDillWeakFileName);
67+
final weakJsPath = p.join(sdkJsDirectory, sdkJsWeakFileName);
68+
final weakJsMapPath = p.join(sdkJsDirectory, sdkJsMapWeakFileName);
69+
70+
final librariesPath = p.join(sdkDirectory, 'lib', 'libraries.json');
71+
final dartdevcSnapshotPath =
72+
p.join(sdkDirectory, 'bin', 'snapshots', 'dartdevc.dart.snapshot');
73+
final kernelWorkerSnapshotPath =
74+
p.join(sdkDirectory, 'bin', 'snapshots', 'kernel_worker.dart.snapshot');
75+
76+
return SdkLayout(
77+
sdkJsWeakFileName: sdkJsWeakFileName,
78+
sdkJsMapWeakFileName: sdkJsMapWeakFileName,
79+
sdkJsSoundFileName: sdkJsSoundFileName,
80+
sdkJsMapSoundFileName: sdkJsMapSoundFileName,
81+
sdkSummarySoundFileName: sdkSummarySoundFileName,
82+
sdkSummaryWeakFileName: sdkSummaryWeakFileName,
83+
sdkFullDillSoundFileName: sdkFullDillSoundFileName,
84+
sdkFullDillWeakFileName: sdkFullDillWeakFileName,
85+
sdkDirectory: sdkDirectory,
86+
soundSummaryPath: soundSummaryPath,
87+
soundFullDillPath: soundFullDillPath,
88+
soundJsPath: soundJsPath,
89+
soundJsMapPath: soundJsMapPath,
90+
weakSummaryPath: weakSummaryPath,
91+
weakFullDillPath: weakFullDillPath,
92+
weakJsPath: weakJsPath,
93+
weakJsMapPath: weakJsMapPath,
94+
librariesPath: librariesPath,
95+
dartdevcSnapshotPath: dartdevcSnapshotPath,
96+
kernelWorkerSnapshotPath: kernelWorkerSnapshotPath,
97+
);
98+
}
99+
100+
final String sdkJsWeakFileName;
101+
final String sdkJsMapWeakFileName;
102+
final String sdkJsSoundFileName;
103+
final String sdkJsMapSoundFileName;
104+
final String sdkSummarySoundFileName;
105+
final String sdkSummaryWeakFileName;
106+
final String sdkFullDillSoundFileName;
107+
final String sdkFullDillWeakFileName;
108+
109+
final String sdkDirectory;
110+
111+
final String soundSummaryPath;
112+
final String soundFullDillPath;
113+
final String soundJsPath;
114+
final String soundJsMapPath;
115+
116+
final String weakSummaryPath;
117+
final String weakFullDillPath;
118+
final String weakJsPath;
119+
final String weakJsMapPath;
120+
121+
final String librariesPath;
122+
123+
final String dartdevcSnapshotPath;
124+
final String kernelWorkerSnapshotPath;
125+
126+
SdkLayout({
127+
required this.sdkJsWeakFileName,
128+
required this.sdkJsMapWeakFileName,
129+
required this.sdkJsSoundFileName,
130+
required this.sdkJsMapSoundFileName,
131+
required this.sdkSummarySoundFileName,
132+
required this.sdkSummaryWeakFileName,
133+
required this.sdkFullDillSoundFileName,
134+
required this.sdkFullDillWeakFileName,
135+
required this.sdkDirectory,
136+
required this.soundSummaryPath,
137+
required this.soundFullDillPath,
138+
required this.soundJsPath,
139+
required this.soundJsMapPath,
140+
required this.weakSummaryPath,
141+
required this.weakFullDillPath,
142+
required this.weakJsPath,
143+
required this.weakJsMapPath,
144+
required this.librariesPath,
145+
required this.dartdevcSnapshotPath,
146+
required this.kernelWorkerSnapshotPath,
147+
});
148+
}
149+
32150
/// Data class describing the SDK layout.
33151
///
34152
/// Provides helpers to convert paths to uris that work on all platforms.
35153
///
36154
/// Call [validate] method to make sure the files in the configuration
37155
/// layout exist before reading the files.
38156
class SdkConfiguration {
39-
// TODO(annagrin): update the tests to take those parameters
40-
// and make all of the paths required (except for the compilerWorkerPath
41-
// that is not used in Flutter).
157+
static final defaultSdkLayout = SdkLayout.defaultSdkLayout;
158+
static final defaultConfiguration =
159+
SdkConfiguration.fromSdkLayout(defaultSdkLayout);
160+
42161
String? sdkDirectory;
43-
String? unsoundSdkSummaryPath;
162+
String? weakSdkSummaryPath;
44163
String? soundSdkSummaryPath;
45164
String? librariesPath;
46165
String? compilerWorkerPath;
47166

48167
SdkConfiguration({
49168
this.sdkDirectory,
50-
this.unsoundSdkSummaryPath,
169+
this.weakSdkSummaryPath,
51170
this.soundSdkSummaryPath,
52171
this.librariesPath,
53172
this.compilerWorkerPath,
54173
});
55174

175+
SdkConfiguration.empty() : this();
176+
177+
SdkConfiguration.fromSdkLayout(SdkLayout sdkLayout)
178+
: this(
179+
sdkDirectory: sdkLayout.sdkDirectory,
180+
weakSdkSummaryPath: sdkLayout.weakSummaryPath,
181+
soundSdkSummaryPath: sdkLayout.soundSummaryPath,
182+
librariesPath: sdkLayout.librariesPath,
183+
compilerWorkerPath: sdkLayout.dartdevcSnapshotPath,
184+
);
185+
56186
static Uri? _toUri(String? path) => path == null ? null : p.toUri(path);
57187
static Uri? _toAbsoluteUri(String? path) =>
58188
path == null ? null : p.toUri(p.absolute(path));
59189

60190
Uri? get sdkDirectoryUri => _toUri(sdkDirectory);
61191
Uri? get soundSdkSummaryUri => _toUri(soundSdkSummaryPath);
62-
Uri? get unsoundSdkSummaryUri => _toUri(unsoundSdkSummaryPath);
192+
Uri? get weakSdkSummaryUri => _toUri(weakSdkSummaryPath);
63193
Uri? get librariesUri => _toUri(librariesPath);
64194

65195
/// Note: has to be ///file: Uri to run in an isolate.
@@ -85,14 +215,23 @@ class SdkConfiguration {
85215
}
86216

87217
void validateSummaries({FileSystem fileSystem = const LocalFileSystem()}) {
88-
if (unsoundSdkSummaryPath == null ||
89-
!fileSystem.file(unsoundSdkSummaryPath).existsSync()) {
218+
validateSoundSummaries(fileSystem: fileSystem);
219+
validateWeakSummaries(fileSystem: fileSystem);
220+
}
221+
222+
void validateWeakSummaries(
223+
{FileSystem fileSystem = const LocalFileSystem()}) {
224+
if (weakSdkSummaryPath == null ||
225+
!fileSystem.file(weakSdkSummaryPath).existsSync()) {
90226
throw InvalidSdkConfigurationException(
91-
'Sdk summary $unsoundSdkSummaryPath does not exist');
227+
'Sdk summary $weakSdkSummaryPath does not exist');
92228
}
229+
}
93230

94-
if (soundSdkSummaryPath == null ||
95-
!fileSystem.file(soundSdkSummaryPath).existsSync()) {
231+
void validateSoundSummaries(
232+
{FileSystem fileSystem = const LocalFileSystem()}) {
233+
if ((soundSdkSummaryPath == null ||
234+
!fileSystem.file(soundSdkSummaryPath).existsSync())) {
96235
throw InvalidSdkConfigurationException(
97236
'Sdk summary $soundSdkSummaryPath does not exist');
98237
}
@@ -116,27 +255,10 @@ class SdkConfiguration {
116255
}
117256
}
118257

119-
/// Implementation for the default SDK configuration layout.
120258
class DefaultSdkConfigurationProvider extends SdkConfigurationProvider {
121-
DefaultSdkConfigurationProvider();
259+
const DefaultSdkConfigurationProvider();
122260

123-
late final SdkConfiguration _configuration = _create();
124-
125-
/// Create and validate configuration matching the default SDK layout.
126261
@override
127-
Future<SdkConfiguration> get configuration async => _configuration;
128-
129-
SdkConfiguration _create() {
130-
final binDir = p.dirname(Platform.resolvedExecutable);
131-
final sdkDir = p.dirname(binDir);
132-
133-
return SdkConfiguration(
134-
sdkDirectory: sdkDir,
135-
unsoundSdkSummaryPath: p.join(sdkDir, 'lib', '_internal', 'ddc_sdk.dill'),
136-
soundSdkSummaryPath:
137-
p.join(sdkDir, 'lib', '_internal', 'ddc_outline_sound.dill'),
138-
librariesPath: p.join(sdkDir, 'lib', 'libraries.json'),
139-
compilerWorkerPath: p.join(binDir, 'snapshots', 'dartdevc.dart.snapshot'),
140-
);
141-
}
262+
Future<SdkConfiguration> get configuration async =>
263+
SdkConfiguration.defaultConfiguration;
142264
}

0 commit comments

Comments
 (0)