Skip to content

Commit 759d7f5

Browse files
authored
Merge branch 'main' into main
2 parents 9fdd02e + cb68ac3 commit 759d7f5

File tree

3 files changed

+34
-131
lines changed

3 files changed

+34
-131
lines changed

test_common/lib/sdk_asset_generator.dart

Lines changed: 28 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import 'package:logging/logging.dart';
88
import 'package:path/path.dart' as p;
99
import 'package:test_common/test_sdk_layout.dart';
1010

11-
/// Generates sdk.js, sdk.map, sdk full dill, and sdk summary files.
12-
///
13-
/// Generates following missing assets if needed:
14-
/// - js, source map, full dill.
11+
/// Generates sdk.js, sdk.map, files.
1512
1613
class SdkAssetGenerator {
1714
bool _sdkAssetsGenerated = false;
@@ -37,58 +34,43 @@ class SdkAssetGenerator {
3734
if (!_sdkAssetsGenerated) {
3835
_sdkAssetsGenerated = true;
3936

40-
// SDK contains sound summary, but SDK js and full dill are
41-
// normally generated by setup tools and their builds,
37+
// SDK full and outline .dill files are shipped with the SDK,
38+
// but the JavaScript and sourcemaps are generated by other tooling
4239
// i.e. flutter SDK or build_web_compilers.
4340
// Generate missing files for tests if needed.
44-
await _generateSdkJavaScript(
45-
canaryFeatures: canaryFeatures,
46-
);
47-
48-
// SDK does not contain any weak assets, generate them.
49-
await _generateSdkJavaScript(
50-
canaryFeatures: canaryFeatures,
51-
);
52-
await _generateSdkSummary();
41+
await _generateSdkJavaScript(canaryFeatures: canaryFeatures);
5342
}
5443
}
5544

56-
String resolveSdkJsPath({
57-
required bool canaryFeatures,
58-
}) =>
45+
String resolveSdkJsPath({required bool canaryFeatures}) =>
5946
switch (ddcModuleFormat) {
6047
ModuleFormat.amd => sdkLayout.amdJsPath,
6148
ModuleFormat.ddc => sdkLayout.ddcJsPath,
62-
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.')
49+
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.'),
6350
};
6451

65-
String resolveSdkSourcemapPath({
66-
required bool canaryFeatures,
67-
}) =>
52+
String resolveSdkSourcemapPath({required bool canaryFeatures}) =>
6853
switch (ddcModuleFormat) {
6954
ModuleFormat.amd => sdkLayout.amdJsMapPath,
7055
ModuleFormat.ddc => sdkLayout.ddcJsMapPath,
71-
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.')
56+
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.'),
7257
};
7358

74-
String resolveSdkJsFilename({
75-
required bool canaryFeatures,
76-
}) =>
59+
String resolveSdkJsFilename({required bool canaryFeatures}) =>
7760
switch (ddcModuleFormat) {
7861
ModuleFormat.amd => sdkLayout.amdJsFileName,
7962
ModuleFormat.ddc => sdkLayout.ddcJsFileName,
80-
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.')
63+
_ => throw Exception('Unsupported DDC module format $ddcModuleFormat.'),
8164
};
8265

83-
Future<void> _generateSdkJavaScript({
84-
required bool canaryFeatures,
85-
}) async {
66+
Future<void> _generateSdkJavaScript({required bool canaryFeatures}) async {
8667
Directory? outputDir;
8768
try {
8869
// Files to copy generated files to.
8970
final outputJsPath = resolveSdkJsPath(canaryFeatures: canaryFeatures);
90-
final outputJsMapPath =
91-
resolveSdkSourcemapPath(canaryFeatures: canaryFeatures);
71+
final outputJsMapPath = resolveSdkSourcemapPath(
72+
canaryFeatures: canaryFeatures,
73+
);
9274
final outputFullDillPath = sdkLayout.fullDillPath;
9375

9476
final hasJsAsset = _exists(outputJsPath);
@@ -104,11 +86,12 @@ class SdkAssetGenerator {
10486

10587
// Files to generate
10688
final jsPath = p.join(
107-
outputDir.path, resolveSdkJsFilename(canaryFeatures: canaryFeatures));
89+
outputDir.path,
90+
resolveSdkJsFilename(canaryFeatures: canaryFeatures),
91+
);
10892
final jsMapPath = p.setExtension(jsPath, '.js.map');
109-
final fullDillPath = p.setExtension(jsPath, '.dill');
11093

111-
_logger.info('Generating js and full dill SDK files...');
94+
_logger.info('Generating SDK JavaScript and sourcemap files...');
11295

11396
final sdkDirectoryUri = fileSystem.directory(sdkLayout.sdkDirectory).uri;
11497
final args = <String>[
@@ -123,7 +106,6 @@ class SdkAssetGenerator {
123106
'org-dartlang-sdk:///lib/libraries.json',
124107
'--modules',
125108
ddcModuleFormat.name,
126-
'--sound-null-safety',
127109
'dart:core',
128110
'-o',
129111
jsPath,
@@ -132,8 +114,11 @@ class SdkAssetGenerator {
132114

133115
final output = <String>[];
134116
_logger.fine('Executing dart ${args.join(' ')}');
135-
final process = await Process.start(sdkLayout.dartPath, args,
136-
workingDirectory: sdkLayout.sdkDirectory);
117+
final process = await Process.start(
118+
sdkLayout.dartPath,
119+
args,
120+
workingDirectory: sdkLayout.sdkDirectory,
121+
);
137122

138123
process.stdout
139124
.transform<String>(utf8.decoder)
@@ -164,88 +149,14 @@ class SdkAssetGenerator {
164149
}
165150
await _moveAndValidate(jsPath, outputJsPath);
166151
await _moveAndValidate(jsMapPath, outputJsMapPath);
167-
await _moveAndValidate(fullDillPath, outputFullDillPath);
168152

169-
_logger.info('Done generating js and full dill SDK files.');
153+
_logger.info('Done generating SDK JavaScript and sourcemap files.');
170154
} catch (e, s) {
171155
_logger.severe(
172-
'Failed to generate SDK js, source map, and full dill', e, s);
173-
rethrow;
174-
} finally {
175-
outputDir?.deleteSync(recursive: true);
176-
}
177-
}
178-
179-
Future<void> _generateSdkSummary() async {
180-
Directory? outputDir;
181-
try {
182-
// Files to copy generated files to.
183-
final outputSummaryPath = sdkLayout.summaryPath;
184-
final hasAssets = _exists(outputSummaryPath);
185-
186-
// Files already exist.
187-
if (hasAssets) return;
188-
189-
// Generate missing files.
190-
outputDir = fileSystem.systemTempDirectory.createTempSync();
191-
final summaryPath = p.join(outputDir.path, sdkLayout.summaryFileName);
192-
193-
_logger.info('Generating SDK summary files...');
194-
195-
final sdkDirectoryUri = fileSystem.directory(sdkLayout.sdkDirectory).uri;
196-
final args = <String>[
197-
sdkLayout.kernelWorkerSnapshotPath,
198-
'--target',
199-
'ddc',
200-
'--multi-root',
201-
'$sdkDirectoryUri',
202-
'--multi-root-scheme',
203-
'org-dartlang-sdk',
204-
'--libraries-file',
205-
'org-dartlang-sdk:///lib/libraries.json',
206-
'--source',
207-
'dart:core',
208-
'--summary-only',
209-
'--sound-null-safety',
210-
'--output',
211-
summaryPath,
212-
if (verbose) '--verbose',
213-
];
214-
215-
_logger.fine('Executing dart ${args.join(' ')}');
216-
final process = await Process.start(sdkLayout.dartAotRuntimePath, args,
217-
workingDirectory: sdkLayout.sdkDirectory);
218-
219-
final output = <String>[];
220-
process.stdout
221-
.transform<String>(utf8.decoder)
222-
.transform<String>(const LineSplitter())
223-
.listen((line) {
224-
_logger.fine(line);
225-
output.add(line);
226-
});
227-
228-
process.stderr
229-
.transform<String>(utf8.decoder)
230-
.transform<String>(const LineSplitter())
231-
.listen((line) {
232-
_logger.warning(line);
233-
output.add(line);
234-
});
235-
236-
await process.exitCode.then((int code) {
237-
if (code != 0) {
238-
_logger
239-
.warning('Error generating $summaryPath: ${output.join('\n')}');
240-
throw Exception('The Dart kernel worker exited unexpectedly');
241-
}
242-
});
243-
244-
await _moveAndValidate(summaryPath, outputSummaryPath);
245-
246-
_logger.info('Done generating SDK summary files.');
247-
} catch (e, s) {
248-
_logger.severe('Failed to generate SDK summary', e, s);
156+
'Failed to generate SDK JavaScript and sourcemap files',
157+
e,
158+
s,
159+
);
249160
rethrow;
250161
} finally {
251162
outputDir?.deleteSync(recursive: true);

test_common/lib/test_sdk_layout.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ class TestSdkLayout {
2727
factory TestSdkLayout.createDefaultFromSdkLayout(SdkLayout sdkLayout) =>
2828
TestSdkLayout(
2929
sdkDirectory: sdkLayout.sdkDirectory,
30-
summaryPath: sdkLayout.summaryPath,
30+
summaryPath: p.join(
31+
sdkLayout.sdkDirectory,
32+
'lib',
33+
'_internal',
34+
'ddc_outline.dill',
35+
),
3136
fullDillPath: p.join(
3237
sdkLayout.sdkDirectory,
3338
'lib',

test_common/test/sdk_asset_generator_test.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ void main() {
2020

2121
late Directory tempDir;
2222
late String sdkDirectory;
23-
late String sdkSummaryPath;
2423
late String compilerWorkerPath;
2524

2625
// Missing assets
27-
late String sdkFullDillPath;
2826
late String amdSdkJsPath;
2927
late String amdSdkJsMapPath;
3028
late String ddcSdkJsPath;
@@ -37,20 +35,17 @@ void main() {
3735
sdkDirectory = tempDir.path;
3836
final copySdkLayout = TestSdkLayout.createDefault(sdkDirectory);
3937

40-
sdkSummaryPath = copySdkLayout.summaryPath;
4138
compilerWorkerPath = copySdkLayout.dartdevcSnapshotPath;
4239

4340
// Copy the SDK directory into a temp directory.
4441
await copyDirectory(TestSdkLayout.defaultSdkDirectory, sdkDirectory);
4542

4643
// Simulate missing assets.
47-
sdkFullDillPath = copySdkLayout.fullDillPath;
4844
amdSdkJsPath = copySdkLayout.amdJsPath;
4945
amdSdkJsMapPath = copySdkLayout.amdJsMapPath;
5046
ddcSdkJsPath = copySdkLayout.ddcJsPath;
5147
ddcSdkJsMapPath = copySdkLayout.ddcJsMapPath;
5248

53-
_deleteIfExists(sdkFullDillPath);
5449
_deleteIfExists(amdSdkJsPath);
5550
_deleteIfExists(amdSdkJsMapPath);
5651
_deleteIfExists(ddcSdkJsPath);
@@ -79,8 +74,6 @@ void main() {
7974
expect(configuration.sdkDirectory, equals(sdkDirectory));
8075
expect(configuration.compilerWorkerPath, equals(compilerWorkerPath));
8176

82-
expect(sdkLayout.summaryPath, equals(sdkSummaryPath));
83-
expect(sdkLayout.fullDillPath, equals(sdkFullDillPath));
8477
expect(sdkLayout.amdJsPath, equals(amdSdkJsPath));
8578
expect(sdkLayout.amdJsMapPath, equals(amdSdkJsMapPath));
8679

@@ -89,8 +82,6 @@ void main() {
8982
configuration.validate();
9083

9184
// Validate all assets exist.
92-
expect(sdkLayout.summaryPath, _exists);
93-
expect(sdkLayout.fullDillPath, _exists);
9485
expect(sdkLayout.amdJsPath, _exists);
9586
expect(sdkLayout.amdJsMapPath, _exists);
9687
});
@@ -113,8 +104,6 @@ void main() {
113104
expect(configuration.sdkDirectory, equals(sdkDirectory));
114105
expect(configuration.compilerWorkerPath, equals(compilerWorkerPath));
115106

116-
expect(sdkLayout.summaryPath, equals(sdkSummaryPath));
117-
expect(sdkLayout.fullDillPath, equals(sdkFullDillPath));
118107
expect(sdkLayout.ddcJsPath, equals(ddcSdkJsPath));
119108
expect(sdkLayout.ddcJsMapPath, equals(ddcSdkJsMapPath));
120109

@@ -123,8 +112,6 @@ void main() {
123112
configuration.validate();
124113

125114
// Validate all assets exist.
126-
expect(sdkLayout.summaryPath, _exists);
127-
expect(sdkLayout.fullDillPath, _exists);
128115
expect(sdkLayout.ddcJsPath, _exists);
129116
expect(sdkLayout.ddcJsMapPath, _exists);
130117
});

0 commit comments

Comments
 (0)