Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 846c5bb

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[dyn_modules] Compile all libraries mentioned in dynamic_interface.yaml
All libraries exported via dynamic_interface.yaml (except 'dart:' libraries) are now always compiled, as if they were specified using --source flag on the gen_kernel / frontend_server command line. This makes sure that exported libraries would be available for dynamic modules even if they are not used in the host app. TEST=pkg/dynamic_modules/test Fixes b/452833638 Change-Id: I513a75bea76a18a3591613ecd68e7307e66a7c24 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458586 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent 3797f3b commit 846c5bb

File tree

11 files changed

+107
-40
lines changed

11 files changed

+107
-40
lines changed

‎pkg/dart2wasm/lib/compile.dart‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:typed_data';
77

88
import 'package:build_integration/file_system/multi_root.dart'
99
show MultiRootFileSystem, MultiRootFileSystemEntity;
10+
import 'package:front_end/src/api_prototype/dynamic_module_validator.dart'
11+
show DynamicInterfaceYamlFile;
1012
import 'package:front_end/src/api_prototype/file_system.dart' show FileSystem;
1113
import 'package:front_end/src/api_unstable/vm.dart'
1214
show
@@ -266,6 +268,23 @@ Future<CompilationResult> _runCfePhase(
266268
compilerOptions.compileSdk = true;
267269
}
268270

271+
List<Uri> additionalSources = const [];
272+
final isDynamicMainModule =
273+
options.dynamicModuleType == DynamicModuleType.main;
274+
if (isDynamicMainModule) {
275+
final dynamicInterfaceUri = options.dynamicInterfaceUri;
276+
if (dynamicInterfaceUri != null) {
277+
final resolvedDynamicInterfaceUri =
278+
await _resolveUri(fileSystem, dynamicInterfaceUri);
279+
final contents =
280+
File.fromUri(resolvedDynamicInterfaceUri!).readAsStringSync();
281+
final dynamicInterfaceYamlFile = DynamicInterfaceYamlFile(contents);
282+
additionalSources = dynamicInterfaceYamlFile
283+
.getUserLibraryUris(dynamicInterfaceUri)
284+
.toList();
285+
}
286+
}
287+
269288
final dynamicMainModuleUri =
270289
await _resolveUri(fileSystem, options.dynamicMainModuleUri);
271290
final isDynamicSubmodule =
@@ -284,7 +303,7 @@ Future<CompilationResult> _runCfePhase(
284303
CompilerResult? compilerResult;
285304
try {
286305
compilerResult = await kernelForProgram(options.mainUri, compilerOptions,
287-
requireMain: !isDynamicSubmodule);
306+
requireMain: !isDynamicSubmodule, additionalSources: additionalSources);
288307
} catch (e, s) {
289308
return CFECrashError(e, s);
290309
}

‎pkg/dynamic_modules/test/data/const_constructor/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import '../../common/testing.dart' as helper;
66
import 'package:expect/expect.dart';
77

