Skip to content

Commit 1e7f9b7

Browse files
author
Anna Gringauze
authored
Create copying sdk configuration provider (#1984)
* Validate only needed summaries in expression_compiler_service * Move shared test functionality into test_common package * Rebase on master * Fix bad merge * Re-enable webdev weak null safety e2e tests * Create copy of the SDK for tests * Modify tests to run with sdk copy * Cleanup * Pull out project definitions into separate file * Add package name to the project and use it in tests * Fix sdk configiuration tests * Update instance_inspection tests * Less changes in chrome_proxy_service.dart * Add sdk configuration provider that copies the sdk directory * Remove duplicate file, fix windows test failures
1 parent 26910ba commit 1e7f9b7

File tree

6 files changed

+198
-188
lines changed

6 files changed

+198
-188
lines changed

dwds/test/fixtures/test_sdk_layout.dart

Lines changed: 0 additions & 159 deletions
This file was deleted.

test_common/lib/sdk_asset_generator.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:test_common/test_sdk_layout.dart';
1313
/// - sound null safety: js, source map, full dill.
1414
/// - weak null safety: js, source map, full dill, summary.
1515
class SdkAssetGenerator {
16-
static bool _sdkAssetsGenerated = false;
16+
bool _sdkAssetsGenerated = false;
1717
final _logger = Logger('SdkAssetGenerator');
1818

1919
final FileSystem fileSystem;
@@ -88,18 +88,15 @@ class SdkAssetGenerator {
8888
'org-dartlang-sdk:///lib/libraries.json',
8989
'--modules',
9090
'amd',
91-
if (soundNullSafety)
92-
'--sound-null-safety'
93-
else
94-
'--no-sound-null-safety',
91+
soundNullSafety ? '--sound-null-safety' : '--no-sound-null-safety',
9592
'dart:core',
9693
'-o',
9794
jsPath,
9895
];
9996

10097
final output = <String>[];
10198
_logger.fine('Executing dart ${args.join(' ')}');
102-
final process = await Process.start(Platform.resolvedExecutable, args,
99+
final process = await Process.start(sdkLayout.dartPath, args,
103100
workingDirectory: sdkLayout.sdkDirectory);
104101

105102
process.stdout
@@ -187,7 +184,7 @@ class SdkAssetGenerator {
187184
];
188185

189186
_logger.fine('Executing dart ${args.join(' ')}');
190-
final process = await Process.start(Platform.resolvedExecutable, args,
187+
final process = await Process.start(sdkLayout.dartPath, args,
191188
workingDirectory: sdkLayout.sdkDirectory);
192189

193190
final output = <String>[];

test_common/lib/test_sdk_configuration.dart

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,85 @@
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:(annagrin) Move to a test_common package.
5+
import 'dart:io';
6+
67
import 'package:dwds/sdk_configuration.dart';
8+
import 'package:logging/logging.dart';
79

810
import 'package:test_common/sdk_asset_generator.dart';
911
import 'package:test_common/test_sdk_layout.dart';
1012

13+
/// Implementation for SDK configuration for tests that can generate
14+
/// missing assets.
15+
///
16+
/// - Generate SDK js, source map, and full dill for weak and sound
17+
/// modes (normally included in flutter SDK or produced by build).
18+
/// - Need to generate SDK summary for weak null safety mode as it
19+
/// is not provided by the SDK installation.
20+
///
21+
/// TODO(annagrin): update to only generating missing sound artifacts
22+
/// for frontend server after we have no uses of weak null safety.
23+
class TestSdkCopyConfigurationProvider extends SdkConfigurationProvider {
24+
final _logger = Logger('TestSdkConfigurationProvider');
25+
26+
final bool _verbose;
27+
late final Directory _sdkDirectory;
28+
SdkConfiguration? _configuration;
29+
30+
late final TestSdkLayout sdkLayout;
31+
32+
TestSdkCopyConfigurationProvider({bool verbose = false})
33+
: _verbose = verbose {
34+
_sdkDirectory = Directory.systemTemp.createTempSync('sdk copy');
35+
sdkLayout = TestSdkLayout.createDefault(_sdkDirectory.path);
36+
}
37+
38+
@override
39+
Future<SdkConfiguration> get configuration async =>
40+
_configuration ??= await _create();
41+
42+
/// Generate missing assets in the default SDK layout.
43+
///
44+
/// Creates a copy of the SDK directory where all the missing assets
45+
/// are generated. Tests using this configuration run using the copy
46+
/// sdk layout to make sure the actual SDK is not modified.
47+
Future<SdkConfiguration> _create() async {
48+
try {
49+
await copyDirectory(
50+
TestSdkLayout.defaultSdkDirectory, _sdkDirectory.path);
51+
} catch (e, s) {
52+
_logger.severe('Failed to create SDK directory copy', e, s);
53+
dispose();
54+
rethrow;
55+
}
56+
57+
try {
58+
final assetGenerator = SdkAssetGenerator(
59+
sdkLayout: sdkLayout,
60+
verboseCompiler: _verbose,
61+
);
62+
63+
await assetGenerator.generateSdkAssets();
64+
return TestSdkLayout.createConfiguration(sdkLayout);
65+
} catch (e, s) {
66+
_logger.severe('Failed generate missing assets', e, s);
67+
dispose();
68+
rethrow;
69+
}
70+
}
71+
72+
void dispose({bool retry = true}) {
73+
try {
74+
if (_sdkDirectory.existsSync()) {
75+
_sdkDirectory.deleteSync(recursive: true);
76+
}
77+
} catch (e, s) {
78+
_logger.warning('Failed delete SDK directory copy', e, s);
79+
dispose(retry: false);
80+
}
81+
}
82+
}
83+
1184
/// Implementation for SDK configuration for tests that can generate
1285
/// missing assets.
1386
///

test_common/lib/test_sdk_layout.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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:io';
6+
57
import 'package:dwds/sdk_configuration.dart';
68
import 'package:path/path.dart' as p;
79

@@ -83,7 +85,11 @@ class TestSdkLayout {
8385
'web',
8486
'dart_stack_trace_mapper.js',
8587
),
86-
dartPath: p.join(sdkLayout.sdkDirectory, 'bin', 'dart'),
88+
dartPath: p.join(
89+
sdkLayout.sdkDirectory,
90+
'bin',
91+
Platform.isWindows ? 'dart.exe' : 'dart',
92+
),
8793
frontendServerSnapshotPath: p.join(
8894
sdkLayout.sdkDirectory,
8995
'bin',
@@ -97,6 +103,12 @@ class TestSdkLayout {
97103
'snapshots',
98104
'kernel_worker.dart.snapshot',
99105
),
106+
devToolsDirectory: p.join(
107+
sdkLayout.sdkDirectory,
108+
'bin',
109+
'resources',
110+
'devtools',
111+
),
100112
);
101113

102114
final String sdkDirectory;
@@ -128,6 +140,7 @@ class TestSdkLayout {
128140
final String frontendServerSnapshotPath;
129141
final String dartdevcSnapshotPath;
130142
final String kernelWorkerSnapshotPath;
143+
final String devToolsDirectory;
131144

132145
const TestSdkLayout({
133146
required this.sdkDirectory,
@@ -145,6 +158,7 @@ class TestSdkLayout {
145158
required this.frontendServerSnapshotPath,
146159
required this.dartdevcSnapshotPath,
147160
required this.kernelWorkerSnapshotPath,
161+
required this.devToolsDirectory,
148162
});
149163

150164
/// Creates configuration from sdk layout.
@@ -156,3 +170,20 @@ class TestSdkLayout {
156170
compilerWorkerPath: sdkLayout.dartdevcSnapshotPath,
157171
);
158172
}
173+
174+
// Update modified files.
175+
Future<void> copyDirectory(String from, String to) async {
176+
if (!Directory(from).existsSync()) return;
177+
await Directory(to).create(recursive: true);
178+
179+
await for (final file in Directory(from).list(followLinks: false)) {
180+
final copyTo = p.join(to, p.relative(file.path, from: from));
181+
if (file is Directory) {
182+
await copyDirectory(file.path, copyTo);
183+
} else if (file is File) {
184+
await File(file.path).copy(copyTo);
185+
} else if (file is Link) {
186+
await Link(copyTo).create(await file.target(), recursive: true);
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)