Skip to content

Commit 97a4280

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe,dartdev,dart2js] Add support for --verbosity option
In response to #44727 TEST=pkg/dartdev/test/commands/compile_test.dart Change-Id: I56b67d9362a415acd721c1cce2f7e2232d2493df Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180566 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
1 parent ee37fff commit 97a4280

File tree

18 files changed

+351
-42
lines changed

18 files changed

+351
-42
lines changed

pkg/compiler/lib/src/commandline_options.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class Flags {
9696
static const String useNewSourceInfo = '--use-new-source-info';
9797
static const String useOldRti = '--use-old-rti';
9898
static const String verbose = '--verbose';
99+
static const String verbosity = '--verbosity';
99100
static const String progress = '--show-internal-progress';
100101
static const String version = '--version';
101102
static const String reportMetrics = '--report-metrics';

pkg/compiler/lib/src/dart2js.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ Future<api.CompilationResult> compile(List<String> argv,
545545
new OptionHandler(Flags.testMode, passThrough),
546546
new OptionHandler('${Flags.dumpSsa}=.+', passThrough),
547547
new OptionHandler('${Flags.cfeInvocationModes}=.+', passThrough),
548+
new OptionHandler('${Flags.verbosity}=.+', passThrough),
548549

549550
// Experimental features.
550551
// We don't provide documentation for these yet.

pkg/compiler/lib/src/kernel/loader.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,22 @@ class KernelLoaderTask extends CompilerTask {
138138
bool verbose = false;
139139
Target target = Dart2jsTarget(targetName, TargetFlags());
140140
fe.FileSystem fileSystem = CompilerFileSystem(_compilerInput);
141+
fe.Verbosity verbosity = _options.verbosity;
141142
fe.DiagnosticMessageHandler onDiagnostic =
142-
(e) => reportFrontEndMessage(_reporter, e);
143+
(fe.DiagnosticMessage message) {
144+
if (fe.Verbosity.shouldPrint(verbosity, message)) {
145+
reportFrontEndMessage(_reporter, message);
146+
}
147+
};
143148
fe.CompilerOptions options = fe.CompilerOptions()
144149
..target = target
145150
..librariesSpecificationUri = _options.librariesSpecificationUri
146151
..packagesFileUri = _options.packageConfig
147152
..explicitExperimentalFlags = _options.explicitExperimentalFlags
148153
..verbose = verbose
149154
..fileSystem = fileSystem
150-
..onDiagnostic = onDiagnostic;
155+
..onDiagnostic = onDiagnostic
156+
..verbosity = verbosity;
151157
bool isLegacy =
152158
await fe.uriUsesLegacyLanguageVersion(resolvedUri, options);
153159
inferNullSafetyMode(_options.enableNonNullable && !isLegacy);
@@ -171,8 +177,8 @@ class KernelLoaderTask extends CompilerTask {
171177
nnbdMode: _options.useLegacySubtyping
172178
? fe.NnbdMode.Weak
173179
: fe.NnbdMode.Strong,
174-
invocationModes:
175-
fe.InvocationMode.parseArguments(_options.cfeInvocationModes));
180+
invocationModes: _options.cfeInvocationModes,
181+
verbosity: verbosity);
176182
component = await fe.compile(initializedCompilerState, verbose,
177183
fileSystem, onDiagnostic, resolvedUri);
178184
if (component == null) return null;

pkg/compiler/lib/src/options.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ class CompilerOptions implements DiagnosticOptions {
433433
/// See `InvocationMode` in
434434
/// `pkg/front_end/lib/src/api_prototype/compiler_options.dart` for all
435435
/// possible options.
436-
String cfeInvocationModes = '';
436+
Set<fe.InvocationMode> cfeInvocationModes = {};
437+
438+
/// Verbosity level used for filtering messages during compilation.
439+
fe.Verbosity verbosity = fe.Verbosity.all;
437440

438441
// -------------------------------------------------
439442
// Options for deprecated features
@@ -547,8 +550,13 @@ class CompilerOptions implements DiagnosticOptions {
547550
.._noSoundNullSafety = _hasOption(options, Flags.noSoundNullSafety)
548551
.._mergeFragmentsThreshold =
549552
_extractIntOption(options, '${Flags.mergeFragmentsThreshold}=')
550-
..cfeInvocationModes =
551-
_extractStringOption(options, '${Flags.cfeInvocationModes}=', '');
553+
..cfeInvocationModes = fe.InvocationMode.parseArguments(
554+
_extractStringOption(options, '${Flags.cfeInvocationModes}=', ''),
555+
onError: onError)
556+
..verbosity = fe.Verbosity.parseArgument(
557+
_extractStringOption(
558+
options, '${Flags.verbosity}=', fe.Verbosity.defaultValue),
559+
onError: onError);
552560
}
553561

554562
void validate() {

pkg/dart2native/bin/dart2native.dart

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

88
import 'package:args/args.dart';
99
import 'package:dart2native/generate.dart';
10+
import 'package:front_end/src/api_prototype/compiler_options.dart'
11+
show Verbosity;
1012

1113
void printUsage(final ArgParser parser) {
1214
print('''
@@ -65,7 +67,16 @@ Remove debugging information from the output and save it separately to the speci
6567
Comma separated list of experimental features.
6668
''')
6769
..addFlag('verbose',
68-
abbr: 'v', negatable: false, help: 'Show verbose output.');
70+
abbr: 'v', negatable: false, help: 'Show verbose output.')
71+
..addOption(
72+
'verbosity',
73+
defaultsTo: Verbosity.defaultValue,
74+
help: '''
75+
Sets the verbosity level used for filtering messages during compilation.
76+
''',
77+
allowed: Verbosity.allowedValues,
78+
allowedHelp: Verbosity.allowedValuesHelp,
79+
);
6980

7081
ArgResults parsedArgs;
7182
try {
@@ -106,6 +117,7 @@ Comma separated list of experimental features.
106117
enableExperiment: parsedArgs['enable-experiment'],
107118
enableAsserts: parsedArgs['enable-asserts'],
108119
verbose: parsedArgs['verbose'],
120+
verbosity: parsedArgs['verbosity'],
109121
extraOptions: parsedArgs['extra-gen-snapshot-options']);
110122
} catch (e) {
111123
stderr.writeln('Failed to generate native files:');

pkg/dart2native/lib/generate.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Future<void> generateNative({
2727
String enableExperiment = '',
2828
bool enableAsserts = false,
2929
bool verbose = false,
30+
String verbosity = 'all',
3031
List<String> extraOptions = const [],
3132
}) async {
3233
final Directory tempDir = Directory.systemTemp.createTempSync();
@@ -58,7 +59,10 @@ Future<void> generateNative({
5859
final kernelResult = await generateAotKernel(Platform.executable, genKernel,
5960
productPlatformDill, sourcePath, kernelFile, packages, defines,
6061
enableExperiment: enableExperiment,
61-
extraGenKernelOptions: ['--invocation-modes=compile']);
62+
extraGenKernelOptions: [
63+
'--invocation-modes=compile',
64+
'--verbosity=$verbosity'
65+
]);
6266
if (kernelResult.exitCode != 0) {
6367
// We pipe both stdout and stderr to stderr because the CFE doesn't print
6468
// errors to stderr. This unfortunately does emit info-only output in

pkg/dart2native/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ executables:
1212
dependencies:
1313
args: ^1.4.0
1414
path: any
15+
front_end:
16+
path: ../front_end
1517

1618
dev_dependencies:

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:io';
77

88
import 'package:dart2native/generate.dart';
99
import 'package:path/path.dart' as path;
10+
import 'package:front_end/src/api_prototype/compiler_options.dart'
11+
show Verbosity;
1012

1113
import '../core.dart';
1214
import '../experiments.dart';
@@ -19,8 +21,17 @@ class Option {
1921
final String flag;
2022
final String help;
2123
final String abbr;
22-
23-
Option({this.flag, this.help, this.abbr});
24+
final String defaultsTo;
25+
final List<String> allowed;
26+
final Map<String, String> allowedHelp;
27+
28+
Option(
29+
{this.flag,
30+
this.help,
31+
this.abbr,
32+
this.defaultsTo,
33+
this.allowed,
34+
this.allowedHelp});
2435
}
2536

2637
final Map<String, Option> commonOptions = {
@@ -32,6 +43,15 @@ Write the output to <file name>.
3243
This can be an absolute or relative path.
3344
''',
3445
),
46+
'verbosity': Option(
47+
flag: 'verbosity',
48+
help: '''
49+
Sets the verbosity level of the compilation.
50+
''',
51+
defaultsTo: Verbosity.defaultValue,
52+
allowed: Verbosity.allowedValues,
53+
allowedHelp: Verbosity.allowedValuesHelp,
54+
),
3555
};
3656

3757
bool checkFile(String sourcePath) {
@@ -53,6 +73,15 @@ class CompileJSCommand extends CompileSubcommandCommand {
5373
commonOptions['outputFile'].flag,
5474
help: commonOptions['outputFile'].help,
5575
abbr: commonOptions['outputFile'].abbr,
76+
defaultsTo: commonOptions['outputFile'].defaultsTo,
77+
)
78+
..addOption(
79+
commonOptions['verbosity'].flag,
80+
help: commonOptions['verbosity'].help,
81+
abbr: commonOptions['verbosity'].abbr,
82+
defaultsTo: commonOptions['verbosity'].defaultsTo,
83+
allowed: commonOptions['verbosity'].allowed,
84+
allowedHelp: commonOptions['verbosity'].allowedHelp,
5685
)
5786
..addFlag(
5887
'minified',
@@ -196,6 +225,14 @@ class CompileNativeCommand extends CompileSubcommandCommand {
196225
help: commonOptions['outputFile'].help,
197226
abbr: commonOptions['outputFile'].abbr,
198227
)
228+
..addOption(
229+
commonOptions['verbosity'].flag,
230+
help: commonOptions['verbosity'].help,
231+
abbr: commonOptions['verbosity'].abbr,
232+
defaultsTo: commonOptions['verbosity'].defaultsTo,
233+
allowed: commonOptions['verbosity'].allowed,
234+
allowedHelp: commonOptions['verbosity'].allowedHelp,
235+
)
199236
..addMultiOption('define', abbr: 'D', valueHelp: 'key=value', help: '''
200237
Define an environment declaration. To specify multiple declarations, use multiple options or use commas to separate key-value pairs.
201238
For example: dart compile $commandName -Da=1,b=2 main.dart''')
@@ -246,6 +283,7 @@ Remove debugging information from the output and save it separately to the speci
246283
enableExperiment: argResults.enabledExperiments.join(','),
247284
debugFile: argResults['save-debugging-info'],
248285
verbose: verbose,
286+
verbosity: argResults['verbosity'],
249287
);
250288
return 0;
251289
} catch (e) {

pkg/dartdev/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ dependencies:
1717
dart2native:
1818
path: ../dart2native
1919
dart_style: any
20+
front_end:
21+
path: ../front_end
2022
intl: any
2123
meta:
2224
path: ../meta

pkg/dartdev/test/commands/compile_test.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,30 @@ void main() {}
310310
reason: 'File not found: $outFile');
311311
});
312312

313+
test('Compile exe without info', () {
314+
final p = project(mainSrc: '''void main() {}''');
315+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
316+
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
317+
318+
var result = p.runSync(
319+
[
320+
'compile',
321+
'exe',
322+
'--verbosity=warning',
323+
'-o',
324+
outFile,
325+
inFile,
326+
],
327+
);
328+
329+
expect(result.stdout,
330+
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
331+
expect(result.stderr, isEmpty);
332+
expect(result.exitCode, 0);
333+
expect(File(outFile).existsSync(), true,
334+
reason: 'File not found: $outFile');
335+
});
336+
313337
test('Compile JS with sound null safety', () {
314338
final p = project(mainSrc: '''void main() {}''');
315339
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
@@ -357,6 +381,30 @@ void main() {}
357381
reason: 'File not found: $outFile');
358382
});
359383

384+
test('Compile JS without info', () {
385+
final p = project(mainSrc: '''void main() {}''');
386+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
387+
final outFile = path.canonicalize(path.join(p.dirPath, 'myjs'));
388+
389+
var result = p.runSync(
390+
[
391+
'compile',
392+
'js',
393+
'--verbosity=warning',
394+
'-o',
395+
outFile,
396+
inFile,
397+
],
398+
);
399+
400+
expect(result.stdout,
401+
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
402+
expect(result.stderr, isEmpty);
403+
expect(result.exitCode, 0);
404+
expect(File(outFile).existsSync(), true,
405+
reason: 'File not found: $outFile');
406+
});
407+
360408
test('Compile AOT snapshot with sound null safety', () {
361409
final p = project(mainSrc: '''void main() {}''');
362410
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
@@ -404,6 +452,30 @@ void main() {}
404452
reason: 'File not found: $outFile');
405453
});
406454

455+
test('Compile AOT snapshot without info', () {
456+
final p = project(mainSrc: '''void main() {}''');
457+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
458+
final outFile = path.canonicalize(path.join(p.dirPath, 'myaot'));
459+
460+
var result = p.runSync(
461+
[
462+
'compile',
463+
'aot-snapshot',
464+
'--verbosity=warning',
465+
'-o',
466+
outFile,
467+
inFile,
468+
],
469+
);
470+
471+
expect(result.stdout,
472+
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
473+
expect(result.stderr, isEmpty);
474+
expect(result.exitCode, 0);
475+
expect(File(outFile).existsSync(), true,
476+
reason: 'File not found: $outFile');
477+
});
478+
407479
test('Compile kernel with sound null safety', () {
408480
final p = project(mainSrc: '''void main() {}''');
409481
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));

0 commit comments

Comments
 (0)