Skip to content

Commit 40bf581

Browse files
MarkzipanCommit Queue
authored andcommitted
[ddc] Adding extraDdcOptions forwarder to frontend server.
Change-Id: Ie2ee13b6089f4f24957e9865d6c2fd7296ed7c30 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433261 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Mark Zhou <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 17c5356 commit 40bf581

File tree

5 files changed

+157
-72
lines changed

5 files changed

+157
-72
lines changed

pkg/dev_compiler/lib/src/command/command.dart

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -96,57 +96,7 @@ Future<CompilerResult> _compile(
9696
bool useIncrementalCompiler = false,
9797
Map<Uri, List<int>>? inputDigests,
9898
}) async {
99-
// TODO(jmesserly): refactor options to share code with dartdevc CLI.
100-
var argParser = ArgParser(allowTrailingOptions: true)
101-
..addFlag(
102-
'help',
103-
abbr: 'h',
104-
help: 'Display this message.',
105-
negatable: false,
106-
)
107-
..addOption('packages', help: 'The package spec file to use.')
108-
// TODO(jmesserly): is this still useful for us, or can we remove it now?
109-
..addFlag(
110-
'summarize-text',
111-
help: 'Emit API summary and AST in .js.txt and .ast.xml files.',
112-
defaultsTo: false,
113-
hide: true,
114-
)
115-
..addFlag(
116-
'track-widget-creation',
117-
help: 'Enable inspecting of Flutter widgets.',
118-
defaultsTo: false,
119-
hide: true,
120-
)
121-
// TODO(jmesserly): add verbose help to show hidden options
122-
..addOption(
123-
'dart-sdk-summary',
124-
help: 'The path to the Dart SDK summary file.',
125-
hide: true,
126-
)
127-
..addMultiOption(
128-
'multi-root',
129-
help:
130-
'The directories to search when encountering uris with the '
131-
'specified multi-root scheme.',
132-
defaultsTo: [Uri.base.path],
133-
)
134-
..addFlag(
135-
'compile-sdk',
136-
help: 'Build an SDK module.',
137-
defaultsTo: false,
138-
hide: true,
139-
)
140-
..addOption(
141-
'libraries-file',
142-
help: 'The path to the libraries.json file for the sdk.',
143-
)
144-
..addOption(
145-
'used-inputs-file',
146-
help: 'If set, the file to record inputs used.',
147-
hide: true,
148-
);
149-
Options.addArguments(argParser);
99+
var argParser = Options.nonSdkArgParser();
150100
var declaredVariables = parseAndRemoveDeclaredVariables(args);
151101
ArgResults argResults;
152102
try {

pkg/dev_compiler/lib/src/command/options.dart

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class Options {
153153
summaryModules: _parseCustomSummaryModules(
154154
args['summary'] as List<String>,
155155
),
156+
nonHotReloadablePackages: Set.from(
157+
args['non-hot-reloadable-package'] as List<String>,
158+
),
156159
moduleFormats: parseModuleFormatOption(args),
157160
moduleName: _getModuleName(args),
158161
multiRootScheme: args['multi-root-scheme'] as String,
@@ -194,6 +197,14 @@ class Options {
194197
'API summary file(s) of imported libraries, optionally\n'
195198
'with module import path: -s path.dill=js/import/path',
196199
)
200+
..addMultiOption(
201+
'non-hot-reloadable-package',
202+
help:
203+
'Specifies that a package should not be hot reloaded.\n'
204+
'Hot reload will be rejected when any such package is modified. '
205+
'This allows the compiler to emit these packages with better '
206+
'performance.',
207+
)
197208
..addFlag(
198209
'summarize',
199210
help: 'Emit an API summary file.',
@@ -227,8 +238,8 @@ class Options {
227238
defaultsTo: false,
228239
hide: hide,
229240
)
230-
// TODO(41852) Define a process for breaking changes before graduating
231-
// from experimental.
241+
// TODO(41852) Define a process for breaking changes before graduating from
242+
// experimental.
232243
..addFlag(
233244
'experimental-emit-debug-metadata',
234245
help:
@@ -368,6 +379,63 @@ class Options {
368379
// that build systems do not depend on passing windows-style paths here.
369380
return p.toUri(moduleName).toString();
370381
}
382+
383+
/// Returns an `ArgParser` for arguments compatible with non-SDK DDC
384+
/// compilations.
385+
static ArgParser nonSdkArgParser() {
386+
// TODO(jmesserly): refactor options to share code with dartdevc CLI.
387+
var argParser = ArgParser(allowTrailingOptions: true)
388+
..addFlag(
389+
'help',
390+
abbr: 'h',
391+
help: 'Display this message.',
392+
negatable: false,
393+
)
394+
..addOption('packages', help: 'The package spec file to use.')
395+
// TODO(jmesserly): is this still useful for us, or can we remove it now?
396+
..addFlag(
397+
'summarize-text',
398+
help: 'Emit API summary and AST in .js.txt and .ast.xml files.',
399+
defaultsTo: false,
400+
hide: true,
401+
)
402+
..addFlag(
403+
'track-widget-creation',
404+
help: 'Enable inspecting of Flutter widgets.',
405+
defaultsTo: false,
406+
hide: true,
407+
)
408+
// TODO(jmesserly): add verbose help to show hidden options
409+
..addOption(
410+
'dart-sdk-summary',
411+
help: 'The path to the Dart SDK summary file.',
412+
hide: true,
413+
)
414+
..addMultiOption(
415+
'multi-root',
416+
help:
417+
'The directories to search when encountering uris with the '
418+
'specified multi-root scheme.',
419+
defaultsTo: [Uri.base.path],
420+
)
421+
..addFlag(
422+
'compile-sdk',
423+
help: 'Build an SDK module.',
424+
defaultsTo: false,
425+
hide: true,
426+
)
427+
..addOption(
428+
'libraries-file',
429+
help: 'The path to the libraries.json file for the sdk.',
430+
)
431+
..addOption(
432+
'used-inputs-file',
433+
help: 'If set, the file to record inputs used.',
434+
hide: true,
435+
);
436+
Options.addArguments(argParser);
437+
return argParser;
438+
}
371439
}
372440

373441
/// Finds explicit module names of the form `path=name` in [summaryPaths],

pkg/dev_compiler/lib/src/compiler/module_builder.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ import 'js_names.dart';
1313
/// The module format to emit.
1414
enum ModuleFormat {
1515
/// ECMAScript 6 module using import and export.
16-
es6,
16+
es6('es6'),
1717

1818
/// CommonJS module (used in Node.js)
19-
common,
19+
common('common'),
2020

2121
/// Asynchronous Module Definition (AMD, used in browsers).
22-
amd,
22+
amd('amd'),
2323

2424
/// Dart Dev Compiler's own format.
25-
ddc,
25+
ddc('ddc'),
2626

2727
// New version of ddc module system that will support hot reload.
2828
// TODO(nshahan) Eventually replace the existing `ddc` with this format.
29-
ddcLibraryBundle,
29+
ddcLibraryBundle('ddc');
30+
31+
const ModuleFormat(this.flagName);
32+
33+
/// The name of the module format passed to DDC's `--modules` flag.
34+
final String flagName;
3035
}
3136

3237
/// Parses a string into a [ModuleFormat].

pkg/frontend_server/lib/frontend_server.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ ArgParser argParser = new ArgParser(allowTrailingOptions: true)
195195
..addMultiOption('enable-experiment',
196196
help: 'Comma separated list of experimental features, e.g. set-literals.',
197197
hide: true)
198+
..addMultiOption(
199+
'extra-ddc-options',
200+
help:
201+
'A comma-separated list of additional command line arguments that will'
202+
'be passed directly to DDC. Example: '
203+
'"--extra-ddc-options=--canary".',
204+
hide: true,
205+
)
198206
..addFlag('split-output-by-packages',
199207
help:
200208
'Split resulting kernel file into multiple files (one per package).',
@@ -694,9 +702,14 @@ class FrontendCompiler implements CompilerInterface {
694702
transformer?.transform(results.component!);
695703

696704
if (_compilerOptions.target!.name == 'dartdevc') {
705+
List<String>? extraDdcOptions = options.wasParsed('extra-ddc-options')
706+
? options.multiOption('extra-ddc-options')
707+
: null;
697708
await writeJavaScriptBundle(results, _kernelBinaryFilename,
698709
options['filesystem-scheme'], options['dartdevc-module-format'],
699-
fullComponent: true, recompileRestart: false);
710+
fullComponent: true,
711+
recompileRestart: false,
712+
extraDdcOptions: extraDdcOptions);
700713
}
701714
await writeDillFile(
702715
results,
@@ -838,7 +851,9 @@ class FrontendCompiler implements CompilerInterface {
838851
/// `recompile-restart` request.
839852
Future<void> writeJavaScriptBundle(KernelCompilationResults results,
840853
String filename, String fileSystemScheme, String moduleFormat,
841-
{required bool fullComponent, required bool recompileRestart}) async {
854+
{required bool fullComponent,
855+
required bool recompileRestart,
856+
List<String>? extraDdcOptions}) async {
842857
PackageConfig packageConfig = await loadPackageConfigUri(
843858
_compilerOptions.packagesFileUri ??
844859
new File('.dart_tool/package_config.json').absolute.uri);
@@ -853,6 +868,7 @@ class FrontendCompiler implements CompilerInterface {
853868
emitDebugMetadata: emitDebugMetadata,
854869
moduleFormat: moduleFormat,
855870
canaryFeatures: canaryFeatures,
871+
extraDdcOptions: extraDdcOptions ?? [],
856872
);
857873
if (fullComponent) {
858874
await bundler.initialize(component, _mainSource, packageConfig);
@@ -1048,9 +1064,14 @@ class FrontendCompiler implements CompilerInterface {
10481064

10491065
if (_compilerOptions.target!.name == 'dartdevc') {
10501066
try {
1067+
List<String>? extraDdcOptions = _options.wasParsed('extra-ddc-options')
1068+
? _options.multiOption('extra-ddc-options')
1069+
: null;
10511070
await writeJavaScriptBundle(results, _kernelBinaryFilename,
10521071
_options['filesystem-scheme'], _options['dartdevc-module-format'],
1053-
fullComponent: false, recompileRestart: recompileRestart);
1072+
fullComponent: false,
1073+
recompileRestart: recompileRestart,
1074+
extraDdcOptions: extraDdcOptions);
10541075
} catch (e) {
10551076
_outputStream.writeln('$e');
10561077
errors.add(e.toString());

pkg/frontend_server/lib/src/javascript_bundle.dart

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:convert';
88
import 'dart:io';
99
import 'dart:typed_data';
1010

11+
import 'package:args/args.dart';
1112
import 'package:dev_compiler/dev_compiler.dart';
1213
import 'package:dev_compiler/src/command/command.dart';
1314
import 'package:dev_compiler/src/kernel/hot_reload_delta_inspector.dart';
@@ -42,12 +43,14 @@ class IncrementalJavaScriptBundler {
4243
this.emitDebugSymbols = false,
4344
this.canaryFeatures = false,
4445
String? moduleFormat,
46+
this.extraDdcOptions = const [],
4547
}) : _moduleFormat = parseModuleFormat(moduleFormat ?? 'amd');
4648

4749
final bool useDebuggerModuleNames;
4850
final bool emitDebugMetadata;
4951
final bool emitDebugSymbols;
5052
final ModuleFormat _moduleFormat;
53+
final List<String> extraDdcOptions;
5154
final bool canaryFeatures;
5255
final FileSystem? _fileSystem;
5356
final Set<Library> _loadedLibraries;
@@ -185,6 +188,20 @@ class IncrementalJavaScriptBundler {
185188
}
186189
}
187190

191+
/// Reports if [option] in [extraDdcOptions] was overridden or extended
192+
/// to [newValue] before being passed to DDC.
193+
void _checkOverriddenExtraDdcOption(
194+
ArgResults extraDdcOptionsResults, String option, dynamic newValue) {
195+
if (extraDdcOptionsResults.wasParsed(option)) {
196+
if (newValue is List) {
197+
if (listEquals(extraDdcOptionsResults[option], newValue)) return;
198+
} else if (newValue == extraDdcOptionsResults[option]) {
199+
return;
200+
}
201+
print("Warning: DDC option '$option' was overridden to '$newValue'.");
202+
}
203+
}
204+
188205
/// Compile each component into a single JavaScript library bundle.
189206
Future<Map<String, Compiler>> compile(
190207
ClassHierarchy classHierarchy,
@@ -221,18 +238,42 @@ class IncrementalJavaScriptBundler {
221238

222239
final String componentUrl =
223240
urlForComponentUri(libraryBundleImport, packageConfig);
224-
// library bundle name to use in trackLibraries
225-
// use full path for tracking if library bundle uri is not a package uri.
241+
// Library bundle name to use in trackLibraries. Use the full path for
242+
// tracking if library bundle uri is not a package uri.
226243
final String libraryBundleName = makeLibraryBundleName(componentUrl);
227-
final Options ddcOptions = new Options(
228-
sourceMap: true,
229-
summarizeApi: false,
230-
emitDebugMetadata: emitDebugMetadata,
231-
emitDebugSymbols: emitDebugSymbols,
232-
moduleName: libraryBundleName,
233-
canaryFeatures: canaryFeatures,
234-
moduleFormats: [_moduleFormat],
235-
);
244+
// Issue a warning when provided [extraDdcOptions] were overridden.
245+
final ArgResults extraDdcOptionsResults =
246+
Options.nonSdkArgParser().parse(extraDdcOptions);
247+
_checkOverriddenExtraDdcOption(
248+
extraDdcOptionsResults, 'source-map', true);
249+
_checkOverriddenExtraDdcOption(
250+
extraDdcOptionsResults, 'summarize', false);
251+
_checkOverriddenExtraDdcOption(extraDdcOptionsResults,
252+
'experimental-emit-debug-metadata', emitDebugMetadata);
253+
_checkOverriddenExtraDdcOption(
254+
extraDdcOptionsResults, 'emit-debug-symbols', emitDebugSymbols);
255+
_checkOverriddenExtraDdcOption(
256+
extraDdcOptionsResults, 'canary', canaryFeatures);
257+
_checkOverriddenExtraDdcOption(
258+
extraDdcOptionsResults, 'module-name', libraryBundleName);
259+
_checkOverriddenExtraDdcOption(
260+
extraDdcOptionsResults, 'modules', [libraryBundleName]);
261+
// Apply existing Frontend Server flags over options selected in
262+
// [extraDdcOptions].
263+
final List<String> ddcArgs = [
264+
...extraDdcOptions,
265+
'--source-map',
266+
'--no-summarize',
267+
emitDebugMetadata
268+
? '--experimental-emit-debug-metadata'
269+
: '--no-experimental-emit-debug-metadata',
270+
emitDebugSymbols ? '--emit-debug-symbols' : '--no-emit-debug-symbols',
271+
canaryFeatures ? '--canary' : '--no-canary',
272+
'--module-name=$libraryBundleName',
273+
'--modules=${_moduleFormat.flagName}',
274+
];
275+
final Options ddcOptions =
276+
new Options.fromArguments(Options.nonSdkArgParser().parse(ddcArgs));
236277
Compiler compiler;
237278
if (ddcOptions.emitLibraryBundle) {
238279
compiler = new LibraryBundleCompiler(

0 commit comments

Comments
 (0)