8-
import 'shared/shared.dart'; // ignore: unused_import
9-
108
/// Verify that default values of const constructor parameters are retained.
119
void main() async {
1210
final result = (await helper.load('entry1.dart')) as String;

‎pkg/dynamic_modules/test/data/extend_class3/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import '../../common/testing.dart' as helper;
6-
// ignore: unused_import
7-
import 'shared/shared.dart';
86
import 'package:expect/expect.dart';
97

108
/// Verify that `is` test works correctly for an instance of a class

‎pkg/dynamic_modules/test/data/extend_class4/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import '../../common/testing.dart' as helper;
6-
// ignore: unused_import
7-
import 'shared/shared.dart';
86
import 'package:expect/expect.dart';
97

108
/// Verify that instance calls work when receiver has a dynamically loaded

‎pkg/dynamic_modules/test/data/extension_type/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import '../../common/testing.dart' as helper;
66
import 'package:expect/expect.dart';
77

8-
import 'shared/shared.dart'; // ignore: unused_import
9-
108
/// A dynamic module is allowed to extend a class in the dynamic interface and
119
/// override its members.
1210
void main() async {

‎pkg/dynamic_modules/test/data/extension_type2/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import '../../common/testing.dart' as helper;
66
import 'package:expect/expect.dart';
77

8-
import 'shared/shared.dart'; // ignore: unused_import
9-
108
void main() async {
119
final result = (await helper.load('entry1.dart')) as int;
1210
Expect.equals(1, result);

‎pkg/dynamic_modules/test/data/mixin_deduplication/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import '../../common/testing.dart' as helper;
66
import 'package:expect/expect.dart';
77

8-
import 'shared/shared.dart'; // ignore: unused_import
9-
108
/// A dynamic module can reference a mixin application which
119
/// could be de-duplicated.
1210
void main() async {

‎pkg/dynamic_modules/test/data/mixin_field/main.dart‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import '../../common/testing.dart' as helper;
66

7-
import 'shared/shared.dart'; // ignore: unused_import
8-
97
/// A dynamic module can use mixin with a field.
108
void main() async {
119
final func = (await helper.load('entry1.dart')) as void Function();

‎pkg/front_end/lib/src/api_prototype/dynamic_module_validator.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
library front_end.dynamic_module_validator;
66

77
export '../kernel/dynamic_module_validator.dart'
8-
show DynamicInterfaceLanguageImplPragmas, DynamicInterfaceSpecification;
8+
show
9+
DynamicInterfaceLanguageImplPragmas,
10+
DynamicInterfaceYamlFile,
11+
DynamicInterfaceSpecification;

‎pkg/front_end/lib/src/kernel/dynamic_module_validator.dart‎

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,81 @@ void validateDynamicModule(
5656
}
5757
}
5858

59+
extension on YamlMap {
60+
void verifyKeys(Set<String> allowedKeys) {
61+
for (dynamic k in keys) {
62+
if (!allowedKeys.contains(k.toString())) {
63+
// Coverage-ignore-block(suite): Not run.
64+
throw 'Unexpected key "$k" in dynamic interface specification';
65+
}
66+
}
67+
}
68+
}
69+
70+
/// Loaded contents of dynamic interface specification yaml file.
71+
class DynamicInterfaceYamlFile {
72+
final YamlNode _root;
73+
74+
DynamicInterfaceYamlFile(String contents) : _root = loadYamlNode(contents) {
75+
if (!isEmpty) {
76+
sections.verifyKeys(const {
77+
'extendable',
78+
'can-be-overridden',
79+
'callable',
80+
});
81+
}
82+
}
83+
84+
bool get isEmpty => _root is! YamlMap;
85+
86+
YamlMap get sections => _root as YamlMap;
87+
88+
YamlList? get extendable => sections['extendable'];
89+
YamlList? get canBeOverridden => sections['can-be-overridden'];
90+
YamlList? get callable => sections['callable'];
91+
92+
// Coverage-ignore(suite): Not run.
93+
Set<String> get libraries => {
94+
for (YamlList section in [?extendable, ?canBeOverridden, ?callable])
95+
for (YamlNode item in section) (item as YamlMap)['library'] as String,
96+
};
97+
98+
// Coverage-ignore(suite): Not run.
99+
Iterable<Uri> getUserLibraryUris(Uri baseUri) => libraries
100+
.where((String lib) => !lib.startsWith('dart:'))
101+
.map((String lib) => baseUri.resolve(lib));
102+
}
103+
59104
/// Parsed dynamic interface specification yaml file.
60105
class DynamicInterfaceSpecification {
61106
// Specified Library, Class and Member nodes.
62107
final Set<TreeNode> extendable = {};
63108
final Set<TreeNode> canBeOverridden = {};
64109
final Set<TreeNode> callable = {};
65110

66-
DynamicInterfaceSpecification(
111+
factoryDynamicInterfaceSpecification(
67112
String dynamicInterfaceSpecification,
68113
Uri baseUri,
69114
Component component,
115+
) => new DynamicInterfaceSpecification.fromYamlFile(
116+
new DynamicInterfaceYamlFile(dynamicInterfaceSpecification),
117+
baseUri,
118+
component,
119+
);
120+
121+
DynamicInterfaceSpecification.fromYamlFile(
122+
DynamicInterfaceYamlFile yamlFile,
123+
Uri baseUri,
124+
Component component,
70125
) {
71-
final YamlNode spec = loadYamlNode(dynamicInterfaceSpecification);
72-
final LibraryIndex libraryIndex = new LibraryIndex.all(component);
126+
if (yamlFile.isEmpty) {
127+
return;
128+
}
73129

74-
// If the spec is empty, the result is a scalar and not a map.
75-
if (spec is! YamlMap) return;
76-
_verifyKeys(spec, const {'extendable', 'can-be-overridden', 'callable'});
130+
final LibraryIndex libraryIndex = new LibraryIndex.all(component);
77131

78132
_parseList(
79-
spec['extendable'],
133+
yamlFile.extendable,
80134
extendable,
81135
baseUri,
82136
component,
@@ -86,7 +140,7 @@ class DynamicInterfaceSpecification {
86140
);
87141

88142
_parseList(
89-
spec['can-be-overridden'],
143+
yamlFile.canBeOverridden,
90144
canBeOverridden,
91145
baseUri,
92146
component,
@@ -96,7 +150,7 @@ class DynamicInterfaceSpecification {
96150
);
97151

98152
_parseList(
99-
spec['callable'],
153+
yamlFile.callable,
100154
callable,
101155
baseUri,
102156
component,
@@ -130,15 +184,6 @@ class DynamicInterfaceSpecification {
130184
}
131185
}
132186

133-
void _verifyKeys(YamlMap map, Set<String> allowedKeys) {
134-
for (dynamic k in map.keys) {
135-
if (!allowedKeys.contains(k.toString())) {
136-
// Coverage-ignore-block(suite): Not run.
137-
throw 'Unexpected key "$k" in dynamic interface specification';
138-
}
139-
}
140-
}
141-
142187
void findNodes(
143188
YamlNode yamlNode,
144189
Set<TreeNode> result,
@@ -151,9 +196,9 @@ class DynamicInterfaceSpecification {
151196
final YamlMap yamlMap = yamlNode as YamlMap;
152197
final bool allowMembers = allowStaticMembers || allowInstanceMembers;
153198
if (allowMembers) {
154-
_verifyKeys(yamlMap, const {'library', 'member'});
199+
yamlMap.verifyKeys(const {'library', 'class', 'member'});
155200
} else {
156-
_verifyKeys(yamlMap, const {'library', 'class'});
201+
yamlMap.verifyKeys(const {'library', 'class'});
157202
}
158203

159204
final String librarySpec = yamlMap['library'] as String;
@@ -163,7 +208,7 @@ class DynamicInterfaceSpecification {
163208
final dynamic yamlClassNode = yamlMap['class'];
164209
if (yamlClassNode is YamlList) {
165210
// Coverage-ignore-block(suite): Not run.
166-
_verifyKeys(yamlMap, const {'library', 'class'});
211+
yamlMap.verifyKeys(const {'library', 'class'});
167212
for (dynamic c in yamlClassNode) {
168213
result.add(libraryIndex.getClass(libraryUri, c as String));
169214
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /