Allow passing the sdk root for analysis to trial_migration.
Also redirects usage warnings to stderr, adds --help, and verifies that the sdk you pass in actually supports NNBD. Change-Id: Ia758f69648f88108b3c0df9de46ab246d3db0c9e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127202 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Janice Collins <jcollins@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
929877c822
commit
7fcff7e87f
@@ -5,3 +5,6 @@ environment:
|
||||
dependencies:
|
||||
_fe_analyzer_shared: 1.0.0
|
||||
analyzer: ^0.37.0
|
||||
dev_dependencies:
|
||||
args: ^1.5.2
|
||||
path: ^1.6.2
|
||||
|
||||
@@ -8,21 +8,51 @@
|
||||
// result of migration, as well as categories (and counts) of exceptions that
|
||||
// occurred.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
|
||||
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
import 'package:args/args.dart';
|
||||
import 'package:nnbd_migration/nnbd_migration.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
main(List<String> args) async {
|
||||
if (args.length > 1) {
|
||||
ArgParser argParser = ArgParser();
|
||||
ArgResults parsedArgs;
|
||||
|
||||
argParser.addFlag('help', abbr: 'h', help: 'Display options');
|
||||
|
||||
argParser.addOption('sdk',
|
||||
abbr: 's',
|
||||
defaultsTo: path.dirname(path.dirname(Platform.resolvedExecutable)),
|
||||
help: 'Select the root of the SDK to analyze against for this run '
|
||||
'(compiled with --nnbd). For example: ../../xcodebuild/DebugX64NNBD/dart-sdk');
|
||||
|
||||
try {
|
||||
parsedArgs = argParser.parse(args);
|
||||
} on ArgParserException {
|
||||
stderr.writeln(argParser.usage);
|
||||
exit(1);
|
||||
}
|
||||
if (parsedArgs['help'] as bool) {
|
||||
print(argParser.usage);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (parsedArgs.rest.length > 1) {
|
||||
throw 'invalid args. Specify *one* argument to get exceptions of interest.';
|
||||
}
|
||||
|
||||
String sdkPath = path.canonicalize(parsedArgs['sdk'] as String);
|
||||
|
||||
warnOnNoAssertions();
|
||||
String categoryOfInterest = args.isEmpty ? null : args.single;
|
||||
warnOnNoSdkNnbd(sdkPath);
|
||||
|
||||
String categoryOfInterest =
|
||||
parsedArgs.rest.isEmpty ? null : parsedArgs.rest.single;
|
||||
var rootUri = Platform.script.resolve('../../..');
|
||||
var listener = _Listener(categoryOfInterest);
|
||||
for (var testPath in [
|
||||
@@ -43,8 +73,8 @@ main(List<String> args) async {
|
||||
]) {
|
||||
print('Migrating $testPath');
|
||||
var testUri = rootUri.resolve(testPath);
|
||||
var contextCollection =
|
||||
AnalysisContextCollection(includedPaths: [testUri.toFilePath()]);
|
||||
var contextCollection = AnalysisContextCollectionImpl(
|
||||
includedPaths: [testUri.toFilePath()], sdkPath: sdkPath);
|
||||
var context = contextCollection.contexts.single;
|
||||
var files = context.contextRoot
|
||||
.analyzedFiles()
|
||||
@@ -85,6 +115,14 @@ main(List<String> args) async {
|
||||
}
|
||||
}
|
||||
|
||||
void printWarning(String warn) {
|
||||
stderr.writeln('''
|
||||
!!!
|
||||
!!! Warning! $warn
|
||||
!!!
|
||||
''');
|
||||
}
|
||||
|
||||
void warnOnNoAssertions() {
|
||||
try {
|
||||
assert(false);
|
||||
@@ -92,11 +130,20 @@ void warnOnNoAssertions() {
|
||||
return;
|
||||
}
|
||||
|
||||
print('''
|
||||
!!!
|
||||
!!! Warning! You didn't --enable-asserts!
|
||||
!!!
|
||||
''');
|
||||
printWarning("You didn't --enable-asserts!");
|
||||
}
|
||||
|
||||
void warnOnNoSdkNnbd(String sdkPath) {
|
||||
// TODO(jcollins-g): contact eng-prod for a more foolproof detection method
|
||||
String libraries = path.join(sdkPath, 'lib', 'libraries.json');
|
||||
try {
|
||||
var decodedJson = JsonDecoder().convert(File(libraries).readAsStringSync());
|
||||
if ((decodedJson['comment:1'] as String).contains('sdk_nnbd')) return;
|
||||
} on Exception {
|
||||
printWarning('Unable to determine whether this SDK supports NNBD');
|
||||
return;
|
||||
}
|
||||
printWarning('SDK at $sdkPath not compiled with --nnbd, use --sdk option');
|
||||
}
|
||||
|
||||
class _Listener implements NullabilityMigrationListener {
|
||||
|
||||
Reference in New Issue
Block a user