mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:39:48 +00:00
[cfe,dartdev,dart2js] Add support for --verbosity option
In response to https://github.com/dart-lang/sdk/issues/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 <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
parent
ee37fff58c
commit
97a4280e52
|
@ -96,6 +96,7 @@ class Flags {
|
|||
static const String useNewSourceInfo = '--use-new-source-info';
|
||||
static const String useOldRti = '--use-old-rti';
|
||||
static const String verbose = '--verbose';
|
||||
static const String verbosity = '--verbosity';
|
||||
static const String progress = '--show-internal-progress';
|
||||
static const String version = '--version';
|
||||
static const String reportMetrics = '--report-metrics';
|
||||
|
|
|
@ -545,6 +545,7 @@ Future<api.CompilationResult> compile(List<String> argv,
|
|||
new OptionHandler(Flags.testMode, passThrough),
|
||||
new OptionHandler('${Flags.dumpSsa}=.+', passThrough),
|
||||
new OptionHandler('${Flags.cfeInvocationModes}=.+', passThrough),
|
||||
new OptionHandler('${Flags.verbosity}=.+', passThrough),
|
||||
|
||||
// Experimental features.
|
||||
// We don't provide documentation for these yet.
|
||||
|
|
|
@ -138,8 +138,13 @@ class KernelLoaderTask extends CompilerTask {
|
|||
bool verbose = false;
|
||||
Target target = Dart2jsTarget(targetName, TargetFlags());
|
||||
fe.FileSystem fileSystem = CompilerFileSystem(_compilerInput);
|
||||
fe.Verbosity verbosity = _options.verbosity;
|
||||
fe.DiagnosticMessageHandler onDiagnostic =
|
||||
(e) => reportFrontEndMessage(_reporter, e);
|
||||
(fe.DiagnosticMessage message) {
|
||||
if (fe.Verbosity.shouldPrint(verbosity, message)) {
|
||||
reportFrontEndMessage(_reporter, message);
|
||||
}
|
||||
};
|
||||
fe.CompilerOptions options = fe.CompilerOptions()
|
||||
..target = target
|
||||
..librariesSpecificationUri = _options.librariesSpecificationUri
|
||||
|
@ -147,7 +152,8 @@ class KernelLoaderTask extends CompilerTask {
|
|||
..explicitExperimentalFlags = _options.explicitExperimentalFlags
|
||||
..verbose = verbose
|
||||
..fileSystem = fileSystem
|
||||
..onDiagnostic = onDiagnostic;
|
||||
..onDiagnostic = onDiagnostic
|
||||
..verbosity = verbosity;
|
||||
bool isLegacy =
|
||||
await fe.uriUsesLegacyLanguageVersion(resolvedUri, options);
|
||||
inferNullSafetyMode(_options.enableNonNullable && !isLegacy);
|
||||
|
@ -171,8 +177,8 @@ class KernelLoaderTask extends CompilerTask {
|
|||
nnbdMode: _options.useLegacySubtyping
|
||||
? fe.NnbdMode.Weak
|
||||
: fe.NnbdMode.Strong,
|
||||
invocationModes:
|
||||
fe.InvocationMode.parseArguments(_options.cfeInvocationModes));
|
||||
invocationModes: _options.cfeInvocationModes,
|
||||
verbosity: verbosity);
|
||||
component = await fe.compile(initializedCompilerState, verbose,
|
||||
fileSystem, onDiagnostic, resolvedUri);
|
||||
if (component == null) return null;
|
||||
|
|
|
@ -433,7 +433,10 @@ class CompilerOptions implements DiagnosticOptions {
|
|||
/// See `InvocationMode` in
|
||||
/// `pkg/front_end/lib/src/api_prototype/compiler_options.dart` for all
|
||||
/// possible options.
|
||||
String cfeInvocationModes = '';
|
||||
Set<fe.InvocationMode> cfeInvocationModes = {};
|
||||
|
||||
/// Verbosity level used for filtering messages during compilation.
|
||||
fe.Verbosity verbosity = fe.Verbosity.all;
|
||||
|
||||
// -------------------------------------------------
|
||||
// Options for deprecated features
|
||||
|
@ -547,8 +550,13 @@ class CompilerOptions implements DiagnosticOptions {
|
|||
.._noSoundNullSafety = _hasOption(options, Flags.noSoundNullSafety)
|
||||
.._mergeFragmentsThreshold =
|
||||
_extractIntOption(options, '${Flags.mergeFragmentsThreshold}=')
|
||||
..cfeInvocationModes =
|
||||
_extractStringOption(options, '${Flags.cfeInvocationModes}=', '');
|
||||
..cfeInvocationModes = fe.InvocationMode.parseArguments(
|
||||
_extractStringOption(options, '${Flags.cfeInvocationModes}=', ''),
|
||||
onError: onError)
|
||||
..verbosity = fe.Verbosity.parseArgument(
|
||||
_extractStringOption(
|
||||
options, '${Flags.verbosity}=', fe.Verbosity.defaultValue),
|
||||
onError: onError);
|
||||
}
|
||||
|
||||
void validate() {
|
||||
|
|
|
@ -7,6 +7,8 @@ import 'dart:io';
|
|||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:dart2native/generate.dart';
|
||||
import 'package:front_end/src/api_prototype/compiler_options.dart'
|
||||
show Verbosity;
|
||||
|
||||
void printUsage(final ArgParser parser) {
|
||||
print('''
|
||||
|
@ -65,7 +67,16 @@ Remove debugging information from the output and save it separately to the speci
|
|||
Comma separated list of experimental features.
|
||||
''')
|
||||
..addFlag('verbose',
|
||||
abbr: 'v', negatable: false, help: 'Show verbose output.');
|
||||
abbr: 'v', negatable: false, help: 'Show verbose output.')
|
||||
..addOption(
|
||||
'verbosity',
|
||||
defaultsTo: Verbosity.defaultValue,
|
||||
help: '''
|
||||
Sets the verbosity level used for filtering messages during compilation.
|
||||
''',
|
||||
allowed: Verbosity.allowedValues,
|
||||
allowedHelp: Verbosity.allowedValuesHelp,
|
||||
);
|
||||
|
||||
ArgResults parsedArgs;
|
||||
try {
|
||||
|
@ -106,6 +117,7 @@ Comma separated list of experimental features.
|
|||
enableExperiment: parsedArgs['enable-experiment'],
|
||||
enableAsserts: parsedArgs['enable-asserts'],
|
||||
verbose: parsedArgs['verbose'],
|
||||
verbosity: parsedArgs['verbosity'],
|
||||
extraOptions: parsedArgs['extra-gen-snapshot-options']);
|
||||
} catch (e) {
|
||||
stderr.writeln('Failed to generate native files:');
|
||||
|
|
|
@ -27,6 +27,7 @@ Future<void> generateNative({
|
|||
String enableExperiment = '',
|
||||
bool enableAsserts = false,
|
||||
bool verbose = false,
|
||||
String verbosity = 'all',
|
||||
List<String> extraOptions = const [],
|
||||
}) async {
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync();
|
||||
|
@ -58,7 +59,10 @@ Future<void> generateNative({
|
|||
final kernelResult = await generateAotKernel(Platform.executable, genKernel,
|
||||
productPlatformDill, sourcePath, kernelFile, packages, defines,
|
||||
enableExperiment: enableExperiment,
|
||||
extraGenKernelOptions: ['--invocation-modes=compile']);
|
||||
extraGenKernelOptions: [
|
||||
'--invocation-modes=compile',
|
||||
'--verbosity=$verbosity'
|
||||
]);
|
||||
if (kernelResult.exitCode != 0) {
|
||||
// We pipe both stdout and stderr to stderr because the CFE doesn't print
|
||||
// errors to stderr. This unfortunately does emit info-only output in
|
||||
|
|
|
@ -12,5 +12,7 @@ executables:
|
|||
dependencies:
|
||||
args: ^1.4.0
|
||||
path: any
|
||||
front_end:
|
||||
path: ../front_end
|
||||
|
||||
dev_dependencies:
|
||||
|
|
|
@ -7,6 +7,8 @@ import 'dart:io';
|
|||
|
||||
import 'package:dart2native/generate.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:front_end/src/api_prototype/compiler_options.dart'
|
||||
show Verbosity;
|
||||
|
||||
import '../core.dart';
|
||||
import '../experiments.dart';
|
||||
|
@ -19,8 +21,17 @@ class Option {
|
|||
final String flag;
|
||||
final String help;
|
||||
final String abbr;
|
||||
final String defaultsTo;
|
||||
final List<String> allowed;
|
||||
final Map<String, String> allowedHelp;
|
||||
|
||||
Option({this.flag, this.help, this.abbr});
|
||||
Option(
|
||||
{this.flag,
|
||||
this.help,
|
||||
this.abbr,
|
||||
this.defaultsTo,
|
||||
this.allowed,
|
||||
this.allowedHelp});
|
||||
}
|
||||
|
||||
final Map<String, Option> commonOptions = {
|
||||
|
@ -32,6 +43,15 @@ Write the output to <file name>.
|
|||
This can be an absolute or relative path.
|
||||
''',
|
||||
),
|
||||
'verbosity': Option(
|
||||
flag: 'verbosity',
|
||||
help: '''
|
||||
Sets the verbosity level of the compilation.
|
||||
''',
|
||||
defaultsTo: Verbosity.defaultValue,
|
||||
allowed: Verbosity.allowedValues,
|
||||
allowedHelp: Verbosity.allowedValuesHelp,
|
||||
),
|
||||
};
|
||||
|
||||
bool checkFile(String sourcePath) {
|
||||
|
@ -53,6 +73,15 @@ class CompileJSCommand extends CompileSubcommandCommand {
|
|||
commonOptions['outputFile'].flag,
|
||||
help: commonOptions['outputFile'].help,
|
||||
abbr: commonOptions['outputFile'].abbr,
|
||||
defaultsTo: commonOptions['outputFile'].defaultsTo,
|
||||
)
|
||||
..addOption(
|
||||
commonOptions['verbosity'].flag,
|
||||
help: commonOptions['verbosity'].help,
|
||||
abbr: commonOptions['verbosity'].abbr,
|
||||
defaultsTo: commonOptions['verbosity'].defaultsTo,
|
||||
allowed: commonOptions['verbosity'].allowed,
|
||||
allowedHelp: commonOptions['verbosity'].allowedHelp,
|
||||
)
|
||||
..addFlag(
|
||||
'minified',
|
||||
|
@ -196,6 +225,14 @@ class CompileNativeCommand extends CompileSubcommandCommand {
|
|||
help: commonOptions['outputFile'].help,
|
||||
abbr: commonOptions['outputFile'].abbr,
|
||||
)
|
||||
..addOption(
|
||||
commonOptions['verbosity'].flag,
|
||||
help: commonOptions['verbosity'].help,
|
||||
abbr: commonOptions['verbosity'].abbr,
|
||||
defaultsTo: commonOptions['verbosity'].defaultsTo,
|
||||
allowed: commonOptions['verbosity'].allowed,
|
||||
allowedHelp: commonOptions['verbosity'].allowedHelp,
|
||||
)
|
||||
..addMultiOption('define', abbr: 'D', valueHelp: 'key=value', help: '''
|
||||
Define an environment declaration. To specify multiple declarations, use multiple options or use commas to separate key-value pairs.
|
||||
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
|
|||
enableExperiment: argResults.enabledExperiments.join(','),
|
||||
debugFile: argResults['save-debugging-info'],
|
||||
verbose: verbose,
|
||||
verbosity: argResults['verbosity'],
|
||||
);
|
||||
return 0;
|
||||
} catch (e) {
|
||||
|
|
|
@ -17,6 +17,8 @@ dependencies:
|
|||
dart2native:
|
||||
path: ../dart2native
|
||||
dart_style: any
|
||||
front_end:
|
||||
path: ../front_end
|
||||
intl: any
|
||||
meta:
|
||||
path: ../meta
|
||||
|
|
|
@ -310,6 +310,30 @@ void main() {}
|
|||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile exe without info', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
|
||||
|
||||
var result = p.runSync(
|
||||
[
|
||||
'compile',
|
||||
'exe',
|
||||
'--verbosity=warning',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stdout,
|
||||
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile JS with sound null safety', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
|
@ -357,6 +381,30 @@ void main() {}
|
|||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile JS without info', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myjs'));
|
||||
|
||||
var result = p.runSync(
|
||||
[
|
||||
'compile',
|
||||
'js',
|
||||
'--verbosity=warning',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stdout,
|
||||
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile AOT snapshot with sound null safety', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
|
@ -404,6 +452,30 @@ void main() {}
|
|||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile AOT snapshot without info', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myaot'));
|
||||
|
||||
var result = p.runSync(
|
||||
[
|
||||
'compile',
|
||||
'aot-snapshot',
|
||||
'--verbosity=warning',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stdout,
|
||||
predicate((o) => !'$o'.contains(soundNullSafetyMessage)));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile kernel with sound null safety', () {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
library front_end.compiler_options;
|
||||
|
||||
import 'package:_fe_analyzer_shared/src/messages/diagnostic_message.dart'
|
||||
show DiagnosticMessageHandler;
|
||||
show DiagnosticMessage, DiagnosticMessageHandler;
|
||||
import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
|
||||
|
||||
import 'package:kernel/ast.dart' show Version;
|
||||
|
||||
|
@ -265,6 +266,9 @@ class CompilerOptions {
|
|||
/// compilation mode when the modes includes [InvocationMode.compile].
|
||||
Set<InvocationMode> invocationModes = {};
|
||||
|
||||
/// Verbosity level used for filtering emitted messages.
|
||||
Verbosity verbosity = Verbosity.all;
|
||||
|
||||
bool isExperimentEnabledByDefault(ExperimentalFlag flag) {
|
||||
return flags.isExperimentEnabled(flag,
|
||||
defaultExperimentFlagsForTesting: defaultExperimentFlagsForTesting);
|
||||
|
@ -455,13 +459,25 @@ class InvocationMode {
|
|||
|
||||
/// Returns the set of information modes from a comma-separated list of
|
||||
/// invocation mode names.
|
||||
static Set<InvocationMode> parseArguments(String arg) {
|
||||
///
|
||||
/// If a name isn't recognized and [onError] is provided, [onError] is called
|
||||
/// with an error messages and an empty set of invocation modes is returned.
|
||||
///
|
||||
/// If a name isn't recognized and [onError] isn't provided, an error is
|
||||
/// thrown.
|
||||
static Set<InvocationMode> parseArguments(String arg,
|
||||
{void Function(String) onError}) {
|
||||
Set<InvocationMode> result = {};
|
||||
for (String name in arg.split(',')) {
|
||||
if (name.isNotEmpty) {
|
||||
InvocationMode mode = fromName(name);
|
||||
if (mode == null) {
|
||||
throw new UnsupportedError("Unknown invocation mode '$name'.");
|
||||
String message = "Unknown invocation mode '$name'.";
|
||||
if (onError != null) {
|
||||
onError(message);
|
||||
} else {
|
||||
throw new UnsupportedError(message);
|
||||
}
|
||||
} else {
|
||||
result.add(mode);
|
||||
}
|
||||
|
@ -482,3 +498,109 @@ class InvocationMode {
|
|||
|
||||
static const List<InvocationMode> values = const [compile];
|
||||
}
|
||||
|
||||
/// Verbosity level used for filtering messages during compilation.
|
||||
class Verbosity {
|
||||
/// Only error messages are emitted.
|
||||
static const Verbosity error =
|
||||
const Verbosity('error', 'Show only error messages');
|
||||
|
||||
/// Error and warning messages are emitted.
|
||||
static const Verbosity warning =
|
||||
const Verbosity('warning', 'Show only error and warning messages');
|
||||
|
||||
/// Error, warning, and info messages are emitted.
|
||||
static const Verbosity info =
|
||||
const Verbosity('info', 'Show error, warning, and info messages');
|
||||
|
||||
/// All messages are emitted.
|
||||
static const Verbosity all = const Verbosity('all', 'Show all messages');
|
||||
|
||||
static const List<Verbosity> values = const [error, warning, info, all];
|
||||
|
||||
/// Returns the names of all options.
|
||||
static List<String> get allowedValues =>
|
||||
[for (Verbosity value in values) value.name];
|
||||
|
||||
/// Returns a map from option name to option help messages.
|
||||
static Map<String, String> get allowedValuesHelp =>
|
||||
{for (Verbosity value in values) value.name: value.help};
|
||||
|
||||
/// Returns the verbosity corresponding to the given [name].
|
||||
///
|
||||
/// If [name] isn't recognized and [onError] is provided, [onError] is called
|
||||
/// with an error messages and [defaultValue] is returned.
|
||||
///
|
||||
/// If [name] isn't recognized and [onError] isn't provided, an error is
|
||||
/// thrown.
|
||||
static Verbosity parseArgument(String name,
|
||||
{void Function(String) onError, Verbosity defaultValue: Verbosity.all}) {
|
||||
for (Verbosity verbosity in values) {
|
||||
if (name == verbosity.name) {
|
||||
return verbosity;
|
||||
}
|
||||
}
|
||||
String message = "Unknown verbosity '$name'.";
|
||||
if (onError != null) {
|
||||
onError(message);
|
||||
return defaultValue;
|
||||
}
|
||||
throw new UnsupportedError(message);
|
||||
}
|
||||
|
||||
static bool shouldPrint(Verbosity verbosity, DiagnosticMessage message) {
|
||||
Severity severity = message.severity;
|
||||
switch (verbosity) {
|
||||
case Verbosity.error:
|
||||
switch (severity) {
|
||||
case Severity.internalProblem:
|
||||
case Severity.error:
|
||||
return true;
|
||||
case Severity.warning:
|
||||
case Severity.info:
|
||||
case Severity.context:
|
||||
case Severity.ignored:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Verbosity.warning:
|
||||
switch (severity) {
|
||||
case Severity.internalProblem:
|
||||
case Severity.error:
|
||||
case Severity.warning:
|
||||
return true;
|
||||
case Severity.info:
|
||||
case Severity.context:
|
||||
case Severity.ignored:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Verbosity.info:
|
||||
switch (severity) {
|
||||
case Severity.internalProblem:
|
||||
case Severity.error:
|
||||
case Severity.warning:
|
||||
case Severity.info:
|
||||
return true;
|
||||
case Severity.context:
|
||||
case Severity.ignored:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Verbosity.all:
|
||||
return true;
|
||||
}
|
||||
throw new UnsupportedError(
|
||||
"Unsupported verbosity $verbosity and severity $severity.");
|
||||
}
|
||||
|
||||
static const String defaultValue = 'all';
|
||||
|
||||
final String name;
|
||||
final String help;
|
||||
|
||||
const Verbosity(this.name, this.help);
|
||||
|
||||
@override
|
||||
String toString() => 'Verbosity($name)';
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import 'package:kernel/ast.dart' as ir;
|
|||
import 'package:kernel/target/targets.dart' show Target;
|
||||
|
||||
import '../api_prototype/compiler_options.dart'
|
||||
show CompilerOptions, InvocationMode;
|
||||
show CompilerOptions, InvocationMode, Verbosity;
|
||||
|
||||
import '../api_prototype/experimental_flags.dart' show ExperimentalFlag;
|
||||
|
||||
|
@ -103,6 +103,7 @@ export '../api_prototype/compiler_options.dart'
|
|||
show
|
||||
CompilerOptions,
|
||||
InvocationMode,
|
||||
Verbosity,
|
||||
parseExperimentalFlags,
|
||||
parseExperimentalArguments;
|
||||
|
||||
|
@ -146,7 +147,8 @@ InitializedCompilerState initializeCompiler(
|
|||
{Map<ExperimentalFlag, bool> explicitExperimentalFlags,
|
||||
bool verify: false,
|
||||
NnbdMode nnbdMode,
|
||||
Set<InvocationMode> invocationModes: const <InvocationMode>{}}) {
|
||||
Set<InvocationMode> invocationModes: const <InvocationMode>{},
|
||||
Verbosity verbosity: Verbosity.all}) {
|
||||
additionalDills.sort((a, b) => a.toString().compareTo(b.toString()));
|
||||
|
||||
// We don't check `target` because it doesn't support '==' and each
|
||||
|
@ -160,7 +162,8 @@ InitializedCompilerState initializeCompiler(
|
|||
explicitExperimentalFlags) &&
|
||||
oldState.options.verify == verify &&
|
||||
oldState.options.nnbdMode == nnbdMode &&
|
||||
equalSets(oldState.options.invocationModes, invocationModes)) {
|
||||
equalSets(oldState.options.invocationModes, invocationModes) &&
|
||||
oldState.options.verbosity == verbosity) {
|
||||
return oldState;
|
||||
}
|
||||
|
||||
|
@ -171,7 +174,8 @@ InitializedCompilerState initializeCompiler(
|
|||
..packagesFileUri = packagesFileUri
|
||||
..explicitExperimentalFlags = explicitExperimentalFlags
|
||||
..verify = verify
|
||||
..invocationModes = invocationModes;
|
||||
..invocationModes = invocationModes
|
||||
..verbosity = verbosity;
|
||||
if (nnbdMode != null) options.nnbdMode = nnbdMode;
|
||||
|
||||
ProcessedOptions processedOpts = new ProcessedOptions(options: options);
|
||||
|
|
|
@ -13,6 +13,7 @@ export '../api_prototype/compiler_options.dart'
|
|||
show
|
||||
CompilerOptions,
|
||||
InvocationMode,
|
||||
Verbosity,
|
||||
parseExperimentalArguments,
|
||||
parseExperimentalFlags;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class Flags {
|
|||
static const String singleRootBase = "--single-root-base";
|
||||
static const String singleRootScheme = "--single-root-scheme";
|
||||
static const String verbose = "--verbose";
|
||||
static const String verbosity = "--verbosity";
|
||||
static const String verify = "--verify";
|
||||
static const String verifySkipPlatform = "--verify-skip-platform";
|
||||
static const String warnOnReachabilityCheck = "--warn-on-reachability-check";
|
||||
|
|
|
@ -26,7 +26,7 @@ import 'package:kernel/target/targets.dart'
|
|||
import 'package:package_config/package_config.dart';
|
||||
|
||||
import '../api_prototype/compiler_options.dart'
|
||||
show CompilerOptions, InvocationMode, DiagnosticMessage;
|
||||
show CompilerOptions, InvocationMode, Verbosity, DiagnosticMessage;
|
||||
|
||||
import '../api_prototype/experimental_flags.dart' as flags;
|
||||
|
||||
|
@ -263,7 +263,9 @@ class ProcessedOptions {
|
|||
}
|
||||
|
||||
void _defaultDiagnosticMessageHandler(DiagnosticMessage message) {
|
||||
printDiagnosticMessage(message, print);
|
||||
if (Verbosity.shouldPrint(_raw.verbosity, message)) {
|
||||
printDiagnosticMessage(message, print);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(askesc): Remove this and direct callers directly to report.
|
||||
|
|
|
@ -195,6 +195,7 @@ const Map<String, ValueSpecification> optionSpecification =
|
|||
Flags.nnbdAgnosticMode: const BoolValue(false),
|
||||
Flags.target: const StringValue(),
|
||||
Flags.verbose: const BoolValue(false),
|
||||
Flags.verbosity: const StringValue(),
|
||||
Flags.verify: const BoolValue(false),
|
||||
Flags.verifySkipPlatform: const BoolValue(false),
|
||||
Flags.warnOnReachabilityCheck: const BoolValue(false),
|
||||
|
@ -308,6 +309,8 @@ ProcessedOptions analyzeCommandLine(String programName,
|
|||
|
||||
final String invocationModes = options[Flags.invocationModes] ?? '';
|
||||
|
||||
final String verbosity = options[Flags.verbosity] ?? Verbosity.defaultValue;
|
||||
|
||||
if (nnbdStrongMode && nnbdWeakMode) {
|
||||
return throw new CommandLineProblem.deprecated(
|
||||
"Can't specify both '${Flags.nnbdStrongMode}' and "
|
||||
|
@ -359,7 +362,8 @@ ProcessedOptions analyzeCommandLine(String programName,
|
|||
..additionalDills = linkDependencies
|
||||
..emitDeps = !noDeps
|
||||
..warnOnReachabilityCheck = warnOnReachabilityCheck
|
||||
..invocationModes = InvocationMode.parseArguments(invocationModes);
|
||||
..invocationModes = InvocationMode.parseArguments(invocationModes)
|
||||
..verbosity = Verbosity.parseArgument(verbosity);
|
||||
|
||||
if (programName == "compile_platform") {
|
||||
if (arguments.length != 5) {
|
||||
|
|
|
@ -95,7 +95,8 @@ CompilerOptions setupCompilerOptions(
|
|||
List<String> experimentalFlags,
|
||||
Uri packagesUri,
|
||||
List<String> errors,
|
||||
String invocationModes) {
|
||||
String invocationModes,
|
||||
String verbosityLevel) {
|
||||
final expFlags = <String>[];
|
||||
if (experimentalFlags != null) {
|
||||
for (String flag in experimentalFlags) {
|
||||
|
@ -103,6 +104,7 @@ CompilerOptions setupCompilerOptions(
|
|||
}
|
||||
}
|
||||
|
||||
Verbosity verbosity = Verbosity.parseArgument(verbosityLevel);
|
||||
return new CompilerOptions()
|
||||
..fileSystem = fileSystem
|
||||
..target = new VmTarget(new TargetFlags(
|
||||
|
@ -139,13 +141,16 @@ CompilerOptions setupCompilerOptions(
|
|||
case Severity.ignored:
|
||||
throw "Unexpected severity: ${message.severity}";
|
||||
}
|
||||
if (printToStdErr) {
|
||||
printDiagnosticMessage(message, stderr.writeln);
|
||||
} else if (printToStdOut) {
|
||||
printDiagnosticMessage(message, stdout.writeln);
|
||||
if (Verbosity.shouldPrint(verbosity, message)) {
|
||||
if (printToStdErr) {
|
||||
printDiagnosticMessage(message, stderr.writeln);
|
||||
} else if (printToStdOut) {
|
||||
printDiagnosticMessage(message, stdout.writeln);
|
||||
}
|
||||
}
|
||||
}
|
||||
..invocationModes = InvocationMode.parseArguments(invocationModes);
|
||||
..invocationModes = InvocationMode.parseArguments(invocationModes)
|
||||
..verbosity = verbosity;
|
||||
}
|
||||
|
||||
abstract class Compiler {
|
||||
|
@ -158,6 +163,7 @@ abstract class Compiler {
|
|||
final List<String> experimentalFlags;
|
||||
final String packageConfig;
|
||||
final String invocationModes;
|
||||
final String verbosityLevel;
|
||||
|
||||
// Code coverage and hot reload are only supported by incremental compiler,
|
||||
// which is used if vm-service is enabled.
|
||||
|
@ -176,7 +182,8 @@ abstract class Compiler {
|
|||
this.supportCodeCoverage: false,
|
||||
this.supportHotReload: false,
|
||||
this.packageConfig: null,
|
||||
this.invocationModes: ''}) {
|
||||
this.invocationModes: '',
|
||||
this.verbosityLevel: Verbosity.defaultValue}) {
|
||||
Uri packagesUri = null;
|
||||
if (packageConfig != null) {
|
||||
packagesUri = Uri.parse(packageConfig);
|
||||
|
@ -200,7 +207,8 @@ abstract class Compiler {
|
|||
experimentalFlags,
|
||||
packagesUri,
|
||||
errors,
|
||||
invocationModes);
|
||||
invocationModes,
|
||||
verbosityLevel);
|
||||
}
|
||||
|
||||
Future<CompilerResult> compile(Uri script) {
|
||||
|
@ -291,7 +299,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
int nullSafety: kNullSafetyOptionUnspecified,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
String invocationModes: ''})
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue})
|
||||
: super(isolateId, fileSystem, platformKernelPath,
|
||||
suppressWarnings: suppressWarnings,
|
||||
enableAsserts: enableAsserts,
|
||||
|
@ -300,7 +309,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
supportHotReload: true,
|
||||
supportCodeCoverage: true,
|
||||
packageConfig: packageConfig,
|
||||
invocationModes: invocationModes);
|
||||
invocationModes: invocationModes,
|
||||
verbosityLevel: verbosityLevel);
|
||||
|
||||
factory IncrementalCompilerWrapper.forExpressionCompilationOnly(
|
||||
Component component,
|
||||
|
@ -379,14 +389,16 @@ class SingleShotCompilerWrapper extends Compiler {
|
|||
int nullSafety: kNullSafetyOptionUnspecified,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
String invocationModes: ''})
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue})
|
||||
: super(isolateId, fileSystem, platformKernelPath,
|
||||
suppressWarnings: suppressWarnings,
|
||||
enableAsserts: enableAsserts,
|
||||
nullSafety: nullSafety,
|
||||
experimentalFlags: experimentalFlags,
|
||||
packageConfig: packageConfig,
|
||||
invocationModes: invocationModes);
|
||||
invocationModes: invocationModes,
|
||||
verbosityLevel: verbosityLevel);
|
||||
|
||||
@override
|
||||
Future<CompilerResult> compileInternal(Uri script) async {
|
||||
|
@ -423,7 +435,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
|
|||
String packageConfig: null,
|
||||
String multirootFilepaths,
|
||||
String multirootScheme,
|
||||
String invocationModes: ''}) async {
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue}) async {
|
||||
IncrementalCompilerWrapper compiler = lookupIncrementalCompiler(isolateId);
|
||||
if (compiler != null) {
|
||||
updateSources(compiler, sourceFiles);
|
||||
|
@ -453,7 +466,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
|
|||
nullSafety: nullSafety,
|
||||
experimentalFlags: experimentalFlags,
|
||||
packageConfig: packageConfig,
|
||||
invocationModes: invocationModes);
|
||||
invocationModes: invocationModes,
|
||||
verbosityLevel: verbosityLevel);
|
||||
}
|
||||
isolateCompilers[isolateId] = compiler;
|
||||
}
|
||||
|
@ -755,6 +769,8 @@ Future _processLoadRequest(request) async {
|
|||
final String multirootFilepaths = request[13];
|
||||
final String multirootScheme = request[14];
|
||||
final String workingDirectory = request[15];
|
||||
// TODO(johnniwinther,bkonyi): Pass verbosity from command line arguments.
|
||||
final String verbosityLevel = Verbosity.defaultValue;
|
||||
|
||||
Uri platformKernelPath = null;
|
||||
List<int> platformKernel = null;
|
||||
|
@ -823,7 +839,8 @@ Future _processLoadRequest(request) async {
|
|||
experimentalFlags,
|
||||
packagesUri,
|
||||
errors,
|
||||
invocationModes);
|
||||
invocationModes,
|
||||
verbosityLevel);
|
||||
|
||||
// script should only be null for kUpdateSourcesTag.
|
||||
assert(script != null);
|
||||
|
@ -850,7 +867,8 @@ Future _processLoadRequest(request) async {
|
|||
packageConfig: packageConfig,
|
||||
multirootFilepaths: multirootFilepaths,
|
||||
multirootScheme: multirootScheme,
|
||||
invocationModes: invocationModes);
|
||||
invocationModes: invocationModes,
|
||||
verbosityLevel: verbosityLevel);
|
||||
} else {
|
||||
FileSystem fileSystem = _buildFileSystem(
|
||||
sourceFiles, platformKernel, multirootFilepaths, multirootScheme);
|
||||
|
@ -862,7 +880,8 @@ Future _processLoadRequest(request) async {
|
|||
nullSafety: nullSafety,
|
||||
experimentalFlags: experimentalFlags,
|
||||
packageConfig: packageConfig,
|
||||
invocationModes: invocationModes);
|
||||
invocationModes: invocationModes,
|
||||
verbosityLevel: verbosityLevel);
|
||||
}
|
||||
|
||||
CompilationResult result;
|
||||
|
|
|
@ -33,6 +33,7 @@ import 'package:front_end/src/api_unstable/vm.dart'
|
|||
ProcessedOptions,
|
||||
Severity,
|
||||
StandardFileSystem,
|
||||
Verbosity,
|
||||
getMessageUri,
|
||||
kernelForProgram,
|
||||
parseExperimentalArguments,
|
||||
|
@ -131,6 +132,10 @@ void declareCompilerOptions(ArgParser args) {
|
|||
args.addOption('invocation-modes',
|
||||
help: 'Provides information to the front end about how it is invoked.',
|
||||
defaultsTo: '');
|
||||
args.addOption('verbosity',
|
||||
help: 'Sets the verbosity level used for filtering messages during '
|
||||
'compilation.',
|
||||
defaultsTo: Verbosity.defaultValue);
|
||||
}
|
||||
|
||||
/// Create ArgParser and populate it with options consumed by [runCompiler].
|
||||
|
@ -215,7 +220,8 @@ Future<int> runCompiler(ArgResults options, String usage) async {
|
|||
mainUri = await convertToPackageUri(fileSystem, mainUri, packagesUri);
|
||||
}
|
||||
|
||||
final errorPrinter = new ErrorPrinter();
|
||||
final verbosity = Verbosity.parseArgument(options['verbosity']);
|
||||
final errorPrinter = new ErrorPrinter(verbosity);
|
||||
final errorDetector = new ErrorDetector(previousErrorHandler: errorPrinter);
|
||||
|
||||
final CompilerOptions compilerOptions = new CompilerOptions()
|
||||
|
@ -232,7 +238,8 @@ Future<int> runCompiler(ArgResults options, String usage) async {
|
|||
}
|
||||
..embedSourceText = embedSources
|
||||
..invocationModes =
|
||||
InvocationMode.parseArguments(options['invocation-modes']);
|
||||
InvocationMode.parseArguments(options['invocation-modes'])
|
||||
..verbosity = verbosity;
|
||||
|
||||
if (nullSafety == null &&
|
||||
compilerOptions.isExperimentEnabled(ExperimentalFlag.nonNullable)) {
|
||||
|
@ -489,10 +496,11 @@ class ErrorDetector {
|
|||
}
|
||||
|
||||
class ErrorPrinter {
|
||||
final Verbosity verbosity;
|
||||
final DiagnosticMessageHandler previousErrorHandler;
|
||||
final compilationMessages = <Uri, List<DiagnosticMessage>>{};
|
||||
|
||||
ErrorPrinter({this.previousErrorHandler});
|
||||
ErrorPrinter(this.verbosity, {this.previousErrorHandler});
|
||||
|
||||
void call(DiagnosticMessage message) {
|
||||
final sourceUri = getMessageUri(message);
|
||||
|
@ -516,7 +524,9 @@ class ErrorPrinter {
|
|||
});
|
||||
for (final Uri sourceUri in sortedUris) {
|
||||
for (final DiagnosticMessage message in compilationMessages[sourceUri]) {
|
||||
printDiagnosticMessage(message, print);
|
||||
if (Verbosity.shouldPrint(verbosity, message)) {
|
||||
printDiagnosticMessage(message, print);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue