Skip to content

Commit 789b1d1

Browse files
Anna GringauzeCommit Queue
Anna Gringauze
authored and
Commit Queue
committed
[frontend_server] Add --canary flag
Closes: #52774 Change-Id: Ie42a803c5b63a41c37984a790ab0406c8939872d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311149 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Anna Gringauze <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent 4949f61 commit 789b1d1

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

pkg/frontend_server/lib/frontend_server.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ ArgParser argParser = ArgParser(allowTrailingOptions: true)
203203
..addOption('dartdevc-module-format',
204204
help: 'The module format to use on for the dartdevc compiler',
205205
defaultsTo: 'amd')
206+
..addFlag('dartdevc-canary',
207+
help: 'Enable canary features in dartdevc compiler', defaultsTo: false)
206208
..addFlag('flutter-widget-cache',
207209
help: 'Enable the widget cache to track changes to Widget subtypes',
208210
defaultsTo: false)
@@ -371,15 +373,17 @@ class BinaryPrinterFactory {
371373
}
372374

373375
class FrontendCompiler implements CompilerInterface {
374-
FrontendCompiler(StringSink? outputStream,
375-
{BinaryPrinterFactory? printerFactory,
376-
this.transformer,
377-
this.unsafePackageSerialization,
378-
this.incrementalSerialization = true,
379-
this.useDebuggerModuleNames = false,
380-
this.emitDebugMetadata = false,
381-
this.emitDebugSymbols = false})
382-
: _outputStream = outputStream ?? stdout,
376+
FrontendCompiler(
377+
StringSink? outputStream, {
378+
BinaryPrinterFactory? printerFactory,
379+
this.transformer,
380+
this.unsafePackageSerialization,
381+
this.incrementalSerialization = true,
382+
this.useDebuggerModuleNames = false,
383+
this.emitDebugMetadata = false,
384+
this.emitDebugSymbols = false,
385+
this.canaryFeatures = false,
386+
}) : _outputStream = outputStream ?? stdout,
383387
printerFactory = printerFactory ?? BinaryPrinterFactory();
384388

385389
/// Fields with initializers
@@ -393,6 +397,7 @@ class FrontendCompiler implements CompilerInterface {
393397
final StringSink _outputStream;
394398
BinaryPrinterFactory printerFactory;
395399
bool useDebuggerModuleNames;
400+
bool canaryFeatures;
396401

397402
/// Initialized in [compile].
398403
late List<Uri> _additionalSources;
@@ -750,6 +755,7 @@ class FrontendCompiler implements CompilerInterface {
750755
emitDebugMetadata: emitDebugMetadata,
751756
moduleFormat: moduleFormat,
752757
soundNullSafety: soundNullSafety,
758+
canaryFeatures: canaryFeatures,
753759
);
754760
if (fullComponent) {
755761
await bundler.initialize(component, _mainSource, packageConfig);

pkg/frontend_server/lib/src/javascript_bundle.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class IncrementalJavaScriptBundler {
3535
this.emitDebugMetadata = false,
3636
this.emitDebugSymbols = false,
3737
this.soundNullSafety = false,
38+
this.canaryFeatures = false,
3839
String? moduleFormat,
3940
}) : _moduleFormat = parseModuleFormat(moduleFormat ?? 'amd');
4041

@@ -43,6 +44,7 @@ class IncrementalJavaScriptBundler {
4344
final bool emitDebugSymbols;
4445
final ModuleFormat _moduleFormat;
4546
final bool soundNullSafety;
47+
final bool canaryFeatures;
4648
final FileSystem? _fileSystem;
4749
final Set<Library> _loadedLibraries;
4850
final Map<Uri, Component> _uriToComponent = <Uri, Component>{};
@@ -208,6 +210,7 @@ class IncrementalJavaScriptBundler {
208210
emitDebugSymbols: emitDebugSymbols,
209211
moduleName: moduleName,
210212
soundNullSafety: soundNullSafety,
213+
canaryFeatures: canaryFeatures,
211214
),
212215
_importToSummary,
213216
_summaryToModule,

pkg/frontend_server/lib/starter.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ Future<int> starter(
8787
return 0;
8888
}
8989

90-
compiler ??= FrontendCompiler(output,
91-
printerFactory: binaryPrinterFactory,
92-
unsafePackageSerialization: options["unsafe-package-serialization"],
93-
incrementalSerialization: options["incremental-serialization"],
94-
useDebuggerModuleNames: options['debugger-module-names'],
95-
emitDebugMetadata: options['experimental-emit-debug-metadata'],
96-
emitDebugSymbols: options['emit-debug-symbols']);
90+
compiler ??= FrontendCompiler(
91+
output,
92+
printerFactory: binaryPrinterFactory,
93+
unsafePackageSerialization: options["unsafe-package-serialization"],
94+
incrementalSerialization: options["incremental-serialization"],
95+
useDebuggerModuleNames: options['debugger-module-names'],
96+
emitDebugMetadata: options['experimental-emit-debug-metadata'],
97+
emitDebugSymbols: options['emit-debug-symbols'],
98+
canaryFeatures: options['dartdevc-canary'],
99+
);
97100

98101
if (options.rest.isNotEmpty) {
99102
return await compiler.compile(options.rest[0], options,

pkg/frontend_server/test/frontend_server_test.dart

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,53 @@ void main(List<String> arguments, SendPort sendPort) {
19011901
];
19021902

19031903
expect(await starter(args), 0);
1904+
1905+
expect(dillFile.existsSync(), true);
1906+
});
1907+
1908+
test('compile to JavaScript with canary features enabled', () async {
1909+
var file = File('${tempDir.path}/foo.dart')..createSync();
1910+
file.writeAsStringSync("main() {\n}\n");
1911+
var packageConfig = File('${tempDir.path}/.dart_tool/package_config.json')
1912+
..createSync(recursive: true)
1913+
..writeAsStringSync('''
1914+
{
1915+
"configVersion": 2,
1916+
"packages": [
1917+
{
1918+
"name": "hello",
1919+
"rootUri": "../",
1920+
"packageUri": "./"
1921+
}
1922+
]
1923+
}
1924+
''');
1925+
var dillFile = File('${tempDir.path}/app.dill');
1926+
var sourcesFile = File('${tempDir.path}/app.dill.sources');
1927+
1928+
expect(dillFile.existsSync(), false);
1929+
expect(sourcesFile.existsSync(), false);
1930+
1931+
final List<String> args = <String>[
1932+
'--sdk-root=${sdkRoot.toFilePath()}',
1933+
'--incremental',
1934+
'--platform=${ddcPlatformKernel.path}',
1935+
'--output-dill=${dillFile.path}',
1936+
'--packages=${packageConfig.path}',
1937+
'--target=dartdevc',
1938+
'--dartdevc-canary',
1939+
file.path,
1940+
];
1941+
1942+
expect(await starter(args), 0);
1943+
1944+
expect(dillFile.existsSync(), true);
1945+
expect(sourcesFile.existsSync(), true);
1946+
var ddcFlags = utf8
1947+
.decode(sourcesFile.readAsBytesSync())
1948+
.split('\n')
1949+
.singleWhere((l) => l.startsWith('// Flags: '));
1950+
expect(ddcFlags, contains('canary'));
19041951
});
19051952

19061953
test('compile to JavaScript with package scheme', () async {
@@ -2441,7 +2488,9 @@ e() {
24412488
expect(await result, 0);
24422489
expect(count, 1);
24432490
frontendServer.close();
2444-
}, timeout: Timeout.none);
2491+
},
2492+
timeout: Timeout.none,
2493+
skip: 'https://github.com/dart-lang/sdk/issues/52775');
24452494

24462495
test('compile to JavaScript, all modules with sound null safety', () async {
24472496
var file = File('${tempDir.path}/foo.dart')..createSync();
@@ -2867,8 +2916,8 @@ e() {
28672916
'--output-dill=${dillFile.path}',
28682917
'--output-incremental-dill=${incrementalDillFile.path}'
28692918
];
2870-
File dart2js = File.fromUri(
2871-
Platform.script.resolve("../../../pkg/compiler/lib/src/dart2js.dart"));
2919+
File dart2js = File.fromUri(Platform.script
2920+
.resolve("../../../pkg/compiler/lib/src/dart2js.dart"));
28722921
expect(dart2js.existsSync(), equals(true));
28732922
File dart2jsOtherFile = File.fromUri(Platform.script
28742923
.resolve("../../../pkg/compiler/lib/src/compiler.dart"));
@@ -2925,7 +2974,8 @@ e() {
29252974
component =
29262975
loadComponentFromBinary(platformKernel.toFilePath(), component);
29272976
expect(component.mainMethod, isNotNull);
2928-
verifyComponent(target, VerificationStage.afterModularTransformations, component);
2977+
verifyComponent(target,
2978+
VerificationStage.afterModularTransformations, component);
29292979

29302980
count += 1;
29312981

@@ -2950,7 +3000,8 @@ e() {
29503000
component =
29513001
loadComponentFromBinary(platformKernel.toFilePath(), component);
29523002
expect(component.mainMethod, isNotNull);
2953-
verifyComponent(target, VerificationStage.afterModularTransformations, component);
3003+
verifyComponent(target,
3004+
VerificationStage.afterModularTransformations, component);
29543005

29553006
count += 1;
29563007

0 commit comments

Comments
 (0